Skip to content
Osma Suominen edited this page Feb 17, 2021 · 5 revisions

Starting with version 1.6, Skosmos provides an easy way of serving Linked Data for your concept URIs.

The idea is that Skosmos provides an /entity URL which, when given a URI as the uri parameter, redirects the client to either an HTML representation (Skosmos web page) or RDF serialization (RDF/XML, Turtle or JSON-LD) of the requested URI/resource, depending on the Accept header sent by the client.

Example configuration

Suppose that:

  1. You have a vocabulary myvocab using the URI namespace http://id.example.org/myvocab/
  2. Concept URIs in your vocabulary are of the form http://id.example.org/myvocab/1234
  3. Your Skosmos installation at http://example.org/skosmos/
  4. The vocabulary myvocab shows up as http://example.org/skosmos/myvocab
  5. You want to serve Linked Data for your concept URIs using Skosmos

To implement this, you need to perform URL redirection/proxying from your concept URIs to the Skosmos /entity URL. For example http://id.example.org/myvocab/1234 should be redirected to http://example.org/skosmos/entity?uri=http://id.example.org/myvocab/1234

If you are using an Apache virtual host for id.example.org you can use mod_rewrite rules within your virtual host configuration to implement this:

RewriteEngine On
RewriteRule ^/myvocab/(.*) http://example.org/skosmos/entity?uri=http://id.example.org/myvocab/$1 [P]

For this rule to work, you will need to enable the Apache modules rewrite, proxy and proxy_http. The [P] flag causes Apache to perform a proxy request, so that the client will directly see the redirect (to HTML or RDF) served by the /entity URL. If you leave out this flag, the client will see two redirects: first the one to the /entity URL and the second one to the HTML or RDF served by the /entity URL.

Forcing the vocabulary to use

Using the above configuration, Skosmos will infer from the URI which vocabulary contains the data for the concepts, based on the void:uriSpace settings in the vocabularies.ttl file. However, sometimes URI namespaces are not so clear-cut. You can pass the /entity URL a vocab parameter (e.g. vocab=myvocab) to force Skosmos to serve the concept data from a specific vocabulary instead of relying on the URL.

Serving vocabulary data files

In addition to providing Linked Data for individual concept and other resource URIs, Skosmos can also offer downloads of the full vocabulary data. However, the actual files must be served by a web server. This may well be the same Apache web server used to run Skosmos.

The download URLs must be defined in the Skosmos configuration file config.ttl using the property void:dataDump. The format is determined from the file extension: .ttl for Turtle, .rdf for RDF/XML, .jsonld for JSON-LD and .mrcx for MARCXML. Multiple URL values may be given to support different formats in parallel.

The vocabulary downloads are served through the REST API. The data method, when called without a uri parameter, will redirect to the download URL. If there are multiple URLs Skosmos will perform content negotiation.

The web server should be configured to serve the files as "attachments" to prevent browsers from trying to display them - otherwise large vocabularies may freeze or crash the browser (see issue #901). Adding this snippet to the Apache virtual host configuration sets all .ttl, .rdf, .jsonld and .mrcx files as attachments:

# set Content-Disposition header for RDF and MARCXML downloads
# so that browsers don't try to render them
<IfModule mod_headers.c>
    <FilesMatch "\.(ttl|rdf|jsonld|mrcx)$">
        Header set Content-Disposition "attachment"
    </FilesMatch>
</IfModule>

AddType text/turtle .ttl
AddType application/ld+json .jsonld