Searching the Eratos Semantic Web
This page describes how you can search the Eratos platform using the SDK
- The Eratos SDK is a powerful data toolkit that empowers users to dynamically search and query the Eratos Semantic Web.
- Resources' metadata can be inspected to understand its properties.
- You can search the Semantic web to find out things such as what spaces you're a part of, the blocks you can access, and what resources contain certain keywords.
How to Explore Eratos
Once you have an Eratos Resource you wish to explore and understand, you can extract the desired metadata of a given Eratos resource using the props
and prop
functions which is used in the following python example:
#Eratos adapter and credentials system
from eratos.creds import AccessTokenCreds
from eratos.adapter import Adapter
import pandas as pd
import pprint
from getpass import getpass
eratos_id = getpass('Enter the eratos key id:')
eratos_secret = getpass('Enter the eratos secret:')
ecreds = AccessTokenCreds(
eratos_id,
eratos_secret
)
eadapter = Adapter(ecreds)
ern = 'ern:e-pn.io:resource:eratos.blocks.silo.maxtemperature'
#Read in Climate Dataset Resource
dataset_block = eadapter.Resource(ern=ern)
print('Climate dataset block metadata: Describes the Dataset block:')
pprint.pprint(dataset_block.props())
print('Extracting primary')
pprint.pprint(dataset_block.prop('primary'))
dataset_metadata = eadapter.Resource(ern=dataset_block.prop('primary'))
print('\n Climate dataset resource metadata: Describes the Dataset Resource:')
pprint.pprint(climate_dataset_metadata.props())
reticulate::use_condaenv("eratoslabs", required=TRUE)
library(reticulate)
library(rjson)
eratosAdapter <- reticulate::import("eratos.adapter")
eratosCreds <- reticulate::import("eratos.creds")
path_to_eratos_creds = "C:/Users/Quinten/Documents/Eratos_tok/mycreds.json"
creds = fromJSON(file = path_to_eratos_creds)
at <- eratosCreds$AccessTokenCreds(creds$key[1], creds$secret[1])
eadapter <- eratosAdapter$Adapter(at)
ern = 'ern:e-pn.io:resource:eratos.blocks.silo.maxtemperature'
#Read in Climate Dataset Resource
dataset_block = eadapter$Resource(ern=ern)
print('Climate dataset block metadata: Describes the Dataset block:')
print(dataset_block$props())
print('Extracting primary')
print(dataset_block$prop('primary'))
dataset_metadata = eadapter$Resource(ern=dataset_block$prop('primary'))
print('\n Climate dataset resource metadata: Describes the Dataset Resource:')
pprint.pprint(climate_dataset_metadata$props())
How to Search the Eratos Semantic Web
To discover and search what is currently in the system, and the ERNs that are associated with that resources you can use the Eratos Search functionality using the search_resources()
function:
search_resources()
returns a list of matching ERNs (can be empty) according to specific query parameters. Must run with an initialized adapter with valid credentials.
resource_list = eadpater.search_resources(
return_limit=-1,
**kwargs)
Where,
return_limit
: A set return limit (integer) on the search. (Default value is -1)kwargs
: argsquery
= A string to query (ex. '*')scope
= 3 potential values, Public, Private, Any. 'Public' searches specifically on resources that are available to all Eratos Users, whereas 'Private' searches on resources in spaces that you have private access too.limit
= An integer depicting the number of resources to limit the return (ex. 20)start
= An integer depicting the start index (ex. 0)exclude
= A list of ERNs to exclude.type
= A list of resource types to search for.excludeType
= A list of types to exclude from the search.owner
= A list of owner ERN's to search against.facets
= A list of facets to search against.geom
= A geospatial geometry to search within.
Search Examples | What Spaces am I a part of?
from eratos.creds import AccessTokenCreds
from eratos.adapter import Adapter
import json
creds_path = "PATH_TO_CREDS_AS_JSON_FILE"
# Opening JSON file
f = open(creds_path)
# returns JSON object as
# a dictionary
creds = json.load(f)
ecreds = AccessTokenCreds(
creds['key'],
creds['secret']
)
eadapter = Adapter(ecreds)
space_Res_list = eadapter.search_resources(type="ern:e-pn.io:schema:space")
for space in space_Res_list:
#print(space.props())
print(space.ern(),space.prop('name'))
reticulate::use_condaenv("eratoslabs", required=TRUE)
library(reticulate)
library(rjson)
eratosAdapter <- reticulate::import("eratos.adapter")
eratosCreds <- reticulate::import("eratos.creds")
path_to_eratos_creds = "PATH_TO_CREDS_AS_JSON_FILE"
creds = fromJSON(file = path_to_eratos_creds)
at <- eratosCreds$AccessTokenCreds(creds$key[1], creds$secret[1])
ad <- eratosAdapter$Adapter(at)
space_Res_list = eadapter$search_resources(type="ern:e-pn.io:schema:space")
for (space in space_Res_list){
#print(space$props())
print(space$ern(),space$prop('name'))
}
Search Examples | What Blocks can I access? (Private, Public)
Private
block_Res_list = eadapter.search_resources(type="ern:e-pn.io:schema:block",
scope = "Private")
for block in block_Res_list:
#print(block.props())
print(block.ern(),block.prop('name'))
block_Res_list = eadapter$search_resources(type="ern:e-pn.io:schema:block",
scope = "Private")
for (block in block_Res_list){
#print(block$props())
print(block$ern(),block$prop('name'))
}
Public
block_Res_list = eadapter.search_resources(type="ern:e-pn.io:schema:block",
scope = "Public")
for block in block_Res_list:
#print(block.props())
print(block.ern(),block.prop('name'))
block_Res_list = eadapter$search_resources(type="ern:e-pn.io:schema:block",
scope = "Public")
for (block in block_Res_list){
#print(block$props())
print(block$ern(),block$prop('name'))
}
Search Examples | String Search (Frost, Fire)
Frost
block_Res_list = eadapter.search_resources(
scope = "Public",
query = "Frost")
for block in block_Res_list:
#print(block.props())
print(block.ern(),block.prop('name'))
block_Res_list = eadapter$search_resources(scope = "Public",
query = "Frost")
for (block in block_Res_list){
#print(block$props())
print(block$ern(),block$prop('name'))
}
Frost Blocks
block_Res_list = eadapter.search_resources(type="ern:e-pn.io:schema:block",
scope = "Public",
query = "Frost")
for block in block_Res_list:
#print(block.props())
print(block.ern(),block.prop('name'))
block_Res_list = eadapter$search_resources(type="ern:e-pn.io:schema:block",
scope = "Public",
query = "Frost")
for (block in block_Res_list){
#print(block$props())
print(block$ern(),block$prop('name'))
}
Fire Blocks
block_Res_list = eadapter.search_resources(type="ern:e-pn.io:schema:block",
scope = "Public"
,query = "Fire")
for block in block_Res_list:
#print(block.props())
print(block.ern(),block.prop('name'))
block_Res_list = eadapter$search_resources(type="ern:e-pn.io:schema:block",
scope = "Public",
query = "Fire")
for (block in block_Res_list){
#print(block$props())
print(block$ern(),block$prop('name'))
}
Updated 8 days ago