public void graph()

in commons-rdf-examples/src/example/UserGuideTest.java [201:248]


    public void graph() throws Exception {
        IRI nameIri = factory.createIRI("http://example.com/name");
        BlankNode aliceBlankNode = factory.createBlankNode();
        Literal aliceLiteral = factory.createLiteral("Alice");
        Triple triple = factory.createTriple(aliceBlankNode, nameIri, aliceLiteral);

        Graph graph = factory.createGraph();

        graph.add(triple);

        IRI bob = factory.createIRI("http://example.com/bob");
        Literal bobName = factory.createLiteral("Bob");
        graph.add(bob, nameIri, bobName);

        System.out.println(graph.contains(triple));

        System.out.println(graph.contains(null, nameIri, bobName));

        System.out.println(graph.size());

        for (Triple t : graph.iterate()) {
            System.out.println(t.getObject());
        }

        for (Triple t : graph.iterate(null, null, bobName)) {
            System.out.println(t.getPredicate());
        }

        try (Stream<? extends Triple> triples = graph.stream()) {
            Stream<RDFTerm> subjects = triples.map(t -> t.getObject());
            String s = subjects.map(RDFTerm::ntriplesString).collect(Collectors.joining(" "));
            System.out.println(s);
        }

        try (Stream<? extends Triple> named = graph.stream(null, nameIri, null)) {
            Stream<? extends Triple> namedB = named.filter(t -> t.getObject().ntriplesString().contains("B"));
            System.out.println(namedB.map(t -> t.getSubject()).findAny().get());
        }

        graph.remove(triple);
        System.out.println(graph.contains(triple));

        graph.remove(null, nameIri, null);

        graph.clear();
        System.out.println(graph.contains(null, null, null));

    }