-- 作者:alexlinym
-- 发布时间:3/19/2011 7:53:00 PM
-- Jena rules reasoner通用规则推理不出东西来,是神马情况啊?大神快出现吧
test1.owl: <?xml version="1.0"?> <rdf:RDF xmlns:xsp="http://www.owl-ontologies.com/2005/08/07/xsp.owl#" xmlns:swrlb="http://www.w3.org/2003/11/swrlb#" xmlns:swrl="http://www.w3.org/2003/11/swrl#" xmlns:protege="http://protege.stanford.edu/plugins/owl/protege#" 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="http://www.owl-ontologies.com/Ontology1300450048.owl#" xmlns:owl="http://www.w3.org/2002/07/owl#" xml:base="http://www.owl-ontologies.com/Ontology1300450048.owl"> <owl:Ontology rdf:about=""/> <owl:Class rdf:ID="Leaf"> <rdfs:subClassOf> <owl:Restriction> <owl:allValuesFrom> <owl:Class rdf:ID="Branch"/> </owl:allValuesFrom> <owl:onProperty> <owl:ObjectProperty rdf:ID="is_part_of"/> </owl:onProperty> </owl:Restriction> </rdfs:subClassOf> </owl:Class> </rdf:RDF> <!-- Created with Protege (with OWL Plugin 3.4, Build 533) http://protege.stanford.edu --> test1.rules: [restriction:(?a rdf:type rdfs:Class),(?b rdf:type rdfs:Class),(?c rdf:type owl:ObjectProperty),(?b owl:onProperty ?c),(?b owl:allValuesFrom ?d),(?a rdfs:subClassOf ?b)-> (?a owl:onProperty ?c),(?a owl:allValuesFrom ?d)] 其中(?b rdf:type rdfs:Class),我用过(?b rdf:type owl:Restriction),也达不到效果 package myfinaltest; import com.hp.hpl.jena.rdf.model.*; import com.hp.hpl.jena.util.FileManager; import com.hp.hpl.jena.util.PrintUtil; import com.hp.hpl.jena.util.iterator.ExtendedIterator; import com.hp.hpl.jena.reasoner.rulesys.Rule; import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner; import java.util.List; import java.io.InputStream; public class myfinaltest { public static void main(String[] args) { String BaseURI = "http://www.owl-ontologies.com/Ontology1300450048.owl#"; PrintUtil.registerPrefix("Base", BaseURI); String filename="file:F:\\ontology\\test1.owl"; String spacename="http://www.owl-ontologies.com/Ontology1300450048.owl#"; String name="Leaf"; InputStream in=FileManager.get().open(filename); Model model=ModelFactory.createDefaultModel(); model.read(in,""); //Print Statement before reasoning in Model model ExtendedIterator iter_1=model.listStatements(); int Count1=0; while(iter_1.hasNext()){ Count1++; System.out.println("Statement"+Count1+":"+PrintUtil.print(iter_1.next())); } System.out.println(); //Load Rules List rules=Rule.rulesFromURL("file:F:\\ontology\\test1.rules"); GenericRuleReasoner reasoner = new GenericRuleReasoner(rules); reasoner.setOWLTranslation(true); reasoner.setTransitiveClosureCaching(true); InfModel infmodel = ModelFactory.createInfModel(reasoner, model); //infmodel.write(System.out, "N-TRIPLE"); //Print Statement after reasoning in Model infmodel Resource resource_2=infmodel.getResource(spacename+name); ExtendedIterator iter_2=infmodel.listStatements(resource_2 ,null, (RDFNode)null); int Count2=0; while(iter_2.hasNext()){ Count2++; System.out.println("Statement"+Count2+":"+PrintUtil.print(iter_2.next())); } } } 输出: Statement1:(Base:is_part_of rdf:type owl:ObjectProperty) Statement2:(Base:Branch rdf:type owl:Class) Statement3:(http://www.owl-ontologies.com/Ontology1300450048.owl rdf:type owl:Ontology) Statement4:(Base:Leaf rdfs:subClassOf -14789782:12ece00b99e:-7fff) Statement5:(Base:Leaf rdf:type owl:Class) Statement6:(-14789782:12ece00b99e:-7fff owl:onProperty Base:is_part_of) Statement7:(-14789782:12ece00b99e:-7fff owl:allValuesFrom Base:Branch) Statement8:(-14789782:12ece00b99e:-7fff rdf:type owl:Restriction) Statement1:(Base:Leaf rdfs:subClassOf -14789782:12ece00b99e:-7fff) Statement2:(Base:Leaf rdf:type owl:Class) Statement3:(Base:Leaf rdfs:subClassOf Base:Leaf) 我想得到的是: Statement1:(Base:Leaf owl:onProperty Base:is_part_of) Statement2:(Base:Leaf owl:allValuesFrom Base:Branch) 我参考的是http://blog.csdn.net/java_2005/archive/2010/05/28/5630205.aspx
|