我正在使用jena对本体进行查询。我得到的结果,当我运行查询来获取有关分配数据属性的值对象,如下所示Student1
如何从sparql结果中提取数据属性值?
"Ashutosh"^^http://www.w3.org/2001/XMLSchema#string is not a URI node
,我应该怎么做,如果我想结果如下
"Ashutosh" or `Ashutosh`
这是我的Java码。如果我想要如上所述的答案,我该怎么办?
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
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.RDFNode;
import com.hp.hpl.jena.util.FileManager;
public class abc {
static String avg;
static String sq="Charlie";
static String tq="'";
static String data;
public static void main(String[] args) {
// TODO Auto-generated method stub
sparqltest();}
static void sparqltest()
{
FileManager.get().addLocatorClassLoader(abc.class.getClassLoader());
Model model= FileManager.get().loadModel("C:/Users/avg/workspacejena32/Jena/bin/ashu.rdf");
//System.out.println("Connected...");
String queryString="prefix avg:<http://www.semanticweb.org/avg/ontologies/2016/3/untitled-ontology-14#>" +
"prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>" +
"SELECT * WHERE {" +
"avg:Student1 avg:Name ?x . filter isLiteral(?x)" +
"}";
//System.out.println("Connected...");
Query query= QueryFactory.create(queryString);
QueryExecution qexec=QueryExecutionFactory.create(query, model);
try {
ResultSet rs = qexec.execSelect();
for (; rs.hasNext() ;)
{
QuerySolution soln = rs.nextSolution() ;
RDFNode a = soln.get("x") ;
data = a.asNode().getLocalName();
} }
catch(Exception e)
{
System.out.println(e.getMessage());
}
}
}
现在有什么问题?在没有看到代码的情况下很难提供帮助,但我想你不要在结果集上使用'getLiteral(“x”)'。 – AKSW
这是我的代码给出below.It给输出作为'“Ashutosh”^^ http://www.w3.org/2001/XMLSchema#string不是一个URI节点,但我只希望'Ashutosh'作为答案。 –