The Madman
The Madman

Reputation: 41

Get Predicates with Prefix from an RDF

When extracting subject, property, and object from a RDF file, I want to replace the IRI of the predicate with the keyword it corresponds to. For example, A general SPARQL query returns these results:

| <http://extbi.dk/resource/727> | <http://extbi.dk/p/population> | "21,749"                                             
| <http://extbi.dk/resource/727> | <http://extbi.dk/p/region> | "Central"                                                
| <http://extbi.dk/resource/727> | <http://extbi.dk/p/id>   | "727" 

What I want to do is: If the prefix keyword for http://extbi.dk/p/ is schema, then my desired result is:

| <http://extbi.dk/resource/727> | <schema:population> | "21,749"                                             
| <http://extbi.dk/resource/727> | <schema:region> | "Central"                                                
| <http://extbi.dk/resource/727> | <schema:id>   | "727" 

I am using Apache Jena.

Upvotes: 0

Views: 280

Answers (1)

Gilles-Antoine Nys
Gilles-Antoine Nys

Reputation: 1481

Prefixes are handled in Jena using PrefixMapping objects.

This example should return QName or null if it doesnt exists:

Node n;
PrefixMapping prefixes = new PrefixMapping.Factory.create();
qnameFor(n.getURI());

shortForm(String URI) can also be used to simplify an URI based on the "original" URI resource.

Here is the link to the Javadoc : Link.

Upvotes: 0

Related Questions