Class RelationAdapter
java.lang.Object
com.semedy.reasoner.reasoning.monitor.RelationAdapter
- All Implemented Interfaces:
BaseRelation
,Relation
- Direct Known Subclasses:
ReasoningMonitorRelation
Adapter to
BaseRelation
. Throws UnsupportedOperationException
when a method is called which is not part of the base relation.- Author:
- Juergen Angele
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
addTuple
(int tupleaddress) add a tuple to the relationboolean
addTuple
(long[] tuple) add a tuple to the relationboolean
addTuple
(TupleBuffer terms) add a tuple to the relationboolean
checkSanity
(String message, boolean shadow) check the sanity of a relationvoid
clear()
remove all tuplesvoid
close()
Close the relation.boolean
containsTuple
(int tuple) Is tuple contained in relation?boolean
containsTuple
(long[] tuple) Is tuple contained in relation?boolean
containsTuple
(TupleBuffer tuple) Is tuple contained in relation?createIndex
(int[] indexedpositions) Get or create a simple (not sorted index) by the argument positions in indexed positions.createSortedIndex
(int[] indexedpositions) ret or create a sorted index given by the argument positions in indexed positionsvoid
delete()
remove all tuples and release filesvoid
deSelect()
release ressources because relation is currently not usedelements()
returns an enumerator for all tupleselements
(long[] filter) returns an filteres enumerator for all tuplesvoid
flush()
Flush the relation.int
getArity()
returns the arity of the relationget the caching infoget standard path for binary fileint
getDirectEncodedType
(int i) get the type of the direct encoded argumentreturns the file name for the relationlong[]
get the groundsreturns a unique identifier for the relationgetIndex
(int[] indexedpositions) Get an index given by the argument positions in indexed positions (if it already exists).get an input buffer for relationint
returns the internal arity of tupleslong
getMaxValue
(int argument) returns the maximal value at that argument positionlong
getMinValue
(int argument) returns the minimal value at that argument positiongetName()
get a unique name of the relationlong
getNumberOfDifferentValues
(int argument) Returns the number of different values at the argument positions.long
getNumberOfDifferentValues
(int argument, long v) Returns the number of values occurring at the argument positions
Used for statisticslong
getNumberOfMatchingTuples
(int[] arguments, long[] values) returns the predicate symbol for the relationgetSortedIndex
(int[] indexedpositions) Get a sorted index given by the argument positions in indexed positions (if it already exists).boolean
may relation contain duplicates?boolean
boolean
isDirectEncoded
(int i) are all values at argument i direct encodedboolean
isEmpty()
Is the relation empty?long[]
isOverwrittenByTuple
(long[] buffer) returns the tuple which will be overwritten by tuple.boolean
Is the relation persistent?boolean
Is the relation temporary only?long
last modification timeboolean
Might there be duplicates?long[]
overwriteTuple
(long[] buffer) Overwrite last argument of tuple.overwriteTuple
(TupleBuffer buffer) Overwrite last argument of tuple.void
readBinaryFromBackup
(String filepath) read tuples from a binary backup filevoid
readTupleFile
(String filepath) read tuples from a (compressed) binary filevoid
registerListener
(RelationListener listener) register a listener for adding, removing, modifying tuplesvoid
boolean
removeTuple
(int tupleaddress) remove a tuple from the relationboolean
removeTuple
(long[] buffer) remove a tuple from the relationboolean
removeTuple
(TupleBuffer buffer) remove a tuple from the relationvoid
select()
initialize it before using itlong
size()
returns the number of tuples in relationlong
return number of bytes used in main memory.void
void
begin transactionvoid
commit last changesvoid
rbort last changesvoid
add all tuples of R to thisvoid
void
writeBinary
(String filepath) write tuples to a binary filevoid
writeBinaryToBackup
(String filepath) write tuples to a binary backup filevoid
writeBinaryWithGrounds
(String filepath) write complete tuples to a binary file
-
Constructor Details
-
RelationAdapter
-
-
Method Details
-
sizeInBytes
public long sizeInBytes()return number of bytes used in main memory. Used for cache management- Specified by:
sizeInBytes
in interfaceBaseRelation
- Returns:
- approximate number of size in bytes
-
getArity
public int getArity()Description copied from interface:BaseRelation
returns the arity of the relation- Specified by:
getArity
in interfaceBaseRelation
- Returns:
- arity of relation
-
elements
Description copied from interface:BaseRelation
returns an enumerator for all tuples- Specified by:
elements
in interfaceBaseRelation
- Returns:
- returns enumerator for tuples
- Throws:
IOException
EDBException
-
size
Description copied from interface:BaseRelation
returns the number of tuples in relation- Specified by:
size
in interfaceBaseRelation
- Returns:
- number of tuples in relation
- Throws:
IOException
EDBException
-
createSortedIndex
Description copied from interface:BaseRelation
ret or create a sorted index given by the argument positions in indexed positions- Specified by:
createSortedIndex
in interfaceBaseRelation
- Returns:
- Throws:
IOException
EDBException
-
getSortedIndex
Description copied from interface:BaseRelation
Get a sorted index given by the argument positions in indexed positions (if it already exists).
Returns null if it does not exist.- Specified by:
getSortedIndex
in interfaceBaseRelation
- Parameters:
indexedpositions
- the indexed positions- Returns:
- the corresponding index or
null
if none is available
-
createIndex
Description copied from interface:BaseRelation
Get or create a simple (not sorted index) by the argument positions in indexed positions.- Specified by:
createIndex
in interfaceBaseRelation
- Parameters:
indexedpositions
- , positions which are indexed- Returns:
- index
- Throws:
IOException
EDBException
-
getIndex
Description copied from interface:BaseRelation
Get an index given by the argument positions in indexed positions (if it already exists).
Returns null if it does not exist.- Specified by:
getIndex
in interfaceBaseRelation
- Parameters:
indexedpositions
- the indexed positions- Returns:
- the corresponding index or
null
if none is available
-
getIdentifier
Description copied from interface:BaseRelation
returns a unique identifier for the relation- Specified by:
getIdentifier
in interfaceBaseRelation
- Returns:
- unique identifier for relation
-
clear
Description copied from interface:BaseRelation
remove all tuples- Specified by:
clear
in interfaceBaseRelation
- Throws:
IOException
EDBException
-
isEmpty
Description copied from interface:BaseRelation
Is the relation empty?- Specified by:
isEmpty
in interfaceBaseRelation
- Returns:
- relation is empty
- Throws:
IOException
-
isPersistent
public boolean isPersistent()Description copied from interface:BaseRelation
Is the relation persistent?- Specified by:
isPersistent
in interfaceBaseRelation
- Returns:
- is the relation persistent
-
close
Description copied from interface:BaseRelation
Close the relation. Must be called to finalize the relation correctly- Specified by:
close
in interfaceBaseRelation
- Throws:
IOException
EDBException
-
getCacheInfo
Description copied from interface:BaseRelation
get the caching info- Specified by:
getCacheInfo
in interfaceBaseRelation
- Returns:
- object containing caching info
-
addTuple
Description copied from interface:BaseRelation
add a tuple to the relation- Specified by:
addTuple
in interfaceBaseRelation
- Parameters:
terms
- the tuple to add- Returns:
- tuple has been added
- Throws:
IOException
EDBException
-
addTuple
Description copied from interface:BaseRelation
add a tuple to the relation- Specified by:
addTuple
in interfaceBaseRelation
- Parameters:
tuple
- the tuple to add- Returns:
- tuple has been added
- Throws:
IOException
EDBException
-
removeTuple
Description copied from interface:BaseRelation
remove a tuple from the relation- Specified by:
removeTuple
in interfaceBaseRelation
- Parameters:
tupleaddress
- , address of tuple in tuple store- Returns:
- true, if tuple has been removed
- Throws:
IOException
EDBException
-
removeTuple
Description copied from interface:BaseRelation
remove a tuple from the relation- Specified by:
removeTuple
in interfaceBaseRelation
- Parameters:
buffer
- , tuple to be removed- Returns:
- true, if tuple has been removed
- Throws:
IOException
EDBException
-
overwriteTuple
Description copied from interface:BaseRelation
Overwrite last argument of tuple.
First arguments are unique keys for tuple
Especially useful for triples [subject,predicate,object]
and object is changed- Specified by:
overwriteTuple
in interfaceBaseRelation
- Parameters:
buffer
- , overwrite tuple- Returns:
- the overwritten tuple
- Throws:
IOException
EDBException
-
overwriteTuple
Description copied from interface:BaseRelation
Overwrite last argument of tuple.
First arguments are unique keys for tuple
Especially useful for triples [subject,predicate,object]
and object is changed- Specified by:
overwriteTuple
in interfaceBaseRelation
- Parameters:
buffer
- , overwrite tuple- Returns:
- the overwritten tuple
- Throws:
IOException
EDBException
-
isOverwrittenByTuple
Description copied from interface:BaseRelation
returns the tuple which will be overwritten by tuple.- Specified by:
isOverwrittenByTuple
in interfaceBaseRelation
- Returns:
- Throws:
IOException
EDBException
-
removeTuple
Description copied from interface:BaseRelation
remove a tuple from the relation- Specified by:
removeTuple
in interfaceBaseRelation
- Parameters:
buffer
- , tuple to be removed- Returns:
- true, if tuple has been removed
- Throws:
IOException
EDBException
-
getInputBuffer
Description copied from interface:BaseRelation
get an input buffer for relation- Specified by:
getInputBuffer
in interfaceBaseRelation
- Returns:
- a tuple store which serves as buffer for input tuples
-
addTuple
Description copied from interface:BaseRelation
add a tuple to the relation- Specified by:
addTuple
in interfaceBaseRelation
- Parameters:
tupleaddress
- the tuple to add- Returns:
- tuple has been added
- Throws:
IOException
EDBException
-
unionRelation
-
subtractRelation
-
getNumberOfDifferentValues
Description copied from interface:Relation
Returns the number of different values at the argument positions.
Used for statistics.- Specified by:
getNumberOfDifferentValues
in interfaceRelation
- Parameters:
argument
- , argument position- Returns:
- Throws:
IOException
-
getNumberOfDifferentValues
Description copied from interface:Relation
Returns the number of values occurring at the argument positions
Used for statistics- Specified by:
getNumberOfDifferentValues
in interfaceRelation
- Parameters:
argument
- , argument positionv
- , the concrete value- Returns:
- Throws:
IOException
-
getMinValue
Description copied from interface:BaseRelation
returns the minimal value at that argument position- Specified by:
getMinValue
in interfaceBaseRelation
- Parameters:
argument
- , argument position @return, minimal value- Throws:
IOException
-
getMaxValue
Description copied from interface:BaseRelation
returns the maximal value at that argument position- Specified by:
getMaxValue
in interfaceBaseRelation
- Parameters:
argument
- , argument position- Returns:
- max value at argument position
- Throws:
IOException
-
removeIndices
public void removeIndices() -
delete
Description copied from interface:Relation
remove all tuples and release files- Specified by:
delete
in interfaceRelation
- Throws:
IOException
-
writeBinary
Description copied from interface:Relation
write tuples to a binary file- Specified by:
writeBinary
in interfaceBaseRelation
- Specified by:
writeBinary
in interfaceRelation
- Throws:
IOException
-
readTupleFile
Description copied from interface:Relation
read tuples from a (compressed) binary file- Specified by:
readTupleFile
in interfaceBaseRelation
- Specified by:
readTupleFile
in interfaceRelation
- Parameters:
filepath
- , the file path to read from- Throws:
IOException
-
getDataFilePath
Description copied from interface:Relation
get standard path for binary file- Specified by:
getDataFilePath
in interfaceRelation
- Returns:
-
select
Description copied from interface:Relation
initialize it before using it- Specified by:
select
in interfaceBaseRelation
- Specified by:
select
in interfaceRelation
- Throws:
IOException
-
deSelect
Description copied from interface:Relation
release ressources because relation is currently not used- Specified by:
deSelect
in interfaceRelation
- Throws:
IOException
-
getPredicateSymbol
Description copied from interface:Relation
returns the predicate symbol for the relation- Specified by:
getPredicateSymbol
in interfaceRelation
- Returns:
-
getFilename
Description copied from interface:Relation
returns the file name for the relation- Specified by:
getFilename
in interfaceRelation
- Returns:
-
transactionRollback
Description copied from interface:Relation
rbort last changes- Specified by:
transactionRollback
in interfaceRelation
- Throws:
IOException
-
transactionCommit
Description copied from interface:Relation
commit last changes- Specified by:
transactionCommit
in interfaceRelation
- Throws:
IOException
-
lastModificationTime
public long lastModificationTime()Description copied from interface:Relation
last modification time- Specified by:
lastModificationTime
in interfaceBaseRelation
- Specified by:
lastModificationTime
in interfaceRelation
- Returns:
- time of last modification
-
addSubRelation
-
mayContainDuplicates
public boolean mayContainDuplicates()Description copied from interface:BaseRelation
Might there be duplicates?- Specified by:
mayContainDuplicates
in interfaceBaseRelation
- Returns:
- , might there be duplicates in relation
-
getNumberOfMatchingTuples
public long getNumberOfMatchingTuples(int[] arguments, long[] values) throws IOException, EDBException - Throws:
IOException
EDBException
-
isDirectEncoded
public boolean isDirectEncoded(int i) Description copied from interface:BaseRelation
are all values at argument i direct encoded- Specified by:
isDirectEncoded
in interfaceBaseRelation
- Parameters:
i
- , argument index- Returns:
-
isTemporary
public boolean isTemporary()Description copied from interface:BaseRelation
Is the relation temporary only?- Specified by:
isTemporary
in interfaceBaseRelation
- Returns:
- is the relation persistent
-
containsTuple
Description copied from interface:BaseRelation
Is tuple contained in relation?- Specified by:
containsTuple
in interfaceBaseRelation
- Parameters:
tuple
- to be checked- Returns:
- tuple is contained
- Throws:
IOException
-
containsTuple
Description copied from interface:BaseRelation
Is tuple contained in relation?- Specified by:
containsTuple
in interfaceBaseRelation
- Parameters:
tuple
- to be checked- Returns:
- tuple is contained
- Throws:
IOException
-
flush
public void flush()Description copied from interface:BaseRelation
Flush the relation. Must be called to finalize the relation correctly- Specified by:
flush
in interfaceBaseRelation
-
hasIndices
public boolean hasIndices() -
checkSanity
Description copied from interface:Relation
check the sanity of a relation- Specified by:
checkSanity
in interfaceRelation
shadow
- , check in shadow tree- Throws:
IOException
-
registerListener
Description copied from interface:BaseRelation
register a listener for adding, removing, modifying tuples- Specified by:
registerListener
in interfaceBaseRelation
-
getGrounds
public long[] getGrounds()Description copied from interface:Relation
get the grounds- Specified by:
getGrounds
in interfaceRelation
- Returns:
-
writeBinaryToBackup
Description copied from interface:Relation
write tuples to a binary backup file- Specified by:
writeBinaryToBackup
in interfaceRelation
- Throws:
IOException
-
readBinaryFromBackup
Description copied from interface:Relation
read tuples from a binary backup file- Specified by:
readBinaryFromBackup
in interfaceRelation
- Throws:
IOException
-
writeBinaryWithGrounds
Description copied from interface:Relation
write complete tuples to a binary file- Specified by:
writeBinaryWithGrounds
in interfaceRelation
- Throws:
IOException
-
getName
Description copied from interface:Relation
get a unique name of the relation -
union
Description copied from interface:BaseRelation
add all tuples of R to this- Specified by:
union
in interfaceBaseRelation
- Throws:
IOException
-
containsTuple
Description copied from interface:BaseRelation
Is tuple contained in relation?- Specified by:
containsTuple
in interfaceBaseRelation
- Parameters:
tuple
- to be checked- Returns:
- tuple is contained
- Throws:
IOException
-
hasDuplicates
public boolean hasDuplicates()Description copied from interface:BaseRelation
may relation contain duplicates?- Specified by:
hasDuplicates
in interfaceBaseRelation
- Returns:
-
transactionBegin
Description copied from interface:Relation
begin transaction- Specified by:
transactionBegin
in interfaceRelation
- Throws:
EDBException
IOException
-
getInternalArity
public int getInternalArity()Description copied from interface:BaseRelation
returns the internal arity of tuples- Specified by:
getInternalArity
in interfaceBaseRelation
- Returns:
-
elements
Description copied from interface:BaseRelation
returns an filteres enumerator for all tuples- Specified by:
elements
in interfaceBaseRelation
- Returns:
- returns enumerator for tuples
- Throws:
IOException
EDBException
-
getDirectEncodedType
public int getDirectEncodedType(int i) Description copied from interface:BaseRelation
get the type of the direct encoded argument- Specified by:
getDirectEncodedType
in interfaceBaseRelation
- Returns:
-