org.openanzo.utils
Class GraphUtils

java.lang.Object
  extended by org.openanzo.utils.GraphUtils

public class GraphUtils
extends java.lang.Object

Set of utility methods for graph operations, mainly dealing with reading and writing data.

Author:
Matthew Roy ( mroy@cambridgesemantics.com )

Constructor Summary
GraphUtils()
           
 
Method Summary
static void addGraph(INamedGraph dest, INamedGraph src)
          Add all statements from src graph to destination graph
static java.lang.Iterable<org.openrdf.model.Statement> getCollectionMembers(org.openrdf.model.Resource list, IDataset dataset)
          Get an Iterable for the members of the RDFList construct provided
static java.lang.Iterable<org.openrdf.model.Value> getCollectionMembers(org.openrdf.model.Resource list, INamedGraph graph)
          Get an Iterable for the members of the RDFList construct provided
static java.lang.Iterable<org.openrdf.model.Statement> getContainerMembers(org.openrdf.model.Resource container, IDataset dataset)
          Get an Iterable for the members of the RDFContainer construct provided
static java.lang.Iterable<org.openrdf.model.Value> getContainerMembers(org.openrdf.model.Resource container, INamedGraph graph)
          Get an Iterable for the members of the RDFContainer construct provided
static java.lang.String graphToString(INamedGraph graph)
          Write the contents of the graph to a string in RDFXML format
static void loadDataset(IDataset dataset, java.io.InputStream rdf, org.openrdf.rio.RDFFormat format, java.lang.String baseURI, int batchSize)
          Load the contents of an input stream into the given dataset.
static void loadGraph(INamedGraph graph, java.io.File file)
          Load data from given file into a graph.
static void loadGraph(INamedGraph graph, java.io.InputStream rdf, org.openrdf.rio.RDFFormat format, java.lang.String baseURI)
          Load the contents of an input stream into given graph, using parser for given format
static void loadGraph(INamedGraph graph, java.io.InputStream rdf, org.openrdf.rio.RDFFormat format, java.lang.String baseURI, int batchSize)
          Load the contents of an input stream into given graph, using parser for given format,batching additions into chunks of given size
static void loadGraph(INamedGraph graph, java.lang.String rdf, org.openrdf.rio.RDFFormat format)
          Load the contents of string into given graph, using parser for given format
static void loadGraphInDataset(IDataset dataset, org.openrdf.model.URI namedGraphURI, java.io.InputStream rdf, org.openrdf.rio.RDFFormat format, java.lang.String baseURI)
          Load the contents of an input stream into a graph with the given URI which is a member of the given dataset.
static void loadGraphInDataset(IDataset dataset, org.openrdf.model.URI namedGraphURI, java.io.InputStream rdf, org.openrdf.rio.RDFFormat format, java.lang.String baseURI, int batchSize)
          Load the contents of an input stream into a graph with the given URI which is a member of the given dataset.
static void writeDataset(IDataset dataset, java.io.OutputStream out)
          Write the contents of the given Dataset's NamedGraphs to the given OutputStream, using TriG Note:Default graph data is not written
static void writeGraph(INamedGraph graph, java.io.OutputStream out)
          Write the contents of the given named graph to the given OutputStream, using RDFXML
static void writeGraph(INamedGraph graph, java.io.Writer writer)
          Write the contents of the given named graph to the given writer, using RDFXML
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphUtils

public GraphUtils()
Method Detail

writeGraph

public static void writeGraph(INamedGraph graph,
                              java.io.Writer writer)
                       throws org.openrdf.rio.RDFHandlerException
Write the contents of the given named graph to the given writer, using RDFXML

Parameters:
graph - Graph to write
writer - Writer to which data is written
Throws:
org.openrdf.rio.RDFHandlerException - if there are exceptions writing the data

writeGraph

public static void writeGraph(INamedGraph graph,
                              java.io.OutputStream out)
                       throws org.openrdf.rio.RDFHandlerException
Write the contents of the given named graph to the given OutputStream, using RDFXML

Parameters:
graph - Graph to write
out - OutputStream to which data is written
Throws:
org.openrdf.rio.RDFHandlerException - if there are exceptions writing the data

writeDataset

public static void writeDataset(IDataset dataset,
                                java.io.OutputStream out)
                         throws org.openrdf.rio.RDFHandlerException
Write the contents of the given Dataset's NamedGraphs to the given OutputStream, using TriG Note:Default graph data is not written

Parameters:
dataset - Graph to write
out - OutputStream to which data is written
Throws:
org.openrdf.rio.RDFHandlerException - if there are exceptions writing the data

graphToString

public static java.lang.String graphToString(INamedGraph graph)
                                      throws java.lang.Exception
Write the contents of the graph to a string in RDFXML format

Parameters:
graph - Graph to write
Returns:
String containing contents of graph in RDFXML
Throws:
java.lang.Exception

loadGraph

public static void loadGraph(INamedGraph graph,
                             java.io.File file)
                      throws java.lang.Exception
Load data from given file into a graph.

Parameters:
graph - Graph to which data is loaded
file - File containing graph data.
Throws:
java.lang.Exception - if there is an error parsing data

loadGraph

public static void loadGraph(INamedGraph graph,
                             java.io.InputStream rdf,
                             org.openrdf.rio.RDFFormat format,
                             java.lang.String baseURI)
                      throws java.lang.Exception
Load the contents of an input stream into given graph, using parser for given format

Parameters:
graph - Graph to which data is loaded
rdf - InputStream containing data
format - Format which data is stored
baseURI - BaseURI of data within stream
Throws:
java.lang.Exception - if there is an error parsing data

loadGraph

public static void loadGraph(INamedGraph graph,
                             java.io.InputStream rdf,
                             org.openrdf.rio.RDFFormat format,
                             java.lang.String baseURI,
                             int batchSize)
                      throws java.lang.Exception
Load the contents of an input stream into given graph, using parser for given format,batching additions into chunks of given size

Parameters:
graph - Graph to which data is loaded
rdf - InputStream containing data
format - Format which data is stored
baseURI - BaseURI of data within stream
batchSize - Size of chunks used during data loading
Throws:
java.lang.Exception - if there is an error parsing data

loadGraph

public static void loadGraph(INamedGraph graph,
                             java.lang.String rdf,
                             org.openrdf.rio.RDFFormat format)
                      throws java.lang.Exception
Load the contents of string into given graph, using parser for given format

Parameters:
graph - Graph to which data is loaded
rdf - String containing data
format - Format which data is stored
Throws:
java.lang.Exception - if there is an error parsing data

loadGraphInDataset

public static void loadGraphInDataset(IDataset dataset,
                                      org.openrdf.model.URI namedGraphURI,
                                      java.io.InputStream rdf,
                                      org.openrdf.rio.RDFFormat format,
                                      java.lang.String baseURI)
                               throws java.lang.Exception
Load the contents of an input stream into a graph with the given URI which is a member of the given dataset. Use parser for given format

Parameters:
dataset - Dataset which contains given NamedGraph
namedGraphURI - URI of graph to which data is loaded
rdf - InputStream containing data
format - Format which data is stored
baseURI - BaseURI of data within stream
Throws:
java.lang.Exception - if there is an error parsing data

loadGraphInDataset

public static void loadGraphInDataset(IDataset dataset,
                                      org.openrdf.model.URI namedGraphURI,
                                      java.io.InputStream rdf,
                                      org.openrdf.rio.RDFFormat format,
                                      java.lang.String baseURI,
                                      int batchSize)
                               throws java.lang.Exception
Load the contents of an input stream into a graph with the given URI which is a member of the given dataset. Use parser for given format,batching additions into chunks of given size

Parameters:
dataset - Dataset which contains given NamedGraph
namedGraphURI - URI of graph to which data is loaded
rdf - InputStream containing data
format - Format which data is stored
baseURI - BaseURI of data within stream
batchSize - Size of chunks used during data loading
Throws:
java.lang.Exception - if there is an error parsing data

loadDataset

public static void loadDataset(IDataset dataset,
                               java.io.InputStream rdf,
                               org.openrdf.rio.RDFFormat format,
                               java.lang.String baseURI,
                               int batchSize)
                        throws java.lang.Exception
Load the contents of an input stream into the given dataset. Use parser for given format,batching additions into chunks of given size

Parameters:
dataset - Dataset to which data is loaded
rdf - InputStream containing data
format - Format which data is stored
baseURI - BaseURI of data within stream
batchSize - Size of chunks used during data loading
Throws:
java.lang.Exception - if there is an error parsing data

addGraph

public static void addGraph(INamedGraph dest,
                            INamedGraph src)
Add all statements from src graph to destination graph

Parameters:
dest - Graph to which statements are added
src - Graph from which statements are added

getContainerMembers

public static java.lang.Iterable<org.openrdf.model.Value> getContainerMembers(org.openrdf.model.Resource container,
                                                                              INamedGraph graph)
Get an Iterable for the members of the RDFContainer construct provided

Parameters:
container - Resource of RDFContainer object
graph - Graph containing data
Returns:
Iterable containing data contained within RDFContainer

getContainerMembers

public static java.lang.Iterable<org.openrdf.model.Statement> getContainerMembers(org.openrdf.model.Resource container,
                                                                                  IDataset dataset)
Get an Iterable for the members of the RDFContainer construct provided

Parameters:
container - Resource of RDFContainer object
dataset - Dataset containing data
Returns:
Iterable containing data contained within RDFContainer

getCollectionMembers

public static java.lang.Iterable<org.openrdf.model.Value> getCollectionMembers(org.openrdf.model.Resource list,
                                                                               INamedGraph graph)
Get an Iterable for the members of the RDFList construct provided

Parameters:
list - Resource of RDFList object
graph - Graph containing data
Returns:
Iterable containing data contained within RDFContainer

getCollectionMembers

public static java.lang.Iterable<org.openrdf.model.Statement> getCollectionMembers(org.openrdf.model.Resource list,
                                                                                   IDataset dataset)
Get an Iterable for the members of the RDFList construct provided

Parameters:
list - Resource of RDFList object
dataset - Dataset containing data
Returns:
Iterable containing data contained within RDFContainer


Copyright © 2007 Cambridge Semantics Inc.. All Rights Reserved.