I'm using Jena to query my ontology, and I'm following Step 8: Querying a Model of this tutorial. The RDF file vc-db-1.rdf being queried here is generated from Step 3: Writing RDF and is shown below:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:vcard="http://www.w3.org/2001/vcard-rdf/3.0#" >
<rdf:Description rdf:nodeID="A0">
<vcard:Family>Smith</vcard:Family>
<vcard:Given>John</vcard:Given>
</rdf:Description>
<rdf:Description rdf:about="http://somewhere/JohnSmith">
<vcard:N rdf:nodeID="A0"/>
<vcard:FN>John Smith</vcard:FN>
</rdf:Description>
</rdf:RDF>
The sample code is tutorial 7 and can be downloaded here.
I noticed that in the line
ResIterator iter = model.listResourcesWithProperty(VCARD.FN);
VCARD.FN is only a property name from the RDF, but not a defined variable in my code. However, it can be successfully recognized here and the code runs without any problem.
But this is not the case with my own RDF file. I created an ontology pottery.owl with Protege and saved it in RDF/XML language. The file content is as followed:
<?xml version="1.0"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#"
xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:swrl="http://www.w3.org/2003/11/swrl#"
xmlns="http://www.owl-ontologies.com/Ontology1369190090.owl#"
xmlns:swrlb="http://www.w3.org/2003/11/swrlb#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="http://www.owl-ontologies.com/Ontology1369190090.owl" >
<rdf:Description rdf:about="">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
</rdf:Description>
<rdf:Description rdf:about="#pottery">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
</rdf:Description>
<rdf:Description rdf:about="#pottery_instance_1">
<rdf:type rdf:resource="#pottery"/>
<pottery.colors rdf:datatype="http://www.w3.org/2001/XMLSchema#string">blue</pottery.colors>
</rdf:Description>
<rdf:Description rdf:about="#pottery.colors">
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
<rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<rdfs:domain rdf:resource="#pottery"/>
</rdf:Description>
</rdf:RDF>
<!-- Created with Protege (with OWL Plugin 3.4.8, Build 629) http://protege.stanford.edu -->
The ontology contains a class pottery, an instance pottery_instance_1, and a datatype property pottery.colors.
And I modified these lines in the original code:
static final String inputFileName = "pottery.owl";
// ...
ResIterator iter = model.listResourcesWithProperty(pottery.colors);
// ...
System.out.println(" " + iter.nextResource()
.getProperty(pottery.colors)
.getString());
This time I got the error "pottery cannot be resolved to a variable."
What's the trick here? Does it have anything to do with the difference between the formats of the two RDFs? Or something else? Thank you.