使用Jena创建sparql查询时出现词汇错误。 以下是我的源代码。错误说 com.hp.hpl.jena.query.QueryParseException:第5行第92列的词法错误。遇到错误:“”(32),之后:“not”。
package mas;
import agent.core.onto.Ontology;
import com.hp.hpl.jena.ontology.OntDocumentManager;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
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.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import java.io.FileInputStream;
/**
*
* @author Naveed Khan
*/
public class NewClass {
public static void main(String arg[])
{
NewClass obj=new NewClass();
String PREFIX="PREFIX seo: <http://www.seontology.org/test/specificOnto.owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
Model m = obj.getModel();
String querystr=PREFIX +
" \n SELECT ?individualaff ?uc "
+ "WHERE { "
+ "?individualaff seo:Requirements_Content ?c. "
+ "filter not exists {?individualaff seo:hasUsecase ?uc } "
+ "}";
try
{
Query query = QueryFactory.create(querystr) ;
QueryExecution qexec = QueryExecutionFactory.create(query, m) ;
ResultSet results = qexec.execSelect() ;
QuerySolution soln = results.nextSolution() ;
}catch(Exception ex) {
ex.printStackTrace(); }
}
private OntModel getModel()
{
OntModel model = null;
if (model == null) {
model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
try {
model.read(new FileInputStream(agent.core.onto.Config.SOURCE_FILE), Ontology.BASE);
} catch (Exception e) {
System.out.println("Loading Model failed:"+ e);
}
}
if (model != null)
return model;
else
return null;
}
}
The error says
com.hp.hpl.jena.query.QueryParseException: Lexical error at line 5, column 92. Encountered: " " (32), after : "not".