Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cmungall committed May 31, 2024
1 parent a4018f4 commit d995397
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/oaklib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3503,7 +3503,7 @@ def _is_uri_or_curie(v):

# batch query results: this allows us to produce buffered output
# for a long-running query
for row_it in chunk(impl.onto_query(query, prefixes=prefixes)):
for row_it in chunk(impl.query(query, prefixes=prefixes)):
rows = []
# collect rows in batch, and set label_fields if not already set
for r in row_it:
Expand Down
14 changes: 13 additions & 1 deletion src/oaklib/query.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""Representation and execution of complex boolean queries.
See also `<https://incatools.github.io/ontology-access-kit/howtos/use-oak-expression-language.html>`_.
"""

import itertools
import logging
import re
Expand Down Expand Up @@ -38,13 +43,19 @@


class OperatorEnum(str, Enum):
"""Boolean operators for queries."""

AND = "and"
OR = "or"
NOT = "not"


class FunctionEnum(str, Enum):
"""Enumeration of types of functions for queries."""

ANCESTOR = "anc"
"""Ancestor query."""

DESCENDANT = "desc"
SUBCLASS = "sub"
CHILD = "child"
Expand All @@ -53,6 +64,7 @@ class FunctionEnum(str, Enum):
MRCA = "mrca"
NON_REDUNDANT = "nr"
GAP_FILL = "gap_fill"
QUERY = "query"


class Query(BaseModel):
Expand Down Expand Up @@ -576,7 +588,7 @@ def chain_results(v):
query_terms = query_terms[1:]
chain_results(eval(expr, {"impl": adapter, "terms": results})) # noqa
elif term.startswith(".query"):
# arbitrary SPARQL query
# arbitrary SPARQL or SQL query (implementation specific)
params = _parse_params(term)
prefixes = params.get("prefixes", None)
query = query_terms[0]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,9 @@ def test_query(self):
reader = csv.DictReader(file, delimiter="\t")
rows = [row for row in reader]
for e in expected:
self.assertIn(e, rows)
self.assertIn(
e, rows, f"Expected {expected} for {query} in {adapter} with args {args}"
)
# for case in cases:
# self.assertIn(case, rows)

Expand Down

0 comments on commit d995397

Please sign in to comment.