public class JenaGraph extends Object implements Graph
Graph implementation using the Jena framework.
Modifier and Type | Class and Description |
---|---|
protected static class |
JenaGraph.GraphConnection
Class holding graph and connection so that we can close the connection after having used the graph.
|
Constructor and Description |
---|
JenaGraph() |
Modifier and Type | Method and Description |
---|---|
void |
add(List<Statement> statements)
Adds given list of Statement objects to the graph.
|
void |
add(Statement statement)
Adds the statement object 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(Node subject,
Node predicate,
Node object)
Returns all statements in the graph matching the pattern.
|
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.
|
protected JenaGraph.GraphConnection |
openGraph()
Generates the Jena graph using options.
|
protected JenaGraph.GraphConnection |
openGraph(boolean forceReload)
Gets the Jena graph using options.
|
QueryResult |
query(String queryString,
String language,
String baseURI)
Query the graph using a base URI.
|
int |
queryCount(String queryString,
String language,
String baseURI)
Counts the number of results of a query.
|
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 |
remove(Statement statement)
Removes the statement object from the graph.
|
void |
setDescription(GraphDescription graphDescription)
Sets the graph description.
|
void |
setNamespaces(Map<String,String> namespaces) |
protected void |
setOptions(Map<String,String> options) |
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.
|
public JenaGraph()
protected JenaGraph.GraphConnection openGraph()
protected JenaGraph.GraphConnection openGraph(boolean forceReload)
The Jena "Convenient" reification style is used when opening models: it allows to ignore reification quadlets when calling the statements list.
forceReload
- boolean stating if the jena graph has to be reloaded using optionspublic void setDescription(GraphDescription graphDescription)
Graph
setDescription
in interface Graph
protected void setOptions(Map<String,String> options)
public void setNamespaces(Map<String,String> namespaces)
public Map<String,String> getNamespaces()
Graph
Namespaces are prefix/namespace bindings, as rdf for http://www.w3.org/1999/02/22-rdf-syntax-ns#.
getNamespaces
in interface Graph
public void add(Statement statement)
Graph
public void add(List<Statement> statements)
Graph
public void remove(Statement statement)
Graph
public void remove(List<Statement> statements)
Graph
public List<Statement> getStatements()
Graph
getStatements
in interface Graph
public List<Statement> getStatements(Node subject, Node predicate, Node object)
Graph
getStatements
in interface Graph
public List<Statement> getStatements(Statement statement)
Graph
getStatements
in interface Graph
statement
- pattern to match, can hold null nodes as wildcardspublic List<Node> getSubjects(Node predicate, Node object)
Graph
getSubjects
in interface Graph
predicate
- predicate pattern, null acceptedobject
- object pattern, null acceptedpublic List<Node> getPredicates(Node subject, Node object)
Graph
getPredicates
in interface Graph
subject
- subject pattern, null acceptedobject
- object pattern, null acceptedpublic List<Node> getObjects(Node subject, Node predicate)
Graph
getObjects
in interface Graph
subject
- subject pattern, null acceptedpredicate
- predicate pattern, null acceptedpublic boolean hasStatement(Statement statement)
Graph
hasStatement
in interface Graph
statement
- statement pattern, can use null as wild cardspublic boolean hasResource(Resource resource)
Graph
hasResource
in interface Graph
public Long size()
XXX AT: this size may not be equal to the number of statements retrieved via getStatements() because it counts each statement property.
public void clear()
Graph
public QueryResult query(String queryString, String language, String baseURI)
Graph
public int queryCount(String queryString, String language, String baseURI)
Graph
queryCount
in interface Graph
queryString
- the query stringlanguage
- the query language (sparql, rdql,...)baseURI
- the base URI to use for querypublic boolean read(InputStream in, String lang, String base)
Graph
read
in interface Graph
in
- input streamlang
- 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.public boolean read(String path, String lang, String base)
Graph
read
in interface Graph
path
- path on file system where to take the serialization filelang
- 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.public boolean write(OutputStream out, String lang, String base)
Graph
write
in interface Graph
out
- output streamlang
- 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.public boolean write(String path, String lang, String base)
Graph
write
in interface Graph
path
- path on file system where to put the serialization filelang
- 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.Copyright © 2015 Nuxeo SA. All rights reserved.