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
ConstructorsConstructorDescriptiona 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 TypeMethodDescriptionvoidaddRelation(String pname, Relation T) add a whole relation R to a predicatebooleanaddTuple(String predicate, TupleBuffer tuple) add tuple to edb.voidaddTupleToIndices(String predicate, long[] codes, Object[] terms) add tuple to edb indicesvoidcreate a backup for the extensional databasevoidbackupOld(String backupfile, SymbolTable symbolTable) Deprecated.voidbulkExport(InterruptFlag interrupt, List<Filter> filters, String resultdirectory, SymbolTable symbolTable) Bulk export of facts for predicate symbols to raw files in result directoryvoidbulkLoadFiles(List<File>[] files, Map<String, Long> counts, Map<String, String> indexToPredicates, String tempdir, SymbolTable symbols) booleanchecks sanity of all bplus treesvoidclear()remove all factsvoidclear join caches of all relationsvoidclose()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 hierarchyvoiddelete()delete all facts and release all filesvoidexportNQuads(List<String> predicates, Writer writer, SymbolTable symbolTable, String iri) export of facts for predicate symbols to N-Quads filevoidexportOOLogic(InterruptFlag interrupt, List<Filter> filters, Writer writer, SymbolTable symbolTable) export of facts for predicate symbols to OO-logic filevoidexportOOLogic(InterruptFlag interrupt, List<Filter> filters, Writer writer, SymbolTable symbolTable, String module) export of facts for predicate symbols to OO-logic file.voidexportOOLogic(InterruptFlag interrupt, List<Filter> filters, String resultFile, SymbolTable symbolTable) export of facts for predicate symbols to OO-logic filevoidexportOOLogic(InterruptFlag interrupt, List<Filter> filters, String resultFile, SymbolTable symbolTable, String module) export of facts for predicate symbols to OO-logic file.voidflush()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 informationvoidtransaction begin for indicesvoidtransaction commit for indicesvoidtransaction rollback for indicesbooleanisEmpty()Is the extensional database empty?booleanIs the relation for predicate empty?booleanIs it a persistent extensional database?voidloadFactsFiles(List<String> files, boolean deleteold, SymbolTable symbolTable, ExternalDataTypeProvider datatypes, BuiltinProvider builtins) reads facts files in ordinary predicate formvoidloadFiles(List<String> files, SymbolTable symbols, ExternalDataTypeProvider dataTypes) load all kind of files (besides OO-logic files)voidrecreateIndices(SymbolTable symbols) recreate indices for propertiesvoidremoveRelation(String predicate) removes all relations for predicate pbooleanremoveTuple(String predicate, TupleBuffer tuple) remove a tuple from edb.voidremoveTupleFromIndices(String predicate, long[] codes, Object[] terms) remove tuple from edb indicesvoidreOpen()reopens a closed extensional databasevoidrestore the edb from a backup file.voidrestore(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.voidrestoreOld(String edbdir, String workdir, String logdir, String backupfile, ExternalDataTypeProvider datatypes, int maxTermLength) restore the edb from a backup file.voidload all mixed relations into RAM.voidStore 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:
IOExceptionSemReasonerException
-
ExtensionalDB
public ExtensionalDB(List<Literal> partitions, Configuration config) throws IOException, SemReasonerException - Throws:
IOExceptionSemReasonerException
-
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:
IOExceptionSemReasonerException
-
-
Method Details
-
selectMixedRelations
load all mixed relations into RAM.
Swap out all bplus nodes afterwards.- Throws:
EDBExceptionIOException
-
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:
IOExceptionSemReasonerException
-
createIndex
public InvertedIndices createIndex(SymbolTable symbols, long propCode) throws IOException, SemReasonerException create indices for property- Parameters:
symbols-- Throws:
IOExceptionSemReasonerException
-
createSchemas
Create a cache for the hierarchy- Throws:
IOExceptionSemReasonerException
-
getSchemas
get schema information- Returns:
-
checkSanity
checks sanity of all bplus trees- Returns:
- Throws:
IOExceptionEDBException
-
reOpen
reopens a closed extensional database- Throws:
IOExceptionSemReasonerException
-
close
Closes the extensional database. Must be called at the end to finalize the db correctly- Specified by:
closein interfaceAutoCloseable- Specified by:
closein 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:
EDBExceptionIOException
-
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:
EDBExceptionIOException
-
removeRelation
removes all relations for predicate p- Parameters:
predicate- , full qualified predicate name- Throws:
EDBExceptionIOException
-
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:
IOExceptionSemReasonerException
-
isEmpty
Is the extensional database empty?- Returns:
- Throws:
EDBExceptionIOException- 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:
IOExceptionEDBException
-
delete
delete all facts and release all files- Throws:
EDBException
-
clearJoinCaches
clear join caches of all relations- Throws:
IOExceptionEDBException
-
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:
IOExceptionDatatypeConfigurationExceptionSemReasonerException
-
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:
IOExceptionInterruptedExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionSemReasonerException
-
backup
public void backup(String edbDir, String backupfile) throws SemReasonerException, IOException, EDBException create a backup for the extensional database- Parameters:
backupfile-- Throws:
IOExceptionEDBExceptionSemReasonerExceptionEDBException
-
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:
IOExceptionEDBExceptionSemReasonerExceptionEDBException
-
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:
InterruptedExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionFileNotFoundExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionFileNotFoundExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionFileNotFoundExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionFileNotFoundExceptionSemReasonerException
-
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:
InterruptedExceptionIOExceptionFileNotFoundExceptionSemReasonerException
-
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:
IOExceptionEDBException
-
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:
IOExceptionEDBException
-
addTuple
public boolean addTuple(String predicate, TupleBuffer tuple) throws IOException, SemReasonerException add tuple to edb.
use partitioning- Parameters:
tuple-- Throws:
IOExceptionSemReasonerException
-
removeTuple
public boolean removeTuple(String predicate, TupleBuffer tuple) throws IOException, SemReasonerException remove a tuple from edb.
use partitioning- Parameters:
tuple-- Throws:
IOExceptionSemReasonerException
-