Skip to content
Snippets Groups Projects
Commit 0ad0ce62 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

MAINT: revert functional renaming in high level api

parent 2f56606d
Branches
No related tags found
No related merge requests found
Pipeline #41406 failed
This commit is part of merge request !112. Comments created here will be created in the context of that merge request.
This diff is collapsed.
* High Level API * High Level API
In addition to the old standard pylib API, new versions of pylib ship with a high level API In addition to the old standard pylib API, new versions of pylib ship with a high level API
that facilitates usage of LinkAhead entities within data analysis scripts. In a nutshell that that facilitates usage of CaosDB entities within data analysis scripts. In a nutshell that
API exposes all properties of LinkAhead Records as standard python attributes making their API exposes all properties of CaosDB Records as standard python attributes making their
access easier. access easier.
Or to spell it out directly in Python: Or to spell it out directly in Python:
#+BEGIN_SRC python #+BEGIN_SRC python
import linkahead as db import caosdb as db
# Old API: # Old API:
r = db.Record() r = db.Record()
r.add_parent("Experiment") r.add_parent("Experiment")
...@@ -16,7 +16,7 @@ Or to spell it out directly in Python: ...@@ -16,7 +16,7 @@ Or to spell it out directly in Python:
r.get_property("alpha").value = 25 # setting properties (old api) r.get_property("alpha").value = 25 # setting properties (old api)
print(r.get_property("alpha").value + 25) # getting properties (old api) print(r.get_property("alpha").value + 25) # getting properties (old api)
from linkahead.high_level_api import convert_to_python_entity from caosdb.high_level_api import convert_to_python_entity
obj = convert_to_python_object(r) # create a high level entity obj = convert_to_python_object(r) # create a high level entity
obj.r = 25 # setting properties (new api) obj.r = 25 # setting properties (new api)
print(obj.r + 25) # getting properties (new api) print(obj.r + 25) # getting properties (new api)
...@@ -27,7 +27,7 @@ Or to spell it out directly in Python: ...@@ -27,7 +27,7 @@ Or to spell it out directly in Python:
** Quickstart ** Quickstart
The module, needed for the high level API is called: The module, needed for the high level API is called:
~linkahead.high_level_api~ ~caosdb.high_level_api~
There are two functions converting entities between the two representation (old API and new API): There are two functions converting entities between the two representation (old API and new API):
- ~convert_to_python_object~: Convert entities from **old** into **new** representation. - ~convert_to_python_object~: Convert entities from **old** into **new** representation.
...@@ -38,11 +38,11 @@ Furthermore there are a few utility functions which expose very practical shorth ...@@ -38,11 +38,11 @@ Furthermore there are a few utility functions which expose very practical shorth
- ~create_record~: Create a new high level entity using the name of a record type and a list of key value pairs as properties. - ~create_record~: Create a new high level entity using the name of a record type and a list of key value pairs as properties.
- ~load_external_record~: Retrieve a record with a specific name and return it as high level entity. - ~load_external_record~: Retrieve a record with a specific name and return it as high level entity.
- ~create_entity_container~: Convert a high level entity into a standard entity including all sub entities. - ~create_entity_container~: Convert a high level entity into a standard entity including all sub entities.
- ~query~: Do a LinkAhead query and return the result as a container of high level objects. - ~query~: Do a CaosDB query and return the result as a container of high level objects.
So as a first example, you could retrieve any record from LinkAhead and use it using its high level representation: So as a first example, you could retrieve any record from CaosDB and use it using its high level representation:
#+BEGIN_SRC python #+BEGIN_SRC python
from linkahead.high_level_api import query from caosdb.high_level_api import query
res = query("FIND Record Experiment") res = query("FIND Record Experiment")
experiment = res[0] experiment = res[0]
...@@ -60,7 +60,7 @@ like the list of output files "output", become immediately available. ...@@ -60,7 +60,7 @@ like the list of output files "output", become immediately available.
**Note** that for the old API you were supposed to run the following series of commands **Note** that for the old API you were supposed to run the following series of commands
to achieve the same result: to achieve the same result:
#+BEGIN_SRC python #+BEGIN_SRC python
import linkahead as db import caosdb as db
res = db.execute_query("FIND Record Experiment") res = db.execute_query("FIND Record Experiment")
output = res.get_property("output") output = res.get_property("output")
...@@ -69,9 +69,9 @@ to achieve the same result: ...@@ -69,9 +69,9 @@ to achieve the same result:
#+END_SRC #+END_SRC
Resolving subproperties makes use of the "resolve_reference" function provided by the high level Resolving subproperties makes use of the "resolve_reference" function provided by the high level
entity class (~LinkAheadPythonEntity~), with the following parameters: entity class (~CaosDBPythonEntity~), with the following parameters:
- ~deep~: Whether to use recursive retrieval - ~deep~: Whether to use recursive retrieval
- ~references~: Whether to use the supplied db.Container to resolve references. This allows offline usage. Set it to None if you want to automatically retrieve entities from the current LinkAhead connection. - ~references~: Whether to use the supplied db.Container to resolve references. This allows offline usage. Set it to None if you want to automatically retrieve entities from the current CaosDB connection.
- ~visited~: Needed for recursion, set this to None. - ~visited~: Needed for recursion, set this to None.
Objects in the high level representation can be serialized to a simple yaml form using the function Objects in the high level representation can be serialized to a simple yaml form using the function
...@@ -94,26 +94,26 @@ print(str(obj)) ...@@ -94,26 +94,26 @@ print(str(obj))
As described in the section [[Quickstart]] the two functions ~convert_to_python_object~ and ~convert_to_entity~ convert As described in the section [[Quickstart]] the two functions ~convert_to_python_object~ and ~convert_to_entity~ convert
entities beetween the high level and the standard representation. entities beetween the high level and the standard representation.
The high level entities are represented using the following classes from the module ~linkahead.high_level_api~: The high level entities are represented using the following classes from the module ~caosdb.high_level_api~:
- ~LinkAheadPythonEntity~: Base class of the following entity classes. - ~CaosDBPythonEntity~: Base class of the following entity classes.
- ~LinkAheadPythonRecord~ - ~CaosDBPythonRecord~
- ~LinkAheadPythonRecordType~ - ~CaosDBPythonRecordType~
- ~LinkAheadPythonProperty~ - ~CaosDBPythonProperty~
- ~LinkAheadPythonMultiProperty~: **WARNING** Not implemented yet. - ~CaosDBPythonMultiProperty~: **WARNING** Not implemented yet.
- ~LinkAheadPythonFile~: Used for file entities and provides an additional ~download~ function for being able to directly retrieve files from LinkAhead. - ~CaosDBPythonFile~: Used for file entities and provides an additional ~download~ function for being able to directly retrieve files from CaosDB.
In addition, there are the following helper structures which are realized as Python data classes: In addition, there are the following helper structures which are realized as Python data classes:
- ~LinkAheadPropertyMetaData~: For storing meta data about properties. - ~CaosDBPropertyMetaData~: For storing meta data about properties.
- ~LinkAheadPythonUnresolved~: The base class of unresolved "things". - ~CaosDBPythonUnresolved~: The base class of unresolved "things".
- ~LinkAheadPythonUnresolvedParent~: Parents of entities are stored as unresolved parents by default, storing an id or a name of a parent (or both). - ~CaosDBPythonUnresolvedParent~: Parents of entities are stored as unresolved parents by default, storing an id or a name of a parent (or both).
- ~LinkAheadPythonUnresolvedReference~: An unresolved reference is a reference property with an id which has not (yet) been resolved to an Entity. - ~CaosDBPythonUnresolvedReference~: An unresolved reference is a reference property with an id which has not (yet) been resolved to an Entity.
The function "resolve_references" can be used to recursively replace ~LinkAheadPythonUnresolvedReferences~ into members of type ~LinkAheadPythonRecords~ The function "resolve_references" can be used to recursively replace ~CaosDBPythonUnresolvedReferences~ into members of type ~CaosDBPythonRecords~
or ~LinkAheadPythonFile~. or ~CaosDBPythonFile~.
Each property stored in a LinkAhead record corresponds to: Each property stored in a CaosDB record corresponds to:
- a member attribute of ~LinkAheadPythonRecord~ **and** - a member attribute of ~CaosDBPythonRecord~ **and**
- an entry in a dict called "metadata" storing a LinkAheadPropertyMetadata object with the following information about proeprties: - an entry in a dict called "metadata" storing a CaosDBPropertyMetadata object with the following information about proeprties:
- ~unit~ - ~unit~
- ~datatype~ - ~datatype~
- ~description~ - ~description~
...@@ -141,7 +141,7 @@ First, the data model will be filled with the parameter values for this specific ...@@ -141,7 +141,7 @@ First, the data model will be filled with the parameter values for this specific
Records are created by the `create_record` function. Parameter values can be set at record creation and also after creation as python properties of the corresponding record instance. The following example shows how to create a record, how to set the parameter at creation and how to set them as python properties Records are created by the `create_record` function. Parameter values can be set at record creation and also after creation as python properties of the corresponding record instance. The following example shows how to create a record, how to set the parameter at creation and how to set them as python properties
#+BEGIN_SRC python #+BEGIN_SRC python
from linkahead.high_level_api import create_record from caosdb.high_level_api import create_record
MonodomainRecord = create_record("MonodomainTissueSimulation") MonodomainRecord = create_record("MonodomainTissueSimulation")
MonodomainRecord.LocalModel = create_record("MitchellSchaefferModel") MonodomainRecord.LocalModel = create_record("MitchellSchaefferModel")
...@@ -166,6 +166,6 @@ Records are created by the `create_record` function. Parameter values can be set ...@@ -166,6 +166,6 @@ Records are created by the `create_record` function. Parameter values can be set
#+END_SRC #+END_SRC
At any position in the algorithm you are free to: At any position in the algorithm you are free to:
- Convert this model to the standard python API and insert or update the records in a running instance of LinkAhead. - Convert this model to the standard python API and insert or update the records in a running instance of CaosDB.
- Serialize this model in the high level API yaml format. This enables the LinkAhead crawler to pickup the file and synchronize it with a running instance - Serialize this model in the high level API yaml format. This enables the CaosDB crawler to pickup the file and synchronize it with a running instance
of LinkAhead. of CaosDB.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment