franz inc logo  
  download learning center franz inc search franz inc resources franz inc          

allegrograph
racer
tbc
services
support
  Learning Center
  Documentation
  Updates
     Info
  FAQ
about

RSS Feeds

AllegroServe at opensource.franz.com

AGGetStatements.java

package com.franz.ag.examples;

import com.franz.ag.*;

public class AGGetStatements {

    /**
     * Demonstrates some basics of retrieval by matching triple parts. 
     *
     * @param args unused
     * @throws AllegroGraphException
     */
    public static void main(String[] args) throws AllegroGraphException {
    
        // Connect to server, which must already be running.
        AllegroGraphConnection ags = new AllegroGraphConnection();
        try {
            ags.enable();
        } catch (Exception e) {
            throw new AllegroGraphException("Server connection problem", e);
        }

        // Create a fresh triple store
        AllegroGraph ts = ags.renew("getstatements", AGPaths.TRIPLE_STORES);

        // Register your namespaces
        ts.registerNamespace("ex","http://example.org/");
        
        // Add some triples to the store
        ts.addStatement("!ex:a","!ex:p", "!ex:b");
        ts.addStatement("!ex:p","!rdfs:domain", "!ex:D");
        ts.addStatement("!ex:p","!rdfs:range", "!ex:R");
        
        // Retrieve triples by matching subject
        Cursor cc = ts.getStatements(false,"!ex:a",null,null);
        System.out.println("Retrieving triples with subject ex:a");
        AGUtils.showTriples(cc);

        // Retrieve triples by matching predicate
        cc = ts.getStatements(false,null,"!rdfs:domain",null);
        System.out.println("Retrieving triples with predicate rdfs:domain");
        AGUtils.showTriples(cc);

        // Retrieve triples by matching object
        cc = ts.getStatements(false,null,null,"!ex:b");
        System.out.println("Retrieving triples with object ex:b");
        AGUtils.showTriples(cc);

        // Close the triple store and disconnect from the server
        ts.closeTripleStore();
        ags.disable();
    }

}

Up | Next

 

© 2008 Franz Inc - Privacy Statement
[ Consulting Services | Franz | TopQuadrant | Racer Systems ]