以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  关于jena中GenericRuleReasoner的推理结果值返回  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=64505)


--  作者:skyhui
--  发布时间:7/9/2008 6:07:00 PM

--  关于jena中GenericRuleReasoner的推理结果值返回
各位高手:
       我想问的是:应用jena的自定义规则推理机(即GenericRuleReasoner)推理之后得到的结果, 其他模块如何调用?jena API中有无现成的函数?
      若无的话 则得修改哪个Jar包下的源代码?
      本体,规则如附件中所示。
        盼高人指点迷津!
        谢先。
--  作者:skyhui
--  发布时间:7/9/2008 6:09:00 PM

--  
这是我的两个模块----自定义模块和调用模块


自定义模块:
package jena.examples.ontology.persistentOntology;


import java.util.ArrayList;
import java.util.List;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.util.ModelLoader;

public class MakeRule{
public static void main(String[] args)
    {   getRuleInf();
   
      }
   public static List  getRuleInf(){  
    String xmlns = "http://www.owl-ontologies.com/manufacturing_ontology.owl#";
    String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
    String file = "D:/manufacturing_ontology.owl";
    
    Model data = ModelLoader.loadModel(file);
    
    

   List rules = Rule.rulesFromURL("file:D:/Jena-2.5.4/etc/myrules.rules");   
   GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
  
   reasoner.setOWLTranslation(true);   // not needed in RDFS case
      reasoner.setTransitiveClosureCaching(true);
   InfModel infModel = ModelFactory.createInfModel(reasoner,data);
   


   



  List list = new ArrayList();

  for ( StmtIterator i=
      infModel.listStatements(null,null,RDFnodes(null));
  i.hasNext();)
   {

     Statement stmt = i.nextStatement();
     list.add(stmt);

  
   }
  
  return list;
  
}

private static RDFNode RDFnodes(Object object) {
// TODO Auto-generated method stub
return null;
}


}


调用模块

package jena.examples.ontology.persistentOntology;

import java.util.ArrayList;
import java.util.List;

import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Statement;

public class Sparql {
public static void main(String[] args){
  String xmlns = "http://www.owl-ontologies.com/manufacturing_ontology.owl#";
  String rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#";
  String rdfs="http://www.w3.org/2000/01/rdf-schema#";
  // List list = OWLReasoner.getInfter();

   List list = MakeRule.getRuleInf();
  
   for(int i = 0; i< list.size();i++){
   Statement stmt = (Statement) list.get(i);
   
  

  }

  
}
}


--  作者:jpz6311whu
--  发布时间:7/10/2008 11:58:00 AM

--  
推理之后的结果就是那个InfModel infModel = ModelFactory.createInfModel(reasoner,data);
直接使用infModel就行了
--  作者:skyhui
--  发布时间:7/15/2008 4:30:00 PM

--  
假如不加 “infModel.write(System.out,"N3");”  得到的推理结果,也正是我想传递的。
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_13 '0.4'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_5 '0.9'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_10 '0.9'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_15 '0.9'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_2 '0.2'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_7 '0.7'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_12 '0.7'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_4 '0.8'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_9 '0.2'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_1 '0.9'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_6 '0.6'^^http://www.w3.org/2001/XMLSchema#float
http://www.owl-ontologies.com/manufacturing_ontology.owl#Supplier_3 '0.9'^^http://www.w3.org/2001/XMLSchema#float


假如加上 “infModel.write(System.out,"N3");” 得到的是很多不相关的本体信息。

调用infModel好像不行啊  jpz6311whu大哥


--  作者:jpz6311whu
--  发布时间:7/19/2008 7:02:00 PM

--  
你在哪一行加这个?
infModel.write(System.out,"N3");”
--  作者:skyhui
--  发布时间:7/21/2008 7:32:00 PM

--  
public class MakeRule{
public static void main(String[] args)
    {   getRuleInf();
   
      }
   public static List  getRuleInf(){  
    String xmlns = "http://www.owl-ontologies.com/manufacturing_ontology.owl#";
    String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
    String file = "D:/manufacturing_ontology.owl";
    
    Model data = ModelLoader.loadModel(file);
    
    

   List rules = Rule.rulesFromURL("file:D:/Jena-2.5.4/etc/myrules.rules");   
   GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
  
   reasoner.setOWLTranslation(true);   // not needed in RDFS case
      reasoner.setTransitiveClosureCaching(true);
   InfModel infModel = ModelFactory.createInfModel(reasoner,data);
   


   

infModel.write(System.out,"N3");




  List list = new ArrayList();

  for ( StmtIterator i=
      infModel.listStatements(null,null,RDFnodes(null));
  i.hasNext();)
   {

     Statement stmt = i.nextStatement();
     list.add(stmt);

  
   }
  
  return list;
  
}

private static RDFNode RDFnodes(Object object) {
// TODO Auto-generated method stub
return null;
}


}


--  作者:skyhui
--  发布时间:7/21/2008 7:34:00 PM

--  
我是在 List方法之前添了infModel.write(System.out,"N3");
位置如楼上所示

请大哥解答


--  作者:skyhui
--  发布时间:7/23/2008 12:45:00 PM

--  
各位高手,
   当“ infModel.getDeductionsModel();”放在程序的不同位置时,自定义规则推理结果也会相改变。
  应该是跟infModel有关,但是要用到里面的那个Api呢?
请高手指点。

p。s.:InfModel的各个方法都已经试过了  都不行啊


--  作者:skyhui
--  发布时间:7/23/2008 12:45:00 PM

--  
各位高手,
   当“ infModel.getDeductionsModel();”放在程序的不同位置时,自定义规则推理结果也会相改变。
  应该是跟infModel有关,但是要用到里面的那个Api呢?
请高手指点。

p。s.:InfModel的各个方法都已经试过了  都不行啊


--  作者:skyhui
--  发布时间:7/27/2008 9:56:00 AM

--  
各位大哥帮帮小弟啊,搞不定就不能像老板交差了。。。。。
--  作者:jpz6311whu
--  发布时间:7/27/2008 1:56:00 PM

--  
以下是引用skyhui在2008-7-23 12:45:00的发言:
各位高手,
    当“ infModel.getDeductionsModel();”放在程序的不同位置时,自定义规则推理结果也会相改变。
   应该是跟infModel有关,但是要用到里面的那个Api呢?
  请高手指点。

p。s.:InfModel的各个方法都已经试过了  都不行啊


infModel.getDeductionsModel();这条语句在哪里,在源代码里面看不到


--  作者:skyhui
--  发布时间:7/28/2008 12:45:00 PM

--  
是放在MakeRule模块中的;我用“System.out.println(“111111111111111”);”作记号,发现将“infModel.getDeductionsModel();”放在哪,则推理结果就出现在哪。
--  作者:skyhui
--  发布时间:7/28/2008 12:51:00 PM

--  
例如我将代码改成如下之后:

public class MakeRule{
public static void main(String[] args)
    {   getRuleInf();
   
      }
   public static List  getRuleInf(){  
    String xmlns = "http://www.owl-ontologies.com/manufacturing_ontology.owl#";
    String rdfs = "http://www.w3.org/2000/01/rdf-schema#";
    String file = "D:/manufacturing_ontology.owl";
    
    Model data = ModelLoader.loadModel(file);
    
    

   List rules = Rule.rulesFromURL("file:D:/Jena-2.5.4/etc/myrules.rules");   
   GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
  
   reasoner.setOWLTranslation(true);   // not needed in RDFS case
      reasoner.setTransitiveClosureCaching(true);
   InfModel infModel = ModelFactory.createInfModel(reasoner,data);
   


   
System.out.println(“111111111111111”);
infModel.getDeductionsModel();
System.out.println(“22222222222222222222”);



  List list = new ArrayList();

  for ( StmtIterator i=
      infModel.listStatements(null,null,RDFnodes(null));
  i.hasNext();)
   {

     Statement stmt = i.nextStatement();
     list.add(stmt);

  
   }
  
  return list;
  
}

private static RDFNode RDFnodes(Object object) {
// TODO Auto-generated method stub
return null;
}


}

则推理结果会在打印了111111111之后被打印出来


--  作者:skyhui
--  发布时间:8/4/2008 4:22:00 PM

--  
大家都不会?!
不是的巴。。。。。

大哥们帮帮我 好吗?


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