Skip to content

Commit

Permalink
fix pre commit issues
Browse files Browse the repository at this point in the history
  • Loading branch information
khaledk2 committed Dec 27, 2024
1 parent b0a8e98 commit 55a08be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 22 deletions.
23 changes: 16 additions & 7 deletions examples/search_values_for_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,36 @@
ress = json.loads(resp.text)
# a list contains the available attributes
for res in ress:
data_source=res.get("data_source")
data_source = res.get("data_source")
if not data_source:
continue
print ("Checking data source: %s "%data_source)
print("Checking data source: %s " % data_source)
attributes = res.get("image")
logging.info("Number of available attributes for images: %s" % len(attributes)) # noqa
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}&data_source={data_source}".format(
base_url=base_url, image_key_values=image_key_values, key=key, data_source=data_source
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)
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)))
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)
38 changes: 23 additions & 15 deletions examples/use_data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@

from utils import base_url

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

data_source_url = "{base_url}resources/data_sources/".format(
base_url=base_url)
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"
'''
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)
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"))
logging.info(
"The size of the returned results is %s" % results.get("results").get("size")
)

0 comments on commit 55a08be

Please sign in to comment.