Examples of MGraph


Examples of org.apache.clerezza.rdf.core.MGraph

     */
    protected abstract MGraph getEmptyMGraph();
   
    @Test
    public void testAddCountAndGetTriples() {
        MGraph graph = getEmptyMGraph();
        Assert.assertEquals(0, graph.size());
        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
        graph.add(triple1);
        Assert.assertEquals(1, graph.size());
        Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, uriRef1);
        Assert.assertTrue(tripleIter.hasNext());
        Triple tripleGot = tripleIter.next();
        Assert.assertEquals(triple1, tripleGot);
        Assert.assertFalse(tripleIter.hasNext());
        BNode bnode = new BNode() {};
        graph.add(new TripleImpl(bnode, uriRef1, uriRef3));
        graph.add(new TripleImpl(bnode, uriRef1, uriRef4));
        tripleIter = graph.filter(null, uriRef1, null);
        Set<NonLiteral> subjectInMatchingTriples = new HashSet<NonLiteral>();
        Set<Resource> objectsInMatchingTriples = new HashSet<Resource>();
        while (tripleIter.hasNext()) {
            Triple triple = tripleIter.next();
            subjectInMatchingTriples.add(triple.getSubject());
            objectsInMatchingTriples.add(triple.getObject());
        }
        Assert.assertEquals(1, subjectInMatchingTriples.size());
        Assert.assertEquals(2, objectsInMatchingTriples.size());
        Set<Resource> expectedObjects = new HashSet<Resource>();
        expectedObjects.add(uriRef3);
        expectedObjects.add(uriRef4);
        Assert.assertEquals(expectedObjects, objectsInMatchingTriples);
        graph.add(new TripleImpl(bnode, uriRef4, bnode));
        tripleIter = graph.filter(null, uriRef4, null);
        Assert.assertTrue(tripleIter.hasNext());
        Triple retrievedTriple = tripleIter.next();
        Assert.assertFalse(tripleIter.hasNext());
        Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
        tripleIter = graph.filter(uriRef1, uriRef2, null);
        Assert.assertTrue(tripleIter.hasNext());
        retrievedTriple = tripleIter.next();
        Assert.assertFalse(tripleIter.hasNext());
        Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

        Assert.assertEquals(retrievedTriple.getSubject(), retrievedTriple.getObject());
    }
   
    @Test
    public void testRemoveAllTriples() {
        MGraph graph = getEmptyMGraph();
        Assert.assertEquals(0, graph.size());
        graph.add(new TripleImpl(uriRef1, uriRef2, uriRef3));
        graph.add(new TripleImpl(uriRef2, uriRef3, uriRef4));
        Assert.assertEquals(2, graph.size());
        graph.clear();
        Assert.assertEquals(0, graph.size());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

        Assert.assertEquals(0, graph.size());
    }

    @Test
    public void testUseTypedLiterals() {
        MGraph graph = getEmptyMGraph();
        Assert.assertEquals(0, graph.size());
        Literal value = new TypedLiteralImpl("<elem>value</elem>",xmlLiteralType);
        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
        graph.add(triple1);
        Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
        Assert.assertTrue(tripleIter.hasNext());
        Resource gotValue = tripleIter.next().getObject();
        Assert.assertEquals(value, gotValue);
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

        Assert.assertEquals(value, gotValue);
    }

    @Test
    public void testUseLanguageLiterals() {
        MGraph graph = getEmptyMGraph();
        Assert.assertEquals(0, graph.size());
        Language language = new Language("it");
        Literal value = new PlainLiteralImpl("<elem>value</elem>",language);
        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, value);
        graph.add(triple1);
        Iterator<Triple> tripleIter = graph.filter(uriRef1, uriRef2, null);
        Assert.assertTrue(tripleIter.hasNext());
        Resource gotValue = tripleIter.next().getObject();
        Assert.assertEquals(value, gotValue);
        Assert.assertEquals(language, ((PlainLiteral)gotValue).getLanguage());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

        Assert.assertEquals(language, ((PlainLiteral)gotValue).getLanguage());
    }

    @Test
    public void testRemoveViaIterator() {
        MGraph graph = getEmptyMGraph();
        Assert.assertEquals(0, graph.size());
        final TripleImpl triple1 = new TripleImpl(uriRef1, uriRef2, uriRef1);
        graph.add(triple1);
        final TripleImpl triple2 = new TripleImpl(uriRef1, uriRef2, uriRef4);
        graph.add(triple2);
        Assert.assertEquals(2, graph.size());
        Iterator<Triple> iterator = graph.iterator();
        while (iterator.hasNext()) {
            iterator.next();
            iterator.remove();
        }
        Assert.assertEquals(0, graph.size());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

        Assert.assertEquals(0, graph.size());
    }

    @Test
    public void testGetSize() throws Exception {
        MGraph graph = getEmptyMGraph();
        // The test graph must always be empty after test fixture setup
        Assert.assertEquals(0, graph.size());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

    }


    @Test
    public void testAddSingleTriple() throws Exception {
        MGraph graph = getEmptyMGraph();
        final Triple triple= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/alice");
        Assert.assertEquals(0, graph.size());
        Assert.assertTrue(graph.add(triple));
        Assert.assertEquals(1, graph.size());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

    }


    @Test
    public void testAddSameTripleTwice() throws Exception {
        MGraph graph = getEmptyMGraph();
        final Triple triple= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/alice");
        Assert.assertEquals(0, graph.size());
        Assert.assertTrue(graph.add(triple));
        Assert.assertFalse(graph.add(triple)); // Graph does not change
        Assert.assertEquals(1, graph.size());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

    }


    @Test
    public void testRemoveSingleTriple() throws Exception {
        MGraph graph = getEmptyMGraph();
        final Triple triple= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/alice");
        Assert.assertTrue(graph.add(triple));
        Assert.assertTrue(graph.remove(triple));
        Assert.assertEquals(0, graph.size());
    }
View Full Code Here

Examples of org.apache.clerezza.rdf.core.MGraph

        Assert.assertEquals(0, graph.size());
    }

    @Test
    public void testRemoveSameTripleTwice() throws Exception {
        MGraph graph = getEmptyMGraph();
        final Triple tripleAlice= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/alice");
        final Triple tripleBob= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/bob");
        Assert.assertTrue(graph.add(tripleAlice));
        Assert.assertTrue(graph.add(tripleBob));
        Assert.assertTrue(graph.remove(tripleAlice));
        Assert.assertFalse(graph.remove(tripleAlice));
        Assert.assertEquals(1, graph.size());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.