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

AGPrologDisjunction.java

package com.franz.ag.examples;

import com.franz.ag.*;


public class AGPrologDisjunction {

    /**
     * Demonstrates some basics of using disjunction and recursion in Prolog.
     * 
     * @param 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("prologdisjunction", AGPaths.TRIPLE_STORES);

        // Load the Kennedy data
        AGLoadNtriples.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));

        // Index the store for faster querying
        AGIndexAllTriples.indexAllTriplesWithTiming(ts);
        
        // Register any namespaces
        ts.registerNamespace("ex", "http://example.org/kennedy/");

        // Disjunction is represented with multiple horn clauses using
        // the <- operator to complement existing rules with the same head.  
        // Note that this group of rules also involves recursion.
        AGPrologRules.addPrologRule("(<-- (ancestor ?x ?y) (q ?x !ex:has-child ?y))", ags);
        AGPrologRules.addPrologRule("(<-  (ancestor ?x ?y) (q ?x !ex:has-child ?z) (ancestor ?z ?y))", ags);
        
        // Find all ancestors of person13
        String pquery = "(?x)" + "(ancestor ?x !ex:person13)";
        AGPrologSelect.doPrologSelect(ts, pquery);
        
        // Find all descendants of person13
        AGPrologRules.addPrologRule("(<-- (descendent ?x ?y) (ancestor ?y ?x))", ags);
        pquery = "(?x)" + "(descendent ?x !ex:person13)";
        AGPrologSelect.doPrologSelect(ts, pquery);
        
        // 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 ]