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

AGPrologFunctorQ.java

package com.franz.ag.examples;

import com.franz.ag.*;

public class AGPrologFunctorQ {

    /**
     * Demonstrates RDFS++ reasoning from within Prolog using functor q
     * 
     * @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("functorq", AGPaths.TRIPLE_STORES);
        
        // Register your namespaces
        ts.registerNamespace("ex","http://example.org/");
        
        // Add some triples to the store
        ts.addStatement("!ex:a","!ex:owned-by","!ex:b");
        ts.addStatement("!ex:c","!ex:owns","!ex:d");
        ts.addStatement("!ex:jans","!ex:owns","!ex:birra");
        ts.addStatement("!ex:owned-by","!owl:inverseOf","!ex:owns");

        // First a query without reasoning using functor q- 
        String pquery = "(?x ?y) (q- ?x !ex:owns ?y)";
        AGPrologSelect.doPrologSelect(ts, pquery);

        // Now demonstrate reasoning with functor q
        pquery = "(?x ?y) (q ?x !ex:owns ?y)";
        AGPrologSelect.doPrologSelect(ts, pquery);

        // Add some more triples to the store
        ts.addStatement("!ex:A","!rdfs:subClassOf", "!ex:B");
        ts.addStatement("!ex:B","!rdfs:subClassOf", "!ex:C");
        ts.addStatement("!ex:a","!rdf:type", "!ex:A");
        
        // Another query without reasoning using functor q- 
        pquery = "(?x ?y) (q- ?x !rdf:type ?y)";
        AGPrologSelect.doPrologSelect(ts, pquery);

        // Now demonstrate reasoning with functor q
        pquery = "(?x ?y) (q ?x !rdf:type ?y)";
        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 ]