Нет выходных данных для правила в Йене, использующего обобщенный аргумент правила

Я создал онтологию в Protege и импортировал эту онтологию в Eclipse, используя Jena. Я написал правила в файле правил и хочу, чтобы вывод правил отображался в Йене, но он не отображает вывод. Программа выполняется без ошибок. Детали онтологии

Вещь
Дети

  • 0-12Months
  • 1-3years
  • 4-7Years
  • 7-12Years

игрушки

  • Велосипеды
  • Строительные блоки
  • куклы
  • Коньки
  • Мягкие игрушки

Добавлено одно свойство типа данных play с дочерними доменами и диапазоном игрушек, играющих в обратном порядке. Добавлено четыре отдельных лица.

  • Jhon экземпляр 0-12 месяцев
  • Мэри экземпляр 1-3 года
  • Сам экземпляр 4-7лет
  • кузнец инстанс 7-12лет
    • Тедди-экземпляр Stuffed_toy написал правило для назначения экземпляра класса 0-12Months, используя свойство playWith как экземпляр stuffed_toys teddy.
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
@prefix df: <http://www.semanticweb.org/ontologies/2014/9/9/child#>
[rule1: (?x rdf:type df:0-12Months)  -> (?x df:playWith ?Stuffed_toys)]
[rule21: (?x df:playWith ?Stuffed_toys) -> print(?x ,'Plays with teddy')]

Код есть;

public class GetStartedSemWeb
{
    static String defaultNameSpace="http://semanticweb.org/ontologies#";
    static OntModel schema = null;
    OntModel infmodel =null;

    public static void main(String[] args) throws IOException
    {
        GetStartedSemWeb getsemweb = new GetStartedSemWeb();
        System.out.println(" Adding  toy ontology ");
        getsemweb.loadontology();
    }

    private void loadontology() throws IOException
    {
        schema = ModelFactory.createOntologyModel();
        java.io.InputStream inschema =FileManager.get().open("C:/Users/Desktop/Documents/PERSONALIZATION_CHILDREN/child.owl");
        schema.read(inschema,defaultNameSpace);
        schema.write(System.out, "RDF/XML");
        String rulefile="C:/Users/Desktop/Documents/PERSONALIZATION_CHILDREN/rule1.txt";
        java.util.List rules1 = Rule.rulesFromURL(rulefile);
        System.out.println(rules1);
        Reasoner reasoner = new GenericRuleReasoner(rules1);
        reasoner = reasoner.bindSchema(schema);
        InfModel infmodel = ModelFactory.createInfModel(reasoner,schema);
        Resource children = infmodel.getResource("http://semanticweb.org/ontologies/2014/9/9/child.owl/Children#");
        System.out.println(children);
        printStatements(infmodel,children,null ,null);
    }

    private static void printStatements(InfModelinfmodel,Resource s, Property p1, Resource o1)
    {
        System.out.println("Children");
        for(StmtIterator i = infmodel.listStatements(s,p1,o1);i.hasNext();)
        {
            System.out.println("Children");
            Statement stmt = i.nextStatement();
            System.out.println(" - "+PrintUtil.print(stmt));
        }
    }
}

RDF / xml КОД ЕСТЬ

     df:RDF xml:base="http://www.semanticweb.org/ontologies/2014/9/9/child.owl"><owl:Ontology               

     rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl"/><!-- 
          ///////////////////////////////////////////////////////////////////////////////////////
      //
       // Object Properties
      //


     ///////////////////////////////////////////////////////////////////////////////////////
           --><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#PlayedBy -->                                   
              <owl:ObjectProperty           


              rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#PlayedBy"> 

           <rdfs:range                            

               rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children"/>  

       <rdfs:domain rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/>        
           </owl:ObjectProperty><!--                     
          http://www.semanticweb.org/ontologies/2014/9/9/child.owl#playWith --> 

          <owl:ObjectProperty 
           rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#playWith">

        <rdfs:domain 

              rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children"/>           

             <owl:inverseOf     

   rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#PlayedBy"/><rdfs:range 

     rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/> 

     </owl:ObjectProperty><!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////

   --><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#0-12Months --><owl:Class              


       rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#0-12Months">


   <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#1-3Years">      

<rdfs:subClassOf 

  rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children"/></owl:Class> 

     <!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#4-7Years --><owl:Class 

   rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#4-7Years"><rdfs:subClassOf 

    rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children"/>

 </owl:Class><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#7-12Years -->  

   <owl:Class rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#7-12Years">

 <rdfs:subClassOf   

   rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children"/></owl:Class>

       <!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Bikes --><owl:Class 

         rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Bikes">

      <rdfs:subClassOf 

      rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/></owl:Class>

      <!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Building_Blocks --><owl:Class 

       rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Building_Blocks">

       <rdfs:subClassOf 

        rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/></owl:Class>

       <!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children --><owl:Class 

       rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Children">

       <rdfs:subClassOf rdf:resource="http://www.w3.org/2002/07/owl#Thing"/><owl:disjointWith 

         rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/>

    </owl:Class><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Doll --><owl:Class 

  rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Doll"><rdfs:subClassOf 

      rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/></owl:Class>

      <!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Skates --><owl:Class 

       rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Skates">

      <rdfs:subClassOf 

   rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/></owl:Class><!-- 

    http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Stuffed_toys --><owl:Class 

   rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Stuffed_toys">

   <rdfs:subClassOf rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"/>

    </owl:Class><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy --><owl:Class 

       rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Toy"><rdfs:subClassOf 

      rdf:resource="http://www.w3.org/2002/07/owl#Thing"/></owl:Class><!-- 
///////////////////////////////////////////////////////////////////////////////////////
//
// Individuals
//
///////////////////////////////////////////////////////////////////////////////////////
 --><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#John --><owl:NamedIndividual 

    rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#John"><rdf:type 

        rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#0-12Months"/>

         </owl:NamedIndividual><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#mary 

--><owl:NamedIndividual 

      rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#mary"><rdf:type 

           rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#1-3Years"/>

     </owl:NamedIndividual><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#sam -->

   <owl:NamedIndividual rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#sam">

  <rdf:type rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#4-7Years"/>

 </owl:NamedIndividual><!-- http://www.semanticweb.org/ontologies/2014/9/9/child.owl#smith -->

  <owl:NamedIndividual 

  rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#smith"><rdf:type 

  rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#7-12Years"/>

    </owl:NamedIndividual><!-- 

  --><owl:NamedIndividual 

     rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#teddy"><rdf:type 

      rdf:resource="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Stuffed_toys"/>

          </owl:NamedIndividual>
///////////////////////////////////////////////////////////////////////////////////////
//
// General axioms
//
///////////////////////////////////////////////////////////////////////////////////////
 --><rdf:Description><rdf:type rdf:resource="http://www.w3.org/2002/07/owl#AllDifferent"/>               

      <owl:distinctMembers rdf:parseType="Collection"><rdf:Description 

     rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#John"/><rdf:Description 

    rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#mary"/><rdf:Description 

    rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#sam"/><rdf:Description 

     rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#smith"/>

    </owl:distinctMembers></rdf:Description><rdf:Description><rdf:type 

     rdf:resource="http://www.w3.org/2002/07/owl#AllDisjointClasses"/><owl:members 

       rdf:parseType="Collection"><rdf:Description 

      rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Bikes"/>

        <rdf:Description

       rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Building_Blocks"/>

      <rdf:Description 

      rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Doll"/><rdf:Description 

         rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Skates"/>

        <rdf:Description 

          rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#Stuffed_toys"/>

         </owl:members></rdf:Description><rdf:Description><rdf:type 

       rdf:resource="http://www.w3.org/2002/07/owl#AllDisjointClasses"/><owl:members 

             rdf:parseType="Collection"><rdf:Description 

           rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#0-12Months"/>

          <rdf:Description rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#1-                         

             3Years"/><rdf:Description 

         rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#4-7Years"/>

             <rdf:Description 

           rdf:about="http://www.semanticweb.org/ontologies/2014/9/9/child.owl#7-12Years"/>

                </owl:members>      </rdf:Description></rdf:RDF>

Я хочу, чтобы вывод для выполнения правила и все операторы дочернего класса были напечатаны, но этого не происходит, помогите мне найти решение, с которым я борюсь много дней.

Большое спасибо за то, что потратили время на мой вопрос. Извините, что не поставили вопрос в правильном формате. я обновил, пожалуйста, дайте мне знать об ошибке, я хочу использовать детскую онтологию и выполнить персонализацию для прогнозирования игрушек, которые нравятся детям в зависимости от их возрастной группы, путем разработки набора правил с помощью рассуждения, пожалуйста, помогите мне найти решение.

0 ответов

Другие вопросы по тегам