Package com.hp.hpl.jena.rdf.model

Examples of com.hp.hpl.jena.rdf.model.InfModel


    // Setup input for the reasoner
    Model input = ModelFactory.createUnion(TestData.foaf,
        TestData.alexdma.getModel());

    // Is alexdma a foaf:Person?
    InfModel inferred = reasoningService.run(input);

    Statement isPerson = TestData.model.createStatement(TestData.alexdma,
        RDF.type, TestData.foaf_Person);

//    log.info("Statements: {}", TestUtils.printStatements(inferred,
//        TestData.enridaga, RDF.type));
    log.info("Is any rdfs:domain of foaf:knows a foaf:Person...(true)? {}",
        inferred.contains(isPerson));

    assertTrue(inferred.contains(isPerson));

    // Reset resource to be clean for other tests
    TestData.alexdma.removeProperties();
  }
View Full Code Here


    // Setup input for the reasoner
    Model input = ModelFactory.createUnion(TestData.foaf,
        TestData.alexdma.getModel());

    // Does alexdma know enridaga?
    InfModel inferred = reasoningService.run(input);

    Statement knowsHim = TestData.model.createStatement(TestData.alexdma,
        TestData.foaf_knows, TestData.enridaga);

    // log.info("Statements: {}", TestUtils.printStatements(inferred,
    //    TestData.enridaga, RDF.type));
    log.info("Does alexdma foaf:knows enridaga?...(true)? {}",
        inferred.contains(knowsHim));

    assertTrue(inferred.contains(knowsHim));

    // Reset resource to be clean for other tests
    TestData.alexdma.removeProperties();
  }
View Full Code Here

        // create the reasoner factory and the reasoner
    Resource conf = model.createResource();
    //conf.addProperty( ReasonerVocabulary.PROPtraceOn, "true" );
    RDFSRuleReasoner reasoner = (RDFSRuleReasoner) RDFSRuleReasonerFactory.theInstance().create(conf);
    // Create inference model
    InfModel infModel = ModelFactory.createInfModel(reasoner, model);
   
    model = infModel;
       
    //RDFReader reader = model.getReader("RDF/XML");
        ModelException.sendMessage(ModelException.INFO,
View Full Code Here

    public void testUnadornedInferenceModel()
        {
        Resource root = resourceInModel( "x ja:reasoner R; R rdf:type ja:ReasonerFactory" );
        Model m = Assembler.general.openModel( root );
        assertInstanceOf( InfModel.class, m );
        InfModel inf = (InfModel) m;
        assertIsoModels( empty, inf.getRawModel() );
        assertInstanceOf( GenericRuleReasoner.class, inf.getReasoner() );
        }
View Full Code Here

        Model a = FileManager.get().loadModel(BASE_DIR + abox);
        // Work around non-deterministic bug in bindSchema
        //        Reasoner r = rf.create(null).bindSchema(t);
        Reasoner r = rf.create(null);
        a.add(t);
        InfModel im = ModelFactory.createInfModel(r, a);
        return im.validate();
    }
View Full Code Here

        Model configurationRuleReasoner = ModelFactory.createDefaultModel();
        com.hp.hpl.jena.rdf.model.Resource configuration = configurationRuleReasoner.createResource();
        configuration.addProperty(ReasonerVocabulary.PROPruleMode, "forward");
        configuration.addProperty(ReasonerVocabulary.PROPsetRDFSLevel, ReasonerVocabulary.RDFS_SIMPLE);
        Reasoner ruleReasoner = RDFSRuleReasonerFactory.theInstance().create(configuration);
        InfModel inf = ModelFactory.createInfModel(ruleReasoner, schemaModel, baseModel);
        inf.read(new ByteArrayInputStream(TURTLE_RDF.getBytes()), "", "TURTLE");
        return inf;
    }
View Full Code Here

                + " (?answer qa:Ҫ���� ?key) "
                + " noValue(?key qa:�÷�) " + " -> "
                + " (?key qa:�÷� ?points)" + "]";
            List rules = Rule.parseRules(ruleSrc);
            Reasoner reasoner = new GenericRuleReasoner(rules);
            InfModel inf = ModelFactory.createInfModel(reasoner,
                model);

            StmtIterator it = inf.getDeductionsModel()
                .listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t " + obj.getString() + "��ȫ�֣�\n");
            }

            ruleSrc = "[rule2: (?keya rdf:type qa:��׼��Ҫ��) "
                + " (?keyb rdf:type qa:��׼��Ҫ��) "
                + " (?keyb qa:��ֵ ?points) "
                + " (?keya ?p ?keyb)"
                + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                + " (?question rdf:type qa:�Ծ�����) "
                + " (?standard rdf:type qa:��׼��) "
                + " (?answer qa:�Ծ������� ?question)"
                + " (?question qa:��׼���� ?standard) "
                + " (?standard qa:Ҫ���� ?keya) "
                + " (?standard qa:Ҫ���� ?keyb) "
                + " (?answer qa:Ҫ���� ?keya) "
                + " noValue(?answer qa:Ҫ���� ?keyb) "
                + " product(?points, 0.5, ?wpoints ) " + " -> "
                + " (?keyb qa:�÷� ?wpoints) " + " ]";
            rules = Rule.parseRules(ruleSrc);
            reasoner = new GenericRuleReasoner(rules);
            InfModel inf2 = ModelFactory.createInfModel(reasoner,
                inf);
            it = inf2.getDeductionsModel().listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t" + obj.getString() + "����֣�\n");
            }

            ruleSrc = "[rule3: (?key rdf:type qa:��׼��Ҫ��) noValue(?key qa:�÷�) -> (?key qa:�÷� 0.0) ]";
            rules = Rule.parseRules(ruleSrc);
            reasoner = new GenericRuleReasoner(rules);
            InfModel inf3 = ModelFactory.createInfModel(reasoner,
                inf2);
            it = inf3.getDeductionsModel().listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t" + obj.getString() + "����֣�\n");
            }
            docList
                .append("------------------------------------------------------------\n");

            ruleSrc = "[rule4: (qa:�Ӱ� qa:�÷� ?jbpoints) "
                + " (qa:��������λ�� qa:�÷� ?wzpoints) "
                + " (qa:н�� qa:�÷� ?xcpoints) "
                + " (qa:�������� qa:�÷� ?hjpoints ) "
                + " sum(?jbpoints, ?wzpoints, ?temp1) "
                + " sum(?temp1, ?xcpoints, ?temp2) "
                + " sum(?temp2, ?hjpoints, ?score) "
                + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                + " (?question rdf:type qa:�Ծ�����) "
                + " (?standard rdf:type qa:��׼��) "
                + " (?answer qa:�Ծ������� ?question)"
                + " (?question qa:��׼���� ?standard) " + " -> "
                + " (?answer qa:�÷� ?score) " + "]";
            rules = Rule.parseRules(ruleSrc);
            reasoner = new GenericRuleReasoner(rules);
            InfModel inf4 = ModelFactory.createInfModel(reasoner,
                inf3);
            it = inf4.getDeductionsModel().listStatements();
            while (it.hasNext()) {
              Statement stmt = it.nextStatement();
              Literal obj = (Literal) stmt.getObject();
              docList.append(stmt.getSubject().getLocalName()
                  + "\t" + stmt.getPredicate().getLocalName()
                  + "\t" + obj.getString() + "\n");
            }
            docList.append("�������");

          } catch (FileNotFoundException ex) {
            JOptionPane.showMessageDialog(frame,
                "�޷����ر���⣬��ȷ��qa.owl������ڵ�ǰĿ¼�¡�", "Error!",
                JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
          } catch (Exception ex) {
            JOptionPane.showMessageDialog(frame,
                "���������鿴error.log�ļ���", "Error!",
                JOptionPane.ERROR_MESSAGE);
            ex.printStackTrace();
          }
        }
      }
    });

    run.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {

        new Thread() {
          public void run() {
            docList.setText("");
            docList.append("��ʼ����\n");
            OntModel model = ModelFactory
                .createOntologyModel(OntModelSpec.OWL_DL_MEM);
            try {
              model.read(new FileInputStream(new File("qa.owl")),
                  null);
              String prefix = "http://www.example.com/qa.owl#";
              PrintUtil.registerPrefix("qa", prefix);

              OntClass hd_c = model.getOntClass(prefix
                  + "�Ծ�����Ļش�");
              Individual zshd_i = hd_c.createIndividual(prefix
                  + "�����Ļش�");
              Individual wt_i = model.getIndividual(prefix
                  + "ͨ���������������Լ��Ĺ������");
              OntProperty wts_p = model.getOntProperty(prefix
                  + "�Ծ�������");
              zshd_i.addProperty(wts_p, wt_i);

              OntProperty ydy_p = model.getObjectProperty(prefix
                  + "Ҫ����");
              for (int i = 0; i < boxes.length; i++) {
                if (boxes[i].isSelected()) {
                  Individual yd_i = model
                      .getIndividual(prefix
                          + boxes[i].getLabel());
                  zshd_i.addProperty(ydy_p, yd_i);
                }
              }

              String ruleSrc = "[rule1: (?key rdf:type qa:��׼��Ҫ��) "
                  + " (?key qa:��ֵ ?points) "
                  + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                  + " (?question rdf:type qa:�Ծ�����) "
                  + " (?standard rdf:type qa:��׼��) "
                  + " (?answer qa:�Ծ������� ?question)"
                  + " (?question qa:��׼���� ?standard) "
                  + " (?standard qa:Ҫ���� ?key) "
                  + " (?answer qa:Ҫ���� ?key) "
                  + " noValue(?key qa:�÷�) "
                  + " -> "
                  + " (?key qa:�÷� ?points)" + "]";
              List rules = Rule.parseRules(ruleSrc);
              Reasoner reasoner = new GenericRuleReasoner(rules);
              InfModel inf = ModelFactory.createInfModel(
                  reasoner, model);

              StmtIterator it = inf.getDeductionsModel()
                  .listStatements();
              while (it.hasNext()) {
                Statement stmt = it.nextStatement();
                Literal obj = (Literal) stmt.getObject();
                docList.append(stmt.getSubject().getLocalName()
                    + "\t"
                    + stmt.getPredicate().getLocalName()
                    + "\t " + obj.getString() + "��ȫ�֣�\n");
              }

              ruleSrc = "[rule2: (?keya rdf:type qa:��׼��Ҫ��) "
                  + " (?keyb rdf:type qa:��׼��Ҫ��) "
                  + " (?keyb qa:��ֵ ?points) "
                  + " (?keya ?p ?keyb)"
                  + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                  + " (?question rdf:type qa:�Ծ�����) "
                  + " (?standard rdf:type qa:��׼��) "
                  + " (?answer qa:�Ծ������� ?question)"
                  + " (?question qa:��׼���� ?standard) "
                  + " (?standard qa:Ҫ���� ?keya) "
                  + " (?standard qa:Ҫ���� ?keyb) "
                  + " (?answer qa:Ҫ���� ?keya) "
                  + " noValue(?answer qa:Ҫ���� ?keyb) "
                  + " product(?points, 0.5, ?wpoints ) "
                  + " -> " + " (?keyb qa:�÷� ?wpoints) "
                  + " ]";
              rules = Rule.parseRules(ruleSrc);
              reasoner = new GenericRuleReasoner(rules);
              InfModel inf2 = ModelFactory.createInfModel(
                  reasoner, inf);
              it = inf2.getDeductionsModel().listStatements();
              while (it.hasNext()) {
                Statement stmt = it.nextStatement();
                Literal obj = (Literal) stmt.getObject();
                docList.append(stmt.getSubject().getLocalName()
                    + "\t"
                    + stmt.getPredicate().getLocalName()
                    + "\t" + obj.getString() + "����֣�\n");
              }

              ruleSrc = "[rule3: (?key rdf:type qa:��׼��Ҫ��) noValue(?key qa:�÷�) -> (?key qa:�÷� 0.0) ]";
              rules = Rule.parseRules(ruleSrc);
              reasoner = new GenericRuleReasoner(rules);
              InfModel inf3 = ModelFactory.createInfModel(
                  reasoner, inf2);
              it = inf3.getDeductionsModel().listStatements();
              while (it.hasNext()) {
                Statement stmt = it.nextStatement();
                Literal obj = (Literal) stmt.getObject();
                docList.append(stmt.getSubject().getLocalName()
                    + "\t"
                    + stmt.getPredicate().getLocalName()
                    + "\t" + obj.getString() + "����֣�\n");
              }
              docList
                  .append("------------------------------------------------------------\n");

              ruleSrc = "[rule4: (qa:�Ӱ� qa:�÷� ?jbpoints) "
                  + " (qa:��������λ�� qa:�÷� ?wzpoints) "
                  + " (qa:н�� qa:�÷� ?xcpoints) "
                  + " (qa:�������� qa:�÷� ?hjpoints ) "
                  + " sum(?jbpoints, ?wzpoints, ?temp1) "
                  + " sum(?temp1, ?xcpoints, ?temp2) "
                  + " sum(?temp2, ?hjpoints, ?score) "
                  + " (?answer rdf:type qa:�Ծ�����Ļش�) "
                  + " (?question rdf:type qa:�Ծ�����) "
                  + " (?standard rdf:type qa:��׼��) "
                  + " (?answer qa:�Ծ������� ?question)"
                  + " (?question qa:��׼���� ?standard) "
                  + " -> " + " (?answer qa:�÷� ?score) " + "]";
              rules = Rule.parseRules(ruleSrc);
              reasoner = new GenericRuleReasoner(rules);
              InfModel inf4 = ModelFactory.createInfModel(
                  reasoner, inf3);
              it = inf4.getDeductionsModel().listStatements();
              while (it.hasNext()) {
                Statement stmt = it.nextStatement();
                Literal obj = (Literal) stmt.getObject();
                docList.append(stmt.getSubject().getLocalName()
                    + "\t"
View Full Code Here

        " -> " +
        " (?key qa:�÷� ?points)"
        + "]";
    List rules = Rule.parseRules(ruleSrc);
    Reasoner reasoner = new GenericRuleReasoner(rules);
    InfModel inf = ModelFactory.createInfModel(reasoner, model);

    PrintUtil.printOut(inf.getDeductionsModel().listStatements());
    System.out.println("-------");

//    ruleSrc = "[rule2: (?key rdf:type qa:��׼��Ҫ��) noValue(?key qa:�÷�) -> (?key qa:�÷� 0.0) ]";
    ruleSrc = "[rule2: (?keya rdf:type qa:��׼��Ҫ��) " +
        " (?keyb rdf:type qa:��׼��Ҫ��) " +
        " (?keyb qa:��ֵ ?points) " +
        " (?keya ?p ?keyb)" +
        " (?answer rdf:type qa:�Ծ�����Ļش�) " +
        " (?question rdf:type qa:�Ծ�����) " +
        " (?standard rdf:type qa:��׼��) " +
        " (?answer qa:�Ծ������� ?question)" +
        " (?question qa:��׼���� ?standard) " +
        " (?standard qa:Ҫ���� ?keya) " +
        " (?standard qa:Ҫ���� ?keyb) " +
        " (?answer qa:Ҫ���� ?keya) " +
        " noValue(?answer qa:Ҫ���� ?keyb) " +   
        " product(?points, 0.5, ?wpoints ) " +
        " -> " +
        " (?keyb qa:�÷� ?wpoints) " +
        " ]";
    rules = Rule.parseRules(ruleSrc);
    reasoner = new GenericRuleReasoner(rules);
    InfModel inf2 = ModelFactory.createInfModel(reasoner, inf);
    PrintUtil.printOut(inf2.getDeductionsModel().listStatements());
    System.out.println("-------");
   
    ruleSrc = "[rule3: (?key rdf:type qa:��׼��Ҫ��) noValue(?key qa:�÷�) -> (?key qa:�÷� 0.0) ]";
    rules = Rule.parseRules(ruleSrc);
    reasoner = new GenericRuleReasoner(rules);
    InfModel inf3 = ModelFactory.createInfModel(reasoner, inf2);
    PrintUtil.printOut(inf3.getDeductionsModel().listStatements());
    System.out.println("-------");
   
    ruleSrc = "[rule4: (qa:�Ӱ� qa:�÷� ?jbpoints) " +
        " (qa:��������λ�� qa:�÷� ?wzpoints) " +
        " (qa:н�� qa:�÷� ?xcpoints) " +
        " (qa:�������� qa:�÷� ?hjpoints ) " +
        " sum(?jbpoints, ?wzpoints, ?temp1) " +
        " sum(?temp1, ?xcpoints, ?temp2) " +
        " sum(?temp2, ?hjpoints, ?score) " +
        " (?answer rdf:type qa:�Ծ�����Ļش�) " +
        " (?question rdf:type qa:�Ծ�����) " +
        " (?standard rdf:type qa:��׼��) " +
        " (?answer qa:�Ծ������� ?question)" +
        " (?question qa:��׼���� ?standard) " +
        " -> " +
        " (?answer qa:�÷� ?score) " +
        "]";
    rules = Rule.parseRules(ruleSrc);
    reasoner = new GenericRuleReasoner(rules);
    InfModel inf4 = ModelFactory.createInfModel(reasoner, inf3);
    PrintUtil.printOut(inf4.getDeductionsModel().listStatements());
    System.out.println("-------");
   
   
  }
View Full Code Here

    public void testUnadornedInferenceModel()
        {
        Resource root = resourceInModel( "x ja:reasoner R; R rdf:type ja:ReasonerFactory" );
        Model m = Assembler.general.openModel( root );
        assertInstanceOf( InfModel.class, m );
        InfModel inf = (InfModel) m;
        assertIsoModels( empty, inf.getRawModel() );
        assertInstanceOf( GenericRuleReasoner.class, inf.getReasoner() );
        }
View Full Code Here

        Statement asserted = base.createStatement(r, p, l);
        r.addProperty(p, l);
       
        List<Rule> rules = Rule.parseRules("(?r eg:p ?v) -> (?v eg:q ?r).");
        GenericRuleReasoner reasoner = new GenericRuleReasoner(rules);
        InfModel inf = ModelFactory.createInfModel(reasoner, base);
        TestUtil.assertIteratorValues(this, inf.listStatements(), new Statement[]{asserted});
       
        Model deductions = inf.getDeductionsModel();
        TestUtil.assertIteratorValues(this, deductions.listStatements(), new Statement[]{});
       
        Graph safeGraph = deductions.getGraph();
        assertTrue(safeGraph instanceof SafeGraph);
       
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.rdf.model.InfModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.