Reputation: 147
I implemented a code that parses off some information from a rdf code but it throws me the following error:
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Line 1, column 126: Unresolved prefixed name: foaf:name
What is the issue that causes this error?
This is my code:
import java.util.Iterator;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.util.FileManager;
public class Main {
public static void main(String args[])
{
sparqlTest();
}
static void sparqlTest()
{
FileManager.get().addLocatorClassLoader(Main.class.getClassLoader());
Model model = FileManager.get().loadModel("c:/Users/Laura/workspace/jena-app/src/data.rdf");
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX foat: <http://xmlns.com/foaf/0.1/> " +
"SELECT * WHERE { " +
" ?person foaf:name ?x ." +
"}";
Query query = QueryFactory.create(queryString);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
try {
ResultSet results = qexec.execSelect();
while (results.hasNext() ) {
QuerySolution soln = results.nextSolution();
Literal name = soln.getLiteral("x");
System.out.println(name);
}
} finally {
qexec.close();
}
}
}
RDF File:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:foaf="http://xmlns.com/foaf/0.1/"
xmlns:admin="http://webns.net/mvcb/">
<foaf:PersonalProfileDocument rdf:about="">
<foaf:maker rdf:resource="#me"/>
<foaf:primaryTopic rdf:resource="#me"/>
<admin:generatorAgent rdf:resource="http://www.ldodds.com/foaf/foaf-a-matic"/>
<admin:errorReportsTo rdf:resource="mailto:[email protected]"/>
</foaf:PersonalProfileDocument>
<foaf:Person rdf:ID="me">
<foaf:name>George V</foaf:name>
<foaf:title>Dr</foaf:title>
<foaf:givenname>George</foaf:givenname>
<foaf:family_name>V</foaf:family_name>
<foaf:nick>jorch</foaf:nick>
<foaf:mbox_sha1sum>b01b5835fa8ae7b7582968a7ecacb9b85503a6c9</foaf:mbox_sha1sum>
<foaf:homepage rdf:resource="betacoding.net"/>
<foaf:phone rdf:resource="tel:123456"/>
<foaf:workplaceHomepage rdf:resource="work"/>
<foaf:workInfoHomepage rdf:resource="development"/>
<foaf:schoolHomepage rdf:resource="a school"/>
<foaf:knows>
<foaf:Person>
<foaf:name>John</foaf:name>
<foaf:mbox_sha1sum>c7856d7a98889cee78a21245301a560e8f74d191</foaf:mbox_sha1sum>
<rdfs:seeAlso rdf:resource="Charlie"/></foaf:Person></foaf:knows>
<foaf:knows>
<foaf:Person>
<foaf:name>Mary</foaf:name>
<foaf:mbox_sha1sum>a61c03838106b21fc083e7bc65e76c511c549d22</foaf:mbox_sha1sum>
<rdfs:seeAlso rdf:resource="Margaret"/></foaf:Person></foaf:knows>
<foaf:knows>
<foaf:Person>
<foaf:name>Charlie</foaf:name>
<foaf:mbox_sha1sum>27f94c268f1a1c6004be361f4045d43c3745c0de</foaf:mbox_sha1sum>
<rdfs:seeAlso rdf:resource="John"/></foaf:Person></foaf:knows></foaf:Person>
</rdf:RDF>
These should be the expected results:
Charlie
Mary
John
George
Upvotes: 2
Views: 173
Reputation: 9648
You are getting the error because you have pointed it to foat
in your query below instead of foaf
.
"PREFIX foat: <http://xmlns.com/foaf/0.1/>"
This should be changed as follows:
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>"
Your updated query should look something like this:
String queryString =
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX foaf: <http://xmlns.com/foaf/0.1/>" +
"SELECT * WHERE { " +
" ?person foaf:name ?x ." +
"}";
Upvotes: 3