如何在eclipse上使用sparql查询推断出新的个体

时间:2014-04-04 16:29:30

标签: java eclipse sparql jena inference

这个程序可能会使用推理技术将其他狮子个体添加到本体中通过推理推导出但我不知道如何解决所有返回的错误。 java代码如下:

package paletrasi;

import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.vocabulary.RDF;
import org.apache.jena.atlas.io.IndentedWriter;
import com.hp.hpl.jena.query.*;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.reasoner.Reasoner;
import org.mindswap.pellet.jena.PelletReasonerFactory;
public class jungle2
{
public static final String NL = System.getProperty("line.separator") ;
public static void main( String[] args ) {
// create the simplest model there is
//
String jungle_file = "C:/Users/acer/workspace/paletrasi/src/paletrasi/junglejena.owl";
// create Pellet reasoner
Reasoner reasoner = PelletReasonerFactory.theInstance().create();
// create an empty model
Model emptyModel = ModelFactory.createDefaultModel( );
//create an inferencing model using Pellet reasoner
InfModel m = ModelFactory.createInfModel( reasoner, emptyModel );
//read the file
m.read( jungle_file );
//Model m = ModelFactory.createDefaultModel();
System.out.println( "We have loaded a model with no. statements = " + m.size() );
String jungle ="http://www.lirmm.fr/jungle#";
String prolog1 = "PREFIX jungle: <"+jungle+">" ;
String prolog2 = "PREFIX rdf: <"+RDF.getURI()+">" ;
//Query string.
String queryString = prolog1 + NL + prolog2 + NL +
"SELECT ?individu WHERE {?individu rdf:type jungle:Lion }" ;
Query query = QueryFactory.create(queryString) ;
//Print with line numbers
query.serialize(new IndentedWriter(System.out,true)) ;
System.out.println() ;
//Create a single execution of this query, apply to a model
//which is wrapped up as a Dataset
QueryExecution qexec = QueryExecutionFactory.create(query, m) ;
//Or QueryExecutionFactory.create(queryString, model) ;
System.out.println("Les Lions : ") ;
try {
//Assumption: it’s a SELECT query.
ResultSet rs = qexec.execSelect() ;
//The order of results is undefined.
for ( ; rs.hasNext() ; )
{
QuerySolution rb = rs.nextSolution() ;
//Get title - variable names do not include the ’?’
RDFNode y = rb.get("individu");
System.out.print("uri : "+y+"--- ");
Resource z = (Resource) rb.getResource("individu");
System.out.println("plus simplement "+z.getLocalName());
}
}
finally
{
//QueryExecution objects should be closed to free any system resources
    qexec.close() ;
    }
}}

错误是:

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/C:/Users/acer/Desktop/apache-jena-2.11.1/apache-jena-2.11.1/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/acer/Downloads/Compressed/pellet-2.3.1/pellet-2.3.1/lib/jena/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Exception in thread "main" org.apache.jena.riot.RiotException: <C:/Users/acer/workspace/paletrasi/src/paletrasi/junglejena.owl> Code: 11/LOWERCASE_PREFERRED in SCHEME: lowercase is preferred in this component
    at org.apache.jena.riot.system.IRIResolver.exceptions(IRIResolver.java:299)
    at org.apache.jena.riot.system.IRIResolver.access$000(IRIResolver.java:31)
    at org.apache.jena.riot.system.IRIResolver$IRIResolverNormal.resolve(IRIResolver.java:402)
    at org.apache.jena.riot.system.IRIResolver$IRIResolverSync.resolve(IRIResolver.java:437)
    at org.apache.jena.riot.system.IRIResolver.resolveIRI(IRIResolver.java:178)
    at org.apache.jena.riot.system.IRIResolver.resolveString(IRIResolver.java:169)
    at org.apache.jena.riot.RiotReader.createParser(RiotReader.java:128)
    at org.apache.jena.riot.RDFParserRegistry$ReaderRIOTFactoryImpl$1.read(RDFParserRegistry.java:141)
    at org.apache.jena.riot.RDFDataMgr.process(RDFDataMgr.java:859)
    at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:255)
    at org.apache.jena.riot.RDFDataMgr.read(RDFDataMgr.java:241)
    at org.apache.jena.riot.adapters.RDFReaderRIOT_Web.read(RDFReaderRIOT_Web.java:96)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.read(ModelCom.java:241)
    at paletrasi.jungle2.main(jungle2.java:32)

所有帮助都是apreciated :)提前谢谢你

2 个答案:

答案 0 :(得分:0)

NotFoundException: C:/Users/acer/workspace/paletrasi/src/paletrasi/jungleJena.owl#

正如它所说 - 没找到。 (为什么最后会有#?)

答案 1 :(得分:0)

此错误的解决方案 &#34;代码:11 / LOWERCASE_PREFERRED in SCHEME:在这个组件中首选小写&#34;  是用小写字母写的。&#34; c:/&#34;不是&#34; C:/&#34;。