Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-pylib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
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-pylib
Commits
fb2da5d0
Commit
fb2da5d0
authored
6 years ago
by
Henrik tom Wörden
Browse files
Options
Downloads
Patches
Plain Diff
MAINT: whitespace changes and renaming
parent
02c51e90
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/caosdb/apiutils.py
+75
-12
75 additions, 12 deletions
src/caosdb/apiutils.py
with
75 additions
and
12 deletions
src/caosdb/apiutils.py
+
75
−
12
View file @
fb2da5d0
...
@@ -58,16 +58,20 @@ def new_record(record_type, name=None, description=None,
...
@@ -58,16 +58,20 @@ def new_record(record_type, name=None, description=None,
r
=
Record
(
name
)
r
=
Record
(
name
)
r
.
add_parent
(
rt
)
r
.
add_parent
(
rt
)
if
tempid
is
not
None
:
if
tempid
is
not
None
:
r
.
id
=
tempid
r
.
id
=
tempid
if
description
is
not
None
:
if
description
is
not
None
:
r
.
description
=
description
r
.
description
=
description
# Add all additional properties, treat iterables als multiple
# Add all additional properties, treat iterables als multiple
# additions.
# additions.
for
k
,
v
in
kwargs
.
items
():
for
k
,
v
in
kwargs
.
items
():
if
hasattr
(
v
,
"
encode
"
)
or
not
isinstance
(
v
,
Iterable
):
if
hasattr
(
v
,
"
encode
"
)
or
not
isinstance
(
v
,
Iterable
):
v
=
[
v
]
v
=
[
v
]
for
vv
in
v
:
for
vv
in
v
:
p
=
Property
(
k
)
p
=
Property
(
k
)
p
.
retrieve
()
p
.
retrieve
()
...
@@ -76,17 +80,21 @@ def new_record(record_type, name=None, description=None,
...
@@ -76,17 +80,21 @@ def new_record(record_type, name=None, description=None,
if
insert
:
if
insert
:
r
.
insert
()
r
.
insert
()
return
r
return
r
def
get_type_of_entity_with
(
id_
):
def
get_type_of_entity_with
(
id_
):
objs
=
Query
(
"
FIND Entity WHICH HAS id={id_}
"
.
format
(
id_
=
id_
)).
execute
()
objs
=
Query
(
"
FIND Entity WHICH HAS id={id_}
"
.
format
(
id_
=
id_
)).
execute
()
if
len
(
objs
)
==
0
:
if
len
(
objs
)
==
0
:
raise
RuntimeError
(
"
ID {} not found.
"
.
format
(
id_
))
raise
RuntimeError
(
"
ID {} not found.
"
.
format
(
id_
))
if
len
(
objs
)
>
1
:
if
len
(
objs
)
>
1
:
raise
RuntimeError
(
raise
RuntimeError
(
"
ID {} is not unique. This is probably a bug in the CaosDB server.
"
.
format
(
id_
))
"
ID {} is not unique. This is probably a bug in the CaosDB server.
"
.
format
(
id_
))
obj
=
objs
[
0
]
obj
=
objs
[
0
]
if
isinstance
(
obj
,
Record
):
if
isinstance
(
obj
,
Record
):
return
Record
return
Record
elif
isinstance
(
obj
,
RecordType
):
elif
isinstance
(
obj
,
RecordType
):
...
@@ -125,6 +133,7 @@ class CaosDBPythonEntity(object):
...
@@ -125,6 +133,7 @@ class CaosDBPythonEntity(object):
@staticmethod
@staticmethod
def
_get_id
():
def
_get_id
():
CaosDBPythonEntity
.
_last_id
-=
1
CaosDBPythonEntity
.
_last_id
-=
1
return
CaosDBPythonEntity
.
_last_id
return
CaosDBPythonEntity
.
_last_id
def
_set_property_from_entity
(
self
,
ent
):
def
_set_property_from_entity
(
self
,
ent
):
...
@@ -140,34 +149,41 @@ class CaosDBPythonEntity(object):
...
@@ -140,34 +149,41 @@ class CaosDBPythonEntity(object):
overwrite: Use this if you definitely only want one property with that name (set to True).
overwrite: Use this if you definitely only want one property with that name (set to True).
"""
"""
self
.
_datatypes
[
name
]
=
datatype
self
.
_datatypes
[
name
]
=
datatype
if
isinstance
(
name
,
Entity
):
if
isinstance
(
name
,
Entity
):
name
=
name
.
name
name
=
name
.
name
if
name
in
self
.
_forbidden
:
if
name
in
self
.
_forbidden
:
raise
RuntimeError
(
"
Entity cannot be converted to a corresponding
"
raise
RuntimeError
(
"
Entity cannot be converted to a corresponding
"
"
Python representation. Name of property
"
+
"
Python representation. Name of property
"
+
name
+
"
is forbidden!
"
)
name
+
"
is forbidden!
"
)
already_exists
=
(
name
in
dir
(
self
))
already_exists
=
(
name
in
dir
(
self
))
if
already_exists
and
not
overwrite
:
if
already_exists
and
not
overwrite
:
# each call to _set_property checks first if it already exists
# each call to _set_property checks first if it already exists
# if yes: Turn the attribute into a list and
# if yes: Turn the attribute into a list and
# place all the elements into that list.
# place all the elements into that list.
att
=
self
.
__getattribute__
(
name
)
att
=
self
.
__getattribute__
(
name
)
if
isinstance
(
att
,
list
):
if
isinstance
(
att
,
list
):
pass
pass
else
:
else
:
old_att
=
self
.
__getattribute__
(
name
)
old_att
=
self
.
__getattribute__
(
name
)
self
.
__setattr__
(
name
,
[
old_att
])
self
.
__setattr__
(
name
,
[
old_att
])
if
is_reference
:
if
is_reference
:
self
.
_references
[
name
]
=
[
self
.
_references
[
name
]
=
[
self
.
_references
[
name
]]
self
.
_references
[
name
]]
att
=
self
.
__getattribute__
(
name
)
att
=
self
.
__getattribute__
(
name
)
att
.
append
(
value
)
att
.
append
(
value
)
if
is_reference
:
if
is_reference
:
self
.
_references
[
name
].
append
(
int
(
value
))
self
.
_references
[
name
].
append
(
int
(
value
))
else
:
else
:
if
is_reference
:
if
is_reference
:
self
.
_references
[
name
]
=
value
self
.
_references
[
name
]
=
value
self
.
__setattr__
(
name
,
value
)
self
.
__setattr__
(
name
,
value
)
if
not
(
already_exists
and
overwrite
):
if
not
(
already_exists
and
overwrite
):
self
.
_properties
.
add
(
name
)
self
.
_properties
.
add
(
name
)
...
@@ -181,6 +197,7 @@ class CaosDBPythonEntity(object):
...
@@ -181,6 +197,7 @@ class CaosDBPythonEntity(object):
prrealpre
=
pr
.
replace
(
"
<
"
,
"
<
"
).
replace
(
"
>
"
,
"
>
"
)
prrealpre
=
pr
.
replace
(
"
<
"
,
"
<
"
).
replace
(
"
>
"
,
"
>
"
)
prreal
=
prrealpre
[
prrealpre
.
index
(
"
<
"
)
+
1
:
prrealpre
.
rindex
(
"
>
"
)]
prreal
=
prrealpre
[
prrealpre
.
index
(
"
<
"
)
+
1
:
prrealpre
.
rindex
(
"
>
"
)]
lst
=
[
self
.
_type_converted_value
(
i
,
prreal
)
for
i
in
val
]
lst
=
[
self
.
_type_converted_value
(
i
,
prreal
)
for
i
in
val
]
return
([
i
[
0
]
for
i
in
lst
],
lst
[
0
][
1
])
return
([
i
[
0
]
for
i
in
lst
],
lst
[
0
][
1
])
def
_type_converted_value
(
self
,
val
,
pr
):
def
_type_converted_value
(
self
,
val
,
pr
):
...
@@ -191,6 +208,7 @@ class CaosDBPythonEntity(object):
...
@@ -191,6 +208,7 @@ class CaosDBPythonEntity(object):
- the converted value
- the converted value
- True if the value has to be interpreted as an id acting as a reference
- True if the value has to be interpreted as an id acting as a reference
"""
"""
if
val
is
None
:
if
val
is
None
:
return
(
None
,
False
)
return
(
None
,
False
)
elif
pr
==
DOUBLE
:
elif
pr
==
DOUBLE
:
...
@@ -219,6 +237,7 @@ class CaosDBPythonEntity(object):
...
@@ -219,6 +237,7 @@ class CaosDBPythonEntity(object):
element are indistinguishable from simple types in this
element are indistinguishable from simple types in this
representation.
"""
representation.
"""
att
=
self
.
__getattribute__
(
name
)
att
=
self
.
__getattribute__
(
name
)
if
isinstance
(
att
,
list
):
if
isinstance
(
att
,
list
):
return
att
return
att
else
:
else
:
...
@@ -237,10 +256,12 @@ class CaosDBPythonEntity(object):
...
@@ -237,10 +256,12 @@ class CaosDBPythonEntity(object):
def
get_parent_names
(
self
):
def
get_parent_names
(
self
):
new_plist
=
[]
new_plist
=
[]
for
p
in
self
.
_parents
:
for
p
in
self
.
_parents
:
obj_type
=
get_type_of_entity_with
(
p
)
obj_type
=
get_type_of_entity_with
(
p
)
ent
=
obj_type
(
id
=
p
).
retrieve
()
ent
=
obj_type
(
id
=
p
).
retrieve
()
new_plist
.
append
(
ent
.
name
)
new_plist
.
append
(
ent
.
name
)
return
new_plist
return
new_plist
def
resolve_references
(
self
,
deep
=
False
,
visited
=
dict
()):
def
resolve_references
(
self
,
deep
=
False
,
visited
=
dict
()):
...
@@ -249,24 +270,28 @@ class CaosDBPythonEntity(object):
...
@@ -249,24 +270,28 @@ class CaosDBPythonEntity(object):
for
j
in
range
(
len
(
self
.
_references
[
i
])):
for
j
in
range
(
len
(
self
.
_references
[
i
])):
new_id
=
self
.
_references
[
i
][
j
]
new_id
=
self
.
_references
[
i
][
j
]
obj_type
=
get_type_of_entity_with
(
new_id
)
obj_type
=
get_type_of_entity_with
(
new_id
)
if
new_id
in
visited
:
if
new_id
in
visited
:
new_object
=
visited
[
new_id
]
new_object
=
visited
[
new_id
]
else
:
else
:
ent
=
obj_type
(
id
=
new_id
).
retrieve
()
ent
=
obj_type
(
id
=
new_id
).
retrieve
()
new_object
=
convert_to_python_object
(
ent
)
new_object
=
convert_to_python_object
(
ent
)
visited
[
new_id
]
=
new_object
visited
[
new_id
]
=
new_object
if
deep
:
if
deep
:
new_object
.
resolve_references
(
deep
,
visited
)
new_object
.
resolve_references
(
deep
,
visited
)
self
.
__getattribute__
(
i
)[
j
]
=
new_object
self
.
__getattribute__
(
i
)[
j
]
=
new_object
else
:
else
:
new_id
=
self
.
_references
[
i
]
new_id
=
self
.
_references
[
i
]
obj_type
=
get_type_of_entity_with
(
new_id
)
obj_type
=
get_type_of_entity_with
(
new_id
)
if
new_id
in
visited
:
if
new_id
in
visited
:
new_object
=
visited
[
new_id
]
new_object
=
visited
[
new_id
]
else
:
else
:
ent
=
obj_type
(
id
=
new_id
).
retrieve
()
ent
=
obj_type
(
id
=
new_id
).
retrieve
()
new_object
=
convert_to_python_object
(
ent
)
new_object
=
convert_to_python_object
(
ent
)
visited
[
new_id
]
=
new_object
visited
[
new_id
]
=
new_object
if
deep
:
if
deep
:
new_object
.
resolve_references
(
deep
,
visited
)
new_object
.
resolve_references
(
deep
,
visited
)
self
.
__setattr__
(
i
,
new_object
)
self
.
__setattr__
(
i
,
new_object
)
...
@@ -276,13 +301,16 @@ class CaosDBPythonEntity(object):
...
@@ -276,13 +301,16 @@ class CaosDBPythonEntity(object):
result
=
str
(
self
.
__class__
.
__name__
)
+
"
\n
"
result
=
str
(
self
.
__class__
.
__name__
)
+
"
\n
"
else
:
else
:
result
=
name
+
"
\n
"
result
=
name
+
"
\n
"
for
p
in
self
.
_properties
:
for
p
in
self
.
_properties
:
value
=
self
.
__getattribute__
(
p
)
value
=
self
.
__getattribute__
(
p
)
if
isinstance
(
value
,
CaosDBPythonEntity
):
if
isinstance
(
value
,
CaosDBPythonEntity
):
result
+=
indent
*
"
\t
"
+
\
result
+=
indent
*
"
\t
"
+
\
value
.
__str__
(
indent
=
indent
+
1
,
name
=
p
)
value
.
__str__
(
indent
=
indent
+
1
,
name
=
p
)
else
:
else
:
result
+=
indent
*
"
\t
"
+
p
+
"
\n
"
result
+=
indent
*
"
\t
"
+
p
+
"
\n
"
return
result
return
result
...
@@ -306,29 +334,38 @@ class CaosDBPythonFile(CaosDBPythonEntity):
...
@@ -306,29 +334,38 @@ class CaosDBPythonFile(CaosDBPythonEntity):
def
_single_convert_to_python_object
(
robj
,
entity
):
def
_single_convert_to_python_object
(
robj
,
entity
):
robj
.
_id
=
entity
.
id
robj
.
_id
=
entity
.
id
for
i
in
entity
.
properties
:
for
i
in
entity
.
properties
:
robj
.
_set_property_from_entity
(
i
)
robj
.
_set_property_from_entity
(
i
)
for
i
in
entity
.
parents
:
for
i
in
entity
.
parents
:
robj
.
_add_parent
(
i
)
robj
.
_add_parent
(
i
)
if
entity
.
path
is
not
None
:
if
entity
.
path
is
not
None
:
robj
.
_path
=
entity
.
path
robj
.
_path
=
entity
.
path
if
entity
.
file
is
not
None
:
if
entity
.
file
is
not
None
:
robj
.
_file
=
entity
.
file
robj
.
_file
=
entity
.
file
# if entity.pickup is not None:
# if entity.pickup is not None:
# robj.pickup = entity.pickup
# robj.pickup = entity.pickup
return
robj
return
robj
def
_single_convert_to_entity
(
entity
,
robj
,
**
kwargs
):
def
_single_convert_to_entity
(
entity
,
robj
,
**
kwargs
):
if
robj
.
_id
is
not
None
:
if
robj
.
_id
is
not
None
:
entity
.
id
=
robj
.
_id
entity
.
id
=
robj
.
_id
if
robj
.
_path
is
not
None
:
if
robj
.
_path
is
not
None
:
entity
.
path
=
robj
.
_path
entity
.
path
=
robj
.
_path
if
robj
.
_file
is
not
None
:
if
robj
.
_file
is
not
None
:
entity
.
file
=
robj
.
_file
entity
.
file
=
robj
.
_file
if
robj
.
pickup
is
not
None
:
if
robj
.
pickup
is
not
None
:
entity
.
pickup
=
robj
.
pickup
entity
.
pickup
=
robj
.
pickup
children
=
[]
children
=
[]
for
parent
in
robj
.
_parents
:
for
parent
in
robj
.
_parents
:
if
sys
.
version_info
[
0
]
<
3
:
if
sys
.
version_info
[
0
]
<
3
:
if
hasattr
(
parent
,
"
encode
"
):
if
hasattr
(
parent
,
"
encode
"
):
...
@@ -344,9 +381,11 @@ def _single_convert_to_entity(entity, robj, **kwargs):
...
@@ -344,9 +381,11 @@ def _single_convert_to_entity(entity, robj, **kwargs):
def
add_property
(
entity
,
prop
,
name
,
recursive
=
False
,
datatype
=
None
):
def
add_property
(
entity
,
prop
,
name
,
recursive
=
False
,
datatype
=
None
):
if
datatype
is
None
:
if
datatype
is
None
:
raise
ArgumentError
(
"
datatype must not be None
"
)
raise
ArgumentError
(
"
datatype must not be None
"
)
if
isinstance
(
prop
,
CaosDBPythonEntity
):
if
isinstance
(
prop
,
CaosDBPythonEntity
):
entity
.
add_property
(
name
=
name
,
value
=
str
(
entity
.
add_property
(
name
=
name
,
value
=
str
(
prop
.
_id
),
datatype
=
datatype
)
prop
.
_id
),
datatype
=
datatype
)
if
recursive
and
not
prop
.
do_not_expand
:
if
recursive
and
not
prop
.
do_not_expand
:
return
convert_to_entity
(
prop
,
recursive
=
recursive
)
return
convert_to_entity
(
prop
,
recursive
=
recursive
)
else
:
else
:
...
@@ -355,16 +394,20 @@ def _single_convert_to_entity(entity, robj, **kwargs):
...
@@ -355,16 +394,20 @@ def _single_convert_to_entity(entity, robj, **kwargs):
if
isinstance
(
prop
,
float
)
or
isinstance
(
prop
,
int
):
if
isinstance
(
prop
,
float
)
or
isinstance
(
prop
,
int
):
prop
=
str
(
prop
)
prop
=
str
(
prop
)
entity
.
add_property
(
name
=
name
,
value
=
prop
,
datatype
=
datatype
)
entity
.
add_property
(
name
=
name
,
value
=
prop
,
datatype
=
datatype
)
return
[]
return
[]
for
prop
in
robj
.
_properties
:
for
prop
in
robj
.
_properties
:
value
=
robj
.
__getattribute__
(
prop
)
value
=
robj
.
__getattribute__
(
prop
)
if
isinstance
(
value
,
list
):
if
isinstance
(
value
,
list
):
if
robj
.
_datatypes
[
prop
][
0
:
4
]
==
"
LIST
"
:
if
robj
.
_datatypes
[
prop
][
0
:
4
]
==
"
LIST
"
:
lst
=
[]
lst
=
[]
for
v
in
value
:
for
v
in
value
:
if
isinstance
(
v
,
CaosDBPythonEntity
):
if
isinstance
(
v
,
CaosDBPythonEntity
):
lst
.
append
(
v
.
_id
)
lst
.
append
(
v
.
_id
)
if
recursive
and
not
v
.
do_not_expand
:
if
recursive
and
not
v
.
do_not_expand
:
children
.
append
(
convert_to_entity
(
children
.
append
(
convert_to_entity
(
v
,
recursive
=
recursive
))
v
,
recursive
=
recursive
))
...
@@ -392,12 +435,14 @@ def _single_convert_to_entity(entity, robj, **kwargs):
...
@@ -392,12 +435,14 @@ def _single_convert_to_entity(entity, robj, **kwargs):
prop
,
prop
,
datatype
=
robj
.
_datatypes
[
prop
],
datatype
=
robj
.
_datatypes
[
prop
],
**
kwargs
))
**
kwargs
))
return
[
entity
]
+
children
return
[
entity
]
+
children
def
convert_to_entity
(
python_object
,
**
kwargs
):
def
convert_to_entity
(
python_object
,
**
kwargs
):
if
isinstance
(
python_object
,
Container
):
if
isinstance
(
python_object
,
Container
):
# Create a list of objects:
# Create a list of objects:
return
[
convert_to_python_object
(
i
,
**
kwargs
)
for
i
in
python_object
]
return
[
convert_to_python_object
(
i
,
**
kwargs
)
for
i
in
python_object
]
elif
isinstance
(
python_object
,
CaosDBPythonRecord
):
elif
isinstance
(
python_object
,
CaosDBPythonRecord
):
return
_single_convert_to_entity
(
Record
(),
python_object
,
**
kwargs
)
return
_single_convert_to_entity
(
Record
(),
python_object
,
**
kwargs
)
...
@@ -415,8 +460,10 @@ def convert_to_entity(python_object, **kwargs):
...
@@ -415,8 +460,10 @@ def convert_to_entity(python_object, **kwargs):
def
convert_to_python_object
(
entity
):
def
convert_to_python_object
(
entity
):
""""""
""""""
if
isinstance
(
entity
,
Container
):
if
isinstance
(
entity
,
Container
):
# Create a list of objects:
# Create a list of objects:
return
[
convert_to_python_object
(
i
)
for
i
in
entity
]
return
[
convert_to_python_object
(
i
)
for
i
in
entity
]
elif
isinstance
(
entity
,
Record
):
elif
isinstance
(
entity
,
Record
):
return
_single_convert_to_python_object
(
CaosDBPythonRecord
(),
entity
)
return
_single_convert_to_python_object
(
CaosDBPythonRecord
(),
entity
)
...
@@ -485,64 +532,80 @@ COMPARED = ["name", "role", "datatype", "description", "importance"]
...
@@ -485,64 +532,80 @@ COMPARED = ["name", "role", "datatype", "description", "importance"]
def
compare_entities
(
old_entity
,
new_entity
):
def
compare_entities
(
old_entity
,
new_entity
):
olddiff
=
{}
newdiff
=
{}
description
=
""
description
=
""
# if old_entity is new_entity:
# return description
if
old_entity
is
new_entity
:
return
(
olddiff
,
newdiff
)
for
attr
in
COMPARED
:
for
attr
in
COMPARED
:
try
:
try
:
old_entity
.
__getattribute__
(
attr
)
oldattr
=
old_entity
.
__getattribute__
(
attr
)
r1
_attr_exists
=
True
old_entity
_attr_exists
=
True
except
BaseException
:
except
BaseException
:
r1_attr_exists
=
False
old_entity_attr_exists
=
False
oldattr
=
None
try
:
try
:
new_entity
.
__getattribute__
(
attr
)
newattr
=
new_entity
.
__getattribute__
(
attr
)
r2
_attr_exists
=
True
new_entity
_attr_exists
=
True
except
BaseException
:
except
BaseException
:
r2_attr_exists
=
False
new_entity_attr_exists
=
False
if
r1_attr_exists
^
r2_attr_exists
:
newattr
=
None
description
+=
attr
+
"
only exists in one
\n
"
continue
if
not
old_entity_attr_exists
and
not
new_entity_attr_exists
:
if
not
r1_attr_exists
and
not
r2_attr_exists
:
continue
continue
if
old_entity_attr_exists
^
new_entity_attr_exists
:
olddiff
[
attr
]
=
old_entity
.
__getattribute__
(
attr
)
newdiff
[
attr
]
=
old_entity
.
__getattribute__
(
attr
)
if
old_entity
.
__getattribute__
(
attr
)
!=
new_entity
.
__getattribute__
(
attr
):
if
old_entity
.
__getattribute__
(
attr
)
!=
new_entity
.
__getattribute__
(
attr
):
description
+=
attr
+
"
differs:
\n
"
description
+=
attr
+
"
differs:
\n
"
description
+=
str
(
old_entity
.
__getattribute__
(
attr
))
+
"
\n
"
description
+=
str
(
old_entity
.
__getattribute__
(
attr
))
+
"
\n
"
description
+=
str
(
new_entity
.
__getattribute__
(
attr
))
+
"
\n
"
description
+=
str
(
new_entity
.
__getattribute__
(
attr
))
+
"
\n
"
# properties
# properties
if
(
len
(
old_entity
.
properties
)
>
0
)
^
(
len
(
new_entity
.
properties
)
>
0
):
if
(
len
(
old_entity
.
properties
)
>
0
)
^
(
len
(
new_entity
.
properties
)
>
0
):
description
+=
"
only one has properties
\n
"
description
+=
"
only one has properties
\n
"
else
:
else
:
for
prop
in
old_entity
.
properties
:
for
prop
in
old_entity
.
properties
:
matching
=
[
p
for
p
in
new_entity
.
properties
if
p
.
name
==
prop
.
name
]
matching
=
[
p
for
p
in
new_entity
.
properties
if
p
.
name
==
prop
.
name
]
if
len
(
matching
)
==
0
:
if
len
(
matching
)
==
0
:
description
+=
"
new_entity is missing the property
'"
+
prop
.
name
+
"'
\n
"
description
+=
"
new_entity is missing the property
'"
+
prop
.
name
+
"'
\n
"
elif
len
(
matching
)
==
1
:
elif
len
(
matching
)
==
1
:
if
(
old_entity
.
get_importance
(
prop
.
name
)
!=
if
(
old_entity
.
get_importance
(
prop
.
name
)
!=
new_entity
.
get_importance
(
prop
.
name
)):
new_entity
.
get_importance
(
prop
.
name
)):
description
+=
"
importance of
'"
+
prop
.
name
+
"'
differs
\n
"
description
+=
"
importance of
'"
+
prop
.
name
+
"'
differs
\n
"
if
((
prop
.
datatype
is
not
None
and
if
((
prop
.
datatype
is
not
None
and
matching
[
0
].
datatype
is
not
None
)
and
matching
[
0
].
datatype
is
not
None
)
and
(
prop
.
datatype
!=
matching
[
0
].
datatype
)):
(
prop
.
datatype
!=
matching
[
0
].
datatype
)):
description
+=
"
datatype of
'"
+
prop
.
name
+
"'
differs
\n
"
description
+=
"
datatype of
'"
+
prop
.
name
+
"'
differs
\n
"
else
:
else
:
raise
NotImplementedError
()
raise
NotImplementedError
()
for
prop
in
new_entity
.
properties
:
for
prop
in
new_entity
.
properties
:
if
len
([
0
for
p
in
old_entity
.
properties
if
p
.
name
==
prop
.
name
])
==
0
:
if
len
([
0
for
p
in
old_entity
.
properties
if
p
.
name
==
prop
.
name
])
==
0
:
description
+=
"
old_entity is missing the property
'"
+
prop
.
name
+
"'
\n
"
description
+=
"
old_entity is missing the property
'"
+
prop
.
name
+
"'
\n
"
# parents
# parents
if
((
len
(
old_entity
.
parents
)
>
0
)
^
(
len
(
new_entity
.
parents
)
>
0
)):
if
((
len
(
old_entity
.
parents
)
>
0
)
^
(
len
(
new_entity
.
parents
)
>
0
)):
description
+=
"
only one has parents
\n
"
description
+=
"
only one has parents
\n
"
else
:
else
:
for
par
in
old_entity
.
parents
:
for
par
in
old_entity
.
parents
:
matching
=
[
p
for
p
in
new_entity
.
parents
if
p
.
name
==
par
.
name
]
matching
=
[
p
for
p
in
new_entity
.
parents
if
p
.
name
==
par
.
name
]
if
len
(
matching
)
==
0
:
if
len
(
matching
)
==
0
:
description
+=
"
new_entity is missing the parent
'"
+
par
.
name
+
"'
\n
"
description
+=
"
new_entity is missing the parent
'"
+
par
.
name
+
"'
\n
"
elif
len
(
matching
)
==
1
:
elif
len
(
matching
)
==
1
:
description
+=
compare_entities
(
par
,
matching
[
0
])
description
+=
compare_entities
(
par
,
matching
[
0
])
else
:
else
:
raise
NotImplementedError
()
raise
NotImplementedError
()
for
par
in
new_entity
.
parents
:
for
par
in
new_entity
.
parents
:
if
len
([
0
for
p
in
old_entity
.
parents
if
p
.
name
==
par
.
name
])
==
0
:
if
len
([
0
for
p
in
old_entity
.
parents
if
p
.
name
==
par
.
name
])
==
0
:
description
+=
"
old_entity is missing the parent
'"
+
par
.
name
+
"'
\n
"
description
+=
"
old_entity is missing the parent
'"
+
par
.
name
+
"'
\n
"
...
...
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