Skip to content

Commit

Permalink
Add a add_nodes endpoint that accepts a list of askem entities or ent…
Browse files Browse the repository at this point in the history
…ities
  • Loading branch information
nanglo123 committed Jul 9, 2024
1 parent 217caf8 commit cc13288
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 33 deletions.
34 changes: 21 additions & 13 deletions mira/dkg/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,31 @@ def get_relations(

if active_add_relation_endpoint:
@api_blueprint.post(
"/add_relation",
response_model=Dict[str, str],
"/add_nodes",
response_model=Union[AskemEntity,Entity],
tags=["relations"],
)
def add_relation(
def add_nodes(
request: Request,
relation_query: RelationQuery = Body(
..., example={"source_curie": "vo:0000022",
"target_curie": "ncbitaxon:644"}
)
node_list: List[Union[AskemEntity, Entity]]
):
"""Add a list of nodes to the DKG"""
for entity in node_list:
request.app.state.client.add_node(entity)
return node_list[0]

@api_blueprint.post(
"/add_relations",
response_model=None,
tags=["relations"],
)
def add_relations(
request: Request,
relation_list: List[Dict[str, Any]]
):
"""Add a relation to the DKG"""
source_curie = relation_query.source_curie
target_curie = relation_query.target_curie
request.app.state.client.create_relation(source_curie, target_curie)
return {"source_curie": source_curie, "relation": "has_parameter",
"target_curie": target_curie}
"""Add a list of relations to the DKG"""
for relation in relation_list:
request.app.state.client.relation(relation)


class IsOntChildResult(BaseModel):
Expand Down
55 changes: 35 additions & 20 deletions mira/dkg/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,33 +307,48 @@ def create_tx(self, query: str, **query_params):
query,
**query_params)

def create_relation(self, source_curie, target_curie):
"""Add a list of relations to the DKG
def add_node(self, entity):
"""Add a node to the DKG
Parameters
----------
source_curie :
The curie of the source of the relations to add.
target_curie :
The curie of the target of the relations to add.
entity:
The node that will be added to the DKG
"""
create_source_node_query = f"MERGE (n {{curie: '{source_curie}' }})"
create_target_node_query = f"MERGE (n {{curie: '{target_curie}' }})"
curie = entity.id
name = entity.name
type = entity.type
obsolete = entity.obsolete
description = entity.description
synonyms = entity.synonyms
alts = entity.alts
xrefs = entity.xrefs
labels = entity.labels

create_source_node_query = (
f"MERGE (n {{curie: '{curie}', "
f"name: '{name}', "
f"type: '{type}', "
f"obsolete: {obsolete}, "
f"description: '{description}', "
f"synonyms: {synonyms}, "
f"alts: {alts}, "
f"xrefs: {xrefs}, "
f"labels: {labels} }} )"
)

self.create_tx(create_source_node_query)
self.create_tx(create_target_node_query)

create_relation_query = (
f"MATCH (source_node {{curie: '{source_curie}'}}), "
f"(target_node {{curie: '{target_curie}'}}) "
f"MERGE (source_node)-[rel:has_parameter]->(target_node)"
f"SET rel.pred = 'probonto:c0000062'"
f"SET rel.source = 'probonto'"
f"SET rel.version = '2.5'"
f"SET rel.graph = 'https://raw.githubusercontent.com/probonto/ontology/master/probonto4ols.owl'"
)

self.create_tx(create_relation_query)
def add_relation(self, relation_dict):
"""Add a relation to the DKG
Parameters
----------
relation_dict:
The dictionary containing the relationship information
"""

pass

def create_single_property_node_index(
self,
Expand Down

0 comments on commit cc13288

Please sign in to comment.