我已经为此工作了几个小时,试图让 Pellet 与 Jenna 一起工作。现在我终于明白了它的工作原理。查询类和推断类进展顺利。例如:
SELECT * WHERE { ?x rdf:type uni:Adult}
但是,当尝试使用此查询标签时:
SELECT * WHERE { ?x ?y "Vincent"^^xsd:string}
返回:
org.mindswap.pellet.jena.PelletReasoner@1b13b5d
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX uni: <http://localhost/SemanticSearch/semanticsearch.owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT *
WHERE
{ ?x ?y "Vincent"^^xsd:string }
{
"head": {
"vars": [ "x" , "y" ]
} ,
"results": {
"bindings": [
mrt 18, 2015 1:06:41 PM org.mindswap.pellet.jena.graph.loader.DefaultGraphLoader addUnsupportedFeature
WARNING: Unsupported axiom: Ignoring range axiom for AnnotationProperty http://www.w3.org/2000/01/rdf-schema#label
mrt 18, 2015 1:06:41 PM org.mindswap.pellet.jena.graph.loader.DefaultGraphLoader addUnsupportedFeature
WARNING: Unsupported axiom: Ignoring range axiom for AnnotationProperty http://localhost/SemanticSearch/semanticsearch.owl#altLabel
]
}
}
我的完整代码如下:
Model rawModel = ModelFactory.createDefaultModel();
Reasoner r = PelletReasonerFactory.theInstance().create();
Model data = FileManager.get().loadModel("file:C:/wamp/www/SemanticSearch/workspace/SemanticSearch/src/semanticsearch.owl");
InfModel model = ModelFactory.createInfModel(r, data);
InputStream in = new FileInputStream(new File("C:/wamp/www/SemanticSearch/semanticsearch.owl"));
System.out.println(model.getReasoner());
String sparqlQueryString1= "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#>"+
" PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
" PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>"+
" PREFIX uni: <http://localhost/SemanticSearch/semanticsearch.owl#>"+
" SELECT * WHERE { ?x ?y \"Vincent\"^^xsd:string}";
System.out.println(sparqlQueryString1);
Query query = QueryFactory.create(sparqlQueryString1);
QueryExecution qexec = QueryExecutionFactory.create(query, model);
ResultSet results = qexec.execSelect();
//ORGINEEL ResultSetFormatter.out(System.out, results, query);
//ALS RDF ResultSetFormatter.outputAsRDF("", results);
ResultSetFormatter.outputAsJSON(results);
qexec.close() ;
}
Jena 中没有查询字符串吗?甚至在我使用 Pellet 时也不行?有没有其他方法可以使用 Jena 和 Pellet 查询我的本体的替代标签?