Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A Fedora repository includes a number of pre-defined predefined 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, you can define a custom CND file which defines namespace prefixes.  Previously, it was possible to control the prefixes used by using SPARQL update or RDF with namespace prefixes, but this functionality does not currently work (see

Jira
serverDuraSpace JIRA
columnskey,summary,type,created,updated,due,assignee,reporter,priority,status,resolution
serverIdc815ca92-fd23-34c2-8fe3-956808caf8c5
keyFCREPO-2376
).

Defining a custom CND file

Warning

The following steps should only be done when the repository is first set up, before any content has been added.

Namespace registry corruption can occur if new namespaces are defined in the CND for a repository that already has content that uses those namespaces with different associated prefixes.

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"].

Code Block
languagejs
titlerepository.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:

Custom Namespace registry

This optional feature allows an administrator to provide a list of custom namespace prefixes that will override the default prefix registry. The custom namespaces are loaded on start-up via a YAML file.  The namespaces can be modified while Fedora is running.  Changes may take a few minutes to take effect.

Below is a sample YAML namespace configuration file, custom_namespaces.yml.  Notice the "awesome" prefix definition at the bottom of the list. We will use this in the following example. NB: the custom file will override all default namespace prefixes.  In other words, the custom file becomes the definitive registry.  Any namespaces that are not prefixed will be returned as full URIs in the response.

Code Block
premis:  http://www.loc.gov/premis/rdf/v1#
test:  info:fedora/test/
memento:  http://mementoweb.org/ns#
rdfs:  http://www.w3.org/2000/01/rdf-schema#
webac:  http://fedora.info/definitions/v4/webac#
acl:  http://www.w3.org/ns/auth/acl#
vcard:  http://www.w3.org/2006/vcard/ns#
xsi:  http://www.w3.org/2001/XMLSchema-instance
xmlns:  http://www.w3.org/2000/xmlns/
rdf:  http://www.w3.org/1999/02/22-rdf-syntax-ns#
fedora:  http://fedora.info/definitions/v4/repository#
xml:  http://www.w3.org/XML/1998/namespace
ebucore:  http://www.ebu.ch/metadata/ontologies/ebucore/ebucore#
ldp:  http://www.w3.org/ns/ldp#
dcterms:  http://purl.org/dc/terms/
iana:  http://www.iana.org/assignments/relation/
xs:  http://www.w3.org/2001/XMLSchema
fedoraconfig:  http://fedora.info/definitions/v4/config#
foaf:  http://xmlns.com/foaf/0.1/
dc:  http://purl.org/dc/elements/1.1/
awesome: http://example.com/awesome/

Fedora can activate the file by using the -Dfcrepo.namespace.registry system parameter, either on the command line or by adding it to the list of other params that provide paths to other configuration files:

Code Block
mvn jetty:run -Dfcrepo.namespace.registry=/my/fedora/path/custom_namespaces.yml

In order to demonstrate how this feature works,  try starting Fedora without  defining a custom namespace registry:

Code Block
mvn jetty:run

Once Fedora is running,  run the following curl command

Code Block
echo "@prefix awesome: <http://example.com/awesome/> . <> awesome:stuff 'waffle' ." | curl -u fedoraAdmin:fedoraAdmin http://localhost:8080/rest/test  -X PUT -H "Content-Type: text/turtle" --data-binary "@-"

When you retrieve this resource,

Code Block
curl -i -u fedoraAdmin:fedoraAdmin http://localhost:8080/rest/test

notice the new predicate is expressed as the full URI.

Code Block
titleoutput
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix fedora:  <http://fedora.info/definitions/v4/repository#> .
@prefix ldp:  <http://www.w3.org/ns/ldp#> .

<http://localhost:8080/rest/test>
...
        <http://example.com/awesome/test>  "waffle" ;
...  

Also notice there are built in prefixes for common namespaces.  Now restart Fedora with the custom namespaces yml enabled:

Code Block
mvn jetty:run -Dfcrepo.namespace.registry=/my/fedora/path/custom_namespaces.yml

Retrieve the item and see how your custom namespace prefix is being used.

Code Block
curl -ufedoraAdmin:fedoraAdmin  http://localhost:8080/rest/test
@prefix awesome:  <http://example.com/awesome/> .
@prefix rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix fedora:  <http://fedora.info/definitions/v4/repository#> .
@prefix ldp:  <http
Code Block
titleCND 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 = 'httpns/ldp#> .

<http://localhost:8080/rest/test>
...
        awesome:test           "waffle" ;
...

Suppose, you later decide that the "awesome" namespace was mislabelled. Instead you really wanted the namespace to be "justokay". Edit the file /my/fedora/path/custom_namespaces.yml to change "awesome" to "justokay", save the file and wait a few seconds, then check the namespace output again:

Code Block
curl -ufedoraAdmin:fedoraAdmin  http://localhost:8080/rest/test

@prefix justokay:  <http://example.com/awesome/> .
@prefix rdf:  <http://www.w3.org/ns/prov#'>
<rel = 'http1999/02/22-rdf-syntax-ns#> .
@prefix fedora:  <http://idfedora.loc.govinfo/vocabularydefinitions/relators/'>
<schema = 'http://schema.org/'>
<skos = 'httpv4/repository#> .
@prefix ldp:  <http://www.w3.org/2004/02/skos/core#'>/ns/ldp#> .

<http://localhost:8080/rest/test>
...
		justokay:test          "waffle" ;
...