Query Engine API for Distributed AtomSpace
Project description
Hyperon DAS
Hi! This package is a query engine API for Distributed AtomSpace (DAS). When is possible execute queries using Pattern Matcher
Table of Contents
Installation
Before you start, make sure you have Python >= 3.8.5 and Pip installed on your system.
You can install and run this project using different methods. Choose the one that suits your needs.
Using-pip
Run the following command to install the project using pip::
pip install hyperon-das
Using-Poetry
If you prefer to manage your Python projects with Poetry, follow these steps:
-
Install Poetry (if you haven't already):
pip install poetry
-
Clone the project repository:
git clone git@github.com:singnet/das-query-engine.git cd das-query-engine
-
Install project dependencies using Poetry:
poetry install
-
Activate the virtual environment created by Poetry:
poetry shell
Now you can run the project within the Poetry virtual environment.
Usage
You can instantiate DAS in three different ways. see below:
Local
This is a local instance of DAS with default settings.
from hyperon_das import DistributedAtomSpace
das = DistributedAtomSpace()
Remote
To create a remote DAS, you need to specify the 'query_engine' parameter as 'remote' and pass the machine, 'host' and 'port' parameters. See below how to do this:
from hyperon_das import DistributedAtomSpace
das = DistributedAtomSpace(query_engine='remote', host='0.0.0.0', port=1234)
Server
To create a DAS server, you will need to specify the 'atomdb' parameter as 'redis_mongo' and pass the database parameters. The databases supported in this release are Redis and MongoDB. Therefore, the minimum expected parameters are:
- mongo_hostname
- mongo_port
- mongo_username
- mongo_password
- redis_hostname
- redis_port
but it is possible to pass other configuration parameters:
- mongo_tls_ca_file
- redis_username
- redis_password
- redis_cluster
- redis_ssl
from hyperon_das import DistributedAtomSpace
das = DistributedAtomSpace(
atomdb='redis_mongo',
mongo_hostname='127.0.0.2',
mongo_port=27017,
mongo_username='mongo',
mongo_password='mongo',
redis_hostname='127.0.0.1',
redis_port=6379
)
Examples
Local DAS
This way it is only possible to make queries in your local memory with the Atoms that you placed in the DAS. See bellow:
from hyperon_das import DistributedAtomSpace
das = DistributedAtomSpace()
das.count_atoms() # (0, 0)
das.add_link({
'type': 'Inheritance',
'targets': [
{'type': 'Concept', 'name': 'human'},
{'type': 'Concept', 'name': 'mammal'}
],
})
das.add_link({
'type': 'Inheritance',
'targets': [
{'type': 'Concept', 'name': 'monkey'},
{'type': 'Concept', 'name': 'mammal'}
]
})
das.count_atoms() # (3, 2)
query = {
'atom_type': 'link',
'type': 'Inheritance',
'targets': [
{'atom_type': 'variable', 'name': 'v1'},
{'atom_type': 'node', 'type': 'Concept', 'name': 'mammal'},
]
}
query_params = {
"toplevel_only": False
}
resp = das.query(query, query_params)
print(resp)
[
{
"handle": "c93e1e758c53912638438e2a7d7f7b7f",
"type": "Inheritance",
"template": ["Inheritance", "Concept", "Concept"],
"targets": [
{
"handle": "af12f10f9ae2002a1607ba0b47ba8407",
"type": "Concept",
"name": "human",
},
{
"handle": "bdfe4e7a431f73386f37c6448afe5840",
"type": "Concept",
"name": "mammal",
},
],
},
{
"handle": "f31dfe97db782e8cec26de18dddf8965",
"type": "Inheritance",
"template": ["Inheritance", "Concept", "Concept"],
"targets": [
{
"handle": "1cdffc6b0b89ff41d68bec237481d1e1",
"type": "Concept",
"name": "monkey",
},
{
"handle": "bdfe4e7a431f73386f37c6448afe5840",
"type": "Concept",
"name": "mammal",
},
],
},
]
Remote DAS
This way it'ss possible to make queries in your local memory and on the remote machine that you need to pass during the creation of DAS instance. See below:
from hyperon_das import DistributedAtomSpace
das = DistributedAtomSpace(query_engine='remote', host='192.32.11.45', port=9000)
In the query method is possible pass query_scope parameter with four available values. This specifying whether you want to make the query local, remote, local and remote or synchronize and remote. If you don't pass the default is "remote_only"
- "local_only"
- Only local query
- "remote_only"
- Only remote query
- "local_and_remote"
- This type is not available yet. So, this will raise an exception
- "synchronous_update"
- Before make query it will commit your local changes and then make the remote query
Local Scope
query = {
'atom_type': 'link',
'type': 'Inheritance',
'targets': [
{'atom_type': 'node', 'type': 'Concept', 'name': 'humana'},
{'atom_type': 'node', 'type': 'Concept', 'name': 'mammala'},
]
}
query_params = {
"toplevel_only": False,
"query_scope": "local_only"
}
resp = das.query(query, query_params)
print(resp)
[]
Remote scope
query = {
'atom_type': 'link',
'type': 'Inheritance',
'targets': [
{'atom_type': 'node', 'type': 'Concept', 'name': 'human'},
{'atom_type': 'node', 'type': 'Concept', 'name': 'mammal'},
]
}
query_params = {
"toplevel_only": False
}
resp = das.query(query, query_params)
print(resp)
[
{
"handle": "c93e1e758c53912638438e2a7d7f7b7f",
"type": "Inheritance",
"template": ["Inheritance", "Concept", "Concept"],
"targets": [
{
"handle": "af12f10f9ae2002a1607ba0b47ba8407",
"type": "Concept",
"name": "human",
},
{
"handle": "bdfe4e7a431f73386f37c6448afe5840",
"type": "Concept",
"name": "mammal",
},
],
}
]
Remote scope synchronized with local Atoms
# Add a local Link
das.add_link({
'type': 'Inheritance',
'targets': [
{'type': 'Concept', 'name': 'monkey'},
{'type': 'Concept', 'name': 'mammal'}
]
})
query = {
'atom_type': 'link',
'type': 'Inheritance',
'targets': [
{'atom_type': 'node', 'type': 'Concept', 'name': 'human'},
{'atom_type': 'node', 'type': 'Concept', 'name': 'mammal'},
]
}
query_params = {
"toplevel_only": False,
"query_scope": "synchronous_update"
}
resp = das.query(query, query_params)
print(resp)
[
{
"handle": "c93e1e758c53912638438e2a7d7f7b7f",
"type": "Inheritance",
"template": ["Inheritance", "Concept", "Concept"],
"targets": [
{
"handle": "af12f10f9ae2002a1607ba0b47ba8407",
"type": "Concept",
"name": "human",
},
{
"handle": "bdfe4e7a431f73386f37c6448afe5840",
"type": "Concept",
"name": "mammal",
},
],
},
{
"handle": "f31dfe97db782e8cec26de18dddf8965",
"type": "Inheritance",
"template": ["Inheritance", "Concept", "Concept"],
"targets": [
{
"handle": "1cdffc6b0b89ff41d68bec237481d1e1",
"type": "Concept",
"name": "monkey",
},
{
"handle": "bdfe4e7a431f73386f37c6448afe5840",
"type": "Concept",
"name": "mammal",
},
],
},
]
Tests
You can run the command below to run the unit tests
make test-unit
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file hyperon_das-0.3.15.tar.gz
.
File metadata
- Download URL: hyperon_das-0.3.15.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a101979c3115f6f476b718ca82722316942fa90afce0ae089657a967f5c9fd68 |
|
MD5 | eb03da4414fbda0e6f99f8f9da2e5efd |
|
BLAKE2b-256 | b6c4e1d7cfec479b82bb2905130c7333296b51296fb5cffe0f6d2efbfa6cd4e8 |
File details
Details for the file hyperon_das-0.3.15-py3-none-any.whl
.
File metadata
- Download URL: hyperon_das-0.3.15-py3-none-any.whl
- Upload date:
- Size: 20.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.1 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 134385748229617a7700c6b37b07c98bc355d9e3963cf7d51a6d2190bfd1429e |
|
MD5 | 852540f2fa58b679f39dffffc2e7e278 |
|
BLAKE2b-256 | c2be886d4d745013a94f3518ccd2554d7ff65fa838a41a61010bc2f21c2d3de1 |