de.fuberlin.wiwiss.ng4j
Interface NamedGraphSet

All Known Subinterfaces:
SWPNamedGraphSet
All Known Implementing Classes:
ARQNamedGraphSet, NamedGraphSetBase, NamedGraphSetDB, NamedGraphSetImpl, NamedGraphSetIO, SemanticWebClient, SWPNamedGraphSetImpl

public interface NamedGraphSet

A set of NamedGraphs and the core part of the Named Graphs for Jena API. For details about Named Graphs see http://www.w3.org/2004/03/trix/.

A set of named graphs is a collection of RDF graphs where each graph has a unique URI name. The collection can be accessed and modified

TODO: define equals()

Author:
Chris Bizer, Richard Cyganiak (richard@cyganiak.de)

Method Summary
 void addGraph(NamedGraph graph)
          Adds a NamedGraph to the set.
 void addQuad(Quad quad)
          Adds a quad to the NamedGraphSet.
 Graph asJenaGraph(Node defaultGraphForAdding)
          Returns the union graph of the NamedGraphSet.
 NamedGraphModel asJenaModel(String defaultGraphForAdding)
          Returns a Jena Model view on the NamedGraphSet, equivalent to the union graph of all graphs in the graph set.
 void clear()
          Deletes all NamedGraphs from the set.
 void close()
          Closes the NamedGraphSet and frees up resources held.
 boolean containsGraph(Node graphName)
          Tells wether the NamedGraphSet contains a NamedGraph.
 boolean containsGraph(String graphNameURI)
          Tells wether the NamedGraphSet contains a NamedGraph.
 boolean containsQuad(Quad pattern)
          Tells wether the NamedGraphSet contains a quad or quads matching a pattern.
 long countGraphs()
          Returns the number of NamedGraphs in the set.
 int countQuads()
          Counts the Quads in the NamedGraphSet.
 NamedGraph createGraph(Node graphName)
          Creates a new NamedGraph and adds it to the set.
 NamedGraph createGraph(String graphNameURI)
          Creates a new NamedGraph and adds it to the set.
 Iterator findQuads(Node graphName, Node subject, Node predicate, Node object)
          Finds Quads that match a pattern.
 Iterator findQuads(Quad pattern)
          Finds Quads that match a quad pattern.
 NamedGraph getGraph(Node graphName)
          Returns the NamedGraph with a specific name from the GraphSet.
 NamedGraph getGraph(String graphNameURI)
          Returns the NamedGraph with a specific name from the GraphSet.
 boolean isEmpty()
          Tells wether the set contains any NamedGraphs.
 Iterator listGraphs()
          Returns an iterator over all NamedGraphs in the set.
 void read(InputStream source, String lang, String baseURI)
          Read Named Graphs from an InputStream into the NamedGraphSet.
 void read(Reader source, String lang, String baseURI)
          Read Named Graphs from a Reader into the NamedGraphSet.
 void read(String url, String lang)
          Read Named Graphs from an URL into the NamedGraphSet.
 void removeGraph(Node graphName)
          Removes a NamedGraph from the set.
 void removeGraph(String graphNameURI)
          Removes the NamedGraph with a specific name.
 void removeQuad(Quad pattern)
          Deletes Quads from the NamedGraphSet.
 void write(OutputStream out, String lang, String baseURI)
          Writes a serialized represention of the NamedGraphSet to an OutputStream.
 void write(Writer out, String lang, String baseURI)
          Writes a serialized represention of the NamedGraphSet to a Writer.
 

Method Detail

addGraph

void addGraph(NamedGraph graph)
Adds a NamedGraph to the set. Will replace a NamedGraph with the same name that is already in the set.

Parameters:
graph - The NamedGraph to be added

removeGraph

void removeGraph(Node graphName)
Removes a NamedGraph from the set. Nothing happens if no graph with that name is contained in the set. Node.ANY will remove all graphs from the set.

Parameters:
graphName - The name of the NamedGraph to be removed

removeGraph

void removeGraph(String graphNameURI)
Removes the NamedGraph with a specific name. Nothing happens if no graph with that name is contained in the set. Node.ANY will remove all graphs from the set.

Parameters:
graphNameURI - The name of the NamedGraph to be removed

containsGraph

boolean containsGraph(Node graphName)
Tells wether the NamedGraphSet contains a NamedGraph.

Parameters:
graphName - The name of a NamedGraph
Returns:
True if the set contains a graph with that name, false otherwise.

containsGraph

boolean containsGraph(String graphNameURI)
Tells wether the NamedGraphSet contains a NamedGraph.

Parameters:
graphNameURI - The name of a NamedGraph
Returns:
True if the set contains a graph with that name, false otherwise.

getGraph

NamedGraph getGraph(Node graphName)
Returns the NamedGraph with a specific name from the GraphSet. Changes to the graph will be reflected in the set.

Parameters:
graphName - The name of the NamedGraph to be returned
Returns:
The graph with that name, or null if no graph with that name is contained in the set

getGraph

NamedGraph getGraph(String graphNameURI)
Returns the NamedGraph with a specific name from the GraphSet. Changes to the graph will be reflected in the set.

Parameters:
graphNameURI - The name of the NamedGraph to be returned
Returns:
The graph with that name, or null if no graph with that name is contained in the set

createGraph

NamedGraph createGraph(Node graphName)
Creates a new NamedGraph and adds it to the set. An existing graph with the same name will be replaced.

Parameters:
graphName - The name of the NamedGraph to be created; must be an URI node
Returns:
The newly created NamedGraph instance

createGraph

NamedGraph createGraph(String graphNameURI)
Creates a new NamedGraph and adds it to the set. An existing graph with the same name will be replaced.

Parameters:
graphNameURI - The name of the NamedGraph to be created; must be an URI
Returns:
The newly created NamedGraph instance

listGraphs

Iterator listGraphs()
Returns an iterator over all NamedGraphs in the set.

Returns:
An iterator over all NamedGraphs in the set

clear

void clear()
Deletes all NamedGraphs from the set.


countGraphs

long countGraphs()
Returns the number of NamedGraphs in the set. Empty graphs are counted.

Returns:
The number of NamedGraphs in the set.

isEmpty

boolean isEmpty()
Tells wether the set contains any NamedGraphs.

Returns:
True if the set contains any NamedGraphs, false otherwise

addQuad

void addQuad(Quad quad)
Adds a quad to the NamedGraphSet. The argument must not contain any wildcards. If the quad is already present, nothing happens. A new named graph will automatically be created if necessary.

Parameters:
quad - A quad to be added to the NamedGraphSet

containsQuad

boolean containsQuad(Quad pattern)
Tells wether the NamedGraphSet contains a quad or quads matching a pattern. Quad patterns are Quad instances with Node.ANY in one or more positions.

Parameters:
pattern - A quad or quad pattern
Returns:
True if The NamedGraphSet contains matching quads, false otherwise

removeQuad

void removeQuad(Quad pattern)
Deletes Quads from the NamedGraphSet. The argument may contain wildcards (Node.ANY). All matching Quads will be deleted. If no Quads match, nothing happens. This operation will not delete any NamedGraphs from the set. Empty NamedGraphs will be retained.

Parameters:
pattern - A quad or quad pattern to be deleted

countQuads

int countQuads()
Counts the Quads in the NamedGraphSet. Identical Triples in different NamedGraphs are counted individually.

Returns:
The number of Quads in the set

findQuads

Iterator findQuads(Quad pattern)
Finds Quads that match a quad pattern. The argument may contain wildcards (Node.ANY).

Parameters:
pattern - A quad or quad pattern
Returns:
An iterator over all Quads that match the pattern

findQuads

Iterator findQuads(Node graphName,
                   Node subject,
                   Node predicate,
                   Node object)
Finds Quads that match a pattern. All arguments may be Node.ANY to match everything in that position.

Parameters:
graphName - The graph to find triples from
subject - The subject to be matched
predicate - The predicate to be matched
object - The object to be matched
Returns:
An iterator over all Quads that match the pattern

asJenaGraph

Graph asJenaGraph(Node defaultGraphForAdding)
Returns the union graph of the NamedGraphSet. The graph is backed by the NamedGraphSet: Subsequent changes to one are reflected in the other.

Add operations to the union graph are all written to the default graph specified as the argument.

Delete operations remove the triple from all NamedGraphs.

Parameters:
defaultGraphForAdding - The name of the default graph used for adding triples; must be an URI
Returns:
A Graph view on the NamedGraphSet

asJenaModel

NamedGraphModel asJenaModel(String defaultGraphForAdding)
Returns a Jena Model view on the NamedGraphSet, equivalent to the union graph of all graphs in the graph set.

Add operations on the returned model are all written to the default graph.

Read and write operations one the returned model have the behaviour of read(String, String) and write(OutputStream, String, String).

All Statements returned by the NamedGraphModel can be casted to NamedGraphStatement to access information about the graphs they are contained in.

Parameters:
defaultGraphForAdding - The name of the default graph used for adding triples; must be an URI
Returns:
A Model view on the NamedGraphSet

close

void close()
Closes the NamedGraphSet and frees up resources held. Any subsequent calls to methods of the object have undefined results.


read

void read(String url,
          String lang)
Read Named Graphs from an URL into the NamedGraphSet. Supported RDF serialization languages are "TRIX", "TRIX-EXT", "TRIG", "RDF/XML", "N-TRIPLE" and "N3".

Serialization languages that support named graphs (like TriX) will take the graph name(s) from the serialization. Other languages will take the URL as the name of the graph.

If some of the graph names from the source are already used in the NamedGraphSet, then the statements from the old graphs will be replaced by those from the source.

Parameters:
url - The source of the input serialization
lang - The RDF serialization language of the input

read

void read(InputStream source,
          String lang,
          String baseURI)
Read Named Graphs from an InputStream into the NamedGraphSet. Supported RDF serialization languages are "TRIX", "TRIX-EXT", "TRIG", "RDF/XML", "N-TRIPLE" and "N3".

Serialization languages that support named graphs (like TriX) will take the graph name(s) from the serialization. Other languages will take the base URI as the name of the graph.

If some of the graph names from the source are already used in the NamedGraphSet, then the statements from the old graphs will be replaced by those from the source.

Parameters:
source - The source of the input serialization
lang - The RDF serialization language of the input
baseURI - The URI from where the input was read

read

void read(Reader source,
          String lang,
          String baseURI)
Read Named Graphs from a Reader into the NamedGraphSet. Supported RDF serialization languages are "TRIX", "TRIX-EXT", "TRIG", "RDF/XML", "N-TRIPLE" and "N3".

Serialization languages that support named graphs (like TriX) will take the graph name(s) from the serialization. Other languages will take the base URI as the name of the graph.

If some of the graph names from the source are already used in the NamedGraphSet, then the statements from the old graphs will be replaced by those from the source.

Parameters:
source - The source of the input serialization
baseURI - The URI from where the input was read
lang - The RDF serialization language of the input

write

void write(OutputStream out,
           String lang,
           String baseURI)
Writes a serialized represention of the NamedGraphSet to an OutputStream. Supported RDF serialization languages are "TRIX", "TRIG", "RDF/XML", "N-TRIPLE" and "N3".

If the specified serialization language doesn't support named graphs, then the union graph will be serialized, and knowledge about the graph name of each statement is lost. Only TriX supports named graphs.

The serialization will be UTF-8 encoded. There is currently no way to select a different encoding.

Parameters:
out - The stream into which the serialization will be written
lang - The RDF serialization language to be used
baseURI - The base URI of the output file, or null if don't care

write

void write(Writer out,
           String lang,
           String baseURI)
Writes a serialized represention of the NamedGraphSet to a Writer. Supported RDF serialization languages are "TRIX", "TRIG", "RDF/XML", "N-TRIPLE" and "N3".

If the specified serialization language doesn't support named graphs, then the union graph will be serialized, and knowledge about the graph name of each statement is lost. Only TriX supports named graphs.

Note that this method might generate wrong results if the Writer is translated to bytes using anything but the system's default encoding. For this reason, write(OutputStream, String, String) should be used if possible.

Parameters:
out - The stream into which the serialization will be written
lang - The RDF serialization language to be used
baseURI - The base URI of the output file, or null if don't care