-
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.
- Loading branch information
Showing
14 changed files
with
86 additions
and
66 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,7 +1,5 @@ | ||
from .indexer import InvertedIndex | ||
from .main import naivesearch | ||
|
||
__all__ = [ | ||
'InvertedIndex' | ||
'naivesearch' | ||
] |
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,8 +1,11 @@ | ||
from .inverted_index import Chunker, InvertedIndex, Reader | ||
from .inverted_index import InvertedIndex, Reader | ||
from .preprocess_composer import Formatter, Chunker, compose_preprocessors | ||
|
||
|
||
__all__ = [ | ||
'Chunker', | ||
'compose_preprocessors', | ||
'Formatter', | ||
'InvertedIndex', | ||
'Reader', | ||
] |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from typing import Callable, List, Optional, Protocol, Type | ||
|
||
|
||
class Formatter(Protocol): | ||
def __init__(self, other: Optional['Formatter'] = None, **kwargs): | ||
... | ||
|
||
def __call__(self, x: str) -> str: | ||
... | ||
|
||
|
||
class Chunker(Protocol): | ||
def __init__(self, formatter: Optional[Formatter]): | ||
... | ||
|
||
def __call__(self, x: str) -> List[str]: | ||
... | ||
|
||
|
||
class Converter(Protocol): | ||
def __init__(self, chunker: Chunker): | ||
... | ||
|
||
def __call__(self, x: str) -> List[str]: | ||
... | ||
|
||
|
||
def compose_preprocessors( | ||
converter: Type[Converter], | ||
chunker: Type[Chunker], | ||
*formatters: Callable[..., Formatter], | ||
) -> Converter: | ||
result = None | ||
for x in reversed(formatters): | ||
result = x(result) | ||
return converter(chunker(result)) |
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,11 @@ | ||
from .chunker import CharacterChunker | ||
from .converter import BigramConverter | ||
from .formatter import UnicodeNormalizer, LowerCaseNormalizer | ||
|
||
|
||
__all__ = [ | ||
'BigramConverter', | ||
'CharacterChunker', | ||
'LowerCaseNormalizer', | ||
'UnicodeNormalizer', | ||
] |
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,11 @@ | ||
from typing import List, Optional | ||
|
||
from naivesearch.indexer import Formatter | ||
|
||
|
||
class CharacterChunker: | ||
def __init__(self, formatter: Optional[Formatter]): | ||
self.formatter = formatter | ||
|
||
def __call__(self, x: str) -> List[str]: | ||
return list(self.formatter(x) if self.formatter else x) |
4 changes: 3 additions & 1 deletion
4
naivesearch/indexer/converter.py → naivesearch/preprocessors/converter.py
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,10 +1,12 @@ | ||
from typing import List | ||
|
||
from naivesearch.indexer import Chunker | ||
|
||
|
||
class BigramConverter: | ||
def __init__(self, chunker: Chunker): | ||
self.chuker = chunker | ||
|
||
def __call__(self, x: str): | ||
def __call__(self, x: str) -> List[str]: | ||
s = self.chuker(x) | ||
return s + [''.join(z) for z in zip(s[0:], s[1:])] |
10 changes: 2 additions & 8 deletions
10
naivesearch/indexer/formatter.py → naivesearch/preprocessors/formatter.py
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
3 changes: 0 additions & 3 deletions
3
naivesearch/indexer/test_chunker.py → naivesearch/preprocessors/test_chunker.py
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
3 changes: 0 additions & 3 deletions
3
naivesearch/indexer/test_converter.py → naivesearch/preprocessors/test_converter.py
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
2 changes: 0 additions & 2 deletions
2
naivesearch/indexer/test_formatter.py → naivesearch/preprocessors/test_formatter.py
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