这个程序可能会使用推理技术向本体中添加其他狮子个体推断出的推理,但我不知道如何解决返回的所有错误。的Java代码如下:如何在eclipse上用sparql查询推断新的人
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 :)谢谢你提前 。
我已经过期#但我得到一个exeption。请检查编辑以查看它。 – Nanis
@ user3347859如果原始错误是filenotfound,那么您不应该编辑问题并进行更改。这使得当前问题的原始问题的答案是错误的。 –