scientio是一个用于组织和查询复杂数据的知识图引擎。
scientio的Python项目详细描述
Roboy科学
关于
Roboy Scientio(来自Lat.Scientia-知识和输入/输出)-用于组织和查询复杂数据的知识图引擎。
依赖关系
要使用scientio,需要安装一个受支持的后端。目前,唯一受支持的后端是neo4j,它可以以多种方式运行 (如果没有可用的远程实例)。我们建议只通过Docker运行它-如下:
docker run \ --publish=7474:7474 --publish=7687:7687 \ --volume=$HOME/neo4j/data:/data \ --volume=$HOME/neo4j/logs:/logs \ neo4j:3.0
安装
通过PIP
安装scientio最简单的方法是通过pip:
pip install scientio
对于开发者
首先,安装依赖项:
pip install -r requirements.txt
然后,您可以在任何IDE中打开存储库,并将
src
文件夹作为源根目录。
基本科学用例
提供本体描述
本体描述是命名实体类型的集合,其中每种类型可以声明一组特定的属性和关系,如下所示:
# my_ontology.yml!OTypeentity:Alien# The name of the ontology type---!OTypeentity:Vulcan# Declare a more specific Alien typemeta:[Alien]properties:# Allowed properties for every Vulcan-name-homeworld-ear_pointiness---!OTypeentity:Human# Declare a more specific Alien typemeta:[Alien]properties:# Allowed properties for every Human-name-homeworldrelationships:[captain_of]# Allowed relationships for every Human
创建一些节点
fromscientio.ontology.ontologyimportOntologyfromscientio.sessionimportSessionfromscientio.ontology.nodeimportNode# Load the ontology from a yaml fileonto=Ontology(path_to_yaml="my_ontology.yml")# Create a session (with default Neo4j backend)sess=Session(ontology=onto,neo4j_address="bolt://localhost:7687",neo4j_username="neo4j",neo4j_password="test")# Get human/vulcan types from ontologyhuman_type=onto.get_type("Human")vulcan_type=onto.get_type("Vulcan")# Create a transient human named "Kirk"kirk=Node(metatype=human_type)kirk.set_name("Kirk")# Create a transient vulcan named "Spock"spock=Node(metatype=vulcan_type)spock.set_name("Spock")# Persist kirk and spocksess.create(kirk)sess.create(spock)
在节点之间添加关系
fromscientio.ontology.ontologyimportOntologyfromscientio.sessionimportSessionfromscientio.ontology.nodeimportNode# Load the ontology from a yaml fileonto=Ontology(path_to_yaml="my_ontology.yml")# Create a session (with default Neo4j backend)sess=Session(ontology=onto,neo4j_address="bolt://localhost:7687",neo4j_username="neo4j",neo4j_password="test")# Get human/vulcan types from ontologyhuman_type=onto.get_type("Human")vulcan_type=onto.get_type("Vulcan")# Create query templates to get the actual kirk/spockkirk=Node(metatype=human_type)spock=Node(metatype=vulcan_type)# Query Kirk and Spock from the database, using# the query nodes we created previously. We're just# gonna assume that the first human is Kirk, and the first# vulcan is Spock.kirk=sess.retrieve(request=kirk)[0]spock=sess.retrieve(request=spock)[0]# Add a relationship between Kirk and Spockkirk.add_relationships({"captain_of":{spock.get_id()}})# Make sure that the new relationship is persistedsess.update(kirk)