我的.owl文件中有五个与我的SPARQL查询匹配的个人,我在" SPARQL查询"中尝试了相同的查询。 Protege,它返回5个人。 但是当我使用Jena库在Eclipse中尝试该查询时,它只返回3个人!
我的代码:
String file="....\\Ontology.owl";
File f=new File(file);
FileReader r=new FileReader(f);
OntModel m=ModelFactory.createOntologyModel();
m.read(r,null);
String req ="" +
"PREFIX m: <http://www.NewOnto1.org/Ontology#>"+
"PREFIX aut:<http://www.NewOnto1.org/Citations#AuthorCite>"+
"PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>"+
"SELECT ?AuthorName ?AuthorField"+
"WHERE{"+
"?x rdf:type m:AuthorCite."+
"?x m:AuthorName ?AuthorName."+
"?x m:AuthorBelongsToField ?AuthorField."+
"FILTER regex(str(?AuthorField),\""+field+"\")."+
"}";
com.hp.hpl.jena.query.Query query = QueryFactory.create(req);
QueryExecution qe = QueryExecutionFactory.create(query, m);
com.hp.hpl.jena.query.ResultSet res = qe.execSelect();
//ResultSetFormatter.out(System.out, res, query);
int leng=0;
while(res.hasNext()){
leng++;
res.next();
}
System.out.println("Length : "+leng);
有关更多信息,我想获得属于特定研究领域(领域)的个人(作者)。