AGFreetextSearch.java
package com.franz.agbase.examples;
import com.franz.agbase.*;
public class AGFreetextSearch {
@param
@throws
public static void main(String[] args) throws AllegroGraphException {
AllegroGraphConnection ags = new AllegroGraphConnection();
try {
ags.enable();
} catch (Exception e) {
throw new AllegroGraphException("Server connection problem", e);
}
AllegroGraph ts = ags.renew("freetextsearch", AGPaths.TRIPLE_STORES);
ts.registerNamespace("ex", "http://example.org/");
ts.registerFreetextPredicate("<http://www.w3.org/2000/01/rdf-schema#comment>");
ts.registerFreetextPredicate("!ex:notes");
ts.addStatement("!ex:jans", "!rdfs:comment", "\"Born in Emmen in the Netherlands\"");
ts.addStatement("!ex:gary", "!rdfs:comment", "\"Born in Springfield in the USA\"");
ts.addStatement("!ex:henk", "!rdfs:label", "\"Born in Emmermeer in the Netherlands\"");
ts.addStatement("!ex:alice", "!ex:notes", "\"wasn't born in Wonderland.\"");
ts.addStatement("!ex:bob", "!ex:notes", "\"your uncle.\"");
ts.addStatement("!ex:fred", "!ex:notes", "\"Lives in Bedrock.\"");
ts.addStatement("!ex:stanley", "!ex:notes", "\"Dr. Livingstone I presume?\"");
ts.addStatement("!ex:fibonacci", "!ex:notes", "\"fib(n+2) = fib(n+1) + fib(n)\"");
String query = "'born'";
System.out.println("Search: " + query);
TriplesIterator cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "(and 'emmen' 'born')";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "(or 'Wonderland' 'Bedrock')";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "(or 'in' 'a')";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "'the'";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "'fib(x)'";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "'Liv??'";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "'Liv*'";
System.out.println("Search: " + query);
cc = ts.getFreetextStatements(query);
AGUtils.showTriples(cc);
query = "(or 'Wonderland' 'Bedrock')";
ValueSetIterator it = ts.getFreetextUniqueSubjects(query);
System.out.println("Subjects matching search: " + query);
AGUtils.showResults(it);
ts.closeTripleStore();
ags.disable();
}
}
Up |
Next