-
Notifications
You must be signed in to change notification settings - Fork 0
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 #47 from UUDigitalHumanitieslab/feature/type-search
Feature/type search
- Loading branch information
Showing
10 changed files
with
168 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,18 @@ | ||
from __future__ import annotations | ||
from typing import Iterable, Callable, Iterator | ||
from aethel.frontend import Sample | ||
from aethel.frontend import LexicalPhrase, LexicalItem | ||
from aethel.mill.types import type_repr | ||
|
||
# The following methods and classes have been extracted from aethel.scripts.search (not part of the published library), with some minor customisations / simplifications. | ||
|
||
def match_type_with_phrase(phrase: LexicalPhrase, type_input: str) -> bool: | ||
return type_input == type_repr(phrase.type) | ||
|
||
def search(bank: Iterable[Sample], query: Callable[[Sample], bool]) -> Iterator[Sample]: | ||
return filter(query, bank) | ||
|
||
def match_word_with_phrase(phrase: LexicalPhrase, word_input: str) -> bool: | ||
return any(match_word_with_item(item, word_input) for item in phrase.items) | ||
|
||
def in_lemma(query_string: str) -> Query: | ||
def f(sample: Sample) -> bool: | ||
return any( | ||
query_string.lower() in item.lemma.lower() | ||
for phrase in sample.lexical_phrases | ||
for item in phrase.items | ||
) | ||
|
||
return Query(f) | ||
|
||
|
||
def in_word(query_string: str) -> Query: | ||
def f(sample: Sample) -> bool: | ||
return any( | ||
query_string.lower() in item.word.lower() | ||
for phrase in sample.lexical_phrases | ||
for item in phrase.items | ||
) | ||
|
||
return Query(f) | ||
|
||
|
||
class Query: | ||
def __init__(self, fn: Callable[[Sample], bool]): | ||
self.fn = fn | ||
|
||
def __and__(self, other: Query) -> Query: | ||
def f(sample: Sample) -> bool: | ||
return self.fn(sample) and other.fn(sample) | ||
|
||
return Query(f) | ||
|
||
def __or__(self, other) -> Query: | ||
def f(sample: Sample) -> bool: | ||
return self.fn(sample) or other.fn(sample) | ||
|
||
return Query(f) | ||
|
||
def __invert__(self) -> Query: | ||
def f(sample: Sample) -> bool: | ||
return not self.fn(sample) | ||
|
||
return Query(f) | ||
|
||
def __xor__(self, other) -> Query: | ||
def f(sample: Sample) -> bool: | ||
return self.fn(sample) ^ other.fn(sample) | ||
|
||
return Query(f) | ||
|
||
def __call__(self, sample: Sample) -> bool: | ||
return self.fn(sample) | ||
def match_word_with_item(item: LexicalItem, word_input: str) -> bool: | ||
return ( | ||
word_input.lower() in item.lemma.lower() | ||
or word_input.lower() in item.word.lower() | ||
) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.search-button:not(:last-child) { | ||
margin-right: .5rem; | ||
} |
Oops, something went wrong.