Package org.jrdf.graph

Examples of org.jrdf.graph.GraphElementFactory


        init();
    }

    private void init() {
        try {
            GraphElementFactory elementFactory = graph.getElementFactory();
            PredicateNode type = elementFactory.createURIReference(RDF.TYPE);
            ObjectNode graphName = elementFactory.createURIReference(GRAPH);
            for (Triple triple : graph.find(ANY_SUBJECT_NODE, type, graphName)) {
                addResource(elementFactory, triple);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
View Full Code Here


    public boolean hasGraph(String name) {
        return graphNameToId.keySet().contains(name);
    }

    public long addGraph(String name) {
        GraphElementFactory graphElementFactory = graph.getElementFactory();
        highestId++;
        Resource resource = tryAddGraph(name, highestId, graphElementFactory);
        graphs.add(resource);
        return highestId;
    }
View Full Code Here

    private static void createNewTriples() throws GraphException {
        System.out.println("Creating new graphs");
        Graph fooGraph = JRDF_FACTORY.getNewGraph("foo");
        Graph barGraph = JRDF_FACTORY.getNewGraph("bar");
        GraphElementFactory barElementFactory = barGraph.getElementFactory();
        URI uri1 = URI.create("urn:hello");
        URI uri2 = URI.create("urn:there");
        Resource resource = barElementFactory.createResource(uri1);
        resource.addValue(uri1, uri2);
        resource.addValue(uri2, uri2);
        GraphElementFactory fooElementFactory = fooGraph.getElementFactory();
        Resource blankResource = fooElementFactory.createResource();
        blankResource.addValue(uri1, uri2);
        blankResource.addValue(uri1, uri1);
        blankResource.addValue(uri2, uri2);
    }
View Full Code Here

        performQuery(graph);
        System.out.println("Example finished.");
    }

    private void populateGraph(Graph graph) throws GraphException {
        GraphElementFactory elementFactory = graph.getElementFactory();
        person = elementFactory.createResource(PERSON);
        address = elementFactory.createResource();
        addressStatement = person.asTriple(HAS_ADDRESS, address);
        graph.add(addressStatement);
        address.addValue(HAS_STREET, "1501 Grant Avenue");
        cityStatement = address.asTriple(HAS_CITY, "Bedford");
        graph.add(cityStatement);
View Full Code Here

     */
    private void performReification(Graph graph) throws Exception {
        System.out.println("Reifying a statement...");

        //get the Factories
        GraphElementFactory elementFactory = graph.getElementFactory();
        TripleFactory tripleFactory = graph.getTripleFactory();

        //create a resource to identify the statement
        URIReference statement = elementFactory.createURIReference(new URI("http://example.org/statement#address"));

        //reify the address statement (person, hasAddress, address)
        tripleFactory.reifyTriple(addressStatement, statement);

        //insert a statement about the original statement
        URIReference manager = elementFactory.createURIReference(new URI("http://example.org/managerid#65"));
        URIReference hasConfirmed = elementFactory.createURIReference(new URI("http://example.org/terms#hasConfirmed"));
        Triple confirmationStatement = tripleFactory.createTriple(manager, hasConfirmed, statement);
        graph.add(confirmationStatement);

        //print the contents
        print("Graph contains (after reification): ", graph);
View Full Code Here

            throws GraphElementFactoryException {
        if (n instanceof URIReference) {
            return getLocalizedResource(n);
        } else if (n instanceof Literal) {
            Literal l = (Literal) n;
            GraphElementFactory elementFactory = _connector.getElementFactory();
            if (l.getDatatypeURI() != null) {
                return elementFactory.createLiteral(l.getLexicalForm(),
                                                    l.getDatatypeURI());
            } else if (l.getLanguage() != null) {
                return elementFactory.createLiteral(l.getLexicalForm(),
                                                    l.getLanguage());
            } else {
                return elementFactory.createLiteral(l.getLexicalForm());
            }
        } else {
            throw new RuntimeException("Error localizing triple; "
                    + n.getClass().getName() + " is not a URIReference "
                    + "or a Literal");
View Full Code Here

TOP

Related Classes of org.jrdf.graph.GraphElementFactory

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.