Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-advanced-user-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-advanced-user-tools
Commits
f8da56c1
Commit
f8da56c1
authored
5 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT minor and comments
parent
b1b9cedd
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosadvancedtools/cfood.py
+28
-6
28 additions, 6 deletions
src/caosadvancedtools/cfood.py
with
28 additions
and
6 deletions
src/caosadvancedtools/cfood.py
+
28
−
6
View file @
f8da56c1
...
...
@@ -38,13 +38,24 @@ ENTITIES = {}
def
get_value
(
prop
):
"""
returns the value of a Property
If the value is an Entity itself, its id is returned instead
"""
if
not
isinstance
(
prop
.
value
,
db
.
Entity
):
return
prop
.
value
else
:
return
str
(
prop
.
value
.
id
)
return
prop
.
value
.
id
def
get_entity
(
name
):
"""
implements a mini cache of RecordTypes
If and only if a RecordType (identified by its name) is not in the
dictionary, it is retrieved from CaosDB.
"""
if
name
not
in
ENTITIES
:
ent
=
db
.
Entity
(
name
=
name
)
ent
.
retrieve
()
...
...
@@ -63,6 +74,9 @@ class AbstractCFood(object):
self
.
use_cache
=
use_cache
self
.
access
=
access
if
self
.
use_cache
:
self
.
identifiable_cache
=
Cache
()
def
treat_match
(
self
,
crawled_file
,
match
):
print
(
crawled_file
)
...
...
@@ -81,8 +95,9 @@ class AbstractCFood(object):
if
self
.
use_cache
:
identifiable_cache
=
Cache
()
identifier
=
Cache
.
hash_entity
(
identifiable
)
print
(
identifier
)
cached_id
=
identifiable_cache
.
check_existing
(
identifier
)
cached_id
=
self
.
identifiable_cache
.
check_existing
(
identifier
)
# retrieve entity for the cached id
if
cached_id
is
not
None
:
existing
=
db
.
execute_query
(
"
FIND {}
"
.
format
(
cached_id
),
...
...
@@ -151,18 +166,25 @@ class AbstractCFood(object):
@staticmethod
def
find_existing
(
entity
):
"""
searches for an entity that matches the identifiable in CaosDB
Characteristics of the identifiable like, properties, name or id are
used for the match.
"""
if
entity
.
name
is
None
:
# TODO multiple parents are ignored! Sufficient?
query_string
=
"
FIND Record
"
+
entity
.
get_parents
()[
0
].
name
#import IPython
# IPython.embed()
query_string
+=
"
with
"
+
"
and
"
.
join
(
[
"'"
+
p
.
name
+
"'
=
'"
+
get_value
(
p
)
+
"'"
for
p
in
entity
.
get_properties
()])
+
str
(
get_value
(
p
)
)
+
"'"
for
p
in
entity
.
get_properties
()])
else
:
query_string
=
"
FIND
'
{}
'"
.
format
(
entity
.
name
)
print
(
query_string
)
q
=
db
.
Query
(
query_string
)
# the identifiable should identify an object uniquely. Thus the query
# is using the unique keyword
try
:
r
=
q
.
execute
(
unique
=
True
)
except
TransactionError
as
er
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment