Package com.semedy.reasoner.api.edb
Class ExtensionalDB
java.lang.Object
com.semedy.reasoner.api.edb.ExtensionalDB
- All Implemented Interfaces:
Closeable
,AutoCloseable
Extensional database is a container for all facts.
It contains a list of edb tuples for each predicate containing all facts for that predicate.
edb tuples may be scanned, index structures may be generated etc.
It contains a list of edb tuples for each predicate containing all facts for that predicate.
edb tuples may be scanned, index structures may be generated etc.
-
Constructor Summary
ConstructorDescriptiona no name main memory edb without transactionsExtensionalDB
(String edbdir, String tempdir, String logDir, Configuration.StorageType storage, Set<String> excludedPredicates, long maxtermstoload, boolean compress, List<Literal> partition, boolean transactionLog, String[] indexedprops, Configuration config) ExtensionalDB
(List<Literal> partitions, Configuration config) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRelation
(String pname, Relation T) add a whole relation R to a predicateboolean
addTuple
(String predicate, TupleBuffer tuple) add tuple to edb.void
addTupleToIndices
(String predicate, long[] codes, Object[] terms) add tuple to edb indicesvoid
create a backup for the extensional databasevoid
backupOld
(String backupfile, SymbolTable symbolTable) Deprecated.void
bulkExport
(InterruptFlag interrupt, List<Filter> filters, String resultdirectory, SymbolTable symbolTable) Bulk export of facts for predicate symbols to raw files in result directoryvoid
bulkLoadFiles
(List<File>[] files, Map<String, Long> counts, Map<String, String> indexToPredicates, String tempdir, SymbolTable symbols) boolean
checks sanity of all bplus treesvoid
clear()
remove all factsvoid
clear join caches of all relationsvoid
close()
Closes the extensional database.createIndex
(SymbolTable symbols, long propCode) create indices for propertycreateRelation
(String predicate) Create a relation for predicate p.createRelation
(String predicate, int number) Create a relation for predicate p.createSchemas
(SymbolTable symbols) Create a cache for the hierarchyvoid
delete()
delete all facts and release all filesvoid
exportNQuads
(List<String> predicates, Writer writer, SymbolTable symbolTable, String iri) export of facts for predicate symbols to N-Quads filevoid
exportOOLogic
(InterruptFlag interrupt, List<Filter> filters, Writer writer, SymbolTable symbolTable) export of facts for predicate symbols to OO-logic filevoid
exportOOLogic
(InterruptFlag interrupt, List<Filter> filters, Writer writer, SymbolTable symbolTable, String module) export of facts for predicate symbols to OO-logic file.void
exportOOLogic
(InterruptFlag interrupt, List<Filter> filters, String resultFile, SymbolTable symbolTable) export of facts for predicate symbols to OO-logic filevoid
exportOOLogic
(InterruptFlag interrupt, List<Filter> filters, String resultFile, SymbolTable symbolTable, String module) export of facts for predicate symbols to OO-logic file.void
flush()
get all inverted indicesgetInvertedIndices
(String property) get inverted indicesget loaders for different file formats, like json, nquads, csvreturns a list of all predicates in the extensional databasegetRelations
(String predicate) return a list of all relations for predicate p (can be more than one)get schema informationvoid
transaction begin for indicesvoid
transaction commit for indicesvoid
transaction rollback for indicesboolean
isEmpty()
Is the extensional database empty?boolean
Is the relation for predicate empty?boolean
Is it a persistent extensional database?void
loadFactsFiles
(List<String> files, boolean deleteold, SymbolTable symbolTable, ExternalDataTypeProvider datatypes, BuiltinProvider builtins) reads facts files in ordinary predicate formvoid
loadFiles
(List<String> files, SymbolTable symbols, ExternalDataTypeProvider dataTypes) load all kind of files (besides OO-logic files)void
recreateIndices
(SymbolTable symbols) recreate indices for propertiesvoid
removeRelation
(String predicate) removes all relations for predicate pboolean
removeTuple
(String predicate, TupleBuffer tuple) remove a tuple from edb.void
removeTupleFromIndices
(String predicate, long[] codes, Object[] terms) remove tuple from edb indicesvoid
reOpen()
reopens a closed extensional databasevoid
restore the edb from a backup file.void
restore
(List<String> predicatesToRestore, boolean restoreSymbolTable, String edbdir, String workdir, String logDir, String backupfile, ExternalDataTypeProvider datatypes, int maxTermLength) restore single predicates and/or symbol table from a backup file.void
restoreOld
(String edbdir, String workdir, String logdir, String backupfile, ExternalDataTypeProvider datatypes, int maxTermLength) restore the edb from a backup file.void
load all mixed relations into RAM.void
Store factory for creating stores inside extensional db
This allows for instance to keep some relations in main memory and other ones as persistent relations
-
Constructor Details
-
ExtensionalDB
a no name main memory edb without transactions- Throws:
IOException
SemReasonerException
-
ExtensionalDB
public ExtensionalDB(List<Literal> partitions, Configuration config) throws IOException, SemReasonerException - Throws:
IOException
SemReasonerException
-
ExtensionalDB
public ExtensionalDB(String edbdir, String tempdir, String logDir, Configuration.StorageType storage, Set<String> excludedPredicates, long maxtermstoload, boolean compress, List<Literal> partition, boolean transactionLog, String[] indexedprops, Configuration config) throws IOException, SemReasonerException - Throws:
IOException
SemReasonerException
-
-
Method Details
-
selectMixedRelations
load all mixed relations into RAM.
Swap out all bplus nodes afterwards.- Throws:
EDBException
IOException
-
getInvertedIndices
get all inverted indices- Returns:
-
getLoaderProvider
get loaders for different file formats, like json, nquads, csv- Returns:
-
getInvertedIndices
get inverted indices- Returns:
-
recreateIndices
recreate indices for properties- Parameters:
symbols
-- Throws:
IOException
SemReasonerException
-
createIndex
public InvertedIndices createIndex(SymbolTable symbols, long propCode) throws IOException, SemReasonerException create indices for property- Parameters:
symbols
-- Throws:
IOException
SemReasonerException
-
createSchemas
Create a cache for the hierarchy- Throws:
IOException
SemReasonerException
-
getSchemas
get schema information- Returns:
-
checkSanity
checks sanity of all bplus trees- Returns:
- Throws:
IOException
EDBException
-
reOpen
reopens a closed extensional database- Throws:
IOException
SemReasonerException
-
close
Closes the extensional database. Must be called at the end to finalize the db correctly- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
flush
- Throws:
IOException
-
getPredicates
returns a list of all predicates in the extensional database -
createRelation
Create a relation for predicate p.
A predicate is given by the name and the arity: name|arity
Example: p|2- Parameters:
predicate
- , full qualified predicate name- Returns:
- created relation
- Throws:
EDBException
IOException
-
createRelation
Create a relation for predicate p.
A predicate is given by the name and the arity: name|arity
Example: p|2- Parameters:
predicate
- , full qualified predicate name- Returns:
- created relation
- Throws:
EDBException
IOException
-
removeRelation
removes all relations for predicate p- Parameters:
predicate
- , full qualified predicate name- Throws:
EDBException
IOException
-
getRelations
return a list of all relations for predicate p (can be more than one)- Parameters:
predicate
- , full qualified predicate name- Returns:
-
addRelation
add a whole relation R to a predicate- Parameters:
pname
- , predicate the relation is added toT
- relation to be added- Throws:
IOException
SemReasonerException
-
isEmpty
Is the extensional database empty?- Returns:
- Throws:
EDBException
IOException
- See Also:
-
isEmpty
Is the relation for predicate empty?- Returns:
- Throws:
EDBException
- See Also:
-
isPersistent
public boolean isPersistent()Is it a persistent extensional database?- Returns:
- See Also:
-
clear
remove all facts- Throws:
IOException
EDBException
-
delete
delete all facts and release all files- Throws:
EDBException
-
clearJoinCaches
clear join caches of all relations- Throws:
IOException
EDBException
-
bulkLoadFiles
public void bulkLoadFiles(List<File>[] files, Map<String, Long> counts, Map<String, throws IOException, SemReasonerException, InterruptedExceptionString> indexToPredicates, String tempdir, SymbolTable symbols) -
loadFactsFiles
public void loadFactsFiles(List<String> files, boolean deleteold, SymbolTable symbolTable, ExternalDataTypeProvider datatypes, BuiltinProvider builtins) throws IOException, DatatypeConfigurationException, SemReasonerException reads facts files in ordinary predicate form- Parameters:
files
- , files to be loadeddeleteold
- , delete old factssymbolTable
- , symbol tabledatatypes
- , external data typesbuiltins
- , the available builtins- Throws:
IOException
DatatypeConfigurationException
SemReasonerException
-
loadFiles
public void loadFiles(List<String> files, SymbolTable symbols, ExternalDataTypeProvider dataTypes) throws IOException, InterruptedException, SemReasonerException load all kind of files (besides OO-logic files)- Parameters:
files
-symbols
-dataTypes
-- Throws:
IOException
InterruptedException
SemReasonerException
-
restoreOld
public void restoreOld(String edbdir, String workdir, String logdir, String backupfile, ExternalDataTypeProvider datatypes, int maxTermLength) throws InterruptedException, IOException, SemReasonerException restore the edb from a backup file.
Clear the edb directory first.
Caution! the current edb may be damaged
Caution! also the backup may be damaged- Parameters:
edbdir
- , the directory for the edbworkdir
- , a directory for temporary fileslogdir
- , a directory for logging filesbackupfile
- , the input file (backupfile)datatypes
- , the external data typesmaxTermLength
- , the max term length to distinguish terms- Throws:
InterruptedException
IOException
SemReasonerException
-
restore
public void restore(String backupfile, String edbDir) throws InterruptedException, IOException, SemReasonerException restore the edb from a backup file.
Clear the edb directory first.
Caution! the current edb may be damaged
Caution! also the backup may be damaged- Parameters:
edbDir
- , the directory for the edbbackupfile
- , the input file (backupfile)- Throws:
InterruptedException
IOException
SemReasonerException
-
restore
public void restore(List<String> predicatesToRestore, boolean restoreSymbolTable, String edbdir, String workdir, String logDir, String backupfile, ExternalDataTypeProvider datatypes, int maxTermLength) throws InterruptedException, IOException, SemReasonerException restore single predicates and/or symbol table from a backup file.
Delete the predicate files and/or symbol table in edb first
Caution! the current edb may be damaged
Caution! also the backup may be damaged- Parameters:
edbdir
- , the directory for the edbworkdir
- , a directory for temporary filesbackupfile
- , the input file (backupfile)- Throws:
InterruptedException
IOException
SemReasonerException
-
backup
public void backup(String edbDir, String backupfile) throws SemReasonerException, IOException, EDBException create a backup for the extensional database- Parameters:
backupfile
-- Throws:
IOException
EDBException
SemReasonerException
EDBException
-
backupOld
@Deprecated public void backupOld(String backupfile, SymbolTable symbolTable) throws SemReasonerException, IOException, EDBException Deprecated.create a backup for the extensional database- Parameters:
backupfile
-symbolTable
-- Throws:
IOException
EDBException
SemReasonerException
EDBException
-
bulkExport
public void bulkExport(InterruptFlag interrupt, List<Filter> filters, String resultdirectory, SymbolTable symbolTable) throws InterruptedException, SemReasonerException Bulk export of facts for predicate symbols to raw files in result directory- Parameters:
interrupt
- , flag to support interrupting the export processfilters
- , predicates together with filters for exportresultdirectory
-symbolTable
-- Throws:
InterruptedException
SemReasonerException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, List<Filter> filters, String resultFile, SymbolTable symbolTable, String module) throws InterruptedException, IOException, SemReasonerException export of facts for predicate symbols to OO-logic file.
Fill into a module, if module is not yet given- Parameters:
interrupt
- , flag to interrupt exportfilters
- , the predicates to be exported, e.g. value|3, member|2 together with filtersresultFile
-symbolTable
-module
-- Throws:
InterruptedException
IOException
FileNotFoundException
SemReasonerException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, List<Filter> filters, Writer writer, SymbolTable symbolTable, String module) throws InterruptedException, IOException, SemReasonerException export of facts for predicate symbols to OO-logic file.
Fill into a module, if module is not yet given- Parameters:
interrupt
- , flag to interrupt exportfilters
- , the predicates to be exported, e.g. value|3, member|2 together with filterswriter
- , the writer to write tosymbolTable
- , the symbolsmodule
- , the module to added, may be null- Throws:
InterruptedException
IOException
FileNotFoundException
SemReasonerException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, List<Filter> filters, String resultFile, SymbolTable symbolTable) throws InterruptedException, IOException, SemReasonerException export of facts for predicate symbols to OO-logic file- Parameters:
interrupt
- , flag to interrupt exportfilters
- , the predicates to be exported, e.g. value|3, member|2 together with filtersresultFile
-symbolTable
-- Throws:
InterruptedException
IOException
FileNotFoundException
SemReasonerException
-
exportOOLogic
public void exportOOLogic(InterruptFlag interrupt, List<Filter> filters, Writer writer, SymbolTable symbolTable) throws InterruptedException, IOException, SemReasonerException export of facts for predicate symbols to OO-logic file- Parameters:
interrupt
- , flag to interrupt exportfilters
- , the predicates to be exported, e.g. value|3, member|2 together with filterswriter
-symbolTable
-- Throws:
InterruptedException
IOException
FileNotFoundException
SemReasonerException
-
exportNQuads
public void exportNQuads(List<String> predicates, Writer writer, SymbolTable symbolTable, String iri) throws InterruptedException, IOException, SemReasonerException export of facts for predicate symbols to N-Quads file- Parameters:
predicates
-writer
-symbolTable
-iri
- , an iri if there is none- Throws:
InterruptedException
IOException
FileNotFoundException
SemReasonerException
-
setRelationFactory
Store factory for creating stores inside extensional db
This allows for instance to keep some relations in main memory and other ones as persistent relations- Parameters:
f
-
-
indexTransactionBegin
transaction begin for indices- Throws:
IOException
-
indexTransactionCommit
transaction commit for indices- Throws:
IOException
-
indexTransactionRollback
transaction rollback for indices- Throws:
IOException
-
addTupleToIndices
public void addTupleToIndices(String predicate, long[] codes, Object[] terms) throws EDBException, IOException add tuple to edb indices- Parameters:
codes
-terms
- unencoded terms in tuple- Throws:
IOException
EDBException
-
removeTupleFromIndices
public void removeTupleFromIndices(String predicate, long[] codes, Object[] terms) throws EDBException, IOException remove tuple from edb indices- Parameters:
codes
-terms
- unencoded terms in tuple- Throws:
IOException
EDBException
-
addTuple
public boolean addTuple(String predicate, TupleBuffer tuple) throws IOException, SemReasonerException add tuple to edb.
use partitioning- Parameters:
tuple
-- Throws:
IOException
SemReasonerException
-
removeTuple
public boolean removeTuple(String predicate, TupleBuffer tuple) throws IOException, SemReasonerException remove a tuple from edb.
use partitioning- Parameters:
tuple
-- Throws:
IOException
SemReasonerException
-