以文本方式查看主题

-  W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWL  (http://bbs.xml.org.cn/index.asp)
--  『 Semantic Web(语义Web)/描述逻辑/本体 』  (http://bbs.xml.org.cn/list.asp?boardid=2)
----  使用Jena对OWL本体进行查询推理  (http://bbs.xml.org.cn/dispbbs.asp?boardid=2&rootid=&id=60678)


--  作者:shalen2008
--  发布时间:3/31/2008 7:42:00 PM

--  使用Jena对OWL本体进行查询推理
前面在"使用jena持久化OWL本体到MySQL(http://bbs.w3china.org/dispbbs.asp?boardID=2&ID=60494)"中说到了把OWL本体在MySQL中的存取,现在终于能做些简单推理了。要主要规则和查询语句的语法。
下面是一个简单的例子:
    有3个类,一个是专家(Expert),一个是研究方向,一个是学科(subject),一个专家有多个研究(research)方向,每个研究方向又关联(associate)着一些学科,现在要查询专家熟悉(familiar_with)的学科。从数据库读取了

OntModel之后,调用以下源代码:

/*使用sparql对本体进行查询*/
public static void searchOnto1(OntModel model){
    /*设置规则*/
    String rule = "[rule1:(?x http://www.owl-ontologies.com/Expert.owl#research ?y) " +
        "(?y http://www.owl-ontologies.com/Expert.owl#associate ?z) " +
        "->(?x http://www.owl-ontologies.com/Expert.owl#familiar_with ?z)]";
  
    /*查询语句*/
    String queryString = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> " +
    "SELECT ?expert ?subject " +
    "WHERE {?expert Expert:familiar_with ?subject} ";
  
    /*创建推理机*/
    Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));
  
    InfModel inf = ModelFactory.createInfModel(reasoner2, model);
    Query query = QueryFactory.create(queryString);
  
    QueryExecution qe = QueryExecutionFactory.create(query, inf);
    ResultSet results = qe.execSelect();
    /*打印结果*/
    ResultSetFormatter.out(System.out, results, query);
    qe.close();
}

附件中是显示结果。

此主题相关图片如下:
按此在新窗口浏览图片


[此贴子已经被作者于2008-4-3 20:49:20编辑过]

--  作者:cassiemudan
--  发布时间:4/4/2008 9:22:00 PM

--  
多谢分享!我刚浏览完SWRL,请问jena的自定义rule规则是不是就是按照SWRL标准来写啊?
可不可以用自定义这样的规则呢:规定某个类的属性之间的关系,如“同一月份客户欠费<客户帐单金额”、“客户帐单中的通话费=语音详单中的基本通话费+长途通话费-优惠费“ 之类的限制?

--  作者:jpz6311whu
--  发布时间:4/4/2008 9:34:00 PM

--  
不是的,jena规则和SWRL标准完全不一样
--  作者:cassiemudan
--  发布时间:4/5/2008 8:54:00 AM

--  
哦 这样 多谢!那jena的规则如何去写 有 什么 规范吗?而SWRL又有谁来遵守使用了呢?
--  作者:futantan
--  发布时间:4/5/2008 9:38:00 AM

--  
好东西!
--  作者:bbym010
--  发布时间:4/5/2008 1:09:00 PM

--  
谢谢分享
--  作者:seventeen_wy
--  发布时间:4/7/2008 10:11:00 PM

--  
谢谢
--  作者:sunrisee
--  发布时间:4/8/2008 11:15:00 AM

--  
谢谢分享,我还在做持久化,进一步的工作还要多向你学习啊

--  作者:supergg
--  发布时间:4/23/2008 1:02:00 PM

--  
先谢谢了,晚上改好运行看看!

--  作者:dasotkb
--  发布时间:4/24/2008 7:00:00 PM

--  
我發現如果在Protege裡面加外掛SWRL且有加入RULES..之後你輸出的owl 如果用jena去parse很像就會出問題耶
--  作者:jpz6311whu
--  发布时间:4/24/2008 10:47:00 PM

--  
以下是引用cassiemudan在2008-4-5 8:54:00的发言:
哦 这样 多谢!那jena的规则如何去写 有 什么 规范吗?而SWRL又有谁来遵守使用了呢?


请看:http://jena.sourceforge.net/inference/index.html
--  作者:cassiemudan
--  发布时间:4/25/2008 9:19:00 AM

--  
嗯  这个后来找到看过了^_^多谢!
发现jena的自定义规则 可以 帮助 查找出 一些 隐藏信息,但是 如果我想加入 限制性的规则 ,在推理时 能推理出 哪些实例 违反了 限制性 规则 似乎 不行。。。
[quoe]以下是引用jpz6311whu在2008-4-24 22:47:00的发言:
以下是引用cassiemudan在2008-4-5 8:54:00的发言:
哦 这样 多谢!那jena的规则如何去写 有 什么 规范吗?而SWRL又有谁来遵守使用了呢?
[/quote]
请看:http://jena.sourceforge.net/inference/index.html


--  作者:jpz6311whu
--  发布时间:4/27/2008 12:10:00 PM

--  
什么是“限制性的规则”,能举个例子么?
--  作者:cassiemudan
--  发布时间:4/27/2008 12:18:00 PM

--  
以下是引用jpz6311whu在2008-4-27 12:10:00的发言:
什么是“限制性的规则”,能举个例子么?


噢 这个名字 是我 自己 取的。比如 我定义 类A的实例 a 的age >类B的实例 b的age
而在本体中我却让 b.age<a.age  这种本体再调用一致性检测 validate一下  检测还是正确的即 检测不出来 那种违反了规则的不一致性
--  作者:jpz6311whu
--  发布时间:4/27/2008 12:51:00 PM

--  
b.age<a.age  

----
这种限制不是owl内置的class限制,用jena规则也比较难表达出来


--  作者:cassiemudan
--  发布时间:4/27/2008 12:59:00 PM

--  
OK Thanks!
--  作者:lmh272
--  发布时间:5/29/2008 11:52:00 AM

--  
真的很好啊,这是我一直在寻找的主题。
可是我一直搞不清楚jena规则的书写语法以及它跟查询语句的关系。
--  作者:jxlhljh
--  发布时间:6/4/2008 7:06:00 PM

--  
楼主现在研究的怎么样了啊,能不能请教一下
--  作者:jxlhljh
--  发布时间:6/4/2008 9:22:00 PM

--  
能不能把你这个例子的原始owl文件发给我实验一下,
--  作者:lmh272
--  发布时间:6/15/2008 9:32:00 AM

--  
谢谢,基本明白了规则和查询语句的关系,
但是规则能否创建在protege
--  作者:lipeiqiang1997
--  发布时间:4/11/2009 10:11:00 PM

--  
楼主能不能把你的OWL文件发给大家,让我们也好好学习一下。分享知识,共同提高。希望楼主能和我们分享一下你的资料。
--  作者:lixiaoming
--  发布时间:4/22/2009 9:03:00 PM

--  
同样希望楼主可以把这个owl给发一下,让我们试验一下
--  作者:shalen2008
--  发布时间:4/23/2009 10:18:00 AM

--  
本体已经上传
http://bbs.w3china.org/dispbbs.asp?boardID=2&ID=74100
--  作者:cxgnj
--  发布时间:5/3/2009 6:20:00 PM

--  
试了一下,得到了结果,多谢楼主!
有个问题想请教下,本人对查询语句的语法不了解,如果想查询某个专家(假设某个专家的名字为abc)的研究学科,下面的查询语句
/*查询语句*/
    String queryString = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> " +
    "SELECT ?expert ?subject " +
    "WHERE {?expert Expert:familiar_with ?subject} ";
该如何修改?
--  作者:shalen2008
--  发布时间:5/4/2009 9:02:00 PM

--  
关于本体的数据库存储我前面就已经写了http://bbs.w3china.org/dispbbs.asp?boardID=2&ID=60494
--  作者:shalen2008
--  发布时间:5/4/2009 9:05:00 PM

--  
我以前写的代码
package utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import struts.bean.Bean;
import struts.bean.Book;
import struts.bean.Encouragement;
import struts.bean.Expert;
import struts.bean.Paper;
import struts.bean.Patent;
import struts.bean.Project;
import struts.bean.SearchListBean;

import com.hp.hpl.jena.db.IDBConnection;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
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.ModelMaker;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.ReasonerRegistry;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;

public class JaneUtils {
    public static String subject = "Subject";

    /* 从文件装载模型 */
    public static OntModel loadModel(String filePath) {
        InputStreamReader in;
        OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
                null);
        try {
            FileInputStream file = new FileInputStream(filePath);
            in = new InputStreamReader(file, "UTF-8");// 处理中文
            model.read(in, null);
            in.close();
            System.out.println("从文件装载模型成功!");
        } catch (FileNotFoundException e) {
            System.out.println("无法打开本体文件,程序将终止");
            System.exit(0);
        } catch (IOException e) {
            e.printStackTrace();
            System.exit(0);
        }
        return model;
    }

    /* 本体中的各个class,同时将各个class的subclass和property */
    public static void readOntology(OntModel model) {
        // the class number
        int j = 0;

        // list classes
        for (Iterator i = model.listClasses(); i.hasNext();) {
            j++;
            OntClass c = (OntClass) i.next();
            String strClass = c.getModel().usePrefix(c.getURI());
            System.out.println(j + strClass.substring(1));

            // to list sub-classes for each class
            for (Iterator k = c.listSubClasses(true); k.hasNext();) {
                System.out.print("  " + "hasSubClass");
                OntClass subclass = (OntClass) k.next();
                String strSubClass = subclass.getModel().usePrefix(
                        subclass.getURI());

                System.out.println(strSubClass.substring(1));
            }

            // list property for each class
            for (Iterator y = c.listDeclaredProperties(true); y.hasNext();) {
                OntProperty property = (OntProperty) y.next();
                String strPropertyName = property.getModel().usePrefix(
                        property.getURI());

                String strRange = property.getRange().toString();
                String strRangeName = property.getModel().usePrefix(strRange);

                // show just the "has" Properties
                if (strPropertyName.substring(1).substring(0, 3).equals("has")) {
                    System.out.print("  ");
                    System.out.print(strPropertyName.substring(1));
                    System.out.println(strRangeName.substring(1));
                }
            }
        }
    }

    /* 查询学科名称 */
    public static String getSujectName() {

        DBPool dbPool = DBPool.getInstance();

        IDBConnection con = dbPool.getConnection();
        OntModel model = JaneUtils.getModelFromDB(con, "expert");

        String NS = "http://www.owl-ontologies.com/Expert.owl#";
        OntClass c = model.getOntClass(NS + "Subject");

        subject = getSub(c);

        dbPool.freeConnection(con);

        return subject;
    }

    /* 查询研究方向名称 */
    public static String getResearchDirection() {
        String researchDirection = "";

        DBPool dbPool = DBPool.getInstance();

        IDBConnection con = dbPool.getConnection();
        OntModel model = JaneUtils.getModelFromDB(con, "expert");

        String NS = "http://www.owl-ontologies.com/Expert.owl#";
        OntClass c = model.getOntClass(NS + "ResearchDirection");

        for (Iterator i = c.listInstances(); i.hasNext();) {
            Individual ont = (Individual) i.next();
            researchDirection += "," + ont.getLocalName();
        }

        dbPool.freeConnection(con);

        researchDirection = researchDirection.substring(1, researchDirection
                .length());
        return researchDirection;
    }

    /* 递归打印所有子类 */
    public static String getSub(OntClass c) {
        for (Iterator i = c.listSubClasses(false); i.hasNext();) {
            OntClass ont = (OntClass) i.next();
            if (!ont.isAnon()) {// 如果不是匿名类,则打印类的名字
                // System.out.println(c.getLocalName());
                subject += "," + ont.getLocalName();
                getSub(ont);
            }
        }
        return subject;
    }

    /* 查询专家具体信息 */
    public static Expert getDetail(String name1) {
        DBPool dbPool = DBPool.getInstance();
        Expert expert = new Expert();
        IDBConnection con = dbPool.getConnection();
        OntModel model = JaneUtils.getModelFromDB(con, "expert");
        String NS = "http://www.owl-ontologies.com/Expert.owl#";

        Individual ont = model.getIndividual(NS + name1);

        DatatypeProperty ep = model.getDatatypeProperty(NS + "E_mail");
        
        if (ont.getPropertyValue(ep) != null) {
            String e_mail = ont.getPropertyValue(ep).toString();
            e_mail = e_mail.substring(0,e_mail.length()-3);
            System.out.println(e_mail);
            expert.setE_mail(e_mail);
        }

        DatatypeProperty name = model.getDatatypeProperty(NS + "name");
        if (ont.getPropertyValue(name) != null) {
            String name2 = ont.getPropertyValue(name).toString();
            name2 = name2.substring(0,name2.length()-3);
            System.out.println(name2);
            expert.setName(name2);
        }

        DatatypeProperty is_Academician = model.getDatatypeProperty(NS
                + "is_Academician");
        if (ont.getPropertyValue(is_Academician) != null) {
            String is_Academician1 = ont.getPropertyValue(is_Academician)
                    .toString();
            
            if(is_Academician1.startsWith("true")){
                expert.setIsAcademician("true");
            }else{
                expert.setIsAcademician("false");
            }
            System.out.println(expert.getIsAcademician());
        }

        DatatypeProperty work_tel = model.getDatatypeProperty(NS + "work_tel");
        if (ont.getPropertyValue(work_tel) != null) {
            String work_tel1 = ont.getPropertyValue(work_tel).toString();
            work_tel1 = work_tel1.substring(0, work_tel1.length() - 3);
            System.out.println(work_tel1);
            expert.setWorkTel(work_tel1);
        }

        DatatypeProperty workplace = model
                .getDatatypeProperty(NS + "workplace");
        if (ont.getPropertyValue(workplace) != null) {
            String workplace1 = ont.getPropertyValue(workplace).toString();
            workplace1 = workplace1.substring(0,workplace1.length()-3);
            System.out.println(workplace1);
            expert.setWorkplace(workplace1);
        }

        DatatypeProperty birthday = model.getDatatypeProperty(NS + "birthday");
        if (ont.getPropertyValue(birthday) != null) {
            String birthday1 = ont.getPropertyValue(birthday).toString();
            birthday1 = birthday1.substring(0, 10).trim();
            System.out.println(birthday1);
            
            expert.setBirthday(birthday1);
        }

        DatatypeProperty gender = model.getDatatypeProperty(NS + "gender");
        if (ont.getPropertyValue(gender) != null) {
            String gender1 = ont.getPropertyValue(gender).toString();
            if(gender1.startsWith("true")){
                expert.setGender("male");
            }else{
                expert.setGender("female");
            }
            System.out.println(expert.getGender());
        }

        DatatypeProperty Graduation_time = model.getDatatypeProperty(NS
                + "Graduation_time");
        if (ont.getPropertyValue(Graduation_time) != null) {
            String Graduation_time1 = ont.getPropertyValue(Graduation_time)
                    .toString();
            Graduation_time1 = Graduation_time1.substring(0, 9).trim();
            System.out.println(Graduation_time1);
            expert.setGraduationTime(Graduation_time1);
        }

        DatatypeProperty ID_card = model.getDatatypeProperty(NS + "ID_card");
        if (ont.getPropertyValue(ID_card) != null) {
            String ID_card1 = ont.getPropertyValue(ID_card).toString();
            ID_card1 = ID_card1.substring(0, ID_card1.length() - 3);
            System.out.println(ID_card1);
            expert.setIDCard(ID_card1);
        }
        
        DatatypeProperty resume = model.getDatatypeProperty(NS + "resume");
        if (ont.getPropertyValue(resume) != null) {
            String resume1 = ont.getPropertyValue(resume).toString();
            System.out.println(resume1);
            expert.setResume(resume1);
        }

        DatatypeProperty home_address = model.getDatatypeProperty(NS
                + "home_address");
        if (ont.getPropertyValue(home_address) != null) {
            String home_address1 = ont.getPropertyValue(home_address)
                    .toString();
            home_address1 = home_address1.substring(0,
                    home_address1.length() - 3);
            System.out.println(home_address1);
            expert.setHomeAddress(home_address1);
        }

        System.out.println(ont.getLocalName());

        ObjectProperty p = model.getObjectProperty(NS + "country_is");
        if (ont.getPropertyValue(p) != null) {
            String p1 = ont.getPropertyValue(p).toString();
            p1 = p1.substring(41,p1.length());
            System.out.println(p1);
            expert.setCountry(p1);
        }

        ObjectProperty research = model.getObjectProperty(NS + "research");
        List<String> SearchDirect = new ArrayList<String>();
        String research2 = "";
        if (ont.listPropertyValues(research) != null) {
            Iterator s = ont.listPropertyValues(research);
            while (s.hasNext()) {
                research2 = s.next().toString();
                research2 = research2.substring(41,research2.length());
                System.out.println(research2);
                SearchDirect.add(research2);
            }
            expert.setSearchDirect(SearchDirect);
        }
        
        List<Book> book = new ArrayList<Book>();
        String bookURL = "";
        ObjectProperty p2 = model.getObjectProperty(NS + "write_book");
        if (ont.listPropertyValues(p2) != null) {
            Iterator s = ont.listPropertyValues(p2);
            while (s.hasNext()) {
                Book b = new Book();
                bookURL = s.next().toString();
                
                Individual ont1 = model.getIndividual(bookURL);
                
                DatatypeProperty bookName = model.getDatatypeProperty(NS + "book_name");
                if (ont1.getPropertyValue(bookName) != null) {
                    String bookName1 = ont1.getPropertyValue(bookName).toString();
                    bookName1 = bookName1.substring(0, bookName1.length() - 3);
                    System.out.println("Book:" + bookName1);
                    b.setName(bookName1);
                }
                
                DatatypeProperty publisherTime = model.getDatatypeProperty(NS + "publish_time");
                if (ont1.getPropertyValue(publisherTime) != null) {
                    String publisherTime1 = ont1.getPropertyValue(publisherTime).toString();
                    publisherTime1 = publisherTime1.substring(0, 10).trim();
                    System.out.println(publisherTime1);
                    b.setPublisherTime(publisherTime1);
                }
                
                ObjectProperty publisher = model.getObjectProperty(NS + "publisher_is");
                if (ont1.getPropertyValue(publisher) != null) {
                    String publisher1 = ont1.getPropertyValue(publisher).toString();
                    publisher1 = publisher1.substring(41,publisher1.length());
                    System.out.println(publisher1);
                    b.setPublisher(publisher1);
                }
                
                ObjectProperty Property = model.getObjectProperty(NS + "bookProperty_is");
                if (ont1.getPropertyValue(Property) != null) {
                    String Property1 = ont1.getPropertyValue(Property).toString();
                    Property1 = Property1.substring(41,Property1.length());
                    System.out.println(Property1);
                    b.setProperty(Property1);
                }
                
                ObjectProperty author = model.getObjectProperty(NS + "book_author_is");
                String author2 = "";
                String author1 = "";
                if (ont1.listPropertyValues(author) != null) {
                    Iterator s1 = ont1.listPropertyValues(author);
                    while (s1.hasNext()) {
                        author2 = s1.next().toString();
                        author2 = author2.substring(41,author2.length());                       
                        author1 = author1 + " " + author2;
                    }
                    System.out.println(author1.trim());
                    b.setAuthor(author1.trim());
                }
                            
                book.add(b);
            }
            expert.setBook(book);
        }

        List<Encouragement> encouragement = new ArrayList<Encouragement>();
        String encouragementURL = "";
        ObjectProperty encouragement1 = model.getObjectProperty(NS + "get_encouragement");
        if (ont.listPropertyValues(encouragement1) != null) {
            Iterator s = ont.listPropertyValues(encouragement1);
            while (s.hasNext()) {
                Encouragement en = new Encouragement();
                encouragementURL = s.next().toString();                
                Individual ont1 = model.getIndividual(encouragementURL);
                
                ObjectProperty author = model.getObjectProperty(NS + "be_got");
                String author2 = "";
                String author1 = "";
                if (ont1.listPropertyValues(author) != null) {
                    Iterator s1 = ont1.listPropertyValues(author);
                    while (s1.hasNext()) {
                        author2 = s1.next().toString();
                        author2 = author2.substring(41,author2.length());
                        System.out.println("encouragement:" + author2);
                        author1 = author1 + " " + author2;
                    }
                    en.setAuthor(author1);
                }            
                
                DatatypeProperty id = model.getDatatypeProperty(NS + "encouragement_num");
                if (ont1.getPropertyValue(id) != null) {
                    String id1 = ont1.getPropertyValue(id).toString();
                    id1 = id1.substring(0, id1.length() - 38);
                    System.out.println(id1);
                    en.setNumber(id1);
                }
                
                ObjectProperty Property = model.getObjectProperty(NS + "type_is");
                if (ont1.getPropertyValue(Property) != null) {
                    String Property1 = ont1.getPropertyValue(Property).toString();
                    Property1 = Property1.substring(41,Property1.length());
                    System.out.println(Property1);
                    en.setType(Property1);
                }
                encouragement.add(en);
            }
            expert.setEncouragement(encouragement);
        }
        

        List<Paper> paper = new ArrayList<Paper>();
        String paperURL = "";
        ObjectProperty paper2 = model.getObjectProperty(NS + "write");
        if (ont.listPropertyValues(paper2) != null) {
            Iterator s = ont.listPropertyValues(paper2);
            while (s.hasNext()) {
                Paper paper1 = new Paper();
                paperURL = s.next().toString();                
                Individual ont1 = model.getIndividual(paperURL);
                
                DatatypeProperty bookName = model.getDatatypeProperty(NS + "paper_name");
                if (ont1.getPropertyValue(bookName) != null) {
                    String bookName1 = ont1.getPropertyValue(bookName).toString();
                    bookName1 = bookName1.substring(0, bookName1.length() - 3);
                    System.out.println("paper:" + bookName1);
                    paper1.setPaperName(bookName1);
                }
                
                DatatypeProperty indexNum = model.getDatatypeProperty(NS + "index_num");
                if (ont1.getPropertyValue(indexNum) != null) {
                    String indexNum1 = ont1.getPropertyValue(indexNum).toString();
                    indexNum1 = indexNum1.substring(0, indexNum1.length() - 38);
                    System.out.println(indexNum1);
                    paper1.setIndexNum(indexNum1);
                }
                
                DatatypeProperty is_domestic_paper = model.getDatatypeProperty(NS
                        + "is_domestic_paper");
                if (ont1.getPropertyValue(is_domestic_paper) != null) {
                    String is_domestic_paper1 = ont1.getPropertyValue(is_domestic_paper)
                            .toString();
                    
                    if(is_domestic_paper1.startsWith("true")){
                        paper1.setDomesticPaper("true");
                    }else{
                        paper1.setDomesticPaper("false");
                    }
                    System.out.println(paper1.getIsDomesticPaper());
                }
                
                ObjectProperty author = model.getObjectProperty(NS + "author_is");
                String author2 = "";
                String author1 = "";
                if (ont1.listPropertyValues(author) != null) {
                    Iterator s1 = ont1.listPropertyValues(author);
                    while (s1.hasNext()) {
                        author2 = s1.next().toString();
                        author2 = author2.substring(41,author2.length());
                        author1 = author1 + " " + author2;
                    }
                    System.out.println(author1.trim());
                    paper1.setAuthor(author1.trim());
                }
                
                ObjectProperty firstAuthor = model.getObjectProperty(NS + "first_author_is");
                String firstAuthor2 = "";
                String firstAuthor1 = "";
                if (ont1.listPropertyValues(firstAuthor) != null) {
                    Iterator s1 = ont1.listPropertyValues(firstAuthor);
                    while (s1.hasNext()) {
                        firstAuthor2 = s1.next().toString();
                        firstAuthor2 = firstAuthor2.substring(41,firstAuthor2.length());
                        firstAuthor1 = firstAuthor1 + " " + firstAuthor2;
                    }
                    System.out.println(firstAuthor1.trim());
                    paper1.setFirstAuthor(firstAuthor1.trim());
                }
                
                ObjectProperty Property = model.getObjectProperty(NS + "publication_is");
                if (ont1.getPropertyValue(Property) != null) {
                    String Property1 = ont1.getPropertyValue(Property).toString();
                    Property1 = Property1.substring(41,Property1.length());
                    System.out.println(Property1);
                    paper1.setPublication(Property1);
                }
                
                DatatypeProperty deliver_time = model.getDatatypeProperty(NS
                        + "deliver_time");
                if (ont1.getPropertyValue(deliver_time) != null) {
                    String deliver_time1 = ont1.getPropertyValue(deliver_time)
                            .toString();
                    deliver_time1 = deliver_time1.substring(0, 10).trim();
                    System.out.println(deliver_time1);
                    paper1.setDeliverTime(deliver_time1);
                }
                paper.add(paper1);               
            }
            expert.setPaper(paper);
        }

        List<Patent> patent = new ArrayList<Patent>();
        String patentURL = "";
        ObjectProperty patent2 = model.getObjectProperty(NS + "create_patent");
        if (ont.listPropertyValues(patent2) != null) {
            Iterator s = ont.listPropertyValues(patent2);
            while (s.hasNext()) {
                Patent patent1 = new Patent();
                patentURL = s.next().toString();                
                Individual ont1 = model.getIndividual(patentURL);
                
                DatatypeProperty bookName = model.getDatatypeProperty(NS + "patend_name");
                if (ont1.getPropertyValue(bookName) != null) {
                    String bookName1 = ont1.getPropertyValue(bookName).toString();
                    bookName1 = bookName1.substring(0, bookName1.length() - 3);
                    System.out.println("Patent:" + bookName1);
                    patent1.setName(bookName1);
                }
                
                DatatypeProperty id = model.getDatatypeProperty(NS + "patent_id");
                if (ont1.getPropertyValue(id) != null) {
                    String id1 = ont1.getPropertyValue(id).toString();
                    id1 = id1.substring(0, id1.length() - 3);
                    System.out.println(id1);
                    patent1.setId(id1);
                }
                
                DatatypeProperty publisherTime = model.getDatatypeProperty(NS + "pass_time");
                if (ont1.getPropertyValue(publisherTime) != null) {
                    String publisherTime1 = ont1.getPropertyValue(publisherTime).toString();
                    publisherTime1 = publisherTime1.substring(0, 10).trim();
                    System.out.println(publisherTime1);
                    patent1.setPassTime(publisherTime1);
                }
                
                ObjectProperty publisher = model.getObjectProperty(NS + "patent_type_is");
                if (ont1.getPropertyValue(publisher) != null) {
                    String publisher1 = ont1.getPropertyValue(publisher).toString();
                    publisher1 = publisher1.substring(41,publisher1.length());
                    System.out.println(publisher1);
                    patent1.setType(publisher1);
                }
                
                ObjectProperty author = model.getObjectProperty(NS + "be_created");
                String author2 = "";
                String author1 = "";
                if (ont1.listPropertyValues(author) != null) {
                    Iterator s1 = ont1.listPropertyValues(author);
                    while (s1.hasNext()) {
                        author2 = s1.next().toString();
                        author2 = author2.substring(41,author2.length());
                        author1 = author1 + " " + author2;
                    }
                    System.out.println(author1.trim());
                    patent1.setAuthor(author1.trim());
                }
                patent.add(patent1);
            }
            expert.setPatent(patent);
        }

        List<Project> project = new ArrayList<Project>();
        String projectURL = "";
        ObjectProperty project2 = model.getObjectProperty(NS + "lead");
        if (ont.listPropertyValues(project2) != null) {
            Iterator s = ont.listPropertyValues(project2);
            while (s.hasNext()) {
                Project project1 = new Project();
                projectURL = s.next().toString();                
                Individual ont1 = model.getIndividual(projectURL);
                
                DatatypeProperty bookName = model.getDatatypeProperty(NS + "project_name");
                if (ont1.getPropertyValue(bookName) != null) {
                    String bookName1 = ont1.getPropertyValue(bookName).toString();
                    bookName1 = bookName1.substring(0, bookName1.length() - 3);
                    System.out.println("Project:" + bookName1);
                    project1.setProjectName(bookName1);
                }
                
                ObjectProperty publisher = model.getObjectProperty(NS + "property_is");
                if (ont1.getPropertyValue(publisher) != null) {
                    String publisher1 = ont1.getPropertyValue(publisher).toString();
                    publisher1 = publisher1.substring(41,publisher1.length());
                    System.out.println(publisher1);
                    project1.setProperty(publisher1);
                }
                
                DatatypeProperty publisherTime = model.getDatatypeProperty(NS + "project_begin_time");
                if (ont1.getPropertyValue(publisherTime) != null) {
                    String publisherTime1 = ont1.getPropertyValue(publisherTime).toString();
                    publisherTime1 = publisherTime1.substring(0, 10).trim();
                    System.out.println(publisherTime1);
                    project1.setProjectBeginTime(publisherTime1);
                }
                
                DatatypeProperty project_end_time = model.getDatatypeProperty(NS + "project_end_time");
                if (ont1.getPropertyValue(project_end_time) != null) {
                    String project_end_time1 = ont1.getPropertyValue(project_end_time).toString();
                    project_end_time1 = project_end_time1.substring(0, 10).trim();
                    System.out.println(project_end_time1);
                    project1.setProjectEndTime(project_end_time1);
                }
                
                DatatypeProperty indexNum = model.getDatatypeProperty(NS + "Cost");
                if (ont1.getPropertyValue(indexNum) != null) {
                    String indexNum1 = ont1.getPropertyValue(indexNum).toString();
                    indexNum1 = indexNum1.substring(0, indexNum1.length() - 38);
                    System.out.println(indexNum1);
                    project1.setCost(indexNum1);
                }
                
                project.add(project1);
            }
            expert.setProject(project);
        }

        dbPool.freeConnection(con);
        
        return expert;
    }

    /* 简单读取本体中的各个class */
    public static void SimpleReadOntology(OntModel model) {
        for (Iterator i = model.listClasses(); i.hasNext();) {
            OntClass c = (OntClass) i.next();
            if (!c.isAnon()) {// 如果不是匿名类,则打印类的名字
                System.out.println(c.getLocalName());
            }
        }
    }

    public static OntModelSpec getModelSpec(ModelMaker maker) {
        /*
         * create a spec for the new ont model that will use no inference over
         * models made by the given maker (which is where we get the persistent
         * models from)
         */
        OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
        spec.setImportModelMaker(maker);
        return spec;
    }

    /* 从文件读取本体并将其存入数据库 */
    public static OntModel createDBModelFromFile(IDBConnection con,
            String name, String filePath) {
        ModelMaker maker = ModelFactory.createModelRDBMaker(con);
        Model base = maker.createModel(name);
        OntModel newmodel = ModelFactory.createOntologyModel(
                getModelSpec(maker), base);
        newmodel.read(filePath);
        System.out.println("本体成功存入数据库!");
        return newmodel;
    }

    /* 从数据库中得到已存入本体 */
    public static OntModel getModelFromDB(IDBConnection con, String name) {
        ModelMaker maker = ModelFactory.createModelRDBMaker(con);
        Model base = maker.getModel(name);
        OntModel newmodel = ModelFactory.createOntologyModel(
                getModelSpec(maker), base);
        System.out.println("本体从数据库读取成功!");
        return newmodel;
    }

    /*获取某学科类的实例名*/
    public static String getSubInstance(String sub){
        String si = "";
        DBPool dbPool = DBPool.getInstance();
        IDBConnection con = dbPool.getConnection();
        OntModel model = JaneUtils.getModelFromDB(con, "expert");
        String NS = "http://www.owl-ontologies.com/Expert.owl#";
        
        OntClass c = model.getOntClass(NS + sub);
        for (Iterator i = c.listInstances(); i.hasNext();) {
            Individual ont = (Individual) i.next();
            si = ont.getLocalName();
        }

        System.out.println(si);
        
        dbPool.freeConnection(con);
        return si;
    }
    
    /* 获取个体及其属性值 */
    public static void getInstance(OntModel model) {
        String NS = "http://www.owl-ontologies.com/Expert.owl#";
        /* 得到本体中的Expert类 */
        OntClass expert = model.getOntClass(NS + "Expert");
        // 打印类名
        System.out.println(expert.getLocalName());

        // 获得其所以个体
        ExtendedIterator it = expert.listInstances();
        // 打印其个体
        while (it.hasNext()) {
            Individual oi = (Individual) it.next();
            System.out.println(oi.getLocalName());

            for (Iterator ipp = expert.listDeclaredProperties(); ipp.hasNext();) {
                OntProperty p = (OntProperty) ipp.next();
                System.out.println("  associated property: " + p.getLocalName()
                        + " : " + oi.getPropertyValue(p));
            }// property ends
        }
    }

    /* 使用sparql对本体进行查询 */
    public static List<SearchListBean> search(Bean bean) {
        DBPool dbPool = DBPool.getInstance();

        IDBConnection con = dbPool.getConnection();
        OntModel model = JaneUtils.getModelFromDB(con, "expert");

        String NS = "http://www.owl-ontologies.com/Expert.owl#";

        /* 设置规则 */
        String rule = "[rule1:(?x http://www.owl-ontologies.com/Expert.owl#research ?y), "
                + " (?s http://www.owl-ontologies.com/Expert.owl#has_research_direction ?y), "
                + " (?s http://www.owl-ontologies.com/Expert.owl#associate ?z) "
                + " ->(?x http://www.owl-ontologies.com/Expert.owl#familiar_with ?z)] " +
                        "[rule2:(?a http://www.owl-ontologies.com/Expert.owl#familiar_with ?b), " +
                        "(?b http://www.owl-ontologies.com/Expert.owl#is_a ?c) " +
                        "->(?a http://www.owl-ontologies.com/Expert.owl#familiar_with ?c)] ";

        System.out.println(rule);
        
        /* 查询语句 */
        // String queryString = "PREFIX
        // Expert:<http://www.owl-ontologies.com/Expert.owl#> " +
        // "SELECT ?expert ?ResearchDirection " +
        // "WHERE {?expert Expert:research ?ResearchDirection} ";
        String queryString1 = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> "
                + "SELECT ?name ?resume "
                + "WHERE {?expert Expert:resume ?resume. ?expert Expert:name ?name.";
        
        String queryString2 = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> "
            + "SELECT ?name ?resume "
            + "WHERE {?expert Expert:resume ?resume. ?expert Expert:name ?name.}";
        
        String queryString = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> "
            + "SELECT ?name ?gender ?TechnicalTitle ?research ?resume "
            + "WHERE {?expert Expert:resume ?resume. " +
                    "?expert Expert:name ?name." +
                    "?expert Expert:gender ?gender." +
                    "?expert Expert:title_code_is ?TechnicalTitle." +
                    "?expert Expert:research ?research.}";
        
        //?expert Expert:familiar_with ?subject.
        //?expert Expert:research ?research.
        // "WHERE {?expert Expert:resume ?resume.?expert Expert:name
        // ?name.?expert Expert:work_tel \"8869565\"}";
        // "WHERE {?expert Expert:resume ?resume.?expert Expert:name ?name.
        // FILTER(?name=\"ChenGuoda\")}";

        if(!bean.getName().equals("")){
            queryString1 += "?expert Expert:name \""+ bean.getName()+"\"@en.";             
        }
        if(!bean.getGender().equals("")){
            queryString1 += "?expert Expert:gender "+ bean.getGender()+".";             
        }
        if(!bean.getTechnicalTitle().equals("other")){
            queryString1 += "?expert Expert:title_code_is Expert:"+ bean.getTechnicalTitle()+".";             
        }
        if(!bean.getResearchDirection().equals("")){
            queryString1 += "?expert Expert:research Expert:"+ bean.getResearchDirection()+".";             
        }
        if(!bean.getSubject().equals("")){
            queryString1 += "?expert Expert:familiar_with Expert:"+ getSubInstance(bean.getSubject())+".";             
        }
        queryString1 += "}";
        
        System.out.println(queryString1);

        /* 创建推理机 */
        Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

        InfModel inf = ModelFactory.createInfModel(reasoner2, model);
        Query query = QueryFactory.create(queryString1);

        QueryExecution qe = QueryExecutionFactory.create(query, inf);
        ResultSet results = qe.execSelect();

        List<SearchListBean> searchList = new ArrayList<SearchListBean>();

        while (results.hasNext()) {
            QuerySolution qs = (QuerySolution) results.next();
            searchList.add(new SearchListBean(
                    qs.getLiteral("name").getString(), qs.getLiteral("resume")
                            .getString()));
            System.out.println(qs.getLiteral("name").getString());
        }


        /* 打印结果 */
        //ResultSetFormatter.out(System.out, results, query);
        qe.close();
        dbPool.freeConnection(con);

        return searchList;
    }

    /* 使用sparql对本体进行查询 */
    public static void searchOnto(OntModel model) {
        Reasoner reasoner = ReasonerRegistry.getOWLMicroReasoner();

        // String rules = "[Rule1:(?x research ?y)(?y associat ?z)->(?x
        // familiar_with ?z)]";
        // reasoner.bind(Rule.parseRule(rules));

        String queryString = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> "
                + "SELECT ?expert ?subject "
                + "WHERE {?expert Expert:familiar_with ?subject} ";

        InfModel inf = ModelFactory.createInfModel(reasoner, model);
        Query query = QueryFactory.create(queryString);

        // Execute the query and obtain results
        QueryExecution qe = QueryExecutionFactory.create(query, inf);
        ResultSet results = qe.execSelect();
        ResultSetFormatter.out(System.out, results, query);
        qe.close();
    }

    /* 使用sparql对本体进行查询 */
    public static void searchOnto1(OntModel model) {
        /* 设置规则 */
        String rule = "[rule1:(?x http://www.owl-ontologies.com/Expert.owl#research ?y) "
                + "(?y http://www.owl-ontologies.com/Expert.owl#associate ?z) "
                + "->(?x http://www.owl-ontologies.com/Expert.owl#familiar_with ?z)]";

        /* 查询语句 */
        String queryString = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> "
                + "SELECT ?expert ?subject "
                + "WHERE {?expert Expert:familiar_with ?subject} ";

        /* 创建推理机 */
        Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

        InfModel inf = ModelFactory.createInfModel(reasoner2, model);
        Query query = QueryFactory.create(queryString);

        QueryExecution qe = QueryExecutionFactory.create(query, inf);
        ResultSet results = qe.execSelect();
        /* 打印结果 */
        ResultSetFormatter.out(System.out, results, query);
        qe.close();
    }
}


--  作者:fairyxiaojun
--  发布时间:5/18/2009 4:58:00 PM

--  
请问要查询expert的实例的属性值name该怎么改呢?
比如要查询ChenGuoda 熟悉的subject代码该怎么改呢?
是不是
"WHERE {?expert Expert:familiar_with ?subject.?expert Expert:name
       ?name.?expert Expert:name \"ChenGuoda\"}";

十分感谢!!


--  作者:jsupeng
--  发布时间:11/10/2009 9:45:00 PM

--  
太好了。
--  作者:binyu3008
--  发布时间:3/20/2010 3:50:00 PM

--  
你好,我按照你的代码持久化存储了我的本体,通过通用规则推理机进行了推理,得到了新知识,可是数据库却没有得到更新,查不到新知识,请问这个问题你有没有遇到过,怎么样修改的?
--  作者:angleangleangle
--  发布时间:4/19/2010 3:42:00 PM

--  
请问楼主查询语言是在什么环境下实现的呢?
--  作者:chenyu8320
--  发布时间:4/27/2010 5:20:00 PM

--  
谢谢!
--  作者:angleangleangle
--  发布时间:5/6/2010 4:12:00 PM

--  
struts是哪个版本?
--  作者:service365
--  发布时间:5/7/2010 1:12:00 AM

--  
以下是引用jpz6311whu在2008-4-4 21:34:00的发言:
不是的,jena规则和SWRL标准完全不一样


用哪种规则比较好?
--  作者:shenxin1986
--  发布时间:5/12/2010 5:11:00 PM

--  
这是用jena进行查询还是用sparql语言进行查询
--  作者:gflzx6506
--  发布时间:5/18/2010 4:24:00 PM

--  
以下是引用shalen2008在2009-5-4 21:05:00的发言:
我以前写的代码

     /* 本体中的各个class,同时将各个class的subclass和property */
     public static void readOntology(OntModel model) {
         // the class number
         int j = 0;

         // list classes
         for (Iterator i = model.listClasses(); i.hasNext();) {
             j++;
             OntClass c = (OntClass) i.next();
             String strClass = c.getModel().usePrefix(c.getURI());
             System.out.println(j + strClass.substring(1));

             // to list sub-classes for each class
             for (Iterator k = c.listSubClasses(true); k.hasNext();) {
                 System.out.print("  " + "hasSubClass");
                 OntClass subclass = (OntClass) k.next();
                 String strSubClass = subclass.getModel().usePrefix(
                         subclass.getURI());

                 System.out.println(strSubClass.substring(1));
             }

             // list property for each class
             for (Iterator y = c.listDeclaredProperties(true); y.hasNext();) {
                 OntProperty property = (OntProperty) y.next();
                 String strPropertyName = property.getModel().usePrefix(
                         property.getURI());

                 String strRange = property.getRange().toString();
                 String strRangeName = property.getModel().usePrefix(strRange);

                 // show just the "has" Properties
                 if (strPropertyName.substring(1).substring(0, 3).equals("has")) {
                     System.out.print("  ");
                     System.out.print(strPropertyName.substring(1));
                     System.out.println(strRangeName.substring(1));
                 }
             }
         }
     }

     



请问下shalen2008  这段程序为什么我每次运行出来 结果都不唯一
总出现错误,说有些变量 没有值
--  作者:springbird
--  发布时间:5/24/2010 10:36:00 AM

--  
好东西,值得收藏
--  作者:oO天天Oo
--  发布时间:5/26/2010 10:59:00 AM

--  
能够走通本体持久化,但是查询部分就是什么都不输出,现在程序如下,还望达人指教
package jena;

import com.hp.hpl.jena.db.DBConnection;
import com.hp.hpl.jena.db.IDBConnection;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ModelMaker;

import com.hp.hpl.jena.query.Query;
import com.hp.hpl.jena.query.QueryExecution;
import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.InfModel;
import com.hp.hpl.jena.reasoner.Reasoner;
import com.hp.hpl.jena.reasoner.rulesys.GenericRuleReasoner;
import com.hp.hpl.jena.reasoner.rulesys.Rule;

public class Sparqlforexpert {
 
 
 
 
 /* 连接数据库 */
 public static IDBConnection connectDB(String DB_URL, String DB_USER,
  String DB_PASSWD, String DB_NAME) {
     return new DBConnection(DB_URL, DB_USER, DB_PASSWD, DB_NAME);
 }
 
 /* 从文件读取本体并将其存入数据库 */
 public static OntModel createDBModelFromFile(IDBConnection con, String name,
    String filePath) {
     ModelMaker maker = ModelFactory.createModelRDBMaker(con);
     Model base = maker.createModel(name);
     OntModel newmodel = ModelFactory.createOntologyModel(
  getModelSpec(maker), base);
     newmodel.read(filePath);
     return newmodel;
 }

 /* 从数据库中得到已存入本体 */
 public static OntModel getModelFromDB(IDBConnection con, String name) {
     ModelMaker maker = ModelFactory.createModelRDBMaker(con);
     Model base = maker.getModel(name);
     OntModel newmodel = ModelFactory.createOntologyModel(
  getModelSpec(maker), base);
     return newmodel;
 }

 public static OntModelSpec getModelSpec(ModelMaker maker) {
     OntModelSpec spec = new OntModelSpec(OntModelSpec.OWL_MEM);
     spec.setImportModelMaker(maker);
     return spec;
 }
 
     

     
     

public static void main(String[] args) {
 
    String DB_URL = "jdbc:mysql://localhost:3306/mydb";
    String DB_USER = "root";
    String DB_PASSWD = "root";
    String DB = "MySQL";
    String DB_DRIVER = "com.mysql.jdbc.Driver";
    
    try {
        Class.forName("com.mysql.jdbc.Driver");
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
  
    //String filePath = "file:C://Program Files//Protege_3.3.1//examples//expert//Expert.owl";
    IDBConnection con = connectDB(DB_URL,DB_USER, DB_PASSWD, DB);
    System.out.println(con);

   // createDBModelFromFile(con, "expert",filePath);  
    OntModel model = getModelFromDB(con, "expert");
    
}
/*使用sparql对本体进行查询*/
public static void searchOnto1(OntModel model) {
    /* 设置规则 */
    String rule = "[rule1:(?x http://www.owl-ontologies.com/Expert.owl#research ?y) "
            + "(?y http://www.owl-ontologies.com/Expert.owl#associate ?z) "
            + "->(?x http://www.owl-ontologies.com/Expert.owl#familiar_with ?z)]";

    /* 查询语句 */
    String queryString = "PREFIX Expert:<http://www.owl-ontologies.com/Expert.owl#> "
            + "SELECT ?expert ?subject "
            + "WHERE {?expert Expert:familiar_with ?subject} ";

    /* 创建推理机 */
    Reasoner reasoner2 = new GenericRuleReasoner(Rule.parseRules(rule));

    InfModel inf = ModelFactory.createInfModel(reasoner2, model);
    Query query = QueryFactory.create(queryString);

    QueryExecution qe = QueryExecutionFactory.create(query, inf);
    ResultSet results = qe.execSelect();
    /* 打印结果 */
    ResultSetFormatter.out(System.out, results, query);
    qe.close();
}

}


--  作者:gflzx6506
--  发布时间:5/26/2010 8:44:00 PM

--  
这个例子的查询 是可以通的。。。
/* 本体中的各个class,同时将各个class的subclass和property
这个例子你实现了吗?
--  作者:oO天天Oo
--  发布时间:5/27/2010 1:04:00 PM

--  
那个都成功的,你这么一说,我后来又看了下,发现少编了一句程序,现在走通了,太感谢了!!!
--  作者:gflzx6506
--  发布时间:5/28/2010 10:22:00 PM

--  
以下是引用oO天天Oo在2010-5-27 13:04:00的发言:
那个都成功的,你这么一说,我后来又看了下,发现少编了一句程序,现在走通了,太感谢了!!!

/* 本体中的各个class,同时将各个class的subclass和property
还有一个这个程序: 获取专家具体信息

这2个程序 我一直没调通 请问下您 是怎么改的?谢谢


--  作者:shenxin1986
--  发布时间:5/31/2010 5:41:00 PM

--  
能输出这个,怎么体现的语义检索?
--  作者:shenxin1986
--  发布时间:6/4/2010 7:56:00 PM

--  
表格没有输出
--  作者:shenxin1986
--  发布时间:6/4/2010 8:19:00 PM

--  

[此贴子已经被作者于2010-6-4 21:50:44编辑过]

--  作者:tracystar
--  发布时间:9/18/2010 11:08:00 AM

--  
谢谢楼主的分享。根据楼主给的owl文件,和上面的程序,是没有查出结果的。程序代码没有问题,看了一下,楼主给出的owl文件中,associate这个属性关系建的不对。associate的定义域应是ResearchDirection,值域是subject,这样才能和推理规则匹配上。另外建好这个关系后,还要添加相应的实例,就能够查出结果了。
--  作者:cooldandans
--  发布时间:6/27/2011 11:04:00 AM

--  
在Export.owl中,个体chenjianer 有个属性familiar_with,其值域就是Computer_Software_and_Theory。当我删除此个体的属性,再次运行程序,发现无结果,到底是怎么回事?到底有没有对加入的规则进行推理呢?
--  作者:yindongbo
--  发布时间:2/24/2012 9:26:00 AM

--  
对啊,感觉制定的规则根本没有发挥作用,根本不能查询出根据规则推理出来的结果
--  作者:yindongbo
--  发布时间:2/24/2012 10:05:00 AM

--  
以下是引用cooldandans在2011-6-27 11:04:00的发言:
在Export.owl中,个体chenjianer 有个属性familiar_with,其值域就是Computer_Software_and_Theory。当我删除此个体的属性,再次运行程序,发现无结果,到底是怎么回事?到底有没有对加入的规则进行推理呢?


我找到原因了,设置规则里面有一个关系名称是错的,和owl文件里得名称不对应,程序里是associate,而owl文件中是associat,把程序中改为associat即可得到理想结果


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