COdb¶
The OjectDatabase is a Graph-Database.
see also: https://en.wikipedia.org/wiki/Graph_database
It aids you in your endeavor to warp the world around you. A GraphDB has no actual data structure, it has a data management structure but without any force to drive you in a specific direction.
So you may build your own world in your DB as you like it. Learning in depth about its nature.
odb was testet with inhaling the whole IMDB with about 30Mio orignal data records using only 27GB of RAM. If you wish to test it for yourself (having 30GB free memory), build the odb an do th following:
cd ../raw-data
cat imdb.calls
# do all curl calls
gunzip *.gz
cd ../build
./7-read-imdb.test 20000000
It yields a statistic like this:
---------------- 12mio things
---------------- 15mio properties
---------------- 5mio reasons
---------------- 0 atoms
---------------- Search in (t)hings or ... or (s)ave&quit:
Now you can search the IMDB using a complete new perspective:
---------------- Search in (t)hings or (r)easons or (p)roperties ...: p
---------------- Search in Properties: .*:HU:.*
1:Carmencita - spanyol tánc:HU::imdbDisplay::0:
Property of: Carmencita
2:A bohóc és kutyái:HU::imdbDisplay::0:
Property of: Le clown et ses chiens
---------------- Search in (t)hings or (r)easons or (p)roperties ...: t
---------------- Search in Things: .*Star.*
Demolishing and Building Up the Star Theatre
Property: 1901
Property: 1:Building Up and Demolishing the Star Theatre:US::dvd::0:
Property: 2:Снос и возведение Звездного Театра:RU::::0:
Property: 3:Demolishing and Building Up the Star Theatre:::original::1:
Property: 4:Star Theatre:US:::copyright title:0:
Property: 5:A Star Theatre lebontása és felépítése:HU::imdbDisplay::0:
Property: 6:Demolishing and Building Up the Star Theatre:US::::0:
Property: Documentary
Property: Short
Property: class:movie
Property: short
Property: tt0000410
odb may support you to build a natural image of relevant links between CThing’s amongst each other using named, unidirectional CReason’s as well as appending things like CProperty’s (descriptive mini data elements), CAtom’s (true data fields) to CThing’s.
You may use the odb linked in your development environment.
Sample code
#include <iostream>
#include "odb.h"
int main()
{
auto oOdb = odb::COdb();
oOdb.print_json( std::cout );
std::cout << '\n';
}
-
class
COdb
: public Identifiable<COdb>¶ The database.
A Object Database itself is an Identifiable object. Enabeling multiple database instances in one application.
- Author
- Manfred Morgner
- Since
- 0.1.17
Public Functions
-
COdb
()¶ Creates a COdb, a database.
We only default construct the database, no copy construction no copy of the database at all. It is not known, what copying the database means.
-
COdb
(COdb const &src)¶ deleted: copy constructor
Copying a databse is not supported yet. We will support it as soon as we find out what it means.
-
COdb &
operator=
(COdb const &src)¶ deleted: Assignment operator
Here we are in the same situation as with copy construction
-
virtual
~COdb
()¶ Some cleanup.
If we wish to convience valgrind we are doing it right, we have to free all links to other objects before leaving the show.
-
void
clear
() Frees all objects.
Frees all known objects at last so far that freeing the object collections releases all memory, bound to them. So valgrind will find nonode left on the table.
-
PNode
MakeNode
(std::string const &crsName = "")¶ Creates a PNode.
Creates a shared_ptr with a new CNode named as given in the call. If no name is given, the name will be the class default
- Parameters
crsName
: The name for the CNode
-
PNode
LoadNode
(size_t nId, std::string const &crsName = "")¶ Creates a PNode with predefined ID.
Creates a shared_ptr with a new CNode named as given in the call. If no name is given, the name will be the class default
- Parameters
nId
: The predefined ID if loading given sets into odbcrsName
: The name for the CNode
-
PProperty
MakeProperty
(std::string const &crsName = "")¶ Creates a PProperty.
Creates a shared_ptr with a new CProperty named as given in the call. If no name is given, the name will be the class default
- Parameters
crsName
: The name for the CProperty
-
PProperty
LoadProperty
(size_t nId, std::string const &crsName = "")¶ Creates a PProperty with predefined ID.
Creates a shared_ptr with a new CProperty named as given in the call. If no name is given, the name will be the class default
- Parameters
nId
: The predefined ID if loading given sets into odbcrsName
: The name for the CProperty
-
PAtom
MakeAtom
(int data, std::string const &crsName = "", std::string const &crsPrefix = "", std::string const &crsSuffix = "", std::string const &crsFormat = "")¶ Creates a PAtom.
Creates a shared_ptr with a new CAtom named as given in the call. If no name is given, the name will be the class default
The data type of the data element in CAtom follows the input data type. It can be if any primitive type or most of the simple containers, like string or vector.
CAtom further on manages the life time of the data element. It’s a unique_ptr
-
PAtom
LoadAtom
(size_t nId, int data, std::string const &crsName = "", std::string const &crsPrefix = "", std::string const &crsSuffix = "", std::string const &crsFormat = "")¶ Creates a PAtom with predefined ID.
Creates a shared_ptr with a new CAtom named as given in the call. If no name is given, the name will be the class default
The data type of the data element in CAtom follows the input data type. It can be if any primitive type or most of the simple containers, like string or vector.
CAtom further on manages the life time of the data element. It’s a unique_ptr
-
PReason
MakeReason
(std::string const &crsName = "")¶ Creates a PReason.
Creates a shared_ptr with a new CReason named as given in the call. If no name is given, the name will be the class default
- Parameters
crsName
: The name for the CReason
-
PReason
LoadReason
(size_t nId, std::string const &crsName = "")¶ Creates a PReason with predefined ID.
Creates a shared_ptr with a new CReason named as given in the call. If no name is given, the name will be the class default
- Parameters
nId
: The predefined ID if loading given sets into odbcrsName
: The name for the CReason
-
PStrand
MakeStrand
(std::string const &crsName = "")¶ Creates a PStrand.
Creates a shared_ptr with a new CStrand named as given in the call. If no name is given, the name will be the class default
- Parameters
crsName
: The name for the CStrand
-
void
print
() const¶ Print out the database (Informative format)
-
void
print
(CAtoms const &crContainer) const¶ Print out container of CAtom objects.
- Parameters
crContainer
: The forward iterable container, containing PAtom’s
-
template <typename T>
voidprint
(CT<T> const &crContainer) const¶ Print out container of CNode’s.
- Parameters
crContainer
: The forward iterable container, containing all CNode instances
-
auto
Escape
(std::string const &crsInput)¶ Replaces 2 with ” and \ with .
- Parameters
crsInput
: The string to be escaped
-
void
print_json
(CNodes const &crContainer, std::ostream &ros)¶ Dump all CNodes in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CNode instancesros
: The output destination
-
void
print_json_stream
(CNodes const &crContainer, std::ostream &ros)¶ Dump all CNodes in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CNode instancesros
: The output destination
-
void
print_json
(CProperties const &crContainer, std::ostream &ros)¶ Dump all CProperty’s in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CProperty instancesros
: The output destination
-
void
print_json_stream
(CProperties const &crContainer, std::ostream &ros)¶ Dump all CProperty’s in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CProperty instancesros
: The output destination
-
void
print_json
(CAtoms const &crContainer, std::ostream &ros)¶ Dump all CAtoms in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CAtom instancesros
: The output destination
-
void
print_json_stream
(CAtoms const &crContainer, std::ostream &ros)¶ Dump all CAtoms in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CAtom instancesros
: The output destination
-
void
print_json
(CReasons const &crContainer, std::ostream &ros)¶ Dump all CReasons in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CReason instancesros
: The output destination
-
void
print_json_stream
(CReasons const &crContainer, std::ostream &ros)¶ Dump all CReasons in Sub-JSON format.
- Parameters
crContainer
: The forward iterable container, containing all CReason instancesros
: The output destination
-
void
print_json
(std::ostream &ros)¶ Dump the hole database in JSON format.
see also: JSON validator+converter: https://jsonformatter.org/
- Sample: Link Atoms to Nodes and Node to Node and dump it as JSON
#include <iostream> #include "odb.h" #include "atom.h" #include "node.h" int main() { auto oOdb = odb::COdb(); auto pNode1 = oOdb.MakeNode("Ulrich"); auto pNode2 = oOdb.MakeNode("Fred"); auto pAtom1 = oOdb.MakeAtom("Leader", "Role"); auto pAtom2 = oOdb.MakeAtom("Member", "Role"); auto pReason = oOdb.MakeReason("pays"); pNode1->Append(pAtom1); pNode2->Append(pAtom2); pNode1->Link(pNode2, pReason); oOdb.print_json(std::cout); }
Output
{ "Object Database Dump": { "Sizes": [ {"P": 0},{"A": 2},{"R": 1},{"T": 2} ], "Properties": [ ], "Atoms": [ { "id": 0, "data": "Leader" }, { "id": 1, "data": "Member" } ], "Reasons": [ { "id": 0, "name": "pays" } ], "Nodes": [ { "id": 0, "name": "Ulrich", "properties": [ ], "atoms": [ {"id": 0} ], "links": [ {"node-id": 1, "reason-id": 0} ] }, { "id": 1, "name": "Fred", "properties": [ ], "atoms": [ {"id": 1} ], "links": [ ] } ] } }
- Parameters
ros
: The output destination
-
void
print_json_stream
(std::ostream &ros)¶ Dump the hole database in JSON format.
- Parameters
ros
: The output destination
-
void
SaveDB
(std::string const &crsFilename)¶ Saves an odb json file.
- Parameters
crsFilename
:
-
bool
LoadDB
(std::string const &crsFilename)¶ Loads an odb json file.
- Parameters
crsFilename
:
-
PNode
FindOrLoadNodeById
(size_t const nId, std::string const &crsName = "")¶ Has to return a node with specified ID, if it does not exists, it is to make.
- Parameters
nId
: The id of the nodecrsName
: The name of the node if it has to be created
-
ONode
FindNodeByProperty
(std::string const &crsProperty)¶ Finds PNode with a named Property only if it’s unique.
- Parameters
crsProperty
: The name for the CProperty
-
CNodes
FindNodesByProperty
(std::string const &crsProperty)¶ Finds PNode with a named Property only if it’s one.
- Parameters
crsProperty
: The name for the CProperty
-
CNodes
FindNodesByProperty
(std::regex const &crsRegex)¶ Finds PNode with a named Property only if it’s one.
- Parameters
crsRegex
: The name for the CProperty
-
PNode
FindOrMakeNodeByProperty
(std::string const &crsNode, std::string const &crsProperty)¶ Finds or creates a PNode with a named Property, which also may be created and assigned.
-
MLinkets
FindNodeLinkingSameNode
(size_t const cnIdNodeA, size_t const cnIdNodeB)¶ Returns the nodes linked by the same reason as the given Nodes.
- Parameters
cnIdNodeA
: Id of one NodecnIdNodeB
: Id of the other one
-
PNode
FindOrMakeNode
(std::string const &crsNode)¶ Has to return a node, if it does not exists, it is to make.
- Parameters
crsNode
: The name of the Node
-
PProperty
FindOrMakeProperty
(std::string const &crsProperty)¶ Has to return a property, if it does not exists, it is to make.
- Parameters
crsProperty
: The name of the Property
-
PReason
FindOrMakeReason
(std::string const &crsReason)¶ Has to return a Reason, if it does not exists, it is to make.
- Parameters
crsReason
: The name of the Reason
-
PAtom
FindOrMakeAtom
(std::string const &crsAtom)¶ Has to return an Atom, if it does not exists, it is to make.
- Parameters
crsAtom
: The name of the Atom
-
bool
AppendProperty2Node
(size_t nProperty, size_t nNode)¶ todo: optimize / Appends a Property to a Node by given index value
-
bool
AppendProperty2Node
(std::string const &crsProperty, std::string const &crsNode)¶ todo: optimize / Appends a Property to a Node by given names
-
bool
AppendProperty2Node
(std::string const &crsProperty, bool const bForce, std::string const &crsNode)¶ todo: optimize / Appends a Property to a Node by given names
-
bool
AppendAtom2Node
(size_t nNode, size_t nAtom)¶ todo: optimize / Appends an Atom to a Node by given index value
-
bool
LinkNode2Node
(size_t nNodeFrom, size_t nReason, size_t nNodeTo)¶ todo: optimize / Links a Node to a Node for a Reason by given index value
-
bool
LinkNode2Node
(std::string const &crsNodeFrom, std::string const &crsReason, std::string const &crsNodeTo)¶ todo: optimize / Links a Node to a Node for a Reason by given names
-
template <typename T>
std::optional<PT<T>>Find
(CT<T> const &croContainer, size_t nId)¶ Finds the T with ID nId.
- Template Parameters
T
: the type of the filtered objects
- Parameters
croContainer
: The container to be filterednId
: The ID of the T
-
auto
FindNode
(size_t nId)¶ API Adapter.
-
auto
FindNodes
(std::string const &crsName)¶ API Adapter.
-
auto
FindNodes
(std::regex const &crsRegex)¶ API Adapter.
-
auto
FindProperty
(size_t nId)¶ API Adapter.
-
auto
FindProperties
(std::string const &crsName)¶ API Adapter.
-
auto
FindProperties
(std::regex const &crsRegex)¶ API Adapter.
-
auto
FindReason
(size_t nId)¶ API Adapter.
-
auto
FindReasons
(std::string const &crsName)¶ API Adapter.
-
auto
FindReasons
(std::regex const &crsRegex)¶ API Adapter.
-
auto
FindAtom
(size_t nId)¶ API Adapter.
-
auto
FindAtoms
(std::string const &crsName)¶ API Adapter.
-
auto
FindAtoms
(std::regex const &crsRegex)¶ API Adapter.
-
auto
FindUnUsedNodes
()¶ find all nodes not linked with anynode
-
auto
FindUnUsedReasons
()¶ find all reasons not used with anynode
-
auto
FindUnUsedProperties
()¶ find all properties not linked to anynode
-
auto
FindUnUsedAtoms
()¶ find all atoms not linked to anynode
-
auto const &
Nodes
() const Access function to call then container of CNode’s.
-
auto const &
Properties
() const Access function to call then container of CProperties.
-
auto const &
Atoms
() const Access function to call then container of CAtom’s.