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

AGFreetextIndex.java

package com.franz.ag.examples;

import com.franz.ag.*;

public class AGFreetextIndex {

    /**
     * Demonstrates Freetext indexing and search on the Kennedy data 
     *
     * @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("kennedy", AGPaths.TRIPLE_STORES);

        // Register any predicates whose objects are to be searched for text
        // You must register predicates before the data is loaded.
        ts.registerFreetextPredicate("<http://example.org/kennedy/first-name>");
        
        // You can confirm that the server got the registration
        String[] ftpreds = ts.getFreetextPredicates();
        AGUtils.printStringArray("getFreetextPredicates:", ftpreds);

        // Load the Kennedy data
        AGLoadNtriples.loadNTriplesWithTiming(ts, AGPaths.dataSources("kennedy.ntriples"));
        
        // Index the store for querying, wait until indexing is complete.
        ts.indexAllTriples(true);

        // Search the store for statements whose objects contain Arnold
        Cursor cc = ts.getFreetextStatements("'Arnold'");
        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 ]