SPARQL查询中未解析的前缀名称:rdfs:subClassOf [英] Unresolved prefixed name: rdfs:subClassOf in SPARQL query
本文介绍了SPARQL查询中未解析的前缀名称:rdfs:subClassOf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;
import java.util.regex.*;
import java.io.*;
import com.hp.hpl.jena.sparql.*;
import com.hp.hpl.jena.*;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.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;
/*
<applet code="Sample" width=275 height=200>
</applet>
*/
//creating applet
public class Sample extends Applet implements ActionListener
{
TextField t;
String msg= " ";
String token[];
int s=60;
public void init()
{
setBackground(Color.gray);
Label qa=new Label("QA SYSTEM",Label.CENTER);
Button search=new Button("Search");
t=new TextField(25);
//Adding text box,button in to applet
add(qa);
add(t);
add(search);
t.addActionListener(this);
search.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
if(str.equals("Search"))
{
msg=t.getText() ;
Pattern pat=Pattern.compile("[ ?]");
String strs[]=pat.split(msg);
for(int i=0;i<strs.length;i++)
System.out.println("Token"+(i+1)+":"+strs[i]);
}
try
{
//opening owl file
InputStream in = new FileInputStream(new File("D:/ds.OWL"));
Model model=ModelFactory.createMemModelMaker().createDefaultModel() ;
model.read(in,null);
in.close();
String queryString ="SELECT ?ds ?o WHERE {?ds rdfs:subClassOf ?o }";
com.hp.hpl.jena.query.Query q = QueryFactory.create(queryString);
QueryExecution qe = QueryExecutionFactory.create(q, model);
ResultSet results = qe.execSelect();
while (results.hasNext())
{
System.out.println(results.getRowNumber() );
}
ResultSetFormatter.out(System.out, results, q);
qe.close();
}catch(Exception e){ System.out.println(e);}
repaint();
}
public void paint(Graphics g)
{
g.drawString("wait...",6,80);
}
}
错误:
com.hp.hpl.jena.query.QueryParseException:第1行,第27列: 未解析的前缀名称:rdfs:subClassOf
com.hp.hpl.jena.query.QueryParseException: Line 1, column 27: Unresolved prefixed name: rdfs:subClassOf
推荐答案
String queryString ="SELECT ?ds ?o WHERE {?ds rdfs:subClassOf ?o }";
应该是
String queryString ="PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?ds ?o WHERE {?ds rdfs:subClassOf ?o }";
这篇关于SPARQL查询中未解析的前缀名称:rdfs:subClassOf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文