Skip to content

Commit

Permalink
Add example of data sources and fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Dec 27, 2024
1 parent 0cfb8b2 commit b0a8e98
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
4 changes: 2 additions & 2 deletions examples/return_studies.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
},
{
"name": "Imaging Method",
"value": "light sheet fluorescence microscopy, spim",
"operator": "equals",
"value": "light sheet fluorescence microscopy",
"operator": "contains",
"resource": "project",
},
],
Expand Down
44 changes: 25 additions & 19 deletions examples/search_values_for_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,30 @@
)

resp = requests.get(url=attrs_url)
res = json.loads(resp.text)
ress = json.loads(resp.text)
# a list contains the available attributes
attributes = res.get("image")
logging.info("Number of available attributes for images: %s" % len(attributes)) # noqa
for res in ress:
data_source=res.get("data_source")
if not data_source:
continue
print ("Checking data source: %s "%data_source)
attributes = res.get("image")
logging.info("Number of available attributes for images: %s" % len(attributes)) # noqa

"""
The user can get the available values for the "Organism" attribute
and the number of images for each value
"""
key = "Organism"
values_attr_url = "{base_url}{image_key_values}?key={key}".format(
base_url=base_url, image_key_values=image_key_values, key=key
)
resp = requests.get(url=values_attr_url)
res = json.loads(resp.text)
# a list contains dicts of the available values with the number of images
buckets = res.get("data")
logging.info("Number of available buckets for attribute %s is %s" % (key, len(buckets)))
# The first bucket
for bucket in buckets:
logging.info("Bucket details: %s " % bucket)
"""
The user can get the available values for the "Organism" attribute
and the number of images for each value
"""
key = "Organism"
values_attr_url = "{base_url}{image_key_values}?key={key}&data_source={data_source}".format(
base_url=base_url, image_key_values=image_key_values, key=key, data_source=data_source
)
print (values_attr_url)
resp = requests.get(url=values_attr_url)
res = json.loads(resp.text)
# a list contains dicts of the available values with the number of images
buckets = res.get("data")
logging.info("Number of available buckets for attribute %s is %s" % (key, len(buckets)))
# The first bucket
for bucket in buckets:
logging.info("Bucket details: %s " % bucket)
31 changes: 31 additions & 0 deletions examples/use_data_sources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import logging
import json
import requests

from utils import base_url

'''
Call the search engine to determine the available data sources'''

data_source_url = "{base_url}resources/data_sources/".format(
base_url=base_url)

logging.info(" getting the available data sources")
resp = requests.get(url=data_source_url)
data_sources = json.loads(resp.text)
logging.info("There are %s data sources available, i.e. %s "%(len(data_sources), ', '.join(data_sources)))
'''
"The data source can be linked to queries to return search results from the specified data source.
For example, the user can limit the search results to "bia" data source when querying the searchengine for "Organism" and "homo sapiens"
'''

key="Organism"
value="homo sapiens"
data_source="bia"
search_url= "{base_url}resources/image/search/?key={key}&value={value}&data_source={data_source}".format(
base_url=base_url, key=key, value=value, data_source=data_source)

resp = requests.get(url=search_url)
results = json.loads(resp.text)

logging.info("The size of the returned results is %s" %results.get("results").get("size"))
3 changes: 2 additions & 1 deletion examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
# url to get the next page for a query, bookmark is needed
image_page_ext = "/resources/image/searchannotation_page/"
# search engine url
base_url = "http://127.0.0.1:5577/api/v1/"
# base_url = "http://127.0.0.1:5577/api/v1/"
base_url = "http://idr-testing.openmicroscopy.org/searchengine2/api/v1/"


logging.basicConfig(stream=sys.stdout, level=logging.INFO)
Expand Down

0 comments on commit b0a8e98

Please sign in to comment.