我正在使用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'作爲答案。 –