Skip to content

Commit

Permalink
switching json attributes edge property to be a list of json strings …
Browse files Browse the repository at this point in the history
…instead of one big json string
  • Loading branch information
EvanDietzMorris committed Aug 7, 2024
1 parent 4322e8f commit fe1058f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions reasoner_transpiler/cypher.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,19 @@ def transform_attributes(result_item, node=False):
ignore_list = RESERVED_NODE_PROPS if node else EDGE_SOURCE_PROPS + RESERVED_EDGE_PROPS
ignore_list += ATTRIBUTE_SKIP_LIST

# an "attributes" attribute in neo4j should be a json list,
# an "attributes" attribute in neo4j should be a list of json strings,
# attempt to start the attributes section of transformed attributes with its contents
json_attributes_attribute = result_item.pop('attributes', None)
json_attributes = []
json_attributes_attribute = result_item.pop('attributes', None)
if json_attributes_attribute:
try:
json_attributes = json.loads(json_attributes_attribute)
if not isinstance(json_attributes, list):
print(f'! attributes property was not a list, ignoring: {json_attributes_attribute}')
except json.JSONDecodeError as e:
print(f'! JSONDecodeError parsing attributes property, it should be a json list, ignoring: {json_attributes_attribute}')
if isinstance(json_attributes_attribute, list):
try:
json_attributes = [json.loads(json_attribute_string)
for json_attribute_string in json_attributes_attribute]
except json.JSONDecodeError:
print(f'!!! JSONDecodeError while parsing attributes property, ignoring: {json_attributes_attribute}')
else:
print(f'!!! the attributes edge property should be a list, ignoring: {json_attributes_attribute}')
transformed_attributes = {
'attributes': json_attributes
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neo4j_csv/edges.csv
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ t2d_associated_with_CASP3,MONDO:0005148,biolink:genetically_associated_with,NCBI
obesity_ga_CASP3,MONDO:0011122,biolink:genetically_associated_with,NCBIGene:836,"{}"
metformin_treats_carcinoma,CHEBI:6801,biolink:treats,MONDO:0004993,"{}"
carcinoma_associated_with_CASP8,MONDO:0004993,biolink:genetically_associated_with,NCBIGene:841,"{}"
carcinoma_associated_with_BRCA1,NCBIGene:672,biolink:gene_associated_with_condition,MONDO:0004993,"{\"publications\": [\"xxx\"], \"attributes\": \"[{\\\"attribute_type_id\\\": \\\"json_attribute_1\\\", \\\"value\\\": \\\"json_value_1\\\"}, {\\\"attribute_type_id\\\": \\\"json_attribute_2\\\", \\\"value\\\": \\\"json_value_2\\\"}, {\\\"attribute_type_id\\\": \\\"json_attribute_3\\\", \\\"value\\\": \\\"json_value_3\\\", \\\"attributes\\\": [{\\\"attribute_type_id\\\": \\\"nested_json_attribute_1\\\", \\\"value\\\": \\\"nested_json_value_1\\\"}] }]\" }"
carcinoma_associated_with_BRCA1,NCBIGene:672,biolink:gene_associated_with_condition,MONDO:0004993,"{\"publications\": [\"xxx\"], \"attributes\": [\"{\\\"attribute_type_id\\\": \\\"json_attribute_1\\\", \\\"value\\\": \\\"json_value_1\\\"}\", \"{\\\"attribute_type_id\\\": \\\"json_attribute_2\\\", \\\"value\\\": \\\"json_value_2\\\"}\", \"{\\\"attribute_type_id\\\": \\\"json_attribute_3\\\", \\\"value\\\": \\\"json_value_3\\\", \\\"attributes\\\": [{\\\"attribute_type_id\\\": \\\"nested_json_attribute_1\\\", \\\"value\\\": \\\"nested_json_value_1\\\"}] }\"] }"
t2d_invalid_predicate_albuminaria,MONDO:0005148,biolink:invalid_predicate,HP:0012592,"{}"
qualified_edge_single_qualifier,PUBCHEM.COMPOUND:5460341,biolink:affects,NCBIGene:283871,"{\"qualified_predicate\": \"biolink:causes\"}"
qualified_edge_multiple_qualifier,PUBCHEM.COMPOUND:5460341,biolink:affects,NCBIGene:283871,"{\"qualified_predicate\": \"biolink:causes\",\"object_aspect_qualifier\": \"activity\",\"object_direction_qualifier\": \"decreased\",\"primary_knowledge_source\": \"infores:ctd\"}}"

0 comments on commit fe1058f

Please sign in to comment.