org.ilrt.inkling.api
Class Graph

java.lang.Object
  |
  +--org.ilrt.inkling.api.Graph
All Implemented Interfaces:
GraphInterface, SimpleQueryInterface
Direct Known Subclasses:
ComplexQuery, UnionGraph

public class Graph
extends java.lang.Object
implements GraphInterface, SimpleQueryInterface

A simple RDF Graph, inspired by http://www.w3.org/2001/12/rubyrdf/basicrdf.rb


The principal methods are

ask(), tell(), askSquish(); also askForObjects() and similar. Also
removeAll(), delete()
See GraphTest to see how they work.

Graph gr = new Graph(null, uri, Util.RDFXML);
gr.load();

Vector classInstances 
=gr.askForSubjects(null,"http://www.w3.org/1999/02/22-rdf-syntax-ns#type",cl);

(returning a Vector of Nodes)

Vector superclasses
=gr.ask(cl,"http://www.w3.org/2000/01/rdf-schema#subClassOf",null);

(returning a Vector of Statements)

java.sql.ResultSet r=gr.askSquish(query);

(returning a ResultSet)

gr.tell(new Statement(new Node(subject),new Node(predicate),new 
Node(object)));

gr.tellAll(vectorOfStatements v);

gr.delete(Statement s);

(s cannot have null Nodes in it as yet)

gr.removeAll();


Constructor Summary
Graph()
           
Graph(java.lang.String base)
          base would normally be the source url
Graph(java.lang.String base, java.lang.String type)
          Type should be taken from Util e.g.
Graph(java.util.Vector statements)
           
Graph(java.util.Vector states, java.lang.String base, java.lang.String type)
           
 
Method Summary
 java.util.Vector ask(java.lang.Object ss, java.lang.Object pp, java.lang.Object oo)
          Simple query method - with lazy strings
 Graph ask(Query query)
          Ask with a query object
 java.util.Vector askForObjects(java.lang.Object ss, java.lang.Object pp, java.lang.Object oo)
          Handy method returning a Vector of object Nodes answering the query
 java.util.Vector askForSubjects(java.lang.Object ss, java.lang.Object pp, java.lang.Object oo)
          Handy method returning a Vector of subject Nodes answering the query
 java.util.Vector askQuery(Node ss, Node pp, Node oo)
          The simple triple query method - with Nodes GraphInterface method
 java.sql.ResultSet askSquish(java.lang.String query)
          Ask with a squish string; returns a ResultSet object, not a Graph.
 boolean delete(Statement statement)
          Delete a specified Statement
 java.lang.String getBase()
          base is usually the source url
static GraphInterface getDefault()
          For Graphs without a uri (base), creates one with a default uri
 java.util.Vector getEdges()
          Returns all properties
 java.lang.String getID()
          legacy - calls getBase()
 java.util.Vector getNodes()
          Returns all subjects and properties
 java.util.Vector getObjects()
          Shortcut for getting all object Nodes in the Graph
 java.util.Vector getPredicates()
          Shortcut for getting all predicates (properties) in the Graph
 int getSize()
          Returns the number of unique Statements in the Graph
 java.util.Vector getStatements()
          returns the full Vector of Statements from the Graph
 java.util.Vector getSubjects()
          Shortcut for getting all subject Nodes in the Graph
 java.lang.String getType()
           
 java.lang.String inspect()
          Returns a string containing the contents of the Graph - for debugging
 void load()
          loads in an RDF graph, using method depending on value of type (you can setType() or set it during initialization, or use gr.load(type)).
 void load(java.lang.String type)
          loads in an RDF graph, using method depending on value of type (you can setType() or set it during initialization, or use gr.load(type)).
 boolean removeAll()
          Remove all Statements in the Graph
 void setBase(java.lang.String base)
          base is usually the source url
 void setID(java.lang.String base)
          legacy - calls setBase()
 void setType(java.lang.String type)
           
 int size()
          Returns the number of unique Statements in the Graph
 void tell(Statement statement)
          Tell one Statement to the Graph
 void tellAll(java.util.Vector states)
          Tell a Vector of Statements to the Graph
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Graph

public Graph()

Graph

public Graph(java.lang.String base)
base would normally be the source url

Graph

public Graph(java.util.Vector statements)

Graph

public Graph(java.lang.String base,
             java.lang.String type)
Type should be taken from Util e.g. Util.RDFXML. You can also setType(Util.RDFXML) Base is the source url states is a list of Statements and can be null.

Graph

public Graph(java.util.Vector states,
             java.lang.String base,
             java.lang.String type)
Method Detail

setType

public void setType(java.lang.String type)

getType

public java.lang.String getType()

load

public void load()
loads in an RDF graph, using method depending on value of type (you can setType() or set it during initialization, or use gr.load(type)). You need to load a Graph with content before using it, e.g. Graph gr = new Graph(null, uri, Util.RDFXML); gr.load();

load

public void load(java.lang.String type)
loads in an RDF graph, using method depending on value of type (you can setType() or set it during initialization, or use gr.load(type)). You need to load a Graph with content before using it, e.g. Graph gr = new Graph(null, uri, null); gr.load(Util.RDFXML);

setBase

public void setBase(java.lang.String base)
base is usually the source url
Specified by:
setBase in interface GraphInterface

getBase

public java.lang.String getBase()
base is usually the source url
Specified by:
getBase in interface GraphInterface

getID

public java.lang.String getID()
legacy - calls getBase()

setID

public void setID(java.lang.String base)
legacy - calls setBase()

getStatements

public java.util.Vector getStatements()
returns the full Vector of Statements from the Graph
Specified by:
getStatements in interface GraphInterface

getDefault

public static GraphInterface getDefault()
For Graphs without a uri (base), creates one with a default uri

tellAll

public void tellAll(java.util.Vector states)
Tell a Vector of Statements to the Graph
Specified by:
tellAll in interface GraphInterface

tell

public void tell(Statement statement)
Tell one Statement to the Graph
Specified by:
tell in interface GraphInterface

askForObjects

public java.util.Vector askForObjects(java.lang.Object ss,
                                      java.lang.Object pp,
                                      java.lang.Object oo)
Handy method returning a Vector of object Nodes answering the query

askForSubjects

public java.util.Vector askForSubjects(java.lang.Object ss,
                                       java.lang.Object pp,
                                       java.lang.Object oo)
Handy method returning a Vector of subject Nodes answering the query

askQuery

public java.util.Vector askQuery(Node ss,
                                 Node pp,
                                 Node oo)
The simple triple query method - with Nodes GraphInterface method
Specified by:
askQuery in interface SimpleQueryInterface

ask

public java.util.Vector ask(java.lang.Object ss,
                            java.lang.Object pp,
                            java.lang.Object oo)
Simple query method - with lazy strings
Specified by:
ask in interface GraphInterface

askSquish

public java.sql.ResultSet askSquish(java.lang.String query)
Ask with a squish string; returns a ResultSet object, not a Graph.
Specified by:
askSquish in interface GraphInterface

ask

public Graph ask(Query query)
Ask with a query object
Specified by:
ask in interface GraphInterface

inspect

public java.lang.String inspect()
Returns a string containing the contents of the Graph - for debugging

getObjects

public java.util.Vector getObjects()
Shortcut for getting all object Nodes in the Graph

getSubjects

public java.util.Vector getSubjects()
Shortcut for getting all subject Nodes in the Graph

getPredicates

public java.util.Vector getPredicates()
Shortcut for getting all predicates (properties) in the Graph

removeAll

public boolean removeAll()
Remove all Statements in the Graph
Specified by:
removeAll in interface GraphInterface

delete

public boolean delete(Statement statement)
Delete a specified Statement
Specified by:
delete in interface GraphInterface

getSize

public int getSize()
Returns the number of unique Statements in the Graph

size

public int size()
Returns the number of unique Statements in the Graph

getNodes

public java.util.Vector getNodes()
Returns all subjects and properties

getEdges

public java.util.Vector getEdges()
Returns all properties