我遇到的问题是com.hp.hpl.jena.query.QueryParseException: Encountered " <PNAME_LN> "rdfs:domain.
这就是我做的。
我使用OWL API来读取xml / owl文档并使用Pellet来推理。因为除了理由我想做一些SPARQL查询,我使用Jena 2.10.0来处理Pellet 2.3.0。由于兼容性,我可以不更改Jena的版本。这是代码:
package loadOnto;
import java.io.File;
import org.mindswap.pellet.KnowledgeBase;
import org.mindswap.pellet.jena.PelletInfGraph;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;
import org.semanticweb.owlapi.model.OWLOntologyManager;
import com.clarkparsia.pellet.owlapiv3.PelletReasoner;
import com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.ModelFactory;
public class load {
public static void main(String[] args) throws OWLOntologyCreationException {
// Get hold of an ontology manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
// We can also load ontologies from files. Create a file object that points to the local copy
File file = new File("G:/Protege/owlfiles/Before_Gather.owl");
// Load the local copy
OWLOntology loadMODIS = manager.loadOntologyFromOntologyDocument(file);
PelletReasoner reasoner = PelletReasonerFactory.getInstance().createNonBufferingReasoner( loadMODIS );
//System.out.println("CheckParsing.should() " + reasoner.isConsistent());
KnowledgeBase kb = reasoner.getKB();
PelletInfGraph graph = new org.mindswap.pellet.jena.PelletReasoner().bind( kb );
InfModel model = ModelFactory.createInfModel( graph );
String PREFIX = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"PREFIX owl: <http://www.w3.org/2002/07/owl#>" +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +
"PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+
"PREFIX seaice: <http://www.semanticweb.org/SeaIceOntology#>" +
"PREFIX repr: <http://sweet.jpl.nasa.gov/2.3/reprDataFormat.owl#>" +
"PREFIX realmCryo: <http://sweet.jpl.nasa.gov/2.3/realmCryo.owl#>" +
"PREFIX relaMath: <http://sweet.jpl.nasa.gov/2.3/relaMath.owl#>";
String SELECT = "select ?domain ";
String WHERE = "where {" +
"?dataset seaice:hasSpatialResolution" + "\"4.0\"^^xsd:float." +
"?dataset seaice:hasDataFormat repr:GeoTIFF."+
"?dataset seaice:recordedDuring seaice:Day."+
"seaice:describe rdfs:domain ?domain."+
//"seaice:describe rdfs:range realmCryo:SeaIce."+
//"?dataset rdf:type ?domain." +
"}" ;
Query queryStr = QueryFactory.create(PREFIX + SELECT + WHERE);
QueryExecution qe = QueryExecutionFactory.create(queryStr, model);
ResultSet rs = qe.execSelect();
ResultSetFormatter.out(System.out,rs);
rs = null; qe.close();
reasoner.dispose();
//System.out.println("Loaded ontology: " + loadMODIS);
}
}
该代码适用于前3个查询,但在添加 "seaice:describe rdfs:domain ?domain."
后,问题立即发生。该代码也适用于&#34; seaice:describe rdfs:domain ?domain.
&#34;单独。错误如下:
Exception in thread "main" com.hp.hpl.jena.query.QueryParseException: Encountered " <PNAME_LN> "rdfs:domain "" at line 1, column 582.
Was expecting one of:
"values" ...
"graph" ...
"optional" ...
"minus" ...
"bind" ...
"service" ...
"filter" ...
"{" ...
"}" ...
";" ...
"," ...
"." ...
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.perform(ParserSPARQL11.java:102)
at com.hp.hpl.jena.sparql.lang.ParserSPARQL11.parse$(ParserSPARQL11.java:53)
at com.hp.hpl.jena.sparql.lang.SPARQLParser.parse(SPARQLParser.java:37)
at com.hp.hpl.jena.query.QueryFactory.parse(QueryFactory.java:156)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:79)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:52)
at com.hp.hpl.jena.query.QueryFactory.create(QueryFactory.java:40)
at loadOnto.load.main(load.java:65)
答案 0 :(得分:4)
一条长线引入了一个错误。您的查询只有一个字词:&#34; seaice:Day.seaice:describe
&#34;在里面。 DOT(.
)在prefix
本地名称内是合法的,因此在DOT之后添加字母会将其放在local
部分内。
.
而不是.