以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 Semantic Web(语义Web)/描述逻辑/本体 』 (http://bbs.xml.org.cn/list.asp?boardid=2) ---- [求助]怎么处理SPARQL查询的结果 (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=61472) |
-- 作者:hmghm -- 发布时间:4/17/2008 1:47:00 PM -- [求助]怎么处理SPARQL查询的结果 使用SPARQL语句查出自己所需要的结果以后,要取其中的数据来用,有什么方法呀?ResultSetFormatter.out()能输出一个数据格式和结果,我只要其中的结果.谢谢 |
-- 作者:jpz6311whu -- 发布时间:4/17/2008 4:46:00 PM -- The application API is in the package com.hp.hpl.jena.query. Other packages contain various parts of the system (execution engine, parsers, testing etc). Most applications will only need to use the main package. Only applications wishing to programmatically build queries or modify the behaviour of the query engine need to use the others packages directly. Key Classes Query - a class that represents the application query. It is a container for all the details of the query. Objects of class Query are normally created by calling one of the methods of QueryFactory methods which provide access to the various parsers. import com.hp.hpl.jena.query.* ; Model model = ... ; String queryString = " .... " ; Query query = QueryFactory.create(queryString) ; QueryExecution qexec = QueryExecutionFactory.create(query, model) ; try { ResultSet results = qexec.execSelect() ; for ( ; results.hasNext() ; ) { QuerySolution soln = results.nextSolution() ; RDFNode x = soln.get("varName") ; // Get a result variable by name. Resource r = soln.getResource("VarR") ; // Get a result variable - must be a resource Literal l = soln.getLiteral("VarL") ; // Get a result variable - must be a literal } } finally { qexec.close() ; } The step of creating a query and then a query execution can be reduced to one step in some common cases: import com.hp.hpl.jena.query.* ; Model model = ... ; String queryString = " .... " ; QueryExecution qexec = QueryExecutionFactory.create(queryString, model) ; try { ResultSet results = qexec.execSelect() ; . . . } finally { qexec.close() ; } Example: processing results to produce a simple text presentation: ResultSetFormatter fmt = new ResultSetFormatter(results, query) ; fmt.printAll(System.out) ; ResultSetFormatter.out(System.out, results, query) ; CONSTRUCT Queries Query query = QueryFactory.create(queryString) ;QueryExecution qexec = QueryExecutionFactory.create(query, model) ;Model resultModel = qexec.execConstruct() ;qexec.close() ; Query query = QueryFactory.create(queryString) ;QueryExecution qexec = QueryExecutionFactory.create(query, model) ;Model resultModel = qexec.execDescribe() ;qexec.close() ; Query query = QueryFactory.create(queryString) ;QueryExecution qexec = QueryExecutionFactory.create(query, model) ;boolean result = qexec.execAsk() ;qexec.close() ; Datasets String dftGraphURI = "file:default-graph.ttl" ;List namedGraphURIs = new ArrayList() ;namedGraphURIs.add("file:named-1.ttl") ;namedGraphURIs.add("file:named-2.ttl") ;Query query = QueryFactory.create(queryString) ;Dataset dataset = DatsetFactory.create(dftGraphURI, namedGraphURIs) ;QueryExecution qExec = QueryExecutionFactory.create(query, dataset) ;try { ... }finally { qExec.close() ; } DataSource dataSource = DatsetFactory.create() ;dataSource.setDefaultModel(model) ;dataSource.addNamedModel("http://example/named-1", modelX) ;dataSource.addNamedModel("http://example/named-2", modelY) ;QueryExecution qExec = QueryExecutionFactory.create(query, dataSource) ; ARQ Documentation Page |
-- 作者:hmghm -- 发布时间:4/18/2008 7:35:00 PM -- 谢谢,我先试试 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
31.982ms |