以文本方式查看主题 - 计算机科学论坛 (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=36821) |
-- 作者:sophia-rener -- 发布时间:8/15/2006 11:30:00 PM -- 请教:用sparql进行检索,检索总是没有结果。哪位大侠帮帮我啊! ![]() 我是要检索一个药的本体:部分代码如下: <?xml version="1.0"?> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns="http://www.owl-ontologies.com/unnamed.owl#" xml:base="http://www.owl-ontologies.com/unnamed.owl"> 。。。。。。。 <Medicine rdf:ID="Carbasalate_Calcium"> <use_for rdf:resource="#Fever"/> <use_for rdf:resource="#Headache"/> </Medicine> 我想找出这个药能治疗的疾病,我的sparql是这样的 String queryString = "SELECT ?jibing " + "WHERE {" + " /"Carbasalate_Calcium/" <use_for> ?jibing. " + " }"; Query query = QueryFactory.create(queryString); QueryExecution qe = QueryExecutionFactory.create(query, infModel); ResultSet results = qe.execSelect(); ResultSetFormatter.out(System.out, results, query); qe.close(); 不知道是哪里出错了,是不是因为没有加前缀,如果要加前缀,应该怎么家呢,帮帮我啊! |
-- 作者:lqm -- 发布时间:8/16/2006 12:26:00 AM -- 我也正在研究如何用SPARQL查询OWL,我们共同研究,多交流哈!!!! 我曾经也提过这样的问题:有位大侠已经帮我解答了一部分,多交流!!! 请参考:::“请问大侠:我在用SPARQL查询RDF模型时遇到的困难,求救”有一些提示哈 |
-- 作者:sophia-rener -- 发布时间:8/16/2006 9:31:00 AM -- 谢谢楼上的提示,我去看了一下,我之前做过向你这样的查询,可以输出结果,但是但是我用的本体是人家的,这次,我是自己做了一个本体和实例,然后对他们进行查询,结果就出不来了。 |
-- 作者:jpz6311whu -- 发布时间:8/16/2006 10:07:00 AM -- 楼主到底要问什么? 如果你问sparql语法中前缀的使用方法,请看 http://www.w3.org/TR/rdf-sparql-query/ 如果你问程序的问题,那么请把完整的程序代码贴出来,以及完整的详细报错贴出来,而且要把owl/rdf文件内容贴出来。 |
-- 作者:sophia-rener -- 发布时间:8/16/2006 10:51:00 AM -- 没有报错阿 就是没有结果 |
-- 作者:sophia-rener -- 发布时间:8/16/2006 10:56:00 AM -- 我的本体和实例是分开放的,然后建立了一个推理模型。接着就是查询,执行没有出错,就是没有结果,但是明明有符合条件的呢,我不知道是哪里出错了 Reasoner owlReasoner = ReasonerRegistry.getOWLReasoner(); Reasoner medReasoner = owlReasoner.bindSchema(m); //Use the reasoner to create a inference model InfModel infModel = ModelFactory.createInfModel(medReasoner, medicineIns); |
-- 作者:sophia-rener -- 发布时间:8/16/2006 11:19:00 AM -- 代码如下: 结果是: ---------------------------------- | zhengzhuang1 | ================ --------------------------------- - public class FindInferredHypernyms { public static void main(String[] args) { InputStream ins = null; 。。。。。。 Model medicineIns = ModelFactory.createMemModelMaker().createDefaultModel(); medicineIns.read(ins,null); // null base URI, since model URIs are absolute 。。。 OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null ); m.read( "http://www.w3.org/2001/sw/WebOnt/guide-src/medicine" ); // Important - free up resources used running the query
[此贴子已经被作者于2006-8-16 12:16:45编辑过]
|
-- 作者:lqm -- 发布时间:8/16/2006 11:26:00 AM -- 我确实想看看你是怎么查询OWL的,我们遇到的问题是一样的哈 只是我还没有看到任何一个OWL的查询结果,很想知道你是怎么弄的啊! 盼望你你演示一下你是怎么查询的哈!!!! |
-- 作者:jpz6311whu -- 发布时间:8/16/2006 11:38:00 AM -- "SELECT ?zhengzhuang1 " + "WHERE {" + " ?zhengzhuang1 <may_couse> ?V. " + " }"; 其中<may_couse>肯定不对,应该写完整的uri |
-- 作者:sophia-rener -- 发布时间:8/16/2006 12:09:00 PM -- 嗬嗬,果然是高手啊!谢谢啊, 加一个前缀就可以了,问题解决了 再弱弱的问一下BASE <http://www.owl-ontologies.com/unnamed.owl> |
-- 作者:jpz6311whu -- 发布时间:8/16/2006 12:40:00 PM -- 2.1.1 Syntax for IRIs The terms delimited by "<>" are IRI references [RFC3987]. They stand for IRIs, either directly, or relative to a base IRI. IRIs are a generalization of URIs [RFC3986] and are fully compatible with URIs and URLs. SPARQL provides two abbreviation mechanisms for IRIs, prefixed names and relative IRIs. Prefixed names Relative IRIs The BASE keyword defines the Base IRI used to resolve relative IRIs per RFC3986 section 5.1.1, "Base URI Embedded in Content". Section 5.1.2, "Base URI from the Encapsulating Entity" defines how the Base IRI may come from an encapsulating document, such as a SOAP envelope with an xml:base directive, or a mime multipart document with a Content-Location header. The "Retrieval URI" identified in 5.1.3, Base "URI from the Retrieval URI", is the URL from which a particular SPARQL query was retrieved. If none of the above specifies the Base URI, the default Base URI (section 5.1.4, "Default Base URI") is used. from |
-- 作者:lqm -- 发布时间:8/16/2006 2:59:00 PM -- 楼主你好,看着你已经找到问题的答案,我好是羡慕啊!! 把你的代码和本体文件全部贴出来让我也好好学习一下好吗???? 我也很想知道怎么做的,我盼望你的指点。。。。。 谢谢!!!! |
-- 作者:lqm -- 发布时间:8/16/2006 10:14:00 PM -- 我也从你的问题中学到了不少知识!!! 谢谢! |
-- 作者:sophia-rener -- 发布时间:8/18/2006 11:49:00 AM -- to: jpz6311whu 谢谢你给我提供的帮助,又为我写论文节省了不少的时间. to:lqm |
-- 作者:lqm -- 发布时间:8/18/2006 3:06:00 PM -- 呵呵,谢谢你得问题,我已经从你们的交流中,找到了启发!!! |
-- 作者:ddl338 -- 发布时间:8/30/2006 7:18:00 PM -- String queryString = "BASE <" + myNS + "> " + "SELECT DISTINCT ?x1 ?x2 " + "WHERE { " + "{?X <from> ?x1. " + "?X <to> ?x2. " + "?X <come> <"+num+">.} UNION " + "{?X <from> ?x2. " + "?X <to> ?x1. " + "?X <go> <"+num+">.} " + "}"; myNS是你的uri |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
140.625ms |