# Reasoner-Pydantic
[![Test status via GitHub Actions](https://github.com/TranslatorSRI/reasoner-pydantic/workflows/test/badge.svg)](https://github.com/TranslatorSRI/reasoner-pydantic/actions?query=workflow%3Atest) [ℹ️](tests/README.md)
[Pydantic](https://pydantic-docs.helpmanual.io/) models for the [Reasoner API](https://github.com/NCATS-Tangerine/NCATS-ReasonerStdAPI) data formats.
These models are very handy when setting up a Reasoner API with [FastAPI](https://fastapi.tiangolo.com/).
## Example usage
```python
from reasoner_pydantic import (
Query, Message, QNode,
KnowledgeGraph, KNode,
Result, NodeBinding,
)
def answer_question(request):
request: Query = Query(**request)
message: Message = request.message
# sanitize incoming message
assert message.query_graph.nodes, 'Query graph has no nodes!'
if message.knowledge_graph is None:
message.knowledge_graph = KnowledgeGraph(nodes={}, edges={})
if message.results is None:
message.results = []
# get query graph node
qnode_id = next(iter(message.query_graph.nodes))
# add knowledge graph node
knode: Node = Node()
knode_id = "foo:bar"
message.knowledge_graph.nodes[knode_id] = knode
# add result
node_binding: NodeBinding = NodeBinding(
id=knode_id,
)
result: Result = Result(
node_bindings={qnode_id: [node_binding]},
edge_bindings={},
foo='bar',
)
message.results.append(result)
return message.json()
```
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
最新资源
- triangle-20190115.3-cp35-cp35m-win_amd64.whl.rar
- triangle-20190115.3-cp27-cp27m-win32.whl.rar
- triangle-20200424-cp36-cp36m-win_amd64.whl.rar
- triangle-20200424-cp36-cp36m-win32.whl.rar
- triangle-20220202-cp37-cp37m-win_amd64.whl.rar
- triangle-20220202-cp38-cp38-win32.whl.rar
- triangle-20220202-cp38-cp38-win_amd64.whl.rar
- triangle-20220202-cp37-cp37m-win32.whl.rar
- triangle-20220202-cp39-cp39-win_amd64.whl.rar
- triangle-20220202-cp39-cp39-win32.whl.rar
- triangle-20220202-cp310-cp310-win_amd64.whl.rar
- triangle-20220202-cp311-cp311-win_amd64.whl.rar
- triangle-20220202-cp310-cp310-win32.whl.rar
- triangle-20220202-cp311-cp311-win32.whl.rar
- trollius-2.2-cp27-cp27m-win_amd64.whl.rar
- trollius-2.2-cp27-cp27m-win32.whl.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈