Skip to content

Commit

Permalink
Initial implementation of resource adding endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
nanglo123 committed Jul 12, 2024
1 parent 65ff736 commit ca47f14
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions mira/dkg/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from mira.dkg.client import AskemEntity, Entity, Relation
from mira.dkg.utils import DKG_REFINER_RELS
from mira.dkg.construct import process_resource

__all__ = [
"api_blueprint",
Expand Down Expand Up @@ -360,6 +361,31 @@ def add_relations(
request.app.state.client.add_relation(relation)


@api_blueprint.post(
"/add_resources",
response_model=None,
tags=["relations"],
)
def add_resources(
request: Request,
resource_list: List[str]
):
for resource in resource_list:
# nodes and edges will be a list of dicts
nodes, edges = process_resource(resource)

# node_info and edge_info are dictionaries that will be
# unpacked when creating instances of entities and relations
entities = [Entity(**node_info) for node_info in nodes]
relations = [Relation(**edge_info) for edge_info in edges]

for entity in entities:
request.app.state.client.add_node(entity)
for relation in relations:
request.app.state.client.add_relation(relation)



class IsOntChildResult(BaseModel):
"""Result of a query to /is_ontological_child"""

Expand Down

0 comments on commit ca47f14

Please sign in to comment.