2014-04-04 18 views
-3

這個程序可能會使用推理技術向本體中添加其他獅子個體推斷出的推理,但我不知道如何解決返回的所有錯誤。的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 :)謝謝你提前 。

回答

0

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

正如它所說 - 未找到。 (爲什麼會出現#上結束了嗎?)

+0

我已經過期#但我得到一個exeption。請檢查編輯以查看它。 – Nanis

+0

@ user3347859如果原始錯誤是filenotfound,那麼您不應該編輯問題並進行更改。這使得當前問題的原始問題的答案是錯誤的。 –

0

解決這個錯誤 「代碼:在方案11/LOWERCASE_PREFERRED:小寫優選在此組件」 是寫在小寫即「C:/」不「C:/」。

+0

真的,這不應該是更像'file:// ...'的東西嗎? –