-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/type search #47
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dba47c3
Fix: key error
XanderVertegaal 962ce8a
New Aethel types in frontend
XanderVertegaal 94cf08f
Working frontend
XanderVertegaal 7daa935
Ugly, working backend
XanderVertegaal 26aedb3
Refactor filter signatures
XanderVertegaal e7099d4
Remove unnecessary pre-filtering
XanderVertegaal 703f350
Fix tests
XanderVertegaal 93990d9
Styling tweaks
XanderVertegaal 4e996d4
Correct table column header
XanderVertegaal b3fb33f
Use dict lookup instead of list
XanderVertegaal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that this pre-filtering loop is not necessary, and we can improve performance slightly by removing it. I compared word and type searches with and without this step using a bigger dataset (3000 samples). Word searches performed slightly better without the pre-filtering (0.04s) step than with it (0.05s), and the same is true for type searches (0.52s with pre-filtering => 0.42s without).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an added benefit, we can drop a lot of code taken from
aethel
insearch.py
.