ibspan.tss.core.semantic
Class Memory

java.lang.Object
  extended by ibspan.tss.core.semantic.Memory

public class Memory
extends Object

This class provides a set of methods for transparent operating on Jena memory-based model.

Examples say more then thousand of words:

Author:
Maciej Gawinecki, Michal Laclavik
See Also:
OntModel, Thing, OWLData

Field Summary
static String DEFAULT_BASE_NS
          Default base namespace URI.
static String DEFAULT_LANG
          Default serialization language.
 
Constructor Summary
Memory()
          Creates Memory with empy model.
Memory(OntModel model)
          Creates Memory object with given model.
Memory(OWLData data)
           
Memory(String rdf)
          Creates Memory object with model with RDF statements represented in language DEFAULT_LANG.
Memory(String rdf, String base)
          Creates Memory object with model including RDF statements represented in language DEFAULT_LANG.
Memory(com.ibm.adtech.jastor.Thing thing)
           
Memory(com.ibm.adtech.jastor.Thing thing, boolean asRoot)
          Creates Memory object with model including resource of given Thing.
 
Method Summary
 void add(Memory mem)
           
 void add(OntModel newModel)
           
 void add(OWLData data)
           
 Resource add(Resource r)
          Creates a copy of given resource if it is not there
 void add(com.ibm.adtech.jastor.Thing thing)
          Remembers thing in memory and registers it as one of the roots.
 Resource addProperties(Resource root)
          Recursive method which copy resource with all properties recursively into memory.
 void addRoot(com.ibm.adtech.jastor.Thing thing)
          Remembers thing in memory and registers it as one of the roots.
 OWLData buildOWLData()
          Creates OWLData containing internal model of this Memory object.
 Resource createAnonResource()
          Creates and returns anonymous resource in the memory.
static OntModel createDefaultOntModel()
          Answer a new ontology model which will process in-memory models of ontologies expressed the default ontology language (OWL).
 String dump()
          Returns a serialized represention of the internal model in a language DEFAULT_LANG.
 OntModel getModel()
          Returns internal model.
protected static String model2rdf(OntModel model)
          Returns a serialized represention of a model in a language DEFAULT_LANG.
protected static String model2rdf(OntModel model, String lang)
          Returns a serialized represention of a model in a language lang.
protected static String model2rdf(OntModel model, String lang, String base)
          Returns a serialized represention of a model in a language DEFAULT_LANG.
protected static OntModel rdf2model(String rdf)
          Add RDF statements represented in language DEFAULT_LANG to the model.
protected static OntModel rdf2model(String rdf, String base)
          Add RDF statements represented in language DEFAULT_LANG to the model.
protected static OntModel rdf2model(String rdf, String base, String lang)
          Add RDF statements represented in language lang to the model.
 void registerRoot(Resource root)
           
 void registerRoot(com.ibm.adtech.jastor.Thing root)
           
 void removeProperties(com.ibm.adtech.jastor.Thing root)
          Recursive method which remove resource with all properties recursively from the memory.
 void removeThing(com.ibm.adtech.jastor.Thing thing)
          Removes thing and related properties from memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_LANG

public static final String DEFAULT_LANG
Default serialization language.

See Also:
Constant Field Values

DEFAULT_BASE_NS

public static final String DEFAULT_BASE_NS
Default base namespace URI.

Constructor Detail

Memory

public Memory()
Creates Memory with empy model.


Memory

public Memory(String rdf)
Creates Memory object with model with RDF statements represented in language DEFAULT_LANG.

Parameters:
rdf - the source input of the input serialization.
See Also:
DEFAULT_LANG

Memory

public Memory(String rdf,
              String base)
Creates Memory object with model including RDF statements represented in language DEFAULT_LANG.

Parameters:
rdf - the source input of the input serialization.
base - the base uri to be used when converting relative URI's to absolute URI's. The base URI may be null if there are no relative URIs to convert. A base URI of "" may permit relative URIs to be used in the model.

Memory

public Memory(OntModel model)
Creates Memory object with given model.

Parameters:
model - existing model.

Memory

public Memory(com.ibm.adtech.jastor.Thing thing)

Memory

public Memory(com.ibm.adtech.jastor.Thing thing,
              boolean asRoot)
       throws AnonymousResourceException
Creates Memory object with model including resource of given Thing.

Parameters:
model - existing model.
Throws:
AnonymousResourceException

Memory

public Memory(OWLData data)
Parameters:
data -
Method Detail

registerRoot

public void registerRoot(com.ibm.adtech.jastor.Thing root)
                  throws AnonymousResourceException
Throws:
AnonymousResourceException

registerRoot

public void registerRoot(Resource root)
                  throws AnonymousResourceException
Throws:
AnonymousResourceException

add

public void add(OWLData data)

add

public void add(Memory mem)

getModel

public OntModel getModel()
Returns internal model.

Returns:
this model.

add

public void add(OntModel newModel)

dump

public String dump()
Returns a serialized represention of the internal model in a language DEFAULT_LANG.

Returns:
serialized representation
See Also:
DEFAULT_LANG

add

public void add(com.ibm.adtech.jastor.Thing thing)
Remembers thing in memory and registers it as one of the roots. More precisely, copies resource of thing into internal model.

Parameters:
thing - given thing
Throws:
AnonymousResourceException

addRoot

public void addRoot(com.ibm.adtech.jastor.Thing thing)
             throws AnonymousResourceException
Remembers thing in memory and registers it as one of the roots. More precisely, copies resource of thing into internal model.

Parameters:
thing - given thing
Throws:
AnonymousResourceException

buildOWLData

public OWLData buildOWLData()
Creates OWLData containing internal model of this Memory object. Syntax language will be set to the value of DEFAULT_LANG and all resources registered as roots will be added as values of withRootURI property of OWLData object.

Returns:
OWLData representing content of this memory

add

public Resource add(Resource r)
Creates a copy of given resource if it is not there

Parameters:
r -

createAnonResource

public Resource createAnonResource()
Creates and returns anonymous resource in the memory.

Returns:
creates resource

createDefaultOntModel

public static OntModel createDefaultOntModel()
Answer a new ontology model which will process in-memory models of ontologies expressed the default ontology language (OWL).

Returns:
a new ontology model.

model2rdf

protected static String model2rdf(OntModel model)
Returns a serialized represention of a model in a language DEFAULT_LANG.

Parameters:
model - the source model of the output serialization.
Returns:
serialized representation
See Also:
DEFAULT_LANG

model2rdf

protected static String model2rdf(OntModel model,
                                  String lang)
Returns a serialized represention of a model in a language lang.

Parameters:
model - the source model of the output serialization.
lang - the language in which the RDF should be serialized
Returns:
serialized representation.

model2rdf

protected static String model2rdf(OntModel model,
                                  String lang,
                                  String base)
Returns a serialized represention of a model in a language DEFAULT_LANG.

Parameters:
model - the source model of the output serialization.
lang - the language in which the RDF should be serialized
base - the base uri for relative URI calculations; null means use only absolute URI's.
Returns:
serialized representation

rdf2model

protected static OntModel rdf2model(String rdf)
Add RDF statements represented in language DEFAULT_LANG to the model.

Parameters:
rdf - the source input of the input serialization.
Returns:
newly serialiazed model.
See Also:
DEFAULT_LANG

rdf2model

protected static OntModel rdf2model(String rdf,
                                    String base)
Add RDF statements represented in language DEFAULT_LANG to the model.

Parameters:
rdf - the source input of the input serialization.
base - the base uri to be used when converting relative URI's to absolute URI's. The base URI may be null if there are no relative URIs to convert. A base URI of "" may permit relative URIs to be used in the model.
Returns:
newly serialiazed model.
See Also:
DEFAULT_LANG

rdf2model

protected static OntModel rdf2model(String rdf,
                                    String base,
                                    String lang)
Add RDF statements represented in language lang to the model.

Parameters:
rdf - the source input of the input serialization.
base - the base uri to be used when converting relative URI's to absolute URI's. The base URI may be null if there are no relative URIs to convert. A base URI of "" may permit relative URIs to be used in the model.
lang - the langauge of the serialization; null selects the default.
Returns:
newly serialiazed model.

addProperties

public Resource addProperties(Resource root)
Recursive method which copy resource with all properties recursively into memory.

Parameters:
r - resource which properties should be added
Returns:
reference to copy of the resource in memory

removeProperties

public void removeProperties(com.ibm.adtech.jastor.Thing root)
Recursive method which remove resource with all properties recursively from the memory. Notice, that also nodes shared with other roots-subgraphs are remove.

Parameters:
root - resource which properties should be removed

removeThing

public void removeThing(com.ibm.adtech.jastor.Thing thing)
                 throws AnonymousResourceException
Removes thing and related properties from memory. Unregisters it from list of root things, if it was registered. Notice, that also nodes shared with other roots-subgraphs are remove.

Parameters:
thing - thing to be removed
Throws:
AnonymousResourceException