Examples of MGraph


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

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

    @Test
    public void testGetSameBNode() throws Exception {
        MGraph graph = getEmptyMGraph();
        BNode bNode = new BNode();
        final UriRef HAS_NAME = new UriRef("http://example.org/ontology/hasName");
        final PlainLiteralImpl name = new PlainLiteralImpl("http://example.org/people/alice");
        final PlainLiteralImpl name2 = new PlainLiteralImpl("http://example.org/people/bob");
        final Triple tripleAlice = new TripleImpl(bNode, HAS_NAME, name);
        final Triple tripleBob = new TripleImpl(bNode, HAS_NAME, name2);
        Assert.assertTrue(graph.add(tripleAlice));
        Assert.assertTrue(graph.add(tripleBob));
        Iterator<Triple> result = graph.filter(null, HAS_NAME, name);
        Assert.assertEquals(bNode, result.next().getSubject());
    }
View Full Code Here

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

        Assert.assertEquals(bNode, result.next().getSubject());
    }

    @Test
    public void testContainsIfContained() 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.contains(triple));
    }
View Full Code Here

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

    }


    @Test
    public void testContainsIfEmpty() 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.assertFalse(graph.contains(triple));
    }
View Full Code Here

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

    }


    @Test
    public void testContainsIfNotContained() throws Exception {
        MGraph graph = getEmptyMGraph();
        final Triple tripleAdd= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/alice");
        final Triple tripleTest= createTriple(
                "http://example.org/ontology/Person",
                "http://example.org/ontology/hasName",
                "http://example.org/people/bob");
        Assert.assertTrue(graph.add(tripleAdd));
        Assert.assertFalse(graph.contains(tripleTest));
    }
View Full Code Here

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

    }


    @Test
    public void testFilterEmptyGraph() throws Exception {
        MGraph graph = getEmptyMGraph();
        Iterator<Triple> i = graph.filter(null, null, null);
        Assert.assertFalse(i.hasNext());
    }
View Full Code Here

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

    }


    @Test
    public void testFilterSingleEntry() 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));

        Iterator<Triple> i = graph.filter(null, null, null);
        Collection<Triple> resultSet= toCollection(i);
        Assert.assertEquals(1, resultSet.size());
        Assert.assertTrue(resultSet.contains(triple));
    }
View Full Code Here

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

    }


    @Test
    public void testFilterByObject() 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));

        Iterator<Triple> iterator;
        Collection<Triple> resultSet;

        // Find bob
        iterator = graph.filter(null, null,
                new UriRef("http://example.org/people/bob"));
        resultSet= toCollection(iterator);
        Assert.assertEquals(1, resultSet.size());
        Assert.assertTrue(resultSet.contains(tripleBob));

        // Find alice
        iterator = graph.filter(null, null,
                new UriRef("http://example.org/people/alice"));
        resultSet= toCollection(iterator);
        Assert.assertEquals(1, resultSet.size());
        Assert.assertTrue(resultSet.contains(tripleAlice));

        // Find both
        iterator = graph.filter(null, null, null);
        resultSet= toCollection(iterator);
        Assert.assertEquals(2, resultSet.size());
        Assert.assertTrue(resultSet.contains(tripleAlice));
        Assert.assertTrue(resultSet.contains(tripleBob));
    }
View Full Code Here

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

        Assert.assertTrue(resultSet.contains(tripleBob));
    }

    @Test
    public void graphEventTestAddRemove() {
        MGraph mGraph = getEmptyMGraph();
        TestGraphListener listener = new TestGraphListener();
        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));       
        mGraph.add(trpl1);
        Assert.assertNull(listener.getEvents());       
        mGraph.add(trpl2);
        Assert.assertEquals(1, listener.getEvents().size());
        Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
        Assert.assertTrue(listener.getEvents().get(0) instanceof  AddEvent);
        listener.resetEvents();
        mGraph.remove(trpl2);
        Assert.assertEquals(1, listener.getEvents().size());
        Assert.assertEquals(trpl2, listener.getEvents().get(0).getTriple());
        Assert.assertTrue(listener.getEvents().get(0) instanceof RemoveEvent);
        listener.resetEvents();       
        mGraph.add(trpl3);
        Assert.assertEquals(1, listener.getEvents().size());
        Assert.assertEquals(trpl3, listener.getEvents().get(0).getTriple());
        Assert.assertTrue(listener.getEvents().get(0) instanceof AddEvent);
        listener.resetEvents();       
        mGraph.remove(trpl4);
        Assert.assertNull(listener.getEvents());
    }
View Full Code Here

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

        Assert.assertNull(listener.getEvents());
    }
   
    @Test
    public void graphEventTestAddAllRemoveAll() {
        MGraph mGraph = getEmptyMGraph();
        TestGraphListener listener = new TestGraphListener();
        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
        MGraph triples = new SimpleMGraph();
        triples.add(trpl1);
        triples.add(trpl2);
        triples.add(trpl3);
        triples.add(trpl4);
        mGraph.addAll(triples);
        List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
        Set<Triple> cumulatedTriples = getCumulatedTriples(cumulatedEvents);
        Assert.assertEquals(3, cumulatedEvents.size());
        Assert.assertTrue(cumulatedEvents.get(0) instanceof AddEvent);
View Full Code Here

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

        Assert.assertTrue(cumulatedTriples.contains(trpl4));
    }

    @Test
    public void graphEventTestFilterRemove() {
        MGraph mGraph = getEmptyMGraph();
        TestGraphListener listener = new TestGraphListener();
        mGraph.addGraphListener(listener, new FilterTriple(uriRef1, uriRef2, null));
        mGraph.addGraphListener(listener, new FilterTriple(bnode2, null, literal2));
        mGraph.addGraphListener(listener, new FilterTriple(null, uriRef4, literal2));
        mGraph.add(trpl1);
        mGraph.add(trpl2);
        mGraph.add(trpl3);
        mGraph.add(trpl4);
        listener.resetCumulatedEvents();
        Iterator<Triple> result = mGraph.filter(null, uriRef2, null);
        while (result.hasNext()) {
            result.next();
            result.remove();
        }
        List<GraphEvent> cumulatedEvents = listener.getCumulatedEvents();
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.