我得到的问题是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。由于兼容性,我无法更改耶拿的版本。 这是代码:
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."
后,问题立即出现。该代码也适用于单独的"seaice:describe rdfs:domain ?domain.
"。错误如下:
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)
一长行引入了一个错误。 您的查询中只有一个术语:"seaice:Day.seaice:describe
"。 DOT(.
)在prefix
本地名称中是合法的,因此在DOT后面添加字母会将其放在local
部分。
- 始终在查询字符串中使用换行符。
- 在三重模式的末尾写空格点:
.
不.