Package com.hp.hpl.jena.reasoner

Examples of com.hp.hpl.jena.reasoner.Reasoner


        if (!conclusionsType.equals(FalseDocument)) {
            conclusions = loadFile(conclusionsRes.toString());
        }
       
        // Construct the inferred graph
        Reasoner reasoner = reasonerF.create(configuration);
        InfGraph graph = reasoner.bind(premises.getGraph());
        Model result = ModelFactory.createModelForGraph(graph);
       
        // Check the results against the official conclusions
        boolean correct = true;
        int goodResult = PASS;
View Full Code Here


     * @return true if the test passes
     * @throws IOException if one of the test files can't be found
     * @throws JenaException if the test can't be found or fails internally
     */
    public boolean runTest(String uri, ReasonerFactory reasonerF, TestCase testcase, Resource configuration) throws IOException {
        Reasoner reasoner = reasonerF.create(configuration);
        return runTest(uri, reasoner, testcase);
    }
View Full Code Here

                {ReasonerRegistry.getRDFSSimpleReasoner(), Boolean.TRUE},
        };
        Model data = ModelFactory.createDefaultModel();
        for ( Object[] test : testSpec )
        {
            Reasoner r = (Reasoner) test[0];
            Boolean safe = (Boolean) test[1];
            InfGraph ig = r.bind( data.getGraph() );
            assertEquals( r.toString(), safe.booleanValue(), ig.getCapabilities().findContractSafe() );
        }
    }
View Full Code Here

        // create a empty union graph
        MultiUnion u = new MultiUnion();
        u.addGraph( base );
        u.setBaseGraph( base );

        Reasoner r = spec.getReasoner();
        // if we have a reasoner in the spec, bind to the union graph and return
        return r == null ? (Graph) u : r.bind( u );
    }
View Full Code Here

    "[rdfs9:  (?x rdfs:subClassOf ?y) (?a rdf:type ?x) -> (?a rdf:type ?y)]" +
    "[restriction2: (?C owl:onProperty ?P), (?C owl:allValuesFrom ?D) -> (?C owl:equivalentClass all(?P, ?D))]" +
    "[rs2: (?D owl:equivalentClass all(?P,?C)), (?X rdf:type ?D) -> (?X rdf:type all(?P,?C))]" +
    "[rp4: (?X rdf:type all(?P, ?C)), (?X ?P ?Y) -> (?Y rdf:type ?C)]"
                          );       
        Reasoner reasoner =  createReasoner(rules);
        InfGraph infgraph = reasoner.bind(data);
        TestUtil.assertIteratorValues(this,
              infgraph.find(b, ty, c), new Object[] {
                  new Triple(b, ty, c)
              } );
    }
View Full Code Here

        "[restrictionProc13: (owl:Thing rdfs:subClassOf all(?P, ?C)) -> (?P rdfs:range ?C)]" +
        "[restrictionSubclass1: unbound(?D) (?X rdf:type ?R), isFunctor(?R) (?D owl:equivalentClass ?R) -> (?X rdf:type ?D)]" +
        "[restrictionSubclass2: bound(?R), isFunctor(?R), (?D owl:equivalentClass ?R),(?X rdf:type ?D) -> (?X rdf:type ?R)]" +
        "[restrictionSubclass2: unbound(?R), (?X rdf:type ?D), (?D owl:equivalentClass ?R) isFunctor(?R) -> (?X rdf:type ?R)]" +
                       ""  );       
        Reasoner reasoner =  createReasoner(rules);
        InfGraph infgraph = reasoner.bind(data);
        TestUtil.assertIteratorValues(this,
              infgraph.find(a, ty, C1), new Object[] {
                  new Triple(a, ty, C1)
              } );
        TestUtil.assertIteratorValues(this,
View Full Code Here

        "[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]" +
        "[rdfs8:  (?a rdfs:subClassOf ?b) (?b rdfs:subClassOf ?c) -> (?a rdfs:subClassOf ?c)]" +
        "[restrictionProc4b: bound(?Y) (?X ?P ?Y), notEqual(?P, rdf:type), (?X rdf:type all(?P, ?C)),-> (?Y rdf:type ?C)]" +
        "[restrictionProc4b: unbound(?Y), (?X rdf:type all(?P, ?C)), (?X ?P ?Y), notEqual(?P, rdf:type),-> (?Y rdf:type ?C)]" +
                       ""  );       
        Reasoner reasoner =  createReasoner(rules);
        InfGraph infgraph = reasoner.bind(data);
        TestUtil.assertIteratorValues(this,
              infgraph.find(null, ty, c), new Object[] {
              } );
    }
View Full Code Here

        "[rdfs9:  (?x rdfs:subClassOf ?y), (?a rdf:type ?x) -> (?a rdf:type ?y)]" +
//        "[-> (rdf:type rdfs:range rdfs:Class)]" +
        "[rdfs3:  (?x ?p ?y), (?p rdfs:range ?c) -> (?y rdf:type ?c)]" +
        "[rdfs7:  (?a rdf:type rdfs:Class) -> (?a rdfs:subClassOf ?a)]"
                        );       
        Reasoner reasoner =  createReasoner(rules);
        InfGraph infgraph = reasoner.bind(data);
        // Get just one result
        ExtendedIterator<Triple> it = infgraph.find(a, ty, null);
        Triple result = it.next();
        assertEquals(result.getSubject(), a);
        assertEquals(result.getPredicate(), ty);
View Full Code Here

        Node p = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#p");
        Node r = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#r");
        Node C1 = NodeFactory.createURI("http://www.hpl.hp.com/semweb/2003/eg#C1");
        data.add(new Triple(a, p, b));
        List<Rule> rules = Rule.parseRules(Util.loadRuleParserFromResourceFile("testing/reasoners/bugs/rdfs-error1.brules"));
        Reasoner reasoner =  createReasoner(rules);
        InfGraph infgraph = reasoner.bind(data);
        TestUtil.assertIteratorValues(this,
            infgraph.find(b, ty, C1),
            new Object[] {
                new Triple(b, ty, C1)
            } );
View Full Code Here

                + " (?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" + 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();
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.reasoner.Reasoner

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.