Old Release

This documentation covers an old version of Fedora. Looking for another version? See all documentation.

Namespaces

A Fedora repository includes a number of pre-defined namespace bindings (essentially, a mapping that connects a particular prefix to a URI, allowing for a more convenient and human-readable rendering of RDF).  Predefined namespaces include DC, FOAF, Fedora, and LDP, among others.  As additional namespaces are used in the course of depositing materials into the repository, each new namespace will automatically be bound to its own prefix the first time it is used.  Once a URI is bound to a particular namespace prefix, it cannot be changed. A full list of the bound namespaces for a given Fedora repository at any given moment can be seen in the HTTP REST interface, as a list of pre-populated "PREFIX ..." bindings in the SPARQL update query text-box.

System-Generated Prefixes

As noted above, as new namespaces are used for the first time, those namespaces will be bound permanently to particular prefixes.  Currently, if the first use of a particular namespace should occur in RDF that is POSTed or PUT to the repository, regardless of any specific prefix binding supplied in the submitted graph, Fedora will instead bind the new namespace to a system-generated namespace in the form "ns00x".  While this behavior is not incorrect, it is inconvenient, and not necessarily user friendly for human interaction with the repository.  In order to avoid this behavior, the following best practices are recommended: (1) define a custom CND file which defines namespace prefixes; (2) use SPARQL update as the initial method of submitting a new namespace binding to the repository; and (3) "initializing" the repository with namespace bindings for the namespaces that are likely to be used, to prevent inadvertent POSTing or PUTting of new namespaces and the consequent exposure of opaque system-generated prefixes.

Defining a custom CND file

In order to define a custom CND file, you must first customize the repository.json file. This is the configuration that is used with the -Dfcrepo.modeshape.configuration setting. In that file, the "node-types" block should be defined as: "node-types" : ["fedora-node-types.cnd", "file:/etc/fcrepo/namespaces.cnd"].

repository.json
{
    "name" : "fedora",
    "jndiName" : "",
    "workspaces" : { ... },
    "storage" : {
        "persistence": { ... },
        "binaryStorage" : { ... }
    },
    "security" : {
        "anonymous" : { ... },
        "providers" : [ ... ]
    },
    "node-types" : ["fedora-node-types.cnd", "file:/etc/fcrepo/namespaces.cnd"]
}

 

The namespaces.cnd file can be used to register namespaces like so:

CND File
<acl = 'http://www.w3.org/ns/auth/acl#'>
<cc = 'http://creativecommons.org/ns#'>
<dcterms = 'http://purl.org/dc/terms/'>
<exif = 'http://www.w3.org/2003/12/exif/ns#'>
<geo = 'http://www.w3.org/2003/01/geo/wgs84_pos#'>
<gn = 'http://www.geonames.org/ontology#'>
<iana = 'http://www.iana.org/assignments/relation/'>
<ore = 'http://www.openarchives.org/ore/terms/'>
<owl = 'http://www.w3.org/2002/07/owl#'>
<prov = 'http://www.w3.org/ns/prov#'>
<rel = 'http://id.loc.gov/vocabulary/relators/'>
<schema = 'http://schema.org/'>
<skos = 'http://www.w3.org/2004/02/skos/core#'>

It is important to note that this should be done when the repository is first set up, before any content has been added.

Using SPARQL-Update to Bind Prefixes

To ensure that specific namespaces are used (i.e., treated as sacred) by Fedora 4 when doing a SPARQL update, ensure that the namespace prefix URI includes a terminating character. Otherwise system-generated JCR namespaces (e.g., ns001, ns002), and not the user-supplied namespaces, will get registered. Therefore, the following statement could lead to unexpected namespaces. F4 will register a system-generated namespace and you would not find "http://myurl.org" namespace in the system.

Problematic Usage
PREFIX esc: <http://myurl.org>
INSERT {
<>
esc:package "ppp";
}
WHERE { }

 

Therefore, the URI prefix in line 1 should have a terminating character, e.g., a slash or a hash. 

Recommended Usage
PREFIX esc: <http://myurl.org/>
. . .


"Initializing" a Repository with Additional Bindings

The inadvertent binding of namespaces to system-generated prefixes can be prevented by preemptively binding the namespaces that are likely to be used to standard prefixes.  This can be accomplished by creating a dummy node in the repository, adding desired namepace prefixes and RDF triples via a SPARQL update query, and then deleting the dummy node and the resulting tombstone to remove traces of this operation from the repository.  Even after all traces of the initialization node have been removed, the namespace bindings will persist in the repository and be available as RDF triples are added in the future.

This workaround should be unnecessary after the completion of: Unable to locate Jira server for this macro. It may be due to Application Link configuration.

Sample Namespace Initialization Script
#!/bin/bash
 
REST="http://localhost:8080/fcrepo/rest"
USER="fedoraAdmin"
PASSWORD="secret3"
 
QUERY="
    PREFIX pcdm: <http://pcdm.org/models#> 
    PREFIX bibo: <http://purl.org/ontology/bibo/>
    INSERT DATA { 
        <> a pcdm:Object ;
            bibo:shortTitle 'Fedora4 Site Initialization Page' .
        }"
 
curl -u $USER:$PASSWORD -X PUT "$REST/initialize/"
curl -u $USER:$PASSWORD -X PATCH -H "Content-Type: application/sparql-update" \
    --data "$QUERY" "$REST/initialize"
curl -u $USER:$PASSWORD -X DELETE "$REST/initialize"
curl -u $USER:$PASSWORD -X DELETE "$REST/initialize/fcr:tombstone"

 

 

 

 

 

  • No labels