From 946f42a7232dc8168249348516a481899985ad44 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Fri, 22 Mar 2024 13:15:03 -0500 Subject: [PATCH 1/3] Removes extra single and double quotes from entities --- src/kgcl_schema/grammar/parser.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/kgcl_schema/grammar/parser.py b/src/kgcl_schema/grammar/parser.py index 456ff51..1237bf7 100644 --- a/src/kgcl_schema/grammar/parser.py +++ b/src/kgcl_schema/grammar/parser.py @@ -575,8 +575,6 @@ def parse_rename(tree, id): old_language = extract(tree, "old_language") new_language = extract(tree, "new_language") - # TODO old_token and new_token are enclosed in '' - term_id_token = extract(tree, "id") if term_id_token is not None: entity, representation = get_entity_representation(term_id_token) @@ -599,7 +597,7 @@ def extract(tree, data): """Extract node.""" node = get_next(tree.find_data(data)) if node is not None: - node_token = next(get_tokens(node)) + node_token = next(get_tokens(node)).strip("'\"") return node_token else: return None From 8e4ed84313fe5ef49718efb44cfab7bf0c5e90a5 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Fri, 22 Mar 2024 13:45:37 -0500 Subject: [PATCH 2/3] reverted change --- src/kgcl_schema/grammar/parser.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/kgcl_schema/grammar/parser.py b/src/kgcl_schema/grammar/parser.py index 1237bf7..456ff51 100644 --- a/src/kgcl_schema/grammar/parser.py +++ b/src/kgcl_schema/grammar/parser.py @@ -575,6 +575,8 @@ def parse_rename(tree, id): old_language = extract(tree, "old_language") new_language = extract(tree, "new_language") + # TODO old_token and new_token are enclosed in '' + term_id_token = extract(tree, "id") if term_id_token is not None: entity, representation = get_entity_representation(term_id_token) @@ -597,7 +599,7 @@ def extract(tree, data): """Extract node.""" node = get_next(tree.find_data(data)) if node is not None: - node_token = next(get_tokens(node)).strip("'\"") + node_token = next(get_tokens(node)) return node_token else: return None From 2405949b26007ab4812069e5f36c908bb45ce386 Mon Sep 17 00:00:00 2001 From: Harshad Hegde Date: Fri, 22 Mar 2024 14:04:09 -0500 Subject: [PATCH 3/3] fixed the quotes issue --- src/data/examples/examples.yaml | 8 ++++---- src/kgcl_schema/grammar/parser.py | 9 +++++++++ tests/cases.py | 12 ++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/data/examples/examples.yaml b/src/data/examples/examples.yaml index 6650833..8bd6052 100644 --- a/src/data/examples/examples.yaml +++ b/src/data/examples/examples.yaml @@ -1,8 +1,8 @@ Test_0: id: CHANGE:001 type: NodeRename - old_value: '''nuclear envelope''' - new_value: '''foo bar''' + old_value: nuclear envelope + new_value: foo bar about_node: GO:0005635 about_node_representation: curie command_with_curie: rename GO:0005635 from 'nuclear envelope' to 'foo bar' @@ -11,8 +11,8 @@ Test_0: Test_1: id: CHANGE:001 type: NodeRename - old_value: '''nucleus''' - new_value: '''bar''' + old_value: nucleus + new_value: bar about_node: GO:0005634 about_node_representation: curie command_with_curie: rename GO:0005634 from 'nucleus' to 'bar' diff --git a/src/kgcl_schema/grammar/parser.py b/src/kgcl_schema/grammar/parser.py index 456ff51..ec37797 100644 --- a/src/kgcl_schema/grammar/parser.py +++ b/src/kgcl_schema/grammar/parser.py @@ -595,16 +595,25 @@ def parse_rename(tree, id): ) + + def extract(tree, data): """Extract node.""" node = get_next(tree.find_data(data)) + # Define this list at the module level if it's static and doesn't change per function call + quote_strip_param_substring = ["_label", "name"] if node is not None: node_token = next(get_tokens(node)) + + if any(substring in data for substring in quote_strip_param_substring): + node_token = node_token.strip("'\"") + return node_token else: return None + def get_tokens(tree): """Get tokens.""" return tree.scan_values(lambda v: isinstance(v, Token)) diff --git a/tests/cases.py b/tests/cases.py index 929890d..5eb24cb 100644 --- a/tests/cases.py +++ b/tests/cases.py @@ -65,8 +65,8 @@ f"rename {NUCLEAR_ENVELOPE_URI} from 'nuclear envelope' to 'foo bar'", NodeRename( id=UID, - old_value="'nuclear envelope'", - new_value="'foo bar'", + old_value="nuclear envelope", + new_value="foo bar", about_node="GO:0005635", about_node_representation="curie", ), @@ -77,8 +77,8 @@ f"rename {NUCLEUS_URI} from 'nucleus' to 'bar'", NodeRename( id=UID, - old_value="'nucleus'", - new_value="'bar'", + old_value="nucleus", + new_value="bar", about_node=NUCLEUS, about_node_representation="curie", ), @@ -89,8 +89,8 @@ # f"""rename {NUCLEUS} from 'nucleus' to 'bobby " tables'""", # f"""rename {NUCLEUS_URI} from 'nucleus' to 'bobby " tables'""", # NodeRename(id=UID, - # old_value="'nucleus'", - # new_value="'bar'", + # old_value="nucleus", + # new_value="bar", # about_node=NUCLEUS, # about_node_representation='curie'), # None