以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  求助:新推理规则的建立的问题!!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=34356)


--  作者:wolf_xjf
--  发布时间:6/14/2006 3:30:00 AM

--  求助:新推理规则的建立的问题!!
小弟我创建了一个本体关系,里面有这样的属性关系:“老师”“教”“课程”(“Teacher”, “teach”,“Project”)和“学生”“选择”“课程”(“Student”,"elective","Project"),现在想创建新的属性关系:hasStudent,用以将前两个三元组合并生成新的三元组(“Teacher”,“hasStudent” ,“Student”),所以我建立了新的规则关系:String rules =  "[rule1: (?a hhu:teach ?b) (?c hhu:elective ?b) -> (?a hhu:hasStudent ?c)]";在程序中我也创建了新属性:Property hasStudent = schema.createProperty(hhu, "hasStudent");接下来我进行推理时程序没有任何结果显示。请大侠们帮我看看问题出在何处,推理程序如下:
 public static void main(String[] args) {
      String hhu = "http://www.hhu.edu.cn#";
   PrintUtil.registerPrefix("hhu", hhu);
      OntModel schema = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null );
      Model data = ModelFactory.createDefaultModel();
      schema.read("file:D:/java/testing/reasoners/bugs/hhuSchema2.owl");
      data.read ("file:D:/java/testing/reasoners/bugs/hhuData2.rdf");   
      Property hasStudent = schema.createProperty(hhu, "hasStudent");      
      String rules =  "[rule1: (?a hhu:teach ?b) (?c hhu:elective ?b) -> (?a hhu:hasStudent ?c)]";                
      Reasoner reasoner = new GenericRuleReasoner(Rule.parseRules(rules));
      InfModel infmodel = ModelFactory.createInfModel(reasoner,schema,data);
      Resource teacher = infmodel.getResource("http://www.hhu.edu.cn#Wang");
     for (StmtIterator i = infmodel.listStatements(teacher,hasStudent,(RDFNode)null); i.hasNext(); ) {
            Statement stmt = i.nextStatement();
            System.out.println(" - " + PrintUtil.print(stmt));
        }
      } 


--  作者:xiahousj
--  发布时间:6/14/2006 9:24:00 AM

--  
"[rule1: (?a hhu:teach ?b) (?c hhu:elective ?b) -> (?a hhu:hasStudent ?c)]";  

(?a hhu:teach ?b) 和(?c hhu:elective ?b)是什么关系?


--  作者:wolf_xjf
--  发布时间:6/14/2006 10:59:00 AM

--  
谢谢楼上,我是初学,不怎么知道这个规则到底该怎么写,(?a hhu:teach ?b) 和(?c hhu:elective ?b)分别指教课与选课关系,两者之间的关系,我不知道该怎么写,你能给我做些指点吗?


--  作者:xiahousj
--  发布时间:6/14/2006 2:13:00 PM

--  
我也是初学哈,我觉得你的这两个关系之间似乎缺少联结词哈。
--  作者:wolf_xjf
--  发布时间:6/14/2006 3:26:00 PM

--  
我把属性关系和规则集,改设为:     
      Property first = schema.createProperty(hhu, "concatFirst");
      Property second = schema.createProperty(hhu, "concatSecond");
      Property hasStudent = schema.createProperty(hhu, "hasStudent");
      Resource p = schema.getResource("http://www.hhu.edu.cn#teach");
      Resource q = schema.getResource("http://www.hhu.edu.cn#inv_elective");
      hasStudent.addProperty(first, p);


      hasStudent.addProperty(second, q);
              
      String rules = "[r1: (?c hhu:concatFirst ?p), (?c hhu:concatSecond ?q) -> " + "[r1b: (?x ?c ?y) <- (?x ?p ?z) (?z ?q ?y)] ]";
可还是不行啊!真的急死人啊!


--  作者:jpz6311whu
--  发布时间:6/14/2006 8:01:00 PM

--  
1、把file:D:/java/testing/reasoners/bugs/hhuSchema2.owl上传上来
2、把file:D:/java/testing/reasoners/bugs/hhuData2.rdf上传上来
--  作者:wolf_xjf
--  发布时间:6/14/2006 8:27:00 PM

--  
谢谢大侠
file:D:/java/testing/reasoners/bugs/hhuSchema2.owl如下:
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF
          [<!ENTITY hhu "http://www.hhu.edu.cn#">
           <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
           <!ENTITY owl "http://www.w3.org/2002/07/owl#">]>
<rdf:RDF xmlns = "&hhu;"
         xmlns:hhu = "&hhu;"
         xml:base = "&hhu;"
         xmlns:xsd = "http://www.w3.org/2001/XMLSchema#"
         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#">

<owl:Ontology rdf:about="">
    <rdfs:comment>An example OWL ontology</rdfs:comment>
      <rdfs:comment>Derived from the DAML Wine ontology at
      http://ontolingua.stanford.edu/doc/chimaera/ontologies/wines.daml
      Substantially changed, in particular the Region based relations.
    </rdfs:comment>
    <rdfs:label>owlDemoSchema</rdfs:label>
</owl:Ontology>

<owl:Class rdf:ID = "Teacher">
  <rdfs:subClassOf>
    <rdf:Description>
      <owl:intersectionOf rdf:parseType="Collection">
        <owl:Restriction>
          <owl:onProperty rdf:resource="#hasTNo" />
          <owl:allvaluesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
          <owl:maxCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxCardinality>
          <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
        </owl:Restriction>
        <owl:Restriction>
          <owl:onProperty rdf:resource="#hasPosition" />  
          <owl:allvaluesFrom rdf:resource="#Position" />
        </owl:Restriction>
        <owl:Restriction>
          <owl:onProperty rdf:resource="#teach" />  
          <owl:allvaluesFrom rdf:resource="#Project" />
        </owl:Restriction>
      </owl:intersectionOf>
    </rdf:Description>
  </rdfs:subClassOf>
</owl:Class>


<owl:Class rdf:ID = "Mentor">  
  <rdfs:subClassOf>
    <rdf:Description>
      <owl:intersectionOf rdf:parseType="Collection">
        <owl:Class rdf:about= "#Teacher"/>
        <owl:Restriction>
           <owl:unionOf rdf:parseType="Collection">
             <owl:Restriction>
               <owl:onProperty rdf:resource="#hasPosition" />  
               <owl:hasvalue rdf:resource="#AssociateProfessor" />
             </owl:Restriction>
             <owl:Restriction>
               <owl:onProperty rdf:resource="#hasPosition" />  
               <owl:hasvalue rdf:resource="#Professor" />
             </owl:Restriction>
           </owl:unionOf>
        </owl:Restriction>
      </owl:intersectionOf>
    </rdf:Description>
  </rdfs:subClassOf>
</owl:Class>
  
<owl:Class rdf:ID = "Student">
  <rdfs:subClassOf>
    <rdf:Description>
      <owl:intersectionOf rdf:parseType="Collection">
        <owl:Restriction>
          <owl:onProperty rdf:resource="#hasSNo" />
          <owl:allvaluesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
          <owl:maxCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxCardinality>
          <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
        </owl:Restriction>
        <owl:Restriction>
          <owl:onProperty rdf:resource="#elective" />  
          <owl:allvaluesFrom rdf:resource="#Project" />
        </owl:Restriction>
      </owl:intersectionOf>
    </rdf:Description>
  </rdfs:subClassOf>
</owl:Class>

<owl:Class rdf:ID = "GradurateStudent">
  <rdfs:subClassOf>
    <owl:Class rdf:about = "#Student"/>
  </rdfs:subClassOf>
  <rdfs:subClassOf>
     <owl:Restriction>
        <owl:onProperty rdf:resource="#hasMentor" />
        <owl:allvaluesFrom rdf:resource="#Mentor" />
        <owl:maxCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxCardinality>
        <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
     </owl:Restriction>
  </rdfs:subClassOf>              
</owl:Class>

<owl:Class rdf:ID = "Project">
  <rdfs:subClassOf>
    <owl:Restriction>
      <owl:onProperty rdf:resource="#hasNo" />
      <owl:allvaluesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
      <owl:maxCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxCardinality>
      <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
    </owl:Restriction>
  </rdfs:subClassOf>
  <rdfs:subClassOf>
     <owl:Restriction>
        <owl:onProperty rdf:resource="#hasCredit" />
        <owl:allvaluesFrom rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
        <owl:maxCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:maxCardinality>
        <owl:minCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">1</owl:minCardinality>
     </owl:Restriction>
  </rdfs:subClassOf>
  <rdfs:subClassOf>
     <owl:Restriction>
        <owl:onProperty rdf:resource="#inv_elective" />
        <owl:allvaluesFrom rdf:resource="#Student"/>
     </owl:Restriction>
  </rdfs:subClassOf>   
</owl:Class>

<owl:Class rdf:ID = "Region">
  <owl:oneOf rdf:parseType="Collection">
    <owl:Thing rdf:about="#GC"/>
    <owl:Thing rdf:about="#SL"/>
    <owl:Thing rdf:about="#KX"/>
    <owl:Thing rdf:about="#SD"/>
  </owl:oneOf>
</owl:Class>


<owl:Class rdf:ID = "Position">
  <owl:oneOf rdf:parseType="Collection">
    <owl:Thing rdf:about="#AssociateProfessor"/>
    <owl:Thing rdf:about="#Professor"/>
    <owl:Thing rdf:about="#NomalTeacher"/>
  </owl:oneOf>
</owl:Class>

<owl:DatatypeProperty rdf:ID="hasTNo">
   <rdfs:domain rdf:resource="#Teacher" />
   <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:ID="hasSNo">
   <rdfs:domain rdf:resource="#Student" />
   <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string" />
</owl:DatatypeProperty>

<owl:DatatypeProperty rdf:ID="hasNo">
   <rdfs:domain rdf:resource="#Project" />
   <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string" />
</owl:DatatypeProperty>

<owl:ObjectProperty rdf:ID="hasPosition">
   <rdfs:domain rdf:resource="#Teacher" />
   <rdfs:range rdf:resource="#Position" />
</owl:ObjectProperty>


<owl:ObjectProperty rdf:ID="hasMentor">
   <rdfs:domain rdf:resource="#GradurateStudent" />
   <rdfs:range rdf:resource="#Mentor" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="teach">
   <rdfs:domain rdf:resource="#Teacher"/>
   <rdfs:range rdf:resource="#Project"/>
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="inv_elective">
    <rdfs:domain rdf:resource="#Project"/>
    <rdfs:range rdf:resource="#Student"/>
    <owl:inverseOf rdf:resource="#elective"/>
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="elective">
   <rdfs:domain rdf:resource="#Student"/>
   <rdfs:range rdf:resource="#Project" />
</owl:ObjectProperty>

<owl:ObjectProperty rdf:ID="hasCredit">
   <rdfs:domain rdf:resource="#Project"/>
   <rdfs:range rdf:resource="http://www.w3.org/2001/XMLSchema#string" />   
</owl:ObjectProperty>    

</rdf:RDF>
file:D:/java/testing/reasoners/bugs/hhuData2.rdf
<?xml version="1.0"?>
<!DOCTYPE rdf:RDF
          [<!ENTITY hhu "http://www.hhu.edu.cn#">
           <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#">
           <!ENTITY owl "http://www.w3.org/2002/07/owl#">]>
<rdf:RDF xmlns = "&hhu;"
         xmlns:hhu = "&hhu;"
         xml:base = "&hhu;"
         xmlns:xsd = "http://www.w3.org/2001/XMLSchema#"
         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#">

<Mentor rdf:ID="Wang">
  <hasTNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">9806</hasTNo>
  <hasPosition rdf:resource="#Professor"/>
  <teach rdf:resource="#ComputerScience"/>
</Mentor>

<Mentor rdf:ID="Wan">
  <hasTNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">9901</hasTNo>
  <hasPosition rdf:resource="#AssociateProfessor"/>
  <teach rdf:resource="#Network"/>
</Mentor>

<Mentor rdf:ID="Chen">
  <hasTNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">9703</hasTNo>
  <hasPosition rdf:resource="#Professor"/>
  <teach rdf:resource="#Software"/>
  <teach rdf:resource="#Compiler"/>
</Mentor>

<Teacher rdf:ID="Li">
  <hasTNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0102</hasTNo>
  <hasPosition rdf:resource="#NomalTeacher"/>
  <teach rdf:resource="#English"/>
</Teacher>


<Teacher rdf:ID="Zhang">
  <hasTNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0423</hasTNo>
  <hasPosition rdf:resource="#NomalTeacher"/>
  <teach rdf:resource="#AI"/>
  <teach rdf:resource="#Communicate"/>
</Teacher>

<Student rdf:ID="Yang">
  <hasSNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0203</hasSNo>
  <elective rdf:resource="#English"/>
  <elective rdf:resource="#Network"/>
  <elective rdf:resource="#Software"/>
</Student>

<Student rdf:ID="Yin">
  <hasSNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0231</hasSNo>
  <elective rdf:resource="#AI"/>
  <elective rdf:resource="#Compiler"/>
  <elective rdf:resource="#Communicate"/>
</Student>

<GradurateStudent rdf:ID="lu" >
  <hasSNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0502</hasSNo>
  <hasMentor rdf:resource="Wang"/>
  <hasMentor>
    <rdf:Description rdf:about="#Dean"/>
  </hasMentor>
  <elective rdf:resource="#AI"/>
  <elective rdf:resource="#Compiler"/>
</GradurateStudent>

<Project rdf:ID="English">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">001</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">16</hasCredit>
</Project>

<Project rdf:ID="ComputerScience">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">003</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">16</hasCredit>
</Project>

<Project rdf:ID="Network">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">027</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</hasCredit>
</Project>

<Project rdf:ID="Communicate">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">043</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">20</hasCredit>
</Project>

<Project rdf:ID="AI">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">016</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</hasCredit>
</Project>

<Project rdf:ID="Software">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">032</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">10</hasCredit>
</Project>

<Project rdf:ID="Compiler">
<hasNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">022</hasNo>
<hasCredit rdf:datatype="http://www.w3.org/2001/XMLSchema#string">16</hasCredit>
</Project>

</rdf:RDF>


谢谢大侠帮我看看!


--  作者:wolf_xjf
--  发布时间:6/15/2006 10:42:00 PM

--  
晕,就这么沉了!老大,
--  作者:jpz6311whu
--  发布时间:6/16/2006 12:14:00 AM

--  
有三元组:Wang teach #ComputerScience
但是没有学生学#ComputerScience这门课
我把学生Yang改了一下:
<Student rdf:ID="Yang">
  <hasSNo rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0203</hasSNo>
  <elective rdf:resource="#English"/>
  <elective rdf:resource="#Network"/>
  <elective rdf:resource="#ComputerScience"/>
</Student>

结果打出来了:
- (hhu:Wang hhu:hasStudent hhu:Yang)

所以程序没有问题,规则没有问题,是示例数据没有,所以没有结果。


--  作者:wolf_xjf
--  发布时间:6/16/2006 3:47:00 AM

--  
谢了老大!真的很是感谢!!!
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
108.887ms