我已经做了几个小时了,试图让佩莱和詹娜一起工作。现在我终于明白了它在起作用。查询类和推理类进展顺利。例如:
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中不可用吗?甚至在我使用佩莱的时候都没有?有没有其他方法可以使用Jena和Pellet查询我的本体的altlabels?
该警告只是说推理器忽略了注释属性上声明的范围。您的查询不应该受到它的影响。
好吧,这有点愚蠢。事实证明,我意外地使用OWL/XML导出了我的本体,并将其保存为RDF/XML修复了这一问题。