|
1 | 1 | # Roboy ScientIO
|
| 2 | + |
| 3 | +## About |
| 4 | + |
2 | 5 | Roboy ScientIO (from Lat. scientia - knowledge and Input/Output) - a Knowledge Graph Engine to organise and query complex data.
|
| 6 | + |
| 7 | +## Dependencies |
| 8 | + |
| 9 | +To use ScientIO, you will need to have one of it's supported back-ends installed. Currently, the only supported back-end is Neo4j, which may be run in a number of ways |
| 10 | +(if you don't have a remote instance available). We recommend simply running it through docker - like this: |
| 11 | + |
| 12 | +```bash |
| 13 | +docker run \ |
| 14 | + --publish=7474:7474 --publish=7687:7687 \ |
| 15 | + --volume=$HOME/neo4j/data:/data \ |
| 16 | + --volume=$HOME/neo4j/logs:/logs \ |
| 17 | + neo4j:3.0 |
| 18 | +``` |
| 19 | + |
| 20 | +## Installation |
| 21 | + |
| 22 | +### Via PIP |
| 23 | + |
| 24 | +The easiest way to install ScientIO is through pip: |
| 25 | + |
| 26 | +`` |
| 27 | +pip install scientio |
| 28 | +`` |
| 29 | + |
| 30 | +### For developers |
| 31 | + |
| 32 | +First, install dependencies: |
| 33 | + |
| 34 | +```bash |
| 35 | +pip install -r requirements.txt |
| 36 | +``` |
| 37 | + |
| 38 | +Then, you may open the repository in any IDE, and mark the |
| 39 | +`src` folder as a sources root. |
| 40 | + |
| 41 | +## Basic ScientIO use-cases |
| 42 | + |
| 43 | +### Supplying an ontology description |
| 44 | + |
| 45 | +The ontology description is a collection of named entity types, where each type may declare a specific set of properties and relationships like this: |
| 46 | + |
| 47 | +```yaml |
| 48 | +# my_ontology.yml |
| 49 | + |
| 50 | +!OType |
| 51 | +entity: Alien # The name of the ontology type |
| 52 | +--- |
| 53 | +!OType |
| 54 | +entity: Vulcan # Declare a more specific Alien type |
| 55 | +meta: [Alien] |
| 56 | +properties: # Allowed properties for every Vulcan |
| 57 | + - name |
| 58 | + - homeworld |
| 59 | + - ear_pointiness |
| 60 | +--- |
| 61 | +!OType |
| 62 | +entity: Human # Declare a more specific Alien type |
| 63 | +meta: [Alien] |
| 64 | +properties: # Allowed properties for every Human |
| 65 | + - name |
| 66 | + - homeworld |
| 67 | +relationships: [captain_of] # Allowed relationships for every Human |
| 68 | +``` |
| 69 | +
|
| 70 | +### Creating some nodes |
| 71 | +
|
| 72 | +```python |
| 73 | +from scientio.ontology.ontology import Ontology |
| 74 | +from scientio.session import Session |
| 75 | +from scientio.ontology.node import Node |
| 76 | + |
| 77 | +# Load the ontology from a yaml file |
| 78 | +onto = Ontology(path_to_yaml="my_ontology.yml") |
| 79 | + |
| 80 | +# Create a session (with default Neo4j backend) |
| 81 | +sess = Session( |
| 82 | + ontology=onto, |
| 83 | + neo4j_address="bolt://localhost:7687", |
| 84 | + neo4j_username="neo4j", |
| 85 | + neo4j_password="test") |
| 86 | + |
| 87 | +# Get human/vulcan types from ontology |
| 88 | +human_type = onto.get_type("Human") |
| 89 | +vulcan_type = onto.get_type("Vulcan") |
| 90 | + |
| 91 | +# Create a transient human named "Kirk" |
| 92 | +kirk = Node(metatype=human_type) |
| 93 | +kirk.set_name("Kirk") |
| 94 | + |
| 95 | +# Create a transient vulcan named "Spock" |
| 96 | +spock = Node(metatype=vulcan_type) |
| 97 | +spock.set_name("Spock") |
| 98 | + |
| 99 | +# Persist kirk and spock |
| 100 | +sess.create(kirk) |
| 101 | +sess.create(spock) |
| 102 | +``` |
| 103 | + |
| 104 | +### Add a relationship between your nodes |
| 105 | + |
| 106 | +```python |
| 107 | +from scientio.ontology.ontology import Ontology |
| 108 | +from scientio.session import Session |
| 109 | +from scientio.ontology.node import Node |
| 110 | + |
| 111 | +# Load the ontology from a yaml file |
| 112 | +onto = Ontology(path_to_yaml="my_ontology.yml") |
| 113 | + |
| 114 | +# Create a session (with default Neo4j backend) |
| 115 | +sess = Session( |
| 116 | + ontology=onto, |
| 117 | + neo4j_address="bolt://localhost:7687", |
| 118 | + neo4j_username="neo4j", |
| 119 | + neo4j_password="test") |
| 120 | + |
| 121 | +# Get human/vulcan types from ontology |
| 122 | +human_type = onto.get_type("Human") |
| 123 | +vulcan_type = onto.get_type("Vulcan") |
| 124 | + |
| 125 | +# Create query templates to get the actual kirk/spock |
| 126 | +kirk = Node(metatype=human_type) |
| 127 | +spock = Node(metatype=vulcan_type) |
| 128 | + |
| 129 | +# Query Kirk and Spock from the database, using |
| 130 | +# the query nodes we created previously. We're just |
| 131 | +# gonna assume that the first human is Kirk, and the first |
| 132 | +# vulcan is Spock. |
| 133 | +kirk = sess.retrieve(request=kirk)[0] |
| 134 | +spock = sess.retrieve(request=spock)[0] |
| 135 | + |
| 136 | +# Add a relationship between Kirk and Spock |
| 137 | +kirk.add_relationships({"captain_of": {spock.get_id()}}) |
| 138 | + |
| 139 | +# Make sure that the new relationship is persisted |
| 140 | +sess.update(kirk) |
| 141 | +``` |
0 commit comments