Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/datadoc/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,7 @@ def test_datadoc():
# Test load dict-representation of a dataset from the triplestore
SEM = ts.namespaces["sem"]
SEMDATA = ts.namespaces["semdata"]
ts.bind("par", "http://sintef.no/dlite/parser#")
iri = SEMDATA["SEM_cement_batch2/77600-23-001/77600-23-001_5kV_400x_m001"]
d = acquire(ts, iri, use_sparql=False)
assert d["@id"] == iri
Expand Down Expand Up @@ -886,6 +887,11 @@ def test_datadoc():
SEMDATA.SEM_cement_batch2,
]

# Search on criterion when the value is an individual
assert search(ts, criteria={"distribution.parser": "par:Hitachi"}) == [
SEMDATA["SEM_cement_batch2/77600-23-001/77600-23-001_5kV_400x_m001"],
]

title = "Nested series of SEM images of cement batch2"
dset = [SEMDATA.SEM_cement_batch2]
# Search with predefined keyword
Expand Down
10 changes: 8 additions & 2 deletions tripper/datadoc/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1466,7 +1466,7 @@ def make_query(
context = get_context(keywords=keywords)
context._create_caches() # pylint: disable=protected-access
expanded = context._expanded # pylint: disable=protected-access

# print("expanded", expanded)
# Add prefixes to triplestore
ts.namespaces.update(keywords.get_prefixes())

Expand Down Expand Up @@ -1506,6 +1506,8 @@ def add_crit(k, v, regex=False, s="iri"):
"""Add criteria to SPARQL query."""
nonlocal n
key = f"@{k[1:]}" if k.startswith("_") else k
# print("key", key)
# print("value", v)
if isinstance(v, list):
for ele in v:
add_crit(key, ele, regex=regex, s=s)
Expand Down Expand Up @@ -1539,7 +1541,7 @@ def add_crit(k, v, regex=False, s="iri"):
f"FILTER REGEX(STR(?{var}), {value}{flags_arg}) ."
)
else:
filters.append(f"FILTER(STR(?{var}) = {value}) .")
filters.append(f"FILTER(?{var} = {value}) .")

for k, v in criteria.items():
add_crit(k, v)
Expand All @@ -1558,6 +1560,10 @@ def add_crit(k, v, regex=False, s="iri"):
{where_statements}
}}
"""
# print("---")
# print(query)
# print("---")

return query


Expand Down
Loading