From 16a14f51129ebb1ee1370c33bc44ec94771e0e4f Mon Sep 17 00:00:00 2001 From: James Fletcher Date: Mon, 16 Dec 2019 10:05:17 +0000 Subject: [PATCH 1/4] Correct the use of .get() in two instances --- kglib/kgcn/examples/diagnosis/diagnosis.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kglib/kgcn/examples/diagnosis/diagnosis.py b/kglib/kgcn/examples/diagnosis/diagnosis.py index 3b712fa8..6ff8ab0c 100644 --- a/kglib/kgcn/examples/diagnosis/diagnosis.py +++ b/kglib/kgcn/examples/diagnosis/diagnosis.py @@ -261,8 +261,8 @@ def get_thing_types(tx): "match $x sub thing; " "not {$x sub @has-attribute;}; " "not {$x sub @key-attribute;}; " - "get;").get('x') - thing_types = [schema_concept.label() for schema_concept in schema_concepts] + "get;") + thing_types = [schema_concept.get('x').label() for schema_concept in schema_concepts] [thing_types.remove(el) for el in ['thing', 'relation', 'entity', 'attribute', 'candidate-diagnosis', 'example-id', 'probability-exists', 'probability-non-exists', 'probability-preexists']] @@ -284,8 +284,8 @@ def get_role_types(tx): "not{$x sub @key-attribute-owner;}; " "not{$x sub @has-attribute-value;}; " "not{$x sub @has-attribute-owner;};" - "get;").get('x') - role_types = ['has'] + [role.label() for role in schema_concepts] + "get;") + role_types = ['has'] + [role.get('x').label() for role in schema_concepts] [role_types.remove(el) for el in ['role', 'candidate-patient', 'candidate-diagnosed-disease']] return role_types From 38abb82860cf755c79cf001c996dd389ef4088a5 Mon Sep 17 00:00:00 2001 From: James Fletcher Date: Mon, 16 Dec 2019 10:19:56 +0000 Subject: [PATCH 2/4] Remove other instances of collect_concepts --- kglib/utils/graph/thing/queries_to_graph_it.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kglib/utils/graph/thing/queries_to_graph_it.py b/kglib/utils/graph/thing/queries_to_graph_it.py index 3b7f36e9..8353ef2d 100644 --- a/kglib/utils/graph/thing/queries_to_graph_it.py +++ b/kglib/utils/graph/thing/queries_to_graph_it.py @@ -194,9 +194,9 @@ def test_graph_is_built_from_grakn_as_expected(self): with session.transaction().read() as tx: combined_graph = build_graph_from_queries(query_sampler_variable_graph_tuples, tx) - person_exp = build_thing(tx.query('match $x isa person; get;').collect_concepts()[0]) - name_exp = build_thing(tx.query('match $x isa name; get;').collect_concepts()[0]) - parentship_exp = build_thing(tx.query('match $x isa parentship; get;').collect_concepts()[0]) + person_exp = build_thing(list(tx.query('match $x isa person; get;'))[0].get('x')) + name_exp = build_thing(list(tx.query('match $x isa name; get;'))[0].get('x')) + parentship_exp = build_thing(list(tx.query('match $x isa parentship; get;'))[0].get('x')) expected_combined_graph = nx.MultiDiGraph() expected_combined_graph.add_node(person_exp, type='person') From 94656b2a1701163f2f5479a4741f24569133fac0 Mon Sep 17 00:00:00 2001 From: James Fletcher Date: Mon, 16 Dec 2019 11:29:58 +0000 Subject: [PATCH 3/4] Fix diagnosis_test according to the new diagnosis schema and queries --- kglib/kgcn/examples/diagnosis/diagnosis_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kglib/kgcn/examples/diagnosis/diagnosis_test.py b/kglib/kgcn/examples/diagnosis/diagnosis_test.py index b2278828..5ab91d4e 100644 --- a/kglib/kgcn/examples/diagnosis/diagnosis_test.py +++ b/kglib/kgcn/examples/diagnosis/diagnosis_test.py @@ -53,8 +53,9 @@ def test_query_made_as_expected(self): expected_query = (f'match' f'$p id V123;' f'$d id V1235;' + f'$kgcn isa kgcn;' f'insert' - f'$pd(predicted-patient: $p, predicted-diagnosed-disease: $d) isa predicted-diagnosis,' + f'$pd(patient: $p, diagnosed-disease: $d, diagnoser: $kgcn) isa diagnosis,' f'has probability-exists 0.993,' f'has probability-non-exists 0.007,' f'has probability-preexists 0.000;') From ab01bb33885b0b51ad4e839be71a7a6fc02188af Mon Sep 17 00:00:00 2001 From: James Fletcher Date: Mon, 16 Dec 2019 11:39:06 +0000 Subject: [PATCH 4/4] Prefer next(answer_itter) over list(answer_iter)[0] --- kglib/utils/graph/thing/queries_to_graph_it.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kglib/utils/graph/thing/queries_to_graph_it.py b/kglib/utils/graph/thing/queries_to_graph_it.py index 8353ef2d..ca80a425 100644 --- a/kglib/utils/graph/thing/queries_to_graph_it.py +++ b/kglib/utils/graph/thing/queries_to_graph_it.py @@ -194,9 +194,9 @@ def test_graph_is_built_from_grakn_as_expected(self): with session.transaction().read() as tx: combined_graph = build_graph_from_queries(query_sampler_variable_graph_tuples, tx) - person_exp = build_thing(list(tx.query('match $x isa person; get;'))[0].get('x')) - name_exp = build_thing(list(tx.query('match $x isa name; get;'))[0].get('x')) - parentship_exp = build_thing(list(tx.query('match $x isa parentship; get;'))[0].get('x')) + person_exp = build_thing(next(tx.query('match $x isa person; get;')).get('x')) + name_exp = build_thing(next(tx.query('match $x isa name; get;')).get('x')) + parentship_exp = build_thing(next(tx.query('match $x isa parentship; get;')).get('x')) expected_combined_graph = nx.MultiDiGraph() expected_combined_graph.add_node(person_exp, type='person')