-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from INCATools/search
Refactored search
- Loading branch information
Showing
33 changed files
with
789 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
------------ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.