簡體   English   中英

Pellet + Jena + SPARQL + com.hp.hpl.jena.query.QueryParseException:遇到了“ <PNAME_LN> “RDFS:域

[英]Pellet + Jena + SPARQL + com.hp.hpl.jena.query.QueryParseException: Encountered “ <PNAME_LN> ”rdfs:domain

com.hp.hpl.jena.query.QueryParseException: Encountered " <PNAME_LN> "rdfs:domain.的問題是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);
    }
}

該代碼在前三個查詢中效果很好,但是添加了"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部分之后添加字母。

  1. 始終在查詢字符串中使用換行符。
  2. 在三元模式的末尾寫下空格. .

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM