AGSailAddStatements.java

package com.franz.agsail.examples;

import com.knowledgereefsystems.agsail.*;

import java.io.File;

import org.openrdf.model.Literal;
import org.openrdf.model.URI;
import org.openrdf.model.ValueFactory;
import org.openrdf.sail.*;

public class AGSailAddStatements {

    /**
     * Demonstrates basics of adding statements in a Sail
     * 
     * @param args unused
     * @throws AllegroGraphException
     */
    public static void main(String[] args) throws SailException {
        
        // Specify the SAIL, including AllegroGraph server and store parameters
        Sail sail = new AllegroSail("localhost", 4567, false, "store", new File(AGPaths.TRIPLE_STORES), 0, 0, false, false);
        
        // Connect to the server and open the specified store (create it if necessary)  
        sail.initialize();
        SailConnection sc = sail.getConnection();
       
        // Create some Values to work with
        ValueFactory f = sail.getValueFactory();
        String ex = "http://example.org/person/";
        URI alice = f.createURI(ex, "alice");
        URI knows = f.createURI(ex, "knows");
        URI age = f.createURI(ex, "age");
        URI bob = f.createURI(ex, "bob");
        Literal lit42 = f.createLiteral(42);
        
        // Add some statements to the store
        sc.addStatement(alice, knows, bob);
        sc.addStatement(alice, age, lit42);
        System.out.println("Sail Connection size: " + sc.size());
        
        // Create some more Values to work with
        f = sail.getValueFactory();
        ex = "http://example.org/";
        String rdf = sc.getNamespace("rdf");
        String rdfs = sc.getNamespace("rdfs");
        URI a = f.createURI(ex, "a");
        URI classA = f.createURI(ex, "A");
        URI classB = f.createURI(ex, "B");
        URI rdf_type = f.createURI(rdf, "type");
        URI rdfs_subClassOf = f.createURI(rdfs, "subClassOf");
        
        // Add some statements to the store
        sc.addStatement(a, rdf_type, classA);
        sc.addStatement(classA,rdfs_subClassOf,classB);

        // Close the connection and shut down the Sail
        sc.close();
        sail.shutDown();
    }
    
}

Up | Next