-
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
1 parent
2706981
commit c3bcee5
Showing
11 changed files
with
509 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import abc | ||
import typing | ||
|
||
|
||
class Paradigms(abc.ABC): | ||
@abc.abstractmethod | ||
def query(self, s: str) -> typing.Tuple[str, list[str]]: ... | ||
|
||
def prepare_args(self, s: str) -> typing.Tuple[str, list[str]]: | ||
xs = [x.strip() for x in s.split(",") if len(x) > 0] | ||
baseform, pos = split_word_and_pos(xs[0]) | ||
xs[0] = f"{baseform}:{pos}" | ||
return baseform, xs | ||
|
||
|
||
def split_word_and_pos(s: str) -> typing.Tuple[str, str]: | ||
n = s.find(":") | ||
if n == -1: | ||
raise NoPartOfSpeechOnBaseform() | ||
word = s[:n].strip() | ||
pos = s[n + 1 :].strip() | ||
return word, pos | ||
|
||
|
||
class NoPartOfSpeechOnBaseform(Exception): | ||
"""The baseform must contain a Part-of-Speech tag.""" |
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,22 @@ | ||
import sys | ||
import typing | ||
|
||
from opentelemetry import trace | ||
from sblex.application.queries import Paradigms | ||
from sblex.fm import FmRunner | ||
|
||
|
||
class FmRunnerParadigms(Paradigms): | ||
def __init__(self, *, fm_runner: FmRunner) -> None: | ||
super().__init__() | ||
self.fm_runner = fm_runner | ||
|
||
def query(self, s: str) -> typing.Tuple[str, list]: | ||
with trace.get_tracer(__name__).start_as_current_span( | ||
sys._getframe().f_code.co_name | ||
) as _process_api_span: | ||
baseform, words = self.prepare_args(s) | ||
print(f"{baseform=}, {words=}") | ||
print(f"{type(self.fm_runner)=}") | ||
result = self.fm_runner.paradigms(words) | ||
return baseform, 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,18 @@ | ||
import sys | ||
|
||
from fastapi import APIRouter, Depends | ||
from opentelemetry import trace | ||
from sblex.application.queries import Paradigms | ||
from sblex.saldo_ws import deps | ||
|
||
router = APIRouter() | ||
|
||
|
||
@router.get("/json/{words}", response_model=list[str]) | ||
async def get_para_json(words: str, paradigms: Paradigms = Depends(deps.get_paradigms)): # noqa: B008 | ||
with trace.get_tracer(__name__).start_as_current_span( | ||
sys._getframe().f_code.co_name | ||
) as _process_api_span: | ||
print(f"{words=}") | ||
_baseform, result = paradigms.query(words) | ||
return 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
Oops, something went wrong.