de.fuberlin.wiwiss.ng4j
Class NamedGraphModel

java.lang.Object
  extended by com.hp.hpl.jena.enhanced.Polymorphic
      extended by com.hp.hpl.jena.enhanced.EnhGraph
          extended by com.hp.hpl.jena.rdf.model.impl.ModelCom
              extended by de.fuberlin.wiwiss.ng4j.NamedGraphModel
All Implemented Interfaces:
Model, ModelCon, ModelGraphInterface, ModelLock, RDFReaderF, RDFWriterF, Lock, PrefixMapping

public class NamedGraphModel
extends com.hp.hpl.jena.rdf.model.impl.ModelCom
implements Model

Jena Model implementation providing a resource-centric view on a NamedGraphSet's union graph. It is backed by the NamedGraphSet. Changes to one are reflected by the other.

All Statements returned by the NamedGraphModel can be casted to NamedGraphStatements. They provide information about which NamedGraphs they are contained in.

All Statements that are added to the model are added to a distinguished default NamedGraph. Removing Statements deletes them from all NamedGraphs in the backing set.

All flavours of the read and write methods support the TriX format which keeps the association of statements and their graph names.

All read operations on other RDF files will load the statements into a graph named with the file's URI, replacing older statements from the same source. This can be very handy for data management.

Methods that return new Models, like Model.query(com.hp.hpl.jena.rdf.model.Selector) and Model.union(com.hp.hpl.jena.rdf.model.Model), will not return new NamedGraphModels but normal Jena ModelMems. (This is because Jena makes it hard to return anything but ModelMems without much copy & paste.)

Note: This class was implemented without considering reification. It still contains reification methods inherited from Jena, but those do probably not work.

TODO: Properly test read and write methods

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.hp.hpl.jena.shared.PrefixMapping
PrefixMapping.Factory, PrefixMapping.IllegalPrefixException, PrefixMapping.JenaLockedException
 
Field Summary
 
Fields inherited from class com.hp.hpl.jena.rdf.model.impl.ModelCom
mapAsStatement, modelReifier
 
Fields inherited from class com.hp.hpl.jena.enhanced.EnhGraph
enhNodes, graph
 
Fields inherited from interface com.hp.hpl.jena.shared.PrefixMapping
Extended, Standard
 
Fields inherited from interface com.hp.hpl.jena.rdf.model.ModelLock
READ, WRITE
 
Constructor Summary
NamedGraphModel(NamedGraphSet graphSet, String defaultGraphForAdding)
          Initialises a NamedGraphModel.
 
Method Summary
 Statement createStatement(Resource s, Property p, RDFNode o)
          Create a Statement instance.
 Resource getDefaultGraphName()
          Returns the name of the default graph (which new statements are added to).
 NamedGraphSet getNamedGraphSet()
          Returns the NamedGraphSet backing this model.
 Resource getResource(String uri)
           
 Resource getResource(String uri, ResourceF f)
           
 StmtIterator listStatements()
          Lists all statements.
 StmtIterator listStatements(Selector selector)
          Lists the statements matching a selector.
 Model read(InputStream reader, String base)
           
 Model read(InputStream reader, String base, String lang)
           
 Model read(Reader reader, String base)
           
 Model read(Reader reader, String base, String lang)
           
 Model read(String url)
           
 Model read(String url, String lang)
           
 Model write(OutputStream writer)
           
 Model write(OutputStream writer, String lang)
           
 Model write(OutputStream writer, String lang, String base)
           
 Model write(Writer writer)
           
 Model write(Writer writer, String lang)
           
 Model write(Writer writer, String lang, String base)
           
 
Methods inherited from class com.hp.hpl.jena.rdf.model.impl.ModelCom
abort, adapt, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, add, addCommon, addNamespaces, asFilter, asModel, asNode, asRDFNode, asStatement, asStatements, asStatements, asStatements, begin, close, commit, contains, contains, contains, contains, contains, contains, contains, contains, contains, contains, contains, containsAll, containsAll, containsAllThenClose, containsAny, containsAny, containsAnyThenClose, containsResource, createAlt, createAlt, createBag, createBag, createList, createList, createList, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createProperty, createProperty, createReifiedStatement, createReifiedStatement, createResource, createResource, createResource, createResource, createResource, createResource, createResource, createSeq, createSeq, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createWorkModel, difference, enterCriticalSection, executeInTransaction, expandPrefix, findTriplesFrom, getAlt, getAlt, getAnyReifiedStatement, getBag, getBag, getBulkUpdateHandler, getDefaultModelPrefixes, getGraph, getHiddenStatements, getLock, getModelLock, getNsPrefixMap, getNsPrefixURI, getNsURIPrefix, getProperty, getProperty, getProperty, getRDFNode, getReader, getReader, getReificationStyle, getRequiredProperty, getSeq, getSeq, getWriter, getWriter, independent, intersect, intersection, isClosed, isEmpty, isIsomorphicWith, isReified, leaveCriticalSection, listBySubject, listNameSpaces, listObjects, listObjectsOfProperty, listObjectsOfProperty, listReifiedStatements, listReifiedStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listSubjects, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, lock, notifyEvent, qnameFor, query, queryHandler, read, register, reifiedToString, remove, remove, remove, remove, remove, remove, remove, removeAll, removeAll, removeAllReifications, removeNsPrefix, removeReification, samePrefixMappingAs, setDefaultModelPrefixes, setNsPrefix, setNsPrefixes, setNsPrefixes, setReaderClassName, setWriterClassName, shortForm, size, statementsToString, supportsSetOperations, supportsTransactions, toString, union, unregister, usePrefix, withDefaultMappings
 
Methods inherited from class com.hp.hpl.jena.enhanced.EnhGraph
asGraph, canSupport, convertTo, equals, getNodeAs, getNodeCacheControl, getPersonality, hashCode, isIsomorphicWith, isValid, setNodeCache
 
Methods inherited from class com.hp.hpl.jena.enhanced.Polymorphic
addView, already, alreadyHasView, asInternal, supports
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.hp.hpl.jena.rdf.model.Model
abort, add, add, add, add, add, add, begin, close, commit, contains, contains, contains, containsAll, containsAll, containsAny, containsAny, containsResource, createList, createList, createList, createLiteral, createLiteral, createLiteral, createProperty, createReifiedStatement, createReifiedStatement, createResource, createResource, createResource, createTypedLiteral, createTypedLiteral, createTypedLiteral, difference, equals, executeInTransaction, getAnyReifiedStatement, getLock, getModelLock, getProperty, getProperty, getReificationStyle, getRequiredProperty, independent, intersection, isClosed, isEmpty, isIsomorphicWith, isReified, listNameSpaces, listObjects, listObjectsOfProperty, listObjectsOfProperty, listReifiedStatements, listReifiedStatements, listStatements, listSubjects, listSubjectsWithProperty, listSubjectsWithProperty, notifyEvent, query, read, register, remove, remove, remove, removeAll, removeAll, removeAllReifications, removeReification, size, supportsSetOperations, supportsTransactions, union, unregister
 
Methods inherited from interface com.hp.hpl.jena.rdf.model.ModelCon
add, add, add, add, add, add, add, add, add, add, add, add, contains, contains, contains, contains, contains, contains, contains, contains, createAlt, createAlt, createBag, createBag, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createLiteral, createProperty, createResource, createResource, createResource, createResource, createSeq, createSeq, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createStatement, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, createTypedLiteral, getAlt, getAlt, getBag, getBag, getProperty, getRDFNode, getSeq, getSeq, listStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listStatements, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, listSubjectsWithProperty, remove, remove, remove, remove
 
Methods inherited from interface com.hp.hpl.jena.rdf.model.ModelGraphInterface
asRDFNode, asStatement, getGraph, queryHandler
 
Methods inherited from interface com.hp.hpl.jena.rdf.model.RDFReaderF
getReader, getReader, setReaderClassName
 
Methods inherited from interface com.hp.hpl.jena.rdf.model.RDFWriterF
getWriter, getWriter, setWriterClassName
 
Methods inherited from interface com.hp.hpl.jena.shared.PrefixMapping
expandPrefix, getNsPrefixMap, getNsPrefixURI, getNsURIPrefix, lock, qnameFor, removeNsPrefix, samePrefixMappingAs, setNsPrefix, setNsPrefixes, setNsPrefixes, shortForm, usePrefix, withDefaultMappings
 
Methods inherited from interface com.hp.hpl.jena.shared.Lock
enterCriticalSection, leaveCriticalSection
 

Constructor Detail

NamedGraphModel

public NamedGraphModel(NamedGraphSet graphSet,
                       String defaultGraphForAdding)
Initialises a NamedGraphModel.

Parameters:
graphSet - A NamedGraphSet to back the model
defaultGraphForAdding - a default graph name to be used when statements are added to the model
Method Detail

getNamedGraphSet

public NamedGraphSet getNamedGraphSet()
Returns the NamedGraphSet backing this model.

Returns:
The NamedGraphSet on which the model is based.

getDefaultGraphName

public Resource getDefaultGraphName()
Returns the name of the default graph (which new statements are added to).

Returns:
The name of the default NamedGraph

createStatement

public Statement createStatement(Resource s,
                                 Property p,
                                 RDFNode o)
Create a Statement instance. (Creating a statement does not add it to the set of statements in the model; see Model::add). This method may return an existing Statement with the correct components and model, or it may construct a fresh one, as it sees fit.

Subsequent operations on the statement or any of its parts may modify this model.

Specified by:
createStatement in interface Model
Overrides:
createStatement in class com.hp.hpl.jena.rdf.model.impl.ModelCom
Parameters:
s - the subject of the statement
p - the predicate of the statement
o - the object of the statement
Returns:
the new statement

listStatements

public StmtIterator listStatements()
Lists all statements. Subsequent operations on those statements may modify this model.

Specified by:
listStatements in interface Model
Overrides:
listStatements in class com.hp.hpl.jena.rdf.model.impl.ModelCom
Returns:
An iterator over all statements in the model.

listStatements

public StmtIterator listStatements(Selector selector)
Lists the statements matching a selector.

Specified by:
listStatements in interface Model
Overrides:
listStatements in class com.hp.hpl.jena.rdf.model.impl.ModelCom
Parameters:
selector - A selector object
Returns:
an iterator over the matching statements

read

public Model read(InputStream reader,
                  String base,
                  String lang)
Specified by:
read in interface Model
Overrides:
read in class com.hp.hpl.jena.rdf.model.impl.ModelCom

read

public Model read(InputStream reader,
                  String base)
Specified by:
read in interface Model
Overrides:
read in class com.hp.hpl.jena.rdf.model.impl.ModelCom

read

public Model read(Reader reader,
                  String base,
                  String lang)
Specified by:
read in interface Model
Overrides:
read in class com.hp.hpl.jena.rdf.model.impl.ModelCom

read

public Model read(Reader reader,
                  String base)
Specified by:
read in interface Model
Overrides:
read in class com.hp.hpl.jena.rdf.model.impl.ModelCom

read

public Model read(String url,
                  String lang)
Specified by:
read in interface Model
Overrides:
read in class com.hp.hpl.jena.rdf.model.impl.ModelCom

read

public Model read(String url)
Specified by:
read in interface Model
Overrides:
read in class com.hp.hpl.jena.rdf.model.impl.ModelCom

write

public Model write(OutputStream writer,
                   String lang,
                   String base)
Specified by:
write in interface Model
Overrides:
write in class com.hp.hpl.jena.rdf.model.impl.ModelCom

write

public Model write(OutputStream writer,
                   String lang)
Specified by:
write in interface Model
Overrides:
write in class com.hp.hpl.jena.rdf.model.impl.ModelCom

write

public Model write(OutputStream writer)
Specified by:
write in interface Model
Overrides:
write in class com.hp.hpl.jena.rdf.model.impl.ModelCom

write

public Model write(Writer writer,
                   String lang,
                   String base)
Specified by:
write in interface Model
Overrides:
write in class com.hp.hpl.jena.rdf.model.impl.ModelCom

write

public Model write(Writer writer,
                   String lang)
Specified by:
write in interface Model
Overrides:
write in class com.hp.hpl.jena.rdf.model.impl.ModelCom

write

public Model write(Writer writer)
Specified by:
write in interface Model
Overrides:
write in class com.hp.hpl.jena.rdf.model.impl.ModelCom

getResource

public Resource getResource(String uri)
Specified by:
getResource in interface Model
Overrides:
getResource in class com.hp.hpl.jena.rdf.model.impl.ModelCom
See Also:
ModelCom.getResource(java.lang.String)

getResource

public Resource getResource(String uri,
                            ResourceF f)
Specified by:
getResource in interface ModelCon
Overrides:
getResource in class com.hp.hpl.jena.rdf.model.impl.ModelCom
See Also:
ModelCom.getResource(java.lang.String, com.hp.hpl.jena.rdf.model.ResourceF)