-
Notifications
You must be signed in to change notification settings - Fork 2
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
1 parent
9389264
commit b21d068
Showing
1 changed file
with
33 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from src import yodict | ||
from src.eyo import Eyo | ||
from src.model import yoModel | ||
from tqdm import tqdm | ||
from typing import Tuple, List | ||
|
||
|
||
class Baseline(yoModel): | ||
|
||
def __init__(self) -> None: | ||
super().__init__() | ||
|
||
yo_dict = yodict.get_safe() | ||
self.model = Eyo(yo_dict) | ||
|
||
def _predict(self, text: str) -> List[Tuple[int, int]]: | ||
"""Fuctuinon for yoword substring predictions by single string""" | ||
res = [] | ||
for replacement in self.model.lint(text): | ||
start_word = replacement.position.index | ||
end_word = start_word + len(replacement.after) | ||
res.append((start_word, end_word)) | ||
return res | ||
|
||
def predict(self, data: List[List[str]], show_progress: bool= False) -> List[List[Tuple[int, int]]]: | ||
"""Function for yoword substring predictions""" | ||
iter_data = data | ||
|
||
if show_progress: | ||
iter_data = tqdm(data, desc="Predcit") | ||
|
||
res = [self._predict(text) for text in iter_data] | ||
return res |