URI Dereferencer

By Omeka Team Dereferences URIs when viewing items, media, and item sets.
Download 1.0.0

URI Dereferencer

Dereferences URIs when viewing items, media, and item sets.

Dereferenceable URIs

Dereferenceable URIs are the backbone of Linked Data. They can be looked up (dereferenced) to provide useful information about the resource that the URI identifies, which in turn refers to other URIs, and so on.

This module looks up URIs on the page and provides users a snapshot of linked data without having to navigate away from the page. It will automatically dereference all "URI" data type values that match a registered service. If you want your custom data type values to be dereferenceable, you must add the uri-value-link class to the anchor tag containing the URI.

Linked data services

Linked data services are JavaScript objects that are responsible for dereferencing URIs and returning information about the resource. This module already comes with a handful of services:

You can create your own linked data service objects by writing them against the following interface and adding them to the global UriDereferencer object.

Service interface

{
    /**
     * Get the name of this service.
     *
     * @return {string}
     */
    getName() {},
    /**
     * Get options for this service.
     *
     * @return {object}
     */
    getOptions() {},
    /**
     * Does this service recognize the URI?
     *
     * @param {string} uri The URI
     * @return {bool}
     */
    isMatch(uri) {},
    /**
     * Get the resource URL of a URI.
     *
     * The resource URL typically dereferences to an RDF file (JSON-LD, XML,
     * etc.) that represents the URI. Note that the service must have cross-
     * origin resource sharing (CORS) enabled.
     *
     * @param {string} uri The URI
     * @return {string}
     */
    getResourceUrl(uri) {},
    /**
     * Get information about the resource in HTML markup.
     *
     * @param {string} uri The URI
     * @param {string} text The response text of the resource
     * @return {string}
     */
    getMarkup(uri, text) {}
}

Service options

Services can modify their options if they require special handling.

  • useProxy: {bool}: (default false) Use the local proxy server if configured? This is useful if the linked data service doesn't allow cross-origin HTTP requests (CORS). Note that the global UriDereferencer object must have set a valid proxyUrl.

Service implementation example

UriDereferencer.addService({
    getName() {
        return 'My Linked Data Service';
    },
    getOptions() {
        // This example assumes this service requires a proxy server
        return {useProxy: true};
    }
    isMatch(uri) {
        return (null !== this.getMatch(uri));
    },
    getResourceUrl(uri) {
        // This example assumes a JSON-LD resource. There are many possible
        // ways to dereference a URL, depending on the service (e.g. RDF/XML,
        // SPARQL endpoint).
        const match = this.getMatch(uri);
        return `http://example.com/vocab/${match[1]}.jsonld`;
    },
    getMarkup(uri, text) {
        // This example assumes JSON response text. You may need to parse the
        // response text differently (e.g. XPath for XML).
        const json = JSON.parse(text);
        return `
        <dl>
            <dt>Label</dt>
            <dd>${json['label']}</dd>
            <dt>Description</dt>
            <dd>${json['description']}</dd>
        </dl>`;
    },
    // Get the URI match (not part of the interface, but useful anyway).
    getMatch(uri) {
        return uri.match(/^https?:\/\/example\.com\/vocab\/(.+)$/);
    }
});
Version Released Minimum Omeka version
1.0.0October 07, 2019 [info]^1.0.0 || ^2.0.0