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

AGTripleIds.java

package com.franz.ag.examples;

import com.franz.ag.*;
import org.openrdf.model.Literal;

public class AGTripleIds {

    /**
     * Demonstrates some basics of triple ids.
     * 
     * @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 for this example.
        AllegroGraph ts = ags.renew("tripleids", AGPaths.TRIPLE_STORES);
        

        // Register any namespaces
        ts.registerNamespace("ex","http://example.org/");

        // Create some triples and add them to the store
        Triple tr1 = ts.newTriple("!ex:Dog","!rdf:type","!owl:Class");  
        Triple tr2 = ts.newTriple("!ex:Dog","!rdfs:subClassOf","!ex:Mammal"); 
        
        // Show the triples and note their ids
        System.out.println("Created and added the following triples to the store:");
        AGUtils.showTriple(tr1);
        AGUtils.showTriple(tr2);
        
        // Get the id for a triple
        long tr2_id = tr2.queryAGId();
        
        // You can also use triple ids to assert facts about triples
        // This can be more space and time efficient than reifying
        // but this is not RDF semantics
        Literal lit = ts.createEncodedLiteral(tr2_id,"triple-id");
        Triple tr3 = ts.newTriple("!ex:person1", "!ex:believes", lit);
        AGUtils.showTriple(tr3);
        
        // Close the store and disconnect from the server.
        ts.closeTripleStore();
        ags.disable();
    }
}

Up | Next

 

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