Package org.apache.marmotta.kiwi.reasoner.model.program

Examples of org.apache.marmotta.kiwi.reasoner.model.program.Justification


    @Test
    public void testJustificationSet() {
        Set<Justification> set = new HashSet<>();

        Justification j1 = new Justification();
        j1.setTriple(i1);
        j1.getSupportingTriples().add(t1);
        j1.getSupportingTriples().add(t4);
        set.add(j1);

        Justification j2 = new Justification();
        j2.setTriple(i4);
        j2.getSupportingTriples().add(t4);
        j2.getSupportingTriples().add(t1);

        Assert.assertTrue(set.contains(j2));

        set.add(j2);

        Assert.assertEquals(1, set.size());


        // j3 differs in the inferred triple
        Justification j3 = new Justification();
        j3.setTriple(i2);
        j3.getSupportingTriples().add(t4);
        j3.getSupportingTriples().add(t1);

        Assert.assertFalse(set.contains(j3));

        set.add(j3);

        Assert.assertEquals(2, set.size());


        // j4 differs in the supporting triples
        Justification j4 = new Justification();
        j4.setTriple(i1);
        j4.getSupportingTriples().add(t2);
        j4.getSupportingTriples().add(t4);

        Assert.assertFalse(set.contains(j4));

        set.add(j4);
View Full Code Here


            KiWiTriple triple = (KiWiTriple)inferred.get(0);
            List<Justification> justifications = Iterations.asList(rcon.listJustificationsForTriple(triple));
            Assert.assertEquals("number of justifications for triple differs from expected result",1,justifications.size());

            Justification j = justifications.get(0);
            Assert.assertEquals("number of supporting triples differs from expected result",1,j.getSupportingTriples().size());
            Assert.assertEquals("number of supporting rules differs from expected result",1,j.getSupportingRules().size());

            Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(0)));

            con.commit();


            // now remove again the base triple and inform the reasoner about it, as a consequence, the inferred
View Full Code Here

            KiWiTriple triple = (KiWiTriple)inferred.get(0);
            List<Justification> justifications = Iterations.asList(rcon.listJustificationsForTriple(triple));
            Assert.assertEquals("number of justifications for triple differs from expected result",1,justifications.size());

            Justification j = justifications.get(0);
            Assert.assertEquals("number of supporting triples differs from expected result",2,j.getSupportingTriples().size());
            Assert.assertEquals("number of supporting rules differs from expected result",1,j.getSupportingRules().size());

            Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(0)));
            Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(1)));

            con.commit();


            // add another triple and check if the incremental reasoning works
View Full Code Here

            updateInferred.executeBatch();
            updateInferred.close();

            // now we create some justifications for the inferred triples and store them
            Set<Justification> justifications = new HashSet<Justification>();
            Justification j1 = new Justification();
            j1.getSupportingRules().add(p.getRules().get(0));
            j1.getSupportingRules().add(p.getRules().get(1));
            j1.getSupportingTriples().add((KiWiTriple) baseTriples.get(0));
            j1.getSupportingTriples().add((KiWiTriple) baseTriples.get(1));
            j1.setTriple((KiWiTriple) infTriples.get(0));
            justifications.add(j1);

            Justification j2 = new Justification();
            j2.getSupportingRules().add(p.getRules().get(1));
            j2.getSupportingTriples().add((KiWiTriple) baseTriples.get(1));
            j2.getSupportingTriples().add((KiWiTriple) baseTriples.get(2));
            j2.setTriple((KiWiTriple) infTriples.get(1));
            justifications.add(j2);

            connection.storeJustifications(justifications);
            connection.commit();
View Full Code Here

            KiWiTriple triple = (KiWiTriple)inferred.get(0);
            List<Justification> justifications = Iterations.asList(rcon.listJustificationsForTriple(triple));
            Assert.assertEquals("number of justifications for triple differs from expected result",1,justifications.size());

            Justification j = justifications.get(0);
            Assert.assertEquals("number of supporting triples differs from expected result",1,j.getSupportingTriples().size());
            Assert.assertEquals("number of supporting rules differs from expected result",1,j.getSupportingRules().size());

            Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(0)));

            con.commit();


            // now remove again the base triple and inform the reasoner about it, as a consequence, the inferred
View Full Code Here

            KiWiTriple triple = (KiWiTriple)inferred.get(0);
            List<Justification> justifications = Iterations.asList(rcon.listJustificationsForTriple(triple));
            Assert.assertEquals("number of justifications for triple differs from expected result",1,justifications.size());

            Justification j = justifications.get(0);
            Assert.assertEquals("number of supporting triples differs from expected result",2,j.getSupportingTriples().size());
            Assert.assertEquals("number of supporting rules differs from expected result",1,j.getSupportingRules().size());

            Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(0)));
            Assert.assertThat("supporting triple does not match expectation", j.getSupportingTriples(), hasItem((KiWiTriple)statements.get(1)));

            con.commit();


            // add another triple and check if the incremental reasoning works
View Full Code Here

                        throw new IllegalArgumentException("Object of rule head may only be a variable, a literal, or a resource; rule: "+rule);


                    KiWiTriple triple = isail.addInferredStatement(subject, property, object);

                    Justification justification = new Justification();
                    justification.setTriple(triple);
                    justification.getSupportingRules().add(rule);
                    justification.getSupportingTriples().addAll(row.getJustifications());
                    justifications.add(justification);

                    // when the batch size is reached, commit the transaction, save the justifications, and start a new
                    // transaction and new justification set
                    if(++counter % config.getBatchSize() == 0) {
View Full Code Here

        Map<KiWiTriple,Collection<Justification>> justificationCache = new HashMap<KiWiTriple, Collection<Justification>>();

        for(Justification justification : justifications) {
            KiWiTriple triple = justification.getTriple();

            Justification newJustification = new Justification();
            newJustification.setSupportingRules(justification.getSupportingRules());
            newJustification.setTriple(triple);

            Set<Justification> tripleJustifications = Collections.singleton(newJustification);

            // resolve inferred triples by replacing them by their justifications
            for(KiWiTriple support : justification.getSupportingTriples()) {
                if(support.isInferred()) {
                    Collection<Justification> supportJustifications = justificationCache.get(support);
                    // cache justifications of triple in case they are needed again in this run
                    if(supportJustifications == null || supportJustifications.size() == 0) {
                        supportJustifications = getJustifications(connection, support, baseJustifications);
                        justificationCache.put(support,supportJustifications);
                    }

                    if(supportJustifications.size() == 0) {
                        log.error("error: inferred triple {} is not justified!",support);
                    }

                    // mix the two sets
                    Set<Justification> oldTripleJustifications = tripleJustifications;
                    tripleJustifications = new HashSet<Justification>();
                    for(Justification j1 : oldTripleJustifications) {
                        for(Justification j2 : supportJustifications) {
                            Justification j3 = new Justification();
                            j3.setTriple(triple);
                            j3.getSupportingTriples().addAll(j1.getSupportingTriples());
                            j3.getSupportingTriples().addAll(j2.getSupportingTriples());
                            j3.getSupportingRules().addAll(j1.getSupportingRules());
                            j3.getSupportingRules().addAll(j2.getSupportingRules());
                            tripleJustifications.add(j3);
                        }
                    }
                } else {
                    for(Justification j : tripleJustifications) {
View Full Code Here

     */
    private void removeDuplicateJustifications(KiWiReasoningConnection connection, Set<Justification> justifications) throws SQLException {
        // remove duplicate justifications
        HashMap<KiWiTriple,Collection<Justification>> justificationCache = new HashMap<KiWiTriple, Collection<Justification>>();
        for(Iterator<Justification> it = justifications.iterator(); it.hasNext(); ) {
            Justification j = it.next();

            Collection<Justification> supportJustifications = justificationCache.get(j.getTriple());
            // cache justifications of triple in case they are needed again in this run
            if(supportJustifications == null) {
                supportJustifications = getJustifications(connection, j.getTriple(), Collections.<Justification>emptySet());
                justificationCache.put(j.getTriple(),supportJustifications);
            }

            if(supportJustifications.contains(j)) {
                it.remove();
            }
View Full Code Here

TOP

Related Classes of org.apache.marmotta.kiwi.reasoner.model.program.Justification

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.