Changing registered namespace prefixes

141 views
Skip to first unread message

Peter Matthew Eichman

unread,
Apr 17, 2015, 10:59:36 AM4/17/15
to fedor...@googlegroups.com
Hello all,

Is there a way to change the registered prefix for a namespace? We had a
couple resources we ingested from RDF that did not have prefix
declarations for the dcterms namespace (http://purl.org/dc/terms/), so it
got assigned the ns003: prefix.

Now, even when we ingest RDF that does have an explicit prefix declaration
for the dcterms namespace (@prefix dcterms: <http://purl.org/dc/terms/>.),
the predicates in that namespace (e.g., title) are still showing up as
ns003:title, and not dcterms:title, as desired. In addition, the namespace
ns003: remains prepopulated in the SPARQL update query box.

I hav also tried issuing an empty SPARQL update query, just with changed
prefix declarations, but that also does not work.

Thanks,
-Peter

Andrew Woods

unread,
Apr 17, 2015, 12:17:27 PM4/17/15
to fedor...@googlegroups.com
Hello Peter, 
Manually manipulating namespace mappings is not something that Fedora wants to expose as an API. The approach, as you see, is to use the namespace mappings that the Fedora user defines in their ingested RDF. 

If the user puts in RDF without namespaces, Fedora creates the namespaces on the user's behalf (ns003, in this case). 
If the user puts in RDF with namespaces, Fedora uses the namespaces provided.

Once a namespace has been registered in Fedora, it is set.

If you would like to write a backend utility for updating namespaces after-the-fact (noting that it would potentially open the door to other issues) we could put it in fcrepo4-labs.
Regards,
Andrew




--
You received this message because you are subscribed to the Google Groups "Fedora Tech" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fedora-tech...@googlegroups.com.
To post to this group, send email to fedor...@googlegroups.com.
Visit this group at http://groups.google.com/group/fedora-tech.
For more options, visit https://groups.google.com/d/optout.

aj...@virginia.edu

unread,
Apr 17, 2015, 12:18:34 PM4/17/15
to fedor...@googlegroups.com
It is possible to define more than one prefix for a namespace, but to my knowledge, the serialization behavior in that case is not defined.

---
A. Soroka
The University of Virginia Library

Adam Wead

unread,
Apr 17, 2015, 3:51:29 PM4/17/15
to fedor...@googlegroups.com
Adam,

I have a related question. In my Hydra app, it's creating the ns002 prefix for http://purl.org/dc/terms/.  Can I update Fedora4 to rename this to something like dcterms? And would it honor the new prefix for existing resources?

It's not required for the application, I'm just wondering how you'd add new prefixes to Fedora4 if you wanted to.

…adam

Andrew Woods

unread,
Apr 17, 2015, 4:39:11 PM4/17/15
to fedor...@googlegroups.com
Hello AdamW,
Rather than a related question, I think this is the same question. As it stands currently, once a namespace is registered into Fedora, it is set. There is no ability to change it until Peter creates such a backend utility ;)
In terms of adding new prefixes, if the namespace is not already registered, then the first time the client specifies a prefix declaration for a namespace in an RDF document, that will register/add the new prefix.
Andrew

Peter Matthew Eichman

unread,
Apr 21, 2015, 11:27:51 AM4/21/15
to fedor...@googlegroups.com
Andrew,

Thanks for the update. I am curious, what (potential) issues do you forsee with updating the namespace prefix mappings after the fact? From what I understand in theory, prefix mappings in RDF are actually pretty arbitrary, so I would think it would be fairly easy to switch from using the auto-generated ns001, ns002, etc., to something more descriptive for human consumption.

And yes, I am planning on looking in to a backend utility to do this, time permitting.

-Peter

Adam Wead

unread,
Apr 22, 2015, 9:34:52 PM4/22/15
to fedor...@googlegroups.com
Peter, Adam, Andrew,

Peter's getting at my use case too. If I start throwing predicates at Fedora with a namespaced URI like http://hotnamespaces.com/terms/1.0/ Fedora prefixes this as ns001. Great! no problem... I'll keep throwing more predicates at it using that custom URI and Fedora will always prefix them "ns001". But... I'd like to specify my own prefix.

It sounds like the easiest way to accomplish this is to register the namespace and its prefix with Fedora prior to creating any predicates, etc. that use it. I can see wanting to change the prefix later, but right now, I'd just like to register a proper prefix other than "nsXXX" in the first place.

…adam

Andrew Woods

unread,
Apr 22, 2015, 9:55:33 PM4/22/15
to fedor...@googlegroups.com
Hello Adam,
The first time a namespace is used, the prefix associated with that namespace is the one that will henceforth stick with that namespace. The process of registering a prefix for a namespace is as simple as adding the desired "prefix" declaration in the prologue of your RDF document or SPARQL update document. If you do not include such a "prefix" declaration, then Fedora will create one for you.
Does that make sense?
Regards,
Andrew

Adam Wead

unread,
Apr 22, 2015, 10:37:10 PM4/22/15
to fedor...@googlegroups.com
Andrew,

Yes, that makes sense. The situation I'm in is that I'm doing everything through ActiveFedora which doesn't pass any prefixes, so I was thinking of performing a kind of "configuration" step that sets up these namespaces in Fedora prior to doing any actual creation of resources. Is there a way to pass a kind of SPARQL update that would make Fedora register the prefix without actually updating or creating anything?

This is a very minor thing, it's just something that would be nice to have....

…adam

Andrew Woods

unread,
Apr 22, 2015, 10:46:04 PM4/22/15
to fedor...@googlegroups.com
Hello Adam,
Generally we recommend that Fedora users NOT touch the main "fedora-node-types.cnd" file, but in the case of simply defining namespace prefixes, it seems innocuous enough.

Andrew

aj...@virginia.edu

unread,
Apr 22, 2015, 10:52:25 PM4/22/15
to fedor...@googlegroups.com
Can you supply some more details about the way in which ActiveFedora is exposing the namespaces used for RDF HTTP responses to users?

That might help us figure out how to support namespace management in a generically-useful way.

---
A. Soroka
The University of Virginia Library

Robert Sanderson

unread,
Apr 22, 2015, 11:28:52 PM4/22/15
to fedor...@googlegroups.com

I'm sure this is unnecessary but +1 to a defined method of updating prefix definitions :)

Rob

Andrew Woods

unread,
Apr 23, 2015, 10:26:24 AM4/23/15
to fedor...@googlegroups.com
Hello Rob,
To be clear, when you say "updating prefix definitions", are you saying:
1) updating the name of a prefix for a given namespace, or
2) updating the namespace which a given prefix represents?

Thanks,
Andrew

Robert Sanderson

unread,
Apr 23, 2015, 10:35:36 AM4/23/15
to fedor...@googlegroups.com

Both seem valuable, though 1 seems higher priority with auto generated prefixes.

R

Adam Wead

unread,
Apr 23, 2015, 3:05:56 PM4/23/15
to fedor...@googlegroups.com
Yes, +1 to #1. I understand that folks can get leery of when speaking of changing namespaces. I'm not trying to argue for changing namespaces, just the prefixes to which they refer. But this exposes my ignorance because I assume that prefixes to namespaces are inconsequential in the sense that as long as the namespaces themselves are correct, it doesn't matter what the prefix is. If I'm wrong about that, please correct me!

I'm +0 to #2, in the sense that I don't know enough to have an informed opinion. Although it seems to me that if you're using a defined namespace that has changed or needs to change, the namespace authority would handle that, i.e. redirects from the old namespace to the new, etc. for compatibility.

…adam

Adam Wead

unread,
Apr 23, 2015, 4:29:50 PM4/23/15
to fedor...@googlegroups.com
Adam,

A simple example is one of the GenericFile objects we use in Sufia. If I create a barebones one of these, it gets sent to Fedora like:


Request body:

<> a <http://pcdm.org/models#Object>;
   <http://purl.org/dc/terms/title> "Some kind of title";
   <http://id.loc.gov/vocabulary/relators/dpt> "us...@example.com";
   <info:fedora/fedora-system:def/model#hasModel> "GenericFile" .

If I do a GET request on that resource, the prefixes all come back as:

@prefix ns004: <http://pcdm.org/models#> .
@prefix ns003: <http://purl.org/dc/terms/> .
@prefix ns001: <info:fedora/fedora-system:def/model#> .

The namespaces are bound up using Ruby's RDF gem, for example RDF::DC.title, for predefined DC terms, or using some of our own such as RDF::URI.new("http://id.loc.gov/vocabulary/relators/dpt") for the depositor. None of them have supplied prefixes because it was never really a concern of ActiveFedora's or Hydra for that matter. Fedora supplies the prefixes as needed. When you're looking at the resource directly in Fedora, it's helpful to have the prefixes so you know what's what, but since Hydra is the layer above the Fedora repository, it was never really a priority to make this happen. We'd also need a mechanism to define prefixes for our custom namespaces, and that's not really a priority either.

My thought was to effect a kind of update that makes Fedora register the prefixes before you add any actual resources. It'd be nice to be able to change the prefixes, but this may cause problems. For example, what happens if you post a resource with one prefix, change the prefix, and then post another resource using the old prefix?

Anyway, like I said in earlier emails, it would be nice to have this, but it's not a requirement!

…adam

aj...@virginia.edu

unread,
Apr 24, 2015, 10:48:05 AM4/24/15
to fedor...@googlegroups.com
I think you should be able to do this with an update containing prefix declarations but no actual RDF.

---
A. Soroka
The University of Virginia Library

Adam Wead

unread,
Apr 24, 2015, 11:02:56 AM4/24/15
to fedor...@googlegroups.com
Cool. I'll give it a shot and report back.

…adam

Adam Wead

unread,
Apr 25, 2015, 10:15:00 AM4/25/15
to fedor...@googlegroups.com
Adam,

I tried it out and no luck. However, I did write a short script that updates each prefixed term with dummy data on a resource and that does the trick. I'll probably use something like this for development so I can recognize namespaces more easily when looking at the resource directly in Fedora.

curl -i -X PUT "http://${URL}/fedora/rest/config"
curl -X PATCH -H "Content-Type: application/sparql-update" --data-binary "@body.rdf" "http://${URL}/fedora/rest/config"
curl -X GET "http://${URL}/fedora/rest/config" | grep "@prefix"
curl -X DELETE "http://${URL}/fedora/rest/config"
curl -X DELETE "http://${URL}/fedora/rest/config/fcr:tombstone"

And the SPARQL

PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX relators: <http://id.loc.gov/vocabulary/relators/>
PREFIX pcdm: <http://pcdm.org/models#>
PREFIX webacl: <http://www.w3.org/ns/auth/acl#>
PREFIX example: <http://example.org/terms/>
INSERT {
<> dcterms:foo "sample data" .
<> relators:foo "sample data" .
<> pcdm:foo "sample data" .
<> webacl:foo "sample data" .
<> example:foo "sample data" .
}
WHERE { }

…adam
Reply all
Reply to author
Forward
0 new messages