以文本方式查看主题 - 中文XML论坛 - 专业的XML技术讨论区 (http://bbs.xml.org.cn/index.asp) -- 『 Semantic Web(语义Web)/描述逻辑/本体 』 (http://bbs.xml.org.cn/list.asp?boardid=2) ---- racer如何在程序中实现对本体推理 (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=74384) |
-- 作者:lixiaoming -- 发布时间:4/20/2009 10:24:00 PM -- racer如何在程序中实现对本体推理 使用例子DIGExample.java import com.hp.hpl.jena.ontology.*; import com.hp.hpl.jena.rdf.model.*; import com.hp.hpl.jena.reasoner.ReasonerRegistry; import com.hp.hpl.jena.reasoner.dig.*; import com.hp.hpl.jena.vocabulary.*; ReasonerVocabulary.EXT_REASONER_URL |
-- 作者:jpz6311whu -- 发布时间:4/21/2009 12:07:00 AM -- m.read( "file:///c:/newAnimal.owl" ); 这读进来之后,把里面三元组打印出来看看,也许已经推理出来了 |
-- 作者:lixiaoming -- 发布时间:4/21/2009 9:12:00 AM -- 按照您的方法,我在后面加入了如下代码: m.read( "file:///c:/newAnimal.owl" ); for (Iterator i = m.listClasses(); i.hasNext();) { OntClass c = (OntClass) i.next(); System.out.println(c.getLocalName()); System.out.println(c.getLocalName() + " is belong to " + c.getSuperClass()); } 打印出来的结果似乎不对: Animal Animal is belong to http://www.w3.org/2002/07/owl#Thing Herbivore Herbivore is belong to http://www.owl-ontologies.com/unnamed.owl#Animal Leaf Leaf is belong to -5d102e05:120c6343cbd:-7ff9 null null is belong to -5d102e05:120c6343cbd:-7ff4 null null is belong to http://www.w3.org/2002/07/owl#Thing Lion Lion is belong to -5d102e05:120c6343cbd:-7ff6 Tree Tree is belong to http://www.owl-ontologies.com/unnamed.owl#Plant null null is belong to http://www.w3.org/2002/07/owl#Thing null null is belong to http://www.w3.org/2002/07/owl#Thing Plant Plant is belong to http://www.w3.org/2002/07/owl#Thing null null is belong to -5d102e05:120c6343cbd:-7ffa null null is belong to http://www.w3.org/2002/07/owl#Thing Giraffe Giraffe is belong to -5d102e05:120c6343cbd:-7ff8 Branch Branch is belong to -5d102e05:120c6343cbd:-7ff7 null null is belong to http://www.owl-ontologies.com/unnamed.owl#Animal Carnivore Carnivore is belong to http://www.owl-ontologies.com/unnamed.owl#Animal |
-- 作者:lixiaoming -- 发布时间:4/21/2009 9:17:00 AM -- 这里是我的本体文件的代码: <?xml version="1.0"?> <rdf:RDF xml:base="http://www.owl-ontologies.com/unnamed.owl" xmlns="http://www.owl-ontologies.com/unnamed.owl#" xmlns:owl="http://www.w3.org/2002/07/owl#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#"> <owl:Ontology rdf:about=""/> <owl:Class rdf:ID="Animal"> <owl:disjointWith> <owl:Class rdf:ID="Plant"/> </owl:disjointWith> </owl:Class> <owl:Class rdf:ID="Herbivore"> <rdfs:subClassOf rdf:resource="#Animal"/> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty> <owl:ObjectProperty rdf:ID="eat"/> </owl:onProperty> <owl:allValuesFrom> <owl:Class rdf:about="#Plant"/> </owl:allValuesFrom> </owl:Restriction> </rdfs:subClassOf> </owl:Class> <owl:Class rdf:about="#Plant"> <owl:disjointWith rdf:resource="#Animal"/> </owl:Class> <owl:Class rdf:ID="Leaf"> <rdfs:subClassOf rdf:resource="#Plant"/> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty> <owl:TransitiveProperty rdf:ID="is_part_of"/> </owl:onProperty> <owl:allValuesFrom> <owl:Class rdf:ID="Branch"/> </owl:allValuesFrom> </owl:Restriction> </rdfs:subClassOf> </owl:Class> <owl:Class rdf:ID="Giraffe"> <rdfs:subClassOf> <owl:Restriction> <owl:onProperty> <owl:ObjectProperty rdf:about="#eat"/> </owl:onProperty> <owl:allValuesFrom rdf:resource="#Leaf"/> </owl:Restriction> </rdfs:subClassOf> <rdfs:subClassOf rdf:resource="#Herbivore"/> </owl:Class> <owl:Class rdf:about="#Branch"> <rdfs:subClassOf rdf:resource="#Plant"/> <rdfs:subClassOf> <owl:Restriction> <owl:allValuesFrom> <owl:Class rdf:ID="Tree"/> </owl:allValuesFrom> <owl:onProperty> <owl:TransitiveProperty rdf:about="#is_part_of"/> </owl:onProperty> </owl:Restriction> </rdfs:subClassOf> </owl:Class> <owl:Class rdf:ID="Lion"> <rdfs:subClassOf> <owl:Class rdf:ID="Carnivore"/> </rdfs:subClassOf> <rdfs:subClassOf> <owl:Restriction> <owl:allValuesFrom rdf:resource="#Herbivore"/> <owl:onProperty> <owl:ObjectProperty rdf:about="#eat"/> </owl:onProperty> </owl:Restriction> </rdfs:subClassOf> </owl:Class> <owl:Class rdf:about="#Carnivore"> <owl:equivalentClass> <owl:Class> <owl:intersectionOf rdf:parseType="Collection"> <owl:Restriction> <owl:onProperty> <owl:ObjectProperty rdf:ID="maineat"/> </owl:onProperty> <owl:allValuesFrom rdf:resource="#Animal"/> </owl:Restriction> <owl:Class rdf:about="#Animal"/> </owl:intersectionOf> </owl:Class> </owl:equivalentClass> </owl:Class> <owl:Class rdf:about="#Tree"> <rdfs:subClassOf rdf:resource="#Plant"/> </owl:Class> <owl:ObjectProperty rdf:ID="eated"> <owl:inverseOf> <owl:ObjectProperty rdf:about="#eat"/> </owl:inverseOf> </owl:ObjectProperty> <owl:ObjectProperty rdf:about="#maineat"> <rdfs:subPropertyOf> <owl:ObjectProperty rdf:about="#eat"/> </rdfs:subPropertyOf> </owl:ObjectProperty> <owl:ObjectProperty rdf:about="#eat"> <owl:inverseOf rdf:resource="#eated"/> </owl:ObjectProperty> <owl:TransitiveProperty rdf:about="#is_part_of"> <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#ObjectProperty"/> </owl:TransitiveProperty> </rdf:RDF> <!-- Created with Protege (with OWL Plugin 2.1, Build 284) http://protege.stanford.edu --> |
-- 作者:jpz6311whu -- 发布时间:4/22/2009 11:10:00 AM -- c.getSuperClass()只能得到一个父类,楼主试试使用listSuperClass()将Lion的所有父类打印出来看看 |
W 3 C h i n a ( since 2003 ) 旗 下 站 点 苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》 |
109.375ms |