You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "Pastrana, Rodrigo (RIS-BCT)" <Ro...@lexisnexis.com> on 2013/03/22 21:47:08 UTC
RDF Model Namespaces
I'm new to Jena RDF API and I'm noticing some unexpected behavior regarding statement namespaces...
I've noticed that URI resources such as "http://www.govtrack.us/data/photos/412483.jpeg" in the below excerpt of the congressional people graph(http://www.govtrack.us/data/rdf/people.rdf.gz)
Are reported to have namespace: " http://www.govtrack.us/data/photos/410069." And local name "jpeg" using the com.hp.hpl.jena.rdf.model.Resource getLocalName(), and getNameSpace().
Is this correct behavior? It looks to me like the dot is being used as a delimiter between the NS and the local name. Is there a way to change that behavior ? thanks!
<foaf:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/R000589">
<foaf:name>E. Rigell</foaf:name>
<usgov:name>E. Rigell</usgov:name>
<vcard:N>
<rdf:Description>
<vcard:Given>E.</vcard:Given>
<vcard:Other>Scott</vcard:Other>
<vcard:Family>Rigell</vcard:Family>
<vcard:Prefix>Rep.</vcard:Prefix>
</rdf:Description>
</vcard:N>
<foaf:gender>male</foaf:gender>
<vcard:BDAY>1960-05-28</vcard:BDAY>
<foaf:img rdf:resource="http://www.govtrack.us/data/photos/412483.jpeg"/>
<usgov:congressBioGuideID>R000589</usgov:congressBioGuideID>
<foaf:title>Rep.</foaf:title>
<foaf:homepage>http://rigell.house.gov/</foaf:homepage>
</foaf:Person>
Thanks, Rodrigo.
Re: RDF Model Namespaces
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Wed, Mar 27, 2013 at 4:48 PM, Pastrana, Rodrigo (RIS-BCT)
<Ro...@lexisnexis.com> wrote:
> Sure, we're converting RDF graphs into a data format understood by our processes.
> It should suffice to say that each non-anonymous, non-literal node 's namespace and name need to be parsed out. Thanks.
If by name namespace and name you mean XML qnames, You're going to
have difficulties with every representation that uses IRIs as
identifiers, not just RDF, and you're going to have difficulties with
every software tool that works with IRIs, not just Jena, because not
all IRIs can be represented using XML qnames.
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
RE: RDF Model Namespaces
Posted by "Pastrana, Rodrigo (RIS-BCT)" <Ro...@lexisnexis.com>.
Sure, we're converting RDF graphs into a data format understood by our processes.
It should suffice to say that each non-anonymous, non-literal node 's namespace and name need to be parsed out. Thanks.
Thanks, Rodrigo.
-----Original Message-----
From: Martynas Jusevičius [mailto:martynas@graphity.org]
Sent: Wednesday, March 27, 2013 4:39 PM
To: users@jena.apache.org
Subject: Re: RDF Model Namespaces
Maybe you could start with explaining what you are trying to achieve?
You stated you want to navigate statements in an RDF graph -- what does this have to do with namespaces and local names?
Martynas
On Wed, Mar 27, 2013 at 10:32 PM, Pastrana, Rodrigo (RIS-BCT) <Ro...@lexisnexis.com> wrote:
>> You claim it's illegal. Why?
> Did I? I pointed out the scenario, and asked if Jena's API can help handle it.
> Are you claiming the "congress people" RDF/XML graph is illegal?
>
> Doesn't really matter, what matters is this scenario will play out in many RDF/XML graphs.
> We want to use JENA, but we have to be able to support RDF/XML graphs such as the congress people...
>
>>The Turtle way is much better for RDF - we have to live with RDF/XML for awhile though.
>
>>You can call the Turtle writer directly with a PrefixMap , whic is more liberal than the PrefixMapping the XML writer needs.
>
> At this point, I'll try anything.
> Read in the people graph, wrote out as turtle, read in turtle version, still having issues same issues with numeric people ids and all .jpg resources.
> Anything else that I could do?
>
> Thanks, Rodrigo.
>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Wednesday, March 27, 2013 2:52 PM
> To: users@jena.apache.org
> Subject: Re: RDF Model Namespaces
>
> On 27/03/13 18:29, Pastrana, Rodrigo (RIS-BCT) wrote:
>>> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>>
>> So basically, a Jena API user interested in a node's NS and name will
>> need to extract the full URI and parse it manually to extract the NS
>> and the Name. Because the
>> com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially
>> return invalid namespaces (if the name starts with a numeral or
>> contains a dot).
>
> You claim it's illegal. Why?
>
>
>
> Let's look at XML namespace 1.0 edition 3:
>
> A names pace is used in a qname which is the PrefixedName gramam production:
>
> [8] PrefixedName ::= Prefix ':' LocalPart
>
> [10] Prefix ::= NCName
>
> /* An XML Name, minus the ":" */
> [4] NCName ::= Name - (Char* ':' Char*)
>
> [5] Name ::= NameStartChar (NameChar)*
>
> Name and NameStarChar exclude "/" so the local part can't include "/" so ("http://www.rdfabout.com/rdf/usgov/congress/", "people/412360") does not work either.
>
>> Being able to navigate every statement in an RDF graph is one of the reasons we are considering JENA, where can we add a feature request for this API? Thanks.
>>
>> Another example is Woodrow Wilson's congress people entry.
>> <foaf:Person
>> rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
>> ...
>> </foaf:Person>
>>
>> Jena represents the statement like this:
>> [http://www.rdfabout.com/rdf/usgov/congress/people/412360,
>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
>> http://xmlns.com/foaf/0.1/Person]
>>
>> But the Subjec'ts namespaces is reported as "http://www.rdfabout.com/rdf/usgov/congress/people/412360" and it's localname as "".
>
> Which is correct. A local part can't start with a digit.
>
> [11] LocalPart ::= NCName
>
> XML allows an empty local part.
>
> In Turtle, you can define the prefix (which is not an XML namspace) as "http://www.rdfabout.com/rdf/usgov/congress/people/"
>
> and get ns:412360
>
> but it's not legal as an XML qname.
>
> The Turtle way is much better for RDF - we have to live with RDF/XML for awhile though.
>
> You can call the Turtle writer directly with a PrefixMap , whic is more liberal than the PrefixMapping the XML writer needs.
>
> Andy
>
>>
>>
>> Thanks, Rodrigo.
>>
>> -----Original Message-----
>> From: Andy Seaborne [mailto:andy@apache.org]
>> Sent: Tuesday, March 26, 2013 8:56 AM
>> To: users@jena.apache.org
>> Subject: Re: RDF Model Namespaces
>>
>> On 25/03/13 17:19, Pastrana, Rodrigo (RIS-BCT) wrote:
>>> In order to use Jena's API to navigate RDF graphs, I need to know
>>> how this particular node is represented. If the node were a literal,
>>> its literallexicalform would be sufficient. Since the node is
>>> represented as an instance of "Resource" the node's label is the
>>> namespace + the localname. However,
>>> "http://www.govtrack.us/data/photos/410069." Is clearly not a NS, and "jpeg" is not its local name.
>>>
>>> Using Jena's API how can one determine if the given "Resource" node
>>> can represented by its literallexicalform, or by its
>>> namespace+localname. Thanks.
>>
>> The full URI should be what you use to determine if two Resources are the same. Namespace/localpart are just syntactic convenience - the code keeps and indexes URIs only.
>>
>> For literals, you need to test the language or datatype as well.
>>
>> "123" is not the integer 123.
>>
>> You can use .equals (of RDFNode, the supertype of Resource and
>> Literal)
>>
>> A Resource is a URI or a blank node.
>>
>> RDFNode has isLiteral()/isURIResource()/isResource()/isAnon() for testing what kind of thing an RDFNode is.
>>
>> By XML, ("http://www.govtrack.us/data/photos/410069.","jpeg") is a
>> qname
>> - in fact the one with the longest local part.
>>
>> This is a qname ("http://www.govtrack.us/data/photos/410069.jp", "eg") for the same URI.
>>
>> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>>
>> Roll on Turtle ...
>>
>> Andy
>>
>> -----------------------------------------
>> The information contained in this e-mail message is intended only for
>> the personal and confidential use of the recipient(s) named above.
>> This message may be an attorney-client communication and/or work
>> product and as such is privileged and confidential. If the reader of
>> this message is not the intended recipient or an agent responsible
>> for delivering it to the intended recipient, you are hereby notified
>> that you have received this document in error and that any review,
>> dissemination, distribution, or copying of this message is strictly
>> prohibited. If you have received this communication in error, please
>> notify us immediately by e-mail, and delete the original message.
>>
>
Re: RDF Model Namespaces
Posted by Martynas Jusevičius <ma...@graphity.org>.
Maybe you could start with explaining what you are trying to achieve?
You stated you want to navigate statements in an RDF graph -- what
does this have to do with namespaces and local names?
Martynas
On Wed, Mar 27, 2013 at 10:32 PM, Pastrana, Rodrigo (RIS-BCT)
<Ro...@lexisnexis.com> wrote:
>> You claim it's illegal. Why?
> Did I? I pointed out the scenario, and asked if Jena's API can help handle it.
> Are you claiming the "congress people" RDF/XML graph is illegal?
>
> Doesn't really matter, what matters is this scenario will play out in many RDF/XML graphs.
> We want to use JENA, but we have to be able to support RDF/XML graphs such as the congress people...
>
>>The Turtle way is much better for RDF - we have to live with RDF/XML for awhile though.
>
>>You can call the Turtle writer directly with a PrefixMap , whic is more liberal than the PrefixMapping the XML writer needs.
>
> At this point, I'll try anything.
> Read in the people graph, wrote out as turtle, read in turtle version, still having issues same issues with numeric people ids and all .jpg resources.
> Anything else that I could do?
>
> Thanks, Rodrigo.
>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Wednesday, March 27, 2013 2:52 PM
> To: users@jena.apache.org
> Subject: Re: RDF Model Namespaces
>
> On 27/03/13 18:29, Pastrana, Rodrigo (RIS-BCT) wrote:
>>> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>>
>> So basically, a Jena API user interested in a node's NS and name will
>> need to extract the full URI and parse it manually to extract the NS
>> and the Name. Because the
>> com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially
>> return invalid namespaces (if the name starts with a numeral or
>> contains a dot).
>
> You claim it's illegal. Why?
>
>
>
> Let's look at XML namespace 1.0 edition 3:
>
> A names pace is used in a qname which is the PrefixedName gramam production:
>
> [8] PrefixedName ::= Prefix ':' LocalPart
>
> [10] Prefix ::= NCName
>
> /* An XML Name, minus the ":" */
> [4] NCName ::= Name - (Char* ':' Char*)
>
> [5] Name ::= NameStartChar (NameChar)*
>
> Name and NameStarChar exclude "/" so the local part can't include "/" so ("http://www.rdfabout.com/rdf/usgov/congress/", "people/412360") does not work either.
>
>> Being able to navigate every statement in an RDF graph is one of the reasons we are considering JENA, where can we add a feature request for this API? Thanks.
>>
>> Another example is Woodrow Wilson's congress people entry.
>> <foaf:Person
>> rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
>> ...
>> </foaf:Person>
>>
>> Jena represents the statement like this:
>> [http://www.rdfabout.com/rdf/usgov/congress/people/412360,
>> http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
>> http://xmlns.com/foaf/0.1/Person]
>>
>> But the Subjec'ts namespaces is reported as "http://www.rdfabout.com/rdf/usgov/congress/people/412360" and it's localname as "".
>
> Which is correct. A local part can't start with a digit.
>
> [11] LocalPart ::= NCName
>
> XML allows an empty local part.
>
> In Turtle, you can define the prefix (which is not an XML namspace) as "http://www.rdfabout.com/rdf/usgov/congress/people/"
>
> and get ns:412360
>
> but it's not legal as an XML qname.
>
> The Turtle way is much better for RDF - we have to live with RDF/XML for awhile though.
>
> You can call the Turtle writer directly with a PrefixMap , whic is more liberal than the PrefixMapping the XML writer needs.
>
> Andy
>
>>
>>
>> Thanks, Rodrigo.
>>
>> -----Original Message-----
>> From: Andy Seaborne [mailto:andy@apache.org]
>> Sent: Tuesday, March 26, 2013 8:56 AM
>> To: users@jena.apache.org
>> Subject: Re: RDF Model Namespaces
>>
>> On 25/03/13 17:19, Pastrana, Rodrigo (RIS-BCT) wrote:
>>> In order to use Jena's API to navigate RDF graphs, I need to know how
>>> this particular node is represented. If the node were a literal, its
>>> literallexicalform would be sufficient. Since the node is represented
>>> as an instance of "Resource" the node's label is the namespace + the
>>> localname. However, "http://www.govtrack.us/data/photos/410069." Is
>>> clearly not a NS, and "jpeg" is not its local name.
>>>
>>> Using Jena's API how can one determine if the given "Resource" node
>>> can represented by its literallexicalform, or by its
>>> namespace+localname. Thanks.
>>
>> The full URI should be what you use to determine if two Resources are the same. Namespace/localpart are just syntactic convenience - the code keeps and indexes URIs only.
>>
>> For literals, you need to test the language or datatype as well.
>>
>> "123" is not the integer 123.
>>
>> You can use .equals (of RDFNode, the supertype of Resource and
>> Literal)
>>
>> A Resource is a URI or a blank node.
>>
>> RDFNode has isLiteral()/isURIResource()/isResource()/isAnon() for testing what kind of thing an RDFNode is.
>>
>> By XML, ("http://www.govtrack.us/data/photos/410069.","jpeg") is a
>> qname
>> - in fact the one with the longest local part.
>>
>> This is a qname ("http://www.govtrack.us/data/photos/410069.jp", "eg") for the same URI.
>>
>> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>>
>> Roll on Turtle ...
>>
>> Andy
>>
>> -----------------------------------------
>> The information contained in this e-mail message is intended only for
>> the personal and confidential use of the recipient(s) named above.
>> This message may be an attorney-client communication and/or work
>> product and as such is privileged and confidential. If the reader of
>> this message is not the intended recipient or an agent responsible for
>> delivering it to the intended recipient, you are hereby notified that
>> you have received this document in error and that any review,
>> dissemination, distribution, or copying of this message is strictly
>> prohibited. If you have received this communication in error, please
>> notify us immediately by e-mail, and delete the original message.
>>
>
RE: RDF Model Namespaces
Posted by "Pastrana, Rodrigo (RIS-BCT)" <Ro...@lexisnexis.com>.
Thanks for your explanation Josh and Andy.
Thanks, Rodrigo.
-----Original Message-----
From: Joshua TAYLOR [mailto:joshuaaaron@gmail.com]
Sent: Wednesday, March 27, 2013 4:53 PM
To: users@jena.apache.org
Subject: Re: RDF Model Namespaces
On Wed, Mar 27, 2013 at 4:32 PM, Pastrana, Rodrigo (RIS-BCT) <Ro...@lexisnexis.com> wrote:
>> You claim it's illegal. Why?
> Did I? I pointed out the scenario, and asked if Jena's API can help handle it.
> Are you claiming the "congress people" RDF/XML graph is illegal?
I'd guess Andy meant where you wrote "Because the
com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially return invalid namespaces (if the name starts with a numeral or contains a dot)." That's not all that relevant though. There's not illegal about the congress people RDF/XML graph. RDF is defined in terms of IRIs, and RDF can be serialized in a number of formats. Some of those formats provide convenient ways to write IRIs in shortened form, but also rule out writing certain of the IRIs in shortened form.
Some of the IRIs in the congress people graph can't be written in the shortened form. It doesn't make the graph illegal in any sense, and it doesn't even mean that the graph can't be serialized in RDF/XML; it only means that not every IRI in the graph can be written in the XML qname format.
> Doesn't really matter, what matters is this scenario will play out in many RDF/XML graphs.
> We want to use JENA, but we have to be able to support RDF/XML graphs such as the congress people...
Jena supports RDF/XML, and you'll be able to use Jena to work with that graph. You won't be able to access everything though XML qnames, though. That's not uncommon, and it's not really a problem. Here's example of Jena code that works with a graph containing the triple you mentioned above. It shows the behavior you've described (i.e., getLocalName returning "") as well as some serializations of the model. The fact that certain IRIs can't be represented in the XML Qname syntax doesn't keep them from being used in RDF graphs, or even from being serialized in RDF/XML.
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;
public class Congress {
public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
Resource wilson = model.createResource( "http://www.rdfabout.com/rdf/usgov/congress/people/412360" );
Resource foafPerson = model.createResource( "http://xmlns.com/foaf/0.1/Person" );
model.add( wilson, RDF.type, foafPerson );
for ( Resource r : new Resource[] { wilson, foafPerson } ) {
System.out.println( "namespace: '" + r.getNameSpace() + "';
localname: '"+r.getLocalName()+"'" );;
}
for ( String format : new String[] { "RDF/XML", "RDF/XML-ABBREV", "TTL" } ) {
System.out.println( "\n== "+format+" ==" );
model.write( System.out, format );
}
}
}
Output:
namespace: 'http://www.rdfabout.com/rdf/usgov/congress/people/412360';
localname: ''
namespace: 'http://xmlns.com/foaf/0.1/'; localname: 'Person'
== RDF/XML ==
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="http://xmlns.com/foaf/0.1/" >
<rdf:Description
rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
</rdf:Description>
</rdf:RDF>
== RDF/XML-ABBREV ==
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="http://xmlns.com/foaf/0.1/">
<j.0:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360"/>
</rdf:RDF>
== TTL ==
<http://www.rdfabout.com/rdf/usgov/congress/people/412360>
a <http://xmlns.com/foaf/0.1/Person> .
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
-----------------------------------------
The information contained in this e-mail message is intended only
for the personal and confidential use of the recipient(s) named
above. This message may be an attorney-client communication and/or
work product and as such is privileged and confidential. If the
reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are
hereby notified that you have received this document in error and
that any review, dissemination, distribution, or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message.
Re: RDF Model Namespaces
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Wed, Mar 27, 2013 at 4:32 PM, Pastrana, Rodrigo (RIS-BCT)
<Ro...@lexisnexis.com> wrote:
>> You claim it's illegal. Why?
> Did I? I pointed out the scenario, and asked if Jena's API can help handle it.
> Are you claiming the "congress people" RDF/XML graph is illegal?
I'd guess Andy meant where you wrote "Because the
com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially
return invalid namespaces (if the name starts with a numeral or
contains a dot)." That's not all that relevant though. There's not
illegal about the congress people RDF/XML graph. RDF is defined in
terms of IRIs, and RDF can be serialized in a number of formats. Some
of those formats provide convenient ways to write IRIs in shortened
form, but also rule out writing certain of the IRIs in shortened form.
Some of the IRIs in the congress people graph can't be written in the
shortened form. It doesn't make the graph illegal in any sense, and
it doesn't even mean that the graph can't be serialized in RDF/XML;
it only means that not every IRI in the graph can be written in the
XML qname format.
> Doesn't really matter, what matters is this scenario will play out in many RDF/XML graphs.
> We want to use JENA, but we have to be able to support RDF/XML graphs such as the congress people...
Jena supports RDF/XML, and you'll be able to use Jena to work with
that graph. You won't be able to access everything though XML qnames,
though. That's not uncommon, and it's not really a problem. Here's
example of Jena code that works with a graph containing the triple you
mentioned above. It shows the behavior you've described (i.e.,
getLocalName returning "") as well as some serializations of the
model. The fact that certain IRIs can't be represented in the XML
Qname syntax doesn't keep them from being used in RDF graphs, or even
from being serialized in RDF/XML.
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.vocabulary.RDF;
public class Congress {
public static void main(String[] args) {
Model model = ModelFactory.createDefaultModel();
Resource wilson = model.createResource(
"http://www.rdfabout.com/rdf/usgov/congress/people/412360" );
Resource foafPerson = model.createResource(
"http://xmlns.com/foaf/0.1/Person" );
model.add( wilson, RDF.type, foafPerson );
for ( Resource r : new Resource[] { wilson, foafPerson } ) {
System.out.println( "namespace: '" + r.getNameSpace() + "';
localname: '"+r.getLocalName()+"'" );;
}
for ( String format : new String[] { "RDF/XML", "RDF/XML-ABBREV", "TTL" } ) {
System.out.println( "\n== "+format+" ==" );
model.write( System.out, format );
}
}
}
Output:
namespace: 'http://www.rdfabout.com/rdf/usgov/congress/people/412360';
localname: ''
namespace: 'http://xmlns.com/foaf/0.1/'; localname: 'Person'
== RDF/XML ==
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="http://xmlns.com/foaf/0.1/" >
<rdf:Description
rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
<rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
</rdf:Description>
</rdf:RDF>
== RDF/XML-ABBREV ==
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="http://xmlns.com/foaf/0.1/">
<j.0:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360"/>
</rdf:RDF>
== TTL ==
<http://www.rdfabout.com/rdf/usgov/congress/people/412360>
a <http://xmlns.com/foaf/0.1/Person> .
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
RE: RDF Model Namespaces
Posted by "Pastrana, Rodrigo (RIS-BCT)" <Ro...@lexisnexis.com>.
> You claim it's illegal. Why?
Did I? I pointed out the scenario, and asked if Jena's API can help handle it.
Are you claiming the "congress people" RDF/XML graph is illegal?
Doesn't really matter, what matters is this scenario will play out in many RDF/XML graphs.
We want to use JENA, but we have to be able to support RDF/XML graphs such as the congress people...
>The Turtle way is much better for RDF - we have to live with RDF/XML for awhile though.
>You can call the Turtle writer directly with a PrefixMap , whic is more liberal than the PrefixMapping the XML writer needs.
At this point, I'll try anything.
Read in the people graph, wrote out as turtle, read in turtle version, still having issues same issues with numeric people ids and all .jpg resources.
Anything else that I could do?
Thanks, Rodrigo.
-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org]
Sent: Wednesday, March 27, 2013 2:52 PM
To: users@jena.apache.org
Subject: Re: RDF Model Namespaces
On 27/03/13 18:29, Pastrana, Rodrigo (RIS-BCT) wrote:
>> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>
> So basically, a Jena API user interested in a node's NS and name will
> need to extract the full URI and parse it manually to extract the NS
> and the Name. Because the
> com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially
> return invalid namespaces (if the name starts with a numeral or
> contains a dot).
You claim it's illegal. Why?
Let's look at XML namespace 1.0 edition 3:
A names pace is used in a qname which is the PrefixedName gramam production:
[8] PrefixedName ::= Prefix ':' LocalPart
[10] Prefix ::= NCName
/* An XML Name, minus the ":" */
[4] NCName ::= Name - (Char* ':' Char*)
[5] Name ::= NameStartChar (NameChar)*
Name and NameStarChar exclude "/" so the local part can't include "/" so ("http://www.rdfabout.com/rdf/usgov/congress/", "people/412360") does not work either.
> Being able to navigate every statement in an RDF graph is one of the reasons we are considering JENA, where can we add a feature request for this API? Thanks.
>
> Another example is Woodrow Wilson's congress people entry.
> <foaf:Person
> rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
> ...
> </foaf:Person>
>
> Jena represents the statement like this:
> [http://www.rdfabout.com/rdf/usgov/congress/people/412360,
> http://www.w3.org/1999/02/22-rdf-syntax-ns#type,
> http://xmlns.com/foaf/0.1/Person]
>
> But the Subjec'ts namespaces is reported as "http://www.rdfabout.com/rdf/usgov/congress/people/412360" and it's localname as "".
Which is correct. A local part can't start with a digit.
[11] LocalPart ::= NCName
XML allows an empty local part.
In Turtle, you can define the prefix (which is not an XML namspace) as "http://www.rdfabout.com/rdf/usgov/congress/people/"
and get ns:412360
but it's not legal as an XML qname.
The Turtle way is much better for RDF - we have to live with RDF/XML for awhile though.
You can call the Turtle writer directly with a PrefixMap , whic is more liberal than the PrefixMapping the XML writer needs.
Andy
>
>
> Thanks, Rodrigo.
>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Tuesday, March 26, 2013 8:56 AM
> To: users@jena.apache.org
> Subject: Re: RDF Model Namespaces
>
> On 25/03/13 17:19, Pastrana, Rodrigo (RIS-BCT) wrote:
>> In order to use Jena's API to navigate RDF graphs, I need to know how
>> this particular node is represented. If the node were a literal, its
>> literallexicalform would be sufficient. Since the node is represented
>> as an instance of "Resource" the node's label is the namespace + the
>> localname. However, "http://www.govtrack.us/data/photos/410069." Is
>> clearly not a NS, and "jpeg" is not its local name.
>>
>> Using Jena's API how can one determine if the given "Resource" node
>> can represented by its literallexicalform, or by its
>> namespace+localname. Thanks.
>
> The full URI should be what you use to determine if two Resources are the same. Namespace/localpart are just syntactic convenience - the code keeps and indexes URIs only.
>
> For literals, you need to test the language or datatype as well.
>
> "123" is not the integer 123.
>
> You can use .equals (of RDFNode, the supertype of Resource and
> Literal)
>
> A Resource is a URI or a blank node.
>
> RDFNode has isLiteral()/isURIResource()/isResource()/isAnon() for testing what kind of thing an RDFNode is.
>
> By XML, ("http://www.govtrack.us/data/photos/410069.","jpeg") is a
> qname
> - in fact the one with the longest local part.
>
> This is a qname ("http://www.govtrack.us/data/photos/410069.jp", "eg") for the same URI.
>
> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>
> Roll on Turtle ...
>
> Andy
>
> -----------------------------------------
> The information contained in this e-mail message is intended only for
> the personal and confidential use of the recipient(s) named above.
> This message may be an attorney-client communication and/or work
> product and as such is privileged and confidential. If the reader of
> this message is not the intended recipient or an agent responsible for
> delivering it to the intended recipient, you are hereby notified that
> you have received this document in error and that any review,
> dissemination, distribution, or copying of this message is strictly
> prohibited. If you have received this communication in error, please
> notify us immediately by e-mail, and delete the original message.
>
Re: RDF Model Namespaces
Posted by Andy Seaborne <an...@apache.org>.
On 27/03/13 18:29, Pastrana, Rodrigo (RIS-BCT) wrote:
>> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>
> So basically, a Jena API user interested in a node's NS and name will
> need to extract the full URI and parse it manually to extract the NS
> and the Name. Because the
> com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially
> return invalid namespaces (if the name starts with a numeral or
> contains a dot).
You claim it's illegal. Why?
Let's look at XML namespace 1.0 edition 3:
A names pace is used in a qname which is the PrefixedName gramam production:
[8] PrefixedName ::= Prefix ':' LocalPart
[10] Prefix ::= NCName
/* An XML Name, minus the ":" */
[4] NCName ::= Name - (Char* ':' Char*)
[5] Name ::= NameStartChar (NameChar)*
Name and NameStarChar exclude "/" so the local part can't include "/" so
("http://www.rdfabout.com/rdf/usgov/congress/", "people/412360")
does not work either.
> Being able to navigate every statement in an RDF graph is one of the reasons we are considering JENA, where can we add a feature request for this API? Thanks.
>
> Another example is Woodrow Wilson's congress people entry.
> <foaf:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
> ...
> </foaf:Person>
>
> Jena represents the statement like this:
> [http://www.rdfabout.com/rdf/usgov/congress/people/412360, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://xmlns.com/foaf/0.1/Person]
>
> But the Subjec'ts namespaces is reported as "http://www.rdfabout.com/rdf/usgov/congress/people/412360" and it's localname as "".
Which is correct. A local part can't start with a digit.
[11] LocalPart ::= NCName
XML allows an empty local part.
In Turtle, you can define the prefix (which is not an XML namspace) as
"http://www.rdfabout.com/rdf/usgov/congress/people/"
and get ns:412360
but it's not legal as an XML qname.
The Turtle way is much better for RDF - we have to live with RDF/XML for
awhile though.
You can call the Turtle writer directly with a PrefixMap , whic is more
liberal than the PrefixMapping the XML writer needs.
Andy
>
>
> Thanks, Rodrigo.
>
> -----Original Message-----
> From: Andy Seaborne [mailto:andy@apache.org]
> Sent: Tuesday, March 26, 2013 8:56 AM
> To: users@jena.apache.org
> Subject: Re: RDF Model Namespaces
>
> On 25/03/13 17:19, Pastrana, Rodrigo (RIS-BCT) wrote:
>> In order to use Jena's API to navigate RDF graphs, I need to know how
>> this particular node is represented. If the node were a literal, its
>> literallexicalform would be sufficient. Since the node is represented
>> as an instance of "Resource" the node's label is the namespace + the
>> localname. However, "http://www.govtrack.us/data/photos/410069." Is
>> clearly not a NS, and "jpeg" is not its local name.
>>
>> Using Jena's API how can one determine if the given "Resource" node
>> can represented by its literallexicalform, or by its
>> namespace+localname. Thanks.
>
> The full URI should be what you use to determine if two Resources are the same. Namespace/localpart are just syntactic convenience - the code keeps and indexes URIs only.
>
> For literals, you need to test the language or datatype as well.
>
> "123" is not the integer 123.
>
> You can use .equals (of RDFNode, the supertype of Resource and Literal)
>
> A Resource is a URI or a blank node.
>
> RDFNode has isLiteral()/isURIResource()/isResource()/isAnon() for testing what kind of thing an RDFNode is.
>
> By XML, ("http://www.govtrack.us/data/photos/410069.","jpeg") is a qname
> - in fact the one with the longest local part.
>
> This is a qname ("http://www.govtrack.us/data/photos/410069.jp", "eg") for the same URI.
>
> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
>
> Roll on Turtle ...
>
> Andy
>
> -----------------------------------------
> The information contained in this e-mail message is intended only
> for the personal and confidential use of the recipient(s) named
> above. This message may be an attorney-client communication and/or
> work product and as such is privileged and confidential. If the
> reader of this message is not the intended recipient or an agent
> responsible for delivering it to the intended recipient, you are
> hereby notified that you have received this document in error and
> that any review, dissemination, distribution, or copying of this
> message is strictly prohibited. If you have received this
> communication in error, please notify us immediately by e-mail, and
> delete the original message.
>
RE: RDF Model Namespaces
Posted by "Pastrana, Rodrigo (RIS-BCT)" <Ro...@lexisnexis.com>.
>The full URI should be what you use to determine if two Resources are the same. Namespace/localpart are just syntactic convenience - the code keeps and indexes URIs only.
Not comparing two nodes.
>For literals, you need to test the language or datatype as well.
No issue with literals.
>"123" is not the integer 123.
>
>You can use .equals (of RDFNode, the supertype of Resource and Literal)
Not comparing two nodes.
>A Resource is a URI or a blank node.
Correct. Not interested in anonymous node's namespace.
However, very much interested in a given URIresource's namespace (when it makes sense) and/or URIresource's localname.
> Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
So basically, a Jena API user interested in a node's NS and name will need to extract the full URI and parse it manually to extract the NS and the Name. Because the com.hp.hpl.jena.rdf.model.Resource.getNameSpace() will potentially return invalid namespaces (if the name starts with a numeral or contains a dot).
Being able to navigate every statement in an RDF graph is one of the reasons we are considering JENA, where can we add a feature request for this API? Thanks.
Another example is Woodrow Wilson's congress people entry.
<foaf:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/412360">
...
</foaf:Person>
Jena represents the statement like this:
[http://www.rdfabout.com/rdf/usgov/congress/people/412360, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://xmlns.com/foaf/0.1/Person]
But the Subjec'ts namespaces is reported as "http://www.rdfabout.com/rdf/usgov/congress/people/412360" and it's localname as "".
Thanks, Rodrigo.
-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org]
Sent: Tuesday, March 26, 2013 8:56 AM
To: users@jena.apache.org
Subject: Re: RDF Model Namespaces
On 25/03/13 17:19, Pastrana, Rodrigo (RIS-BCT) wrote:
> In order to use Jena's API to navigate RDF graphs, I need to know how
> this particular node is represented. If the node were a literal, its
> literallexicalform would be sufficient. Since the node is represented
> as an instance of "Resource" the node's label is the namespace + the
> localname. However, "http://www.govtrack.us/data/photos/410069." Is
> clearly not a NS, and "jpeg" is not its local name.
>
> Using Jena's API how can one determine if the given "Resource" node
> can represented by its literallexicalform, or by its
> namespace+localname. Thanks.
The full URI should be what you use to determine if two Resources are the same. Namespace/localpart are just syntactic convenience - the code keeps and indexes URIs only.
For literals, you need to test the language or datatype as well.
"123" is not the integer 123.
You can use .equals (of RDFNode, the supertype of Resource and Literal)
A Resource is a URI or a blank node.
RDFNode has isLiteral()/isURIResource()/isResource()/isAnon() for testing what kind of thing an RDFNode is.
By XML, ("http://www.govtrack.us/data/photos/410069.","jpeg") is a qname
- in fact the one with the longest local part.
This is a qname ("http://www.govtrack.us/data/photos/410069.jp", "eg") for the same URI.
Because "410069.jpeg" is illegal as an XML qname local part, it is not returned by Jena.
Roll on Turtle ...
Andy
-----------------------------------------
The information contained in this e-mail message is intended only
for the personal and confidential use of the recipient(s) named
above. This message may be an attorney-client communication and/or
work product and as such is privileged and confidential. If the
reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are
hereby notified that you have received this document in error and
that any review, dissemination, distribution, or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message.
Re: RDF Model Namespaces
Posted by Andy Seaborne <an...@apache.org>.
On 25/03/13 17:19, Pastrana, Rodrigo (RIS-BCT) wrote:
> In order to use Jena's API to navigate RDF graphs, I need to know how
> this particular node is represented. If the node were a literal, its
> literallexicalform would be sufficient. Since the node is represented
> as an instance of "Resource" the node's label is the namespace + the
> localname. However, "http://www.govtrack.us/data/photos/410069." Is
> clearly not a NS, and "jpeg" is not its local name.
>
> Using Jena's API how can one determine if the given "Resource" node
> can represented by its literallexicalform, or by its
> namespace+localname. Thanks.
The full URI should be what you use to determine if two Resources are
the same. Namespace/localpart are just syntactic convenience - the code
keeps and indexes URIs only.
For literals, you need to test the language or datatype as well.
"123" is not the integer 123.
You can use .equals (of RDFNode, the supertype of Resource and Literal)
A Resource is a URI or a blank node.
RDFNode has isLiteral()/isURIResource()/isResource()/isAnon() for
testing what kind of thing an RDFNode is.
By XML, ("http://www.govtrack.us/data/photos/410069.","jpeg") is a qname
- in fact the one with the longest local part.
This is a qname ("http://www.govtrack.us/data/photos/410069.jp", "eg")
for the same URI.
Because "410069.jpeg" is illegal as an XML qname local part, it is not
returned by Jena.
Roll on Turtle ...
Andy
RE: RDF Model Namespaces
Posted by "Pastrana, Rodrigo (RIS-BCT)" <Ro...@lexisnexis.com>.
In order to use Jena's API to navigate RDF graphs, I need to know how this particular node is represented.
If the node were a literal, its literallexicalform would be sufficient. Since the node is represented as an instance of "Resource" the node's label is the namespace + the localname. However, "http://www.govtrack.us/data/photos/410069." Is clearly not a NS, and "jpeg" is not its local name.
Using Jena's API how can one determine if the given "Resource" node can represented by its literallexicalform, or by its namespace+localname. Thanks.
Thanks, Rodrigo.
-----Original Message-----
From: Andy Seaborne [mailto:andy@apache.org]
Sent: Friday, March 22, 2013 4:59 PM
To: users@jena.apache.org
Subject: Re: RDF Model Namespaces
On 22/03/13 20:47, Pastrana, Rodrigo (RIS-BCT) wrote:
> I'm new to Jena RDF API and I'm noticing some unexpected behavior regarding statement namespaces...
> I've noticed that URI resources such as
> "http://www.govtrack.us/data/photos/412483.jpeg" in the below excerpt
> of the congressional people
> graph(http://www.govtrack.us/data/rdf/people.rdf.gz)
> Are reported to have namespace: " http://www.govtrack.us/data/photos/410069." And local name "jpeg" using the com.hp.hpl.jena.rdf.model.Resource getLocalName(), and getNameSpace().
> Is this correct behavior? It looks to me like the dot is being used as a delimiter between the NS and the local name. Is there a way to change that behavior ? thanks!
>
>
> <foaf:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/R000589">
> <foaf:name>E. Rigell</foaf:name>
> <usgov:name>E. Rigell</usgov:name>
> <vcard:N>
> <rdf:Description>
> <vcard:Given>E.</vcard:Given>
> <vcard:Other>Scott</vcard:Other>
> <vcard:Family>Rigell</vcard:Family>
> <vcard:Prefix>Rep.</vcard:Prefix>
> </rdf:Description>
> </vcard:N>
> <foaf:gender>male</foaf:gender>
> <vcard:BDAY>1960-05-28</vcard:BDAY>
> <foaf:img rdf:resource="http://www.govtrack.us/data/photos/412483.jpeg"/>
> <usgov:congressBioGuideID>R000589</usgov:congressBioGuideID>
> <foaf:title>Rep.</foaf:title>
> <foaf:homepage>http://rigell.house.gov/</foaf:homepage>
> </foaf:Person>
>
>
> Thanks, Rodrigo.
Jena is finding the maximal XML qname - the namespace mechanism can't be sure that it isn't going to be used a property. Both properties (must) and types (can be) qnames in RDF/XML. RDF does not distinguish classes/properties/individuals.
http://www.govtrack.us/data/photos/412483.jpeg
An XML qname local part can't start with a digit or a "." so "jpeg" is the longest local part.
> Is this correct behavior?
Yes
> Is there a way to change that behavior ?
No - the RDF/XML serializer is relying on it.
But what are you using the namespace/localname for ?
If it's display, then you are not bound by the XML restrictions and can split it yourself. The resource is the URI - it does not carry it's namespace with it.
In Turtle, the prefix names are not restricted, but then there is not a requirement to split a URI ever anyway.
Andy
>
>
-----------------------------------------
The information contained in this e-mail message is intended only
for the personal and confidential use of the recipient(s) named
above. This message may be an attorney-client communication and/or
work product and as such is privileged and confidential. If the
reader of this message is not the intended recipient or an agent
responsible for delivering it to the intended recipient, you are
hereby notified that you have received this document in error and
that any review, dissemination, distribution, or copying of this
message is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message.
Re: RDF Model Namespaces
Posted by Andy Seaborne <an...@apache.org>.
On 22/03/13 20:47, Pastrana, Rodrigo (RIS-BCT) wrote:
> I'm new to Jena RDF API and I'm noticing some unexpected behavior regarding statement namespaces...
> I've noticed that URI resources such as "http://www.govtrack.us/data/photos/412483.jpeg" in the below excerpt of the congressional people graph(http://www.govtrack.us/data/rdf/people.rdf.gz)
> Are reported to have namespace: " http://www.govtrack.us/data/photos/410069." And local name "jpeg" using the com.hp.hpl.jena.rdf.model.Resource getLocalName(), and getNameSpace().
> Is this correct behavior? It looks to me like the dot is being used as a delimiter between the NS and the local name. Is there a way to change that behavior ? thanks!
>
>
> <foaf:Person rdf:about="http://www.rdfabout.com/rdf/usgov/congress/people/R000589">
> <foaf:name>E. Rigell</foaf:name>
> <usgov:name>E. Rigell</usgov:name>
> <vcard:N>
> <rdf:Description>
> <vcard:Given>E.</vcard:Given>
> <vcard:Other>Scott</vcard:Other>
> <vcard:Family>Rigell</vcard:Family>
> <vcard:Prefix>Rep.</vcard:Prefix>
> </rdf:Description>
> </vcard:N>
> <foaf:gender>male</foaf:gender>
> <vcard:BDAY>1960-05-28</vcard:BDAY>
> <foaf:img rdf:resource="http://www.govtrack.us/data/photos/412483.jpeg"/>
> <usgov:congressBioGuideID>R000589</usgov:congressBioGuideID>
> <foaf:title>Rep.</foaf:title>
> <foaf:homepage>http://rigell.house.gov/</foaf:homepage>
> </foaf:Person>
>
>
> Thanks, Rodrigo.
Jena is finding the maximal XML qname - the namespace mechanism can't be
sure that it isn't going to be used a property. Both properties (must)
and types (can be) qnames in RDF/XML. RDF does not distinguish
classes/properties/individuals.
http://www.govtrack.us/data/photos/412483.jpeg
An XML qname local part can't start with a digit or a "." so "jpeg" is
the longest local part.
> Is this correct behavior?
Yes
> Is there a way to change that behavior ?
No - the RDF/XML serializer is relying on it.
But what are you using the namespace/localname for ?
If it's display, then you are not bound by the XML restrictions and can
split it yourself. The resource is the URI - it does not carry it's
namespace with it.
In Turtle, the prefix names are not restricted, but then there is not a
requirement to split a URI ever anyway.
Andy
>
>