简体   繁体   中英

how to deduce new individuals with sparql query on eclipse

this program might use the inference technique for adding to the ontology other lion individuals deduced by inference but i don't know how to resolve all the errors returned. The java code is as follow:

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() ;
    }
}}

the errors are:

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)

all help is apreciated :) thank you in advance .

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

as it says - not found. (Why is there a # on the end?)

解决这个错误“代码:11/LOWERCASE_PREFERRED in SCHEME:lowercase is preferred in this component”是小写,即“c:/”而不是“C:/”。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM