# 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()
```
Python库 | reasoner-pydantic-1.2.0.1.tar.gz
版权申诉
123 浏览量
2022-04-14
06:00:48
上传
评论
收藏 5KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- 基于SIFT特征点提取和RASIC算法实现全景图像拼接python源码+文档说明+界面截图+详细注释(95分以上课程大作业)
- 基于matlab实现眼部判别的疲劳检测系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的异常姿势识别系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 隐藏文件展示工具,用来展示被病毒隐藏的文件
- 基于Matlab的图像分割系统+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB指纹门禁GUI设计源码+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于Matlab的仪表指数识别系统霍夫曼变换+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB 的霍夫曼变换答题卡识别带GUI界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于MATLAB 疲劳驾驶检测专识别GUI源码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
- 基于matlab的虫害侵蚀系统带Gui界面+源代码+全部数据+文档说明+详细注释+使用说明+截图(高分课程设计)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈