以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  急救:关于Rule!  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=25315)


--  作者:chengqh
--  发布时间:12/12/2005 7:21:00 PM

--  急救:关于Rule!
我在jena中写个简单程序,先创建一个简单的本体模型model,有三个资源:a,b,c两个属性parentOf 和spouseOf,他们的关系是(a    parentOf    b),(a    spouseOf    c)现在我写一个规则文件里面包含一条规则[rule:(?a http://some/spouseOf ?b),(?a http://some/parentOf ?c)->(?c http://some/parentOf ?b)],目的是得出c 也是b 的父母,可是程序却不能得到我的期望,如果改用在程序中直接写规则就可以得出,就是不能从文件中读出规则,这个错误错在那里啊?各位大峡指点!!!


代码如下:
    public static void main(String[] args) {
    Model model=ModelFactory.createDefaultModel();
    Resource a=model.createResource("http://some/a");
    Resource b=model.createResource("http://some/b");
    Resource c=model.createResource("http://some/c");

    Property parentOf=model.createProperty("http://some/parentOf");
    Property spouseOf=model.createProperty("http://some/spouseOf");
    a.addProperty(parentOf,b);
    a.addProperty(spouseOf,c);
    Resource con=model.createResource();
    con.addProperty(ReasonerVocabulary.PROPruleMode,"hybrid");
    con.addProperty(ReasonerVocabulary.PROPruleSet,"D:\\example\\untitled4\\rule.rules");
    Reasoner reasoner=GenericRuleReasonerFactory.theInstance().create(con);
    InfModel inf=ModelFactory.createInfModel(reasoner,model);
    StmtIterator stmt=inf.listStatements(c,parentOf,b);
    Statement st=stmt.nextStatement();
    System.out.print(st.toString());
  }


--  作者:jpz6311whu
--  发布时间:12/12/2005 10:34:00 PM

--  
曾经遇到过这种情况,rule文件编码问题,统一改为utf-8就可以了。
原因是java默认的字符编码为unicode,jena解析rule文件也是按照unicode解析的,所以如果你的rule文件里面出现不属于unicode的编码就会出错。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
47.363ms