通过耶拿的rdf推理规则

时间:2013-04-28 14:50:37

标签: jena reasoning jena-rules

我想表达这种关系:如果文章X有作者Y,并且作者有影响因素中等或高(3类:低,中,高)那么本文被认为是强烈推荐的。

(?x computer-science#hasAuthor ?y)(?y computer-science#hasInfluenceFactor computer-science#High) -> (?x computer-science#isImportant computer-science#importantfactor)

是我的想法吗?

这里有一些本体论片段

<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor">
    <rdf:type rdf:resource="&owl;TransitiveProperty"/>
    <owl:propertyDisjointWith rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#isAuthorOf"/>
    <rdfs:range>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor"/>
            <owl:someValuesFrom rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#author"/>
        </owl:Restriction>
    </rdfs:range>
    <rdfs:domain>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor"/>
            <owl:someValuesFrom rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article"/>
        </owl:Restriction>
    </rdfs:domain>
</owl:ObjectProperty>
   <owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor">
    <rdf:type rdf:resource="&owl;TransitiveProperty"/>
    <rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#author"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#influenceFator"/>
</owl:ObjectProperty>
<owl:NamedIndividual rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#High">
    <rdf:type rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#influenceFator"/>
</owl:NamedIndividual>
<owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#isImportant">
    <rdf:type rdf:resource="&owl;TransitiveProperty"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#importantFactor"/>
    <rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#influenceFator"/>
</owl:ObjectProperty>
  <owl:NamedIndividual rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#importantFactor">
    <rdf:type rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#importantFactor"/>
</owl:NamedIndividual>

真诚地感谢任何观众提出我的问题:)

1 个答案:

答案 0 :(得分:0)

您不需要创建规则来表达您的本体,您可以完全在OWL中完成。首先,我们根据您的示例定义一个本体,但是使用一些新的公理。特别是,我们定义了两个新的类表达式:InfluentialArticleImportantArticle。一篇有影响力的文章具有高度或中等影响力,一位重要的作者写了至少一篇有影响力的文章:

@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>.
@prefix owl: <http://www.w3.org/2002/07/owl#>.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix cs: <http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#>.

# properties
cs:hasAuthor
  a       owl:ObjectProperty ;
  rdfs:domain cs:Article ;
  rdfs:range cs:Author .

cs:wrote
  a owl:ObjectPropert ;
  owl:inverseOf cs:hasAuthor .

# classes
cs:hasInfluenceFactor
  a       owl:ObjectProperty ;
  rdfs:domain cs:Article ;
  rdfs:range cs:InfluenceFactor .

cs:InfluenceFactor
  owl:equivalentClass
    [a owl:Class ;
     owl:oneOf ( cs:high cs:medium cs:low )
    ].

cs:Author a owl:Class.
cs:Article a owl:Class.

# axioms

# an influential article has a high or medium impact
cs:InfluentialArticle
  rdfs:subClassOf cs:Article ;
  owl:equivalentClass [
    owl:unionOf (
      [a owl:Restriction ;
       owl:onProperty cs:hasInfluenceFactor ;
       owl:hasValue cs:high]
      [a owl:Restriction ;
       owl:onProperty cs:hasInfluenceFactor ;
       owl:hasValue cs:medium
      ]
    )
  ].

# an important author wrote an influential article
cs:ImportantAuthor
  rdfs:subClassOf cs:Author ;
  owl:equivalentClass [
    a owl:Restriction ;
    owl:onProperty cs:wrote ;
    owl:someValuesFrom cs:InfluentialArticle
  ].

# individuals

# fred wrote a lousy paper
cs:fred
  a cs:Author.
cs:article1
  a cs:Article ;
  cs:hasInfluenceFactor cs:low ;
  cs:hasAuthor cs:fred.

# jane wrote a good paper
cs:jane
  a cs:Author.
cs:article2
  a cs:Article ;
  cs:hasInfluenceFactor cs:high ;
  cs:hasAuthor cs:jane.

现在我们可以编写一些Jena代码来加载这个本体并使用内置的推理器处理它:

package examples;

import java.util.Iterator;

import com.hp.hpl.jena.ontology.*;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.util.FileManager;

public class ReasonerExample
{
    String NS = "http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#";

    public static void main( String[] args ) {
        new ReasonerExample().run();
    }

    public void run() {
        OntModel m = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM_MICRO_RULE_INF );
        FileManager.get().readModel( m, "src/main/resources/comp-sci.ttl" );

        // list all authors
        System.out.println( "All authors:" );
        OntClass author = m.getOntClass( NS + "Author" );
        for (Iterator<? extends OntResource> i = author.listInstances(); i.hasNext(); ) {
            System.out.println( "  " + i.next().getURI() );
        }

        // list high impact authors
        OntClass importantAuthor = m.getOntClass( NS + "ImportantAuthor" );
        System.out.println( "Important authors:" );
        for (Iterator<? extends OntResource> i = importantAuthor.listInstances(); i.hasNext(); ) {
            System.out.println( "  " + i.next().getURI() );
        }
    }
}

其中给出了以下输出:

All authors:
  http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#jane
  http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#fred
Important authors:
  http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#jane

注意我还修改了你的名字以使用OWL约定:类的大写字母,其他一切的小写字母。我还简化了域和范围约束,这有点奇怪。

<强>更新

根据原始海报的评论,我使用Jena的rdfcat工具将本体转换为RDF / XML,如下所示:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:cs="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Class rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
  <owl:Class rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Author"/>
  <owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
    <rdfs:range rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Author"/>
  </owl:ObjectProperty>
  <owl:ObjectProperty rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor">
    <rdfs:domain rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
    <rdfs:range>
      <rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#InfluenceFactor">
        <owl:equivalentClass>
          <owl:Class>
            <owl:oneOf rdf:parseType="Collection">
              <rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#high"/>
              <rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#medium"/>
              <rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#low"/>
            </owl:oneOf>
          </owl:Class>
        </owl:equivalentClass>
      </rdf:Description>
    </rdfs:range>
  </owl:ObjectProperty>
  <rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#ImportantAuthor">
    <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Author"/>
    <owl:equivalentClass>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectPropert rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#wrote">
            <owl:inverseOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasAuthor"/>
          </owl:ObjectPropert>
        </owl:onProperty>
        <owl:someValuesFrom>
          <rdf:Description rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#InfluentialArticle">
            <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#Article"/>
            <owl:equivalentClass rdf:parseType="Resource">
              <owl:unionOf rdf:parseType="Collection">
                <owl:Restriction>
                  <owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor"/>
                  <owl:hasValue rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#high"/>
                </owl:Restriction>
                <owl:Restriction>
                  <owl:onProperty rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#hasInfluenceFactor"/>
                  <owl:hasValue rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#medium"/>
                </owl:Restriction>
              </owl:unionOf>
            </owl:equivalentClass>
          </rdf:Description>
        </owl:someValuesFrom>
      </owl:Restriction>
    </owl:equivalentClass>
  </rdf:Description>
  <cs:Article rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article2">
    <cs:hasInfluenceFactor rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#high"/>
    <cs:hasAuthor>
      <cs:Author rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#jane"/>
    </cs:hasAuthor>
  </cs:Article>
  <cs:Article rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#article1">
    <cs:hasInfluenceFactor rdf:resource="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#low"/>
    <cs:hasAuthor>
      <cs:Author rdf:about="http://www.semanticweb.org/aero/ontologies/2013/1/computer-science#fred"/>
    </cs:hasAuthor>
  </cs:Article>
</rdf:RDF>