Nuxeo ECM Projects 5.4.3-SNAPSHOT

org.nuxeo.ecm.platform.relations.jena
Class JenaGraph

java.lang.Object
  extended by org.nuxeo.ecm.platform.relations.jena.JenaGraph
All Implemented Interfaces:
Serializable, Graph

public class JenaGraph
extends Object
implements Graph

Jena plugin for NXRelations.

Graph implementation using the Jena framework.

Author:
Anahide Tchertchian
See Also:
Serialized Form

Constructor Summary
JenaGraph()
           
 
Method Summary
 void add(List<Statement> statements)
          Adds given list of Statement objects to the graph.
 void clear()
          Clears the graph, removing all statements in it.
 Map<String,String> getNamespaces()
          Returns namespaces for the graph.
 List<Node> getObjects(Node subject, Node predicate)
          Gets items matching the statement pattern (subject, predicate, null).
 List<Node> getPredicates(Node subject, Node object)
          Gets items matching the statement pattern (subject, null, object).
 List<Statement> getStatements()
          Returns all statements in the graph.
 List<Statement> getStatements(Statement statement)
          Returns all statements in the graph matching the pattern.
 List<Node> getSubjects(Node predicate, Node object)
          Get items matching the statement pattern (null, predicate, object).
 boolean hasResource(Resource resource)
          Returns true if given resource appears in any statement of the graph.
 boolean hasStatement(Statement statement)
          Returns true if given statement pattern is in the graph.
 QueryResult query(String queryString, String language, String baseURI)
          Query the graph using a base URI.
 boolean read(InputStream in, String lang, String base)
          Parses source into the graph.
 boolean read(String path, String lang, String base)
          Parses source into the graph.
 void remove(List<Statement> statements)
          Removes given list of Statement objects from the graph.
 void setName(String name)
          Sets name for the graph.
 void setNamespaces(Map<String,String> namespaces)
          Sets namespaces for the graph.
 void setOptions(Map<String,String> options)
          Sets options for the graph.
 Long size()
          Returns the number of statements in the graph.
 boolean write(OutputStream out, String lang, String base)
          Serializes graph.
 boolean write(String path, String lang, String base)
          Serializes graph.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JenaGraph

public JenaGraph()
Method Detail

setName

public void setName(String name)
Description copied from interface: Graph
Sets name for the graph.

Specified by:
setName in interface Graph
Parameters:
name - the new name

setOptions

public void setOptions(Map<String,String> options)
Description copied from interface: Graph
Sets options for the graph.

Options are typically: which backend to use, additional parameters for backend (e.g. for instance SQL backend, host, port, user/password...).

Specified by:
setOptions in interface Graph
Parameters:
options - map of options for the graph

setNamespaces

public void setNamespaces(Map<String,String> namespaces)
Description copied from interface: Graph
Sets namespaces for the graph.

Namespaces are prefix/namespace bindings, as rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#. TODO AT: maybe share same namespaces with the relation service?

Specified by:
setNamespaces in interface Graph
Parameters:
namespaces - map of namespace bindings for the graph

getNamespaces

public Map<String,String> getNamespaces()
Description copied from interface: Graph
Returns namespaces for the graph.

Namespaces are prefix/namespace bindings, as rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#.

Specified by:
getNamespaces in interface Graph

add

public void add(List<Statement> statements)
Description copied from interface: Graph
Adds given list of Statement objects to the graph.

If the graph has reification support, the statement properties are also added to the graph too.

Specified by:
add in interface Graph
Parameters:
statements - list of Statement instances to add

remove

public void remove(List<Statement> statements)
Description copied from interface: Graph
Removes given list of Statement objects from the graph.

If the graph has reification support, the deleted statements properties are removed too.

Specified by:
remove in interface Graph
Parameters:
statements - List of Statement instances to remove

getStatements

public List<Statement> getStatements()
Description copied from interface: Graph
Returns all statements in the graph.

If the graph has reification support, the statements properties are retrieved too.

Specified by:
getStatements in interface Graph
Returns:
list of Statement instances

getStatements

public List<Statement> getStatements(Statement statement)
Description copied from interface: Graph
Returns all statements in the graph matching the pattern.

If the graph has reification support, the statements properties are retrieved too.

Specified by:
getStatements in interface Graph
Parameters:
statement - pattern to match, can hold null nodes as wildcards
Returns:
list of Statement instances matching the pattern

getSubjects

public List<Node> getSubjects(Node predicate,
                              Node object)
Description copied from interface: Graph
Get items matching the statement pattern (null, predicate, object).

Specified by:
getSubjects in interface Graph
Parameters:
predicate - predicate pattern, null accepted
object - object pattern, null accepted
Returns:
list of subjects

getPredicates

public List<Node> getPredicates(Node subject,
                                Node object)
Description copied from interface: Graph
Gets items matching the statement pattern (subject, null, object).

Specified by:
getPredicates in interface Graph
Parameters:
subject - subject pattern, null accepted
object - object pattern, null accepted
Returns:
list of predicates

getObjects

public List<Node> getObjects(Node subject,
                             Node predicate)
Description copied from interface: Graph
Gets items matching the statement pattern (subject, predicate, null).

Specified by:
getObjects in interface Graph
Parameters:
subject - subject pattern, null accepted
predicate - predicate pattern, null accepted
Returns:
list of node objects

hasStatement

public boolean hasStatement(Statement statement)
Description copied from interface: Graph
Returns true if given statement pattern is in the graph.

Specified by:
hasStatement in interface Graph
Parameters:
statement - statement pattern, can use null as wild cards
Returns:
true or false

hasResource

public boolean hasResource(Resource resource)
Description copied from interface: Graph
Returns true if given resource appears in any statement of the graph.

Specified by:
hasResource in interface Graph
Returns:
true or false

size

public Long size()
Returns the number of statements in the graph.

XXX AT: this size may not be equal to the number of statements retrieved via getStatements() because it counts each statement property.

Specified by:
size in interface Graph
Returns:
integer number of statements in the graph

clear

public void clear()
Description copied from interface: Graph
Clears the graph, removing all statements in it.

Specified by:
clear in interface Graph

query

public QueryResult query(String queryString,
                         String language,
                         String baseURI)
Description copied from interface: Graph
Query the graph using a base URI.

Specified by:
query in interface Graph
Parameters:
queryString - the query string
language - the query language (sparql, rdql,...)
baseURI - the base URI to use for query
Returns:
QueryResult instance

read

public boolean read(InputStream in,
                    String lang,
                    String base)
Description copied from interface: Graph
Parses source into the graph.

Specified by:
read in interface Graph
Parameters:
in - input stream
lang - format for the input serialization, may be "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE" and "N3". The default value, represented by null, is "RDF/XML".
base - base uri to be used when converting relative uris to absolute uris, may be null. If set to "", allows relative uris to be used in the model.
Returns:
true on success, else false

read

public boolean read(String path,
                    String lang,
                    String base)
Description copied from interface: Graph
Parses source into the graph.

Specified by:
read in interface Graph
Parameters:
path - path on file system where to take the serialization file
lang - format for the input serialization, may be "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE" and "N3". The default value, represented by null, is "RDF/XML".
base - base uri to be used when converting relative uris to absolute uris, may be null. If set to "", allows relative uris to be used in the model.
Returns:
true on success, else false

write

public boolean write(OutputStream out,
                     String lang,
                     String base)
Description copied from interface: Graph
Serializes graph.

Specified by:
write in interface Graph
Parameters:
out - output stream
lang - format for the input serialization, may be "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE" and "N3". The default value, represented by null, is "RDF/XML".
base - base uri to be used when converting relative uris to absolute uris, may be null. If set to "", allows relative uris to be used in the model.
Returns:
true on success, else false

write

public boolean write(String path,
                     String lang,
                     String base)
Description copied from interface: Graph
Serializes graph.

Specified by:
write in interface Graph
Parameters:
path - path on file system where to put the serialization file
lang - format for the input serialization, may be "RDF/XML", "RDF/XML-ABBREV", "N-TRIPLE" and "N3". The default value, represented by null, is "RDF/XML".
base - base uri to be used when converting relative uris to absolute uris, may be null. If set to "", allows relative uris to be used in the model.
Returns:
true on success, else false

Nuxeo ECM Projects 5.4.3-SNAPSHOT

Copyright © 2011 Nuxeo SAS. All Rights Reserved.