Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
CaosDB Crawler
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
CaosDB Crawler
Commits
bdf7c3da
Commit
bdf7c3da
authored
Dec 16, 2021
by
Alexander Schlemmer
Browse files
Options
Downloads
Patches
Plain Diff
FIX: properties of identifiables are resolved now correctly
parent
bdd9f128
No related branches found
No related tags found
1 merge request
!53
Release 0.1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/newcrawler/crawl.py
+22
-3
22 additions, 3 deletions
src/newcrawler/crawl.py
src/newcrawler/identifiable_adapters.py
+32
-12
32 additions, 12 deletions
src/newcrawler/identifiable_adapters.py
unittests/test_tool.py
+5
-1
5 additions, 1 deletion
unittests/test_tool.py
with
59 additions
and
16 deletions
src/newcrawler/crawl.py
+
22
−
3
View file @
bdf7c3da
...
...
@@ -107,7 +107,6 @@ class Crawler(object):
if
generalStore
is
None
:
self
.
generalStore
=
GeneralStore
()
self
.
identifiableAdapter
=
identifiableAdapter
if
identifiableAdapter
is
None
:
self
.
identifiableAdapter
=
LocalStorageIdentifiableAdapter
()
...
...
@@ -176,7 +175,6 @@ class Crawler(object):
return
self
.
updateList
def
synchronize
(
self
,
updateList
:
list
[
db
.
Record
]):
"""
Carry out the actual synchronization.
...
...
@@ -207,6 +205,12 @@ class Crawler(object):
# Walk backwards through list, so that deletion is possible:
for
i
in
reversed
(
range
(
len
(
updateList
))):
record
=
updateList
[
i
]
if
record
.
parents
[
0
].
name
==
"
Measurement
"
:
breakpoint
()
# resolve references first:
self
.
identifiableAdapter
.
resolve_references
(
record
)
identifiable
=
self
.
identifiableAdapter
.
retrieve_identifiable
(
record
)
# if there is no identifiable, move record from update list to insert list:
...
...
@@ -227,17 +231,32 @@ class Crawler(object):
identical
=
True
for
j
in
range
(
2
):
# TODO: should be implemented elsewhere
for
label
in
(
"
properties
"
,
"
parents
"
):
for
label
in
(
"
parents
"
,
):
if
len
(
comp
[
j
][
label
])
>
0
:
identical
=
False
break
if
not
identical
:
break
for
key
in
comp
[
0
][
"
properties
"
]:
for
attribute
in
(
"
datatype
"
,
"
importance
"
):
if
(
"
datatype
"
in
comp
[
0
][
"
properties
"
][
key
]
and
comp
[
0
][
"
properties
"
][
key
][
"
datatype
"
]
is
not
None
and
comp
[
1
][
"
properties
"
][
key
][
"
datatype
"
]
!=
comp
[
1
][
"
properties
"
][
key
][
"
datatype
"
]):
identical
=
False
break
if
"
value
"
in
comp
[
0
][
"
properties
"
][
key
]:
identical
=
False
if
not
identical
:
break
if
identical
:
del
updateList
[
i
]
continue
else
:
breakpoint
()
pass
return
(
insertList
,
updateList
)
...
...
This diff is collapsed.
Click to expand it.
src/newcrawler/identifiable_adapters.py
+
32
−
12
View file @
bdf7c3da
...
...
@@ -95,6 +95,9 @@ class IdentifiableAdapter(object):
"""
pass
@abstractmethod
def
resolve_references
(
self
,
record
:
db
.
Record
):
pass
def
get_identifiable
(
self
,
record
:
db
.
Record
):
registered_identifiable
=
self
.
get_registered_identifiable
(
record
)
...
...
@@ -241,20 +244,10 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
raise
NotImplementedError
(
"
Non-identifiable references cannot
"
"
be used as properties in identifiables.
"
)
value_identifiable
=
self
.
retrieve_identified_record
(
prop
.
value
)
if
value_identifiable
is
None
:
raise
RuntimeError
(
"
The identifiable which is used as property
"
"
here has to be inserted first.
"
)
if
value_identifiable
.
id
is
None
:
raise
RuntimeError
(
"
The entity has not been assigned an ID.
"
)
prop
.
value
=
value_identifiable
.
id
if
prop
.
value
!=
prop_record
.
value
:
if
prop
.
name
==
"
project
"
:
breakpoint
()
return
False
return
True
...
...
@@ -268,3 +261,30 @@ class LocalStorageIdentifiableAdapter(IdentifiableAdapter):
if
len
(
candidates
)
==
0
:
return
None
return
candidates
[
0
]
def
_resolve_reference
(
self
,
value
:
db
.
Entity
):
registered
=
self
.
get_registered_identifiable
(
value
)
if
registered
is
None
:
raise
NotImplementedError
(
"
Non-identifiable references cannot
"
"
be used as properties in identifiables.
"
)
value_identifiable
=
self
.
retrieve_identified_record
(
value
)
if
value_identifiable
is
None
:
raise
RuntimeError
(
"
The identifiable which is used as property
"
"
here has to be inserted first.
"
)
if
value_identifiable
.
id
is
None
:
raise
RuntimeError
(
"
The entity has not been assigned an ID.
"
)
return
value_identifiable
.
id
def
resolve_references
(
self
,
record
:
db
.
Record
):
for
prop
in
record
.
properties
:
if
isinstance
(
prop
.
value
,
db
.
Entity
):
prop
.
value
=
self
.
_resolve_reference
(
prop
.
value
)
if
isinstance
(
prop
.
value
,
list
):
for
element_index
in
range
(
len
(
prop
.
value
)):
element
=
prop
.
value
[
element_index
]
if
isinstance
(
element
,
db
.
Entity
):
prop
.
value
[
element_index
]
=
self
.
_resolve_reference
(
element
)
This diff is collapsed.
Click to expand it.
unittests/test_tool.py
+
5
−
1
View file @
bdf7c3da
...
...
@@ -19,6 +19,7 @@ from pytest import raises
# - DONE: provenance in structure elements and converters for properties of records
# - TODO: list whether information from structure elements and converters was used
def
rfp
(
*
pathcomponents
):
"""
Return full path.
...
...
@@ -26,12 +27,14 @@ def rfp(*pathcomponents):
"""
return
join
(
dirname
(
__file__
),
*
pathcomponents
)
def
dircheckstr
(
*
pathcomponents
):
"""
Return the debug tree identifier for a given path.
"""
return
"
newcrawler.structure_elements.Directory:
"
+
basename
(
join
(
*
pathcomponents
))
+
"
,
"
+
rfp
(
"
test_directories
"
,
"
examples_article
"
,
*
pathcomponents
)
def
test_crawler
():
crawler
=
Crawler
(
debug
=
True
)
crawler
.
crawl_directory
(
rfp
(
"
test_directories
"
,
"
examples_article
"
),
...
...
@@ -291,9 +294,11 @@ def test_crawler_update_list():
assert
len
(
comp
[
1
][
"
properties
"
])
==
0
insl
,
updl
=
crawler
.
synchronize
(
crawler
.
updateList
)
breakpoint
()
assert
len
(
insl
)
==
0
assert
len
(
updl
)
==
0
def
test_identifiable_adapter
():
query
=
IdentifiableAdapter
.
create_query_for_identifiable
(
db
.
Record
().
add_parent
(
"
Person
"
)
...
...
@@ -302,7 +307,6 @@ def test_identifiable_adapter():
assert
query
.
lower
()
==
"
find record person with
'
first_name
'
=
'
a
'
and
'
last_name
'
=
'
b
'
"
def
test_provenance_debug_data
():
crawler
=
Crawler
(
debug
=
True
)
crawler
.
crawl_directory
(
rfp
(
"
test_directories
"
,
"
examples_article
"
),
...
...
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