Skip to content

Commit

Permalink
Merge pull request #42 from INCATools/search
Browse files Browse the repository at this point in the history
Refactored search
  • Loading branch information
cmungall authored Apr 28, 2022
2 parents c41c8f5 + 3593ed5 commit c134ea5
Show file tree
Hide file tree
Showing 33 changed files with 789 additions and 107 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ test:

## Compiled

MODELS = ontology_metadata obograph validation_datamodel summary_statistics_datamodel lexical_index mapping_rules_datamodel text_annotator search_results oxo taxon_constraints similarity
MODELS = ontology_metadata obograph validation_datamodel summary_statistics_datamodel lexical_index mapping_rules_datamodel text_annotator search_results oxo taxon_constraints similarity search_datamodel

pyclasses: $(patsubst %, src/oaklib/datamodels/%.py, $(MODELS))
jsonschema: $(patsubst %, src/oaklib/datamodels/%.schema.json, $(MODELS))
Expand Down
2 changes: 2 additions & 0 deletions docs/datamodels/funowl/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. funowl:

# FunOwl

FunOwl provided an OWL axiom-oriented datamodel, contrasting from a more graph-oriented data scientist oriented data model
Expand Down
2 changes: 2 additions & 0 deletions docs/datamodels/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ not need this.
:caption: Contents:

ontology-metadata/index
search/index
obograph/index
sssom/index
funowl/index
Expand All @@ -31,3 +32,4 @@ not need this.
text-annotator/index



2 changes: 2 additions & 0 deletions docs/intro/tutorial04.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ To illustrate this we will first introduce the :ref:`OboGraphInterface` which us
OboGraphs
---------

See `OboGraph Datamodel <https://incatools.github.io/ontology-access-kit/datamodels/obograph/index.html>`_

In this datamodel, an ontology is conceived of as a Graph, with a graph consisting of

- nodes
Expand Down
6 changes: 4 additions & 2 deletions docs/intro/tutorial05.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Command Line Usage
runoak -i obolibrary:fbbt.obo viz FBbt:00004751 -p i,p -o wing-vein.png
Then open wing-vein.png
Then open the file wing-vein.png using a tool such as Preview, or in a web browser.

If you omit the --output option then the png will be written to a temp file and immediately opened:

Expand All @@ -26,7 +26,9 @@ If you omit the --output option then the png will be written to a temp file and
How this works
---------------

- First,
- First, the :ref:`OboGraphInterface` is invoked to query all ancestors of the term
- in this case the implementation is :ref:`pronto` plus graph walking code
- after an obograph is generated this is passed to the obographviz library

Programmatic usage
---------------
Expand Down
9 changes: 7 additions & 2 deletions docs/intro/tutorial06.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
Part 6: Working With OWO
Part 6: Working With OWL
=====================

.. warning ::
this functionality is not available until v0.3.0
we are waiting for one rdflib PR (https://github.com/RDFLib/rdflib/pull/1686) to be merged...
OAK comes bundled with the `funowl <https://github.com/hsolbrig/funowl/>`_ library

TODO: funowl is not yet bundled, we are waiting for one rdflib PR (https://github.com/RDFLib/rdflib/pull/1686) to be merged...

OWL Datamodel
--------------

See :ref:`funowl`

OwlInterface
------------
17 changes: 16 additions & 1 deletion docs/intro/tutorial07.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,17 @@
Part 7: SQLite files
=============
=============

Download a SQLite file
----------------

Query
------

Building your own SQLite files
-------------------

Python
------

Other RDBMSs
------------
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SPARQLWrapper = "^2.0.0"
SQLAlchemy = "^1.4.32"
linkml-runtime = "^1.2.3"
networkx = "^2.7.1"
sssom = "^0.3.7"
sssom = "^0.3.8"
ratelimit = "^2.2.1"
appdirs = "^1.4.4"

Expand Down
4 changes: 3 additions & 1 deletion src/oaklib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import click
import rdflib
from linkml_runtime.dumpers import yaml_dumper, json_dumper
from oaklib.datamodels.search import create_search_configuration
from oaklib.datamodels.validation_datamodel import ValidationConfiguration
from oaklib.implementations.aggregator.aggregator_implementation import AggregatorImplementation
from oaklib.implementations.sqldb.sql_implementation import SqlImplementation
Expand Down Expand Up @@ -179,7 +180,8 @@ def search(terms, output: str):
impl = settings.impl
if isinstance(impl, SearchInterface):
for t in terms:
for curie_it in chunk(impl.basic_search(t)):
cfg = create_search_configuration(t)
for curie_it in chunk(impl.basic_search(cfg.search_terms[0], config=cfg)):
logging.info('** Next chunk:')
for curie, label in impl.get_labels_for_curies(curie_it):
print(f'{curie} ! {label}')
Expand Down
Empty file.
75 changes: 75 additions & 0 deletions src/oaklib/datamodels/search.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
from dataclasses import dataclass
from typing import List

from deprecated.classic import deprecated
from oaklib.datamodels.search_datamodel import SearchBaseConfiguration, SearchProperty, SearchTermSyntax
from oaklib.datamodels.vocabulary import LABEL_PREDICATE, SYNONYM_PREDICATES
from oaklib.types import PRED_CURIE

DEFAULT_SEARCH_PROPERTIES = [SearchProperty.LABEL, SearchProperty.ALIAS]

def create_search_configuration(term: str) -> "SearchConfiguration":

if len(term) > 1:
prop = term[0]
code = term[1]
rest = term[2:]
if code == '~':
cfg = SearchBaseConfiguration([rest],
is_partial=True)
syntax = SearchTermSyntax.PLAINTEXT
elif code == '/':
cfg = SearchBaseConfiguration([rest],
syntax=SearchTermSyntax.REGULAR_EXPRESSION)
elif code == '=':
cfg = SearchBaseConfiguration([rest],
is_partial=False)
elif code == '^':
cfg = SearchBaseConfiguration([rest],
syntax=SearchTermSyntax.STARTS_WITH)
else:
cfg = SearchBaseConfiguration([term], properties=DEFAULT_SEARCH_PROPERTIES)
prop = None
if prop:
if prop == 't':
props = [SearchProperty.LABEL, SearchProperty.ALIAS]
elif prop == '.':
props = [SearchProperty.ANYTHING]
elif prop == 'l':
props = [SearchProperty.LABEL]
else:
raise ValueError(f'Unknown property code: {prop}')
cfg.properties = [SearchProperty(p) for p in props]
return cfg
else:
return SearchConfiguration([term], properties=DEFAULT_SEARCH_PROPERTIES)

def search_properties_to_predicates(props: List[SearchProperty]) -> List[PRED_CURIE]:
preds = set()
for p in props:
if p == SearchProperty(SearchProperty.LABEL):
preds.add(LABEL_PREDICATE)
elif p == SearchProperty(SearchProperty.ALIAS):
preds.update(SYNONYM_PREDICATES + [LABEL_PREDICATE])
else:
raise ValueError(p)
return list(preds)

@dataclass
class SearchConfiguration(SearchBaseConfiguration):
"""
Parameters for altering behavior of search
.. note ::
many of these parameters are not yet implemented
"""

@deprecated()
def use_label_only(self) -> "SearchConfiguration":
self.include_label = False
self.include_id = False
self.include_definition = False
self.include_aliases = False
self.properties = [SearchProperty.LABEL]
return self
Loading

0 comments on commit c134ea5

Please sign in to comment.