ExactConceptParser can now recognize concepts by their names

This commit is contained in:
2020-05-21 16:27:18 +02:00
parent d357329f51
commit 37d3d16e21
17 changed files with 347 additions and 112 deletions
+8 -8
View File
@@ -288,7 +288,7 @@ def decode_enum(enum_repr: str):
return None
def str_concept(t, skip_key=None):
def str_concept(t, drop_name=None):
"""
The key,id identifiers of a concept are stored in a tuple
we want to return the key and the id, separated by a pipe
@@ -298,21 +298,21 @@ def str_concept(t, skip_key=None):
>>> assert str_concept((None, "id")) == "c:|id:"
>>> assert str_concept(("key", None)) == "c:key:"
>>> assert str_concept((None, None)) == ""
>>> assert str_concept(Concept(key="foo", id="bar")) == "c:foo|bar:"
>>> assert str_concept(Concept(key="foo", id="bar"), skip_key=True) == "c:|bar:"
>>> assert str_concept(Concept(name="foo", id="bar")) == "c:foo|bar:"
>>> assert str_concept(Concept(name="foo", id="bar"), drop_name=True) == "c:|bar:"
:param t:
:param skip_key: True if we only want the id (and not the key)
:param drop_name: True if we only want the id (and not the key)
:return:
"""
if isinstance(t, tuple):
key, id_ = t[0], t[1]
name, id_ = t[0], t[1]
else:
key, id_ = t.key, t.id
name, id_ = t.key, t.id
if key is None and id_ is None:
if name is None and id_ is None:
return ""
result = 'c:' if (key is None or skip_key) else "c:" + key
result = 'c:' if (name is None or drop_name) else "c:" + name
if id_:
result += "|" + id_
return result + ":"