-- 作者:dorothyle
-- 发布时间:10/13/2010 5:22:00 PM
-- [求助]利用SPAQL对本体进行查询总是报错
大家好,遇到了一点问题,请有经验的朋友帮忙给指点一二: 我用Protege构建了一个关于服装的本体,定义了两个类,一个是服装,一个是文档,文档类有两个子类,一个是图片,一个是其他文档。对于服装这个类定义了一些数据类型属性,包括color, texture,kind, name, pattern, style等。同时我创建了一个服装类的实例H,我想通过以下语句,实现控制台输出实例H的颜色。语句如下: import com.hp.hpl.jena.ontology.OntDocumentManager; import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.query.*; import com.hp.hpl.jena.rdf.model.InfModel; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.reasoner.*; public class Costume2{ public static void main(String args[]) { OntModel model = ModelFactory.createOntologyModel(); OntDocumentManager dm = model.getDocumentManager(); dm.addAltEntry("http://Costume.owl#", "file:" + "Costume.owl"); model.read("file:e:/ontologies/BeijingOpera/Costume.owl"); String prefix= "PREFIX owl: <http://www.w3.org/2002/07/owl#>" + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + "PREFIX base: <http://Costume.owl#> "; String k = "?base:H "; String select = "SELECT ?color "; String where = "WHERE {" + k + "base:color ?color }" ; Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); Query query = QueryFactory.create(prefix + select + where); InfModel inf = ModelFactory.createInfModel(reasoner, model); QueryExecution qe = QueryExecutionFactory.create(query,inf); ResultSet results = qe.execSelect(); ResultSetFormatter.out(System.out,results,query); } } 语句没有提示报错,但是控制台没有输出。控制台的出错提示如下: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/D:/pellet-2.2.0/lib/jena/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/D:/ARQ-2.8.5/lib/slf4j-log4j12-1.5.8.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Line 1, column 216: Unresolved prefixed[color=#FF0000] name: :H at [/color]com.hp.hpl.jena.sparql.lang.ParserBase.throwParseException(ParserBase.java:543) at com.hp.hpl.jena.sparql.lang.ParserBase.resolvePName(ParserBase.java:232) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.PrefixedName(SPARQLParser10.java:2077) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.IRIref(SPARQLParser10.java:2061) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.VarOrIRIref(SPARQLParser10.java:1279) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.Verb(SPARQLParser10.java:1081) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.PropertyListNotEmpty(SPARQLParser10.java:1002) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.TriplesSameSubject(SPARQLParser10.java:985) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.TriplesBlock(SPARQLParser10.java:645) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.GroupGraphPatternSub(SPARQLParser10.java:555) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.GroupGraphPattern(SPARQLParser10.java:518) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.WhereClause(SPARQLParser10.java:330) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.SelectQuery(SPARQLParser10.java:108) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.Query(SPARQLParser10.java:36) at com.hp.hpl.jena.sparql.lang.sparql_10.SPARQLParser10.QueryUnit(SPARQLParser10.java:28) at com.hp.hpl.jena.sparql.lang.ParserSPARQL10$1.exec(ParserSPARQL10.java:35) at com.hp.hpl.jena.sparql.lang.ParserSPARQL10.perform(ParserSPARQL10.java:82) at com.hp.hpl.jena.sparql.lang.ParserSPARQL10.parse(ParserSPARQL10.java:39) at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:129) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:72) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:43) at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:31) at Costume2.main(Costume2.java:23) 其中红字显示的地方应该是我想显示的实例,这里我改了几个实例的名称,但总是这个地方报错,大家帮我看看吧。
|