feat(reader): multi-word and phrasal verb detector in reader (Task 14)
This commit is contained in:
1 parent
37a1f1ab35
commit
1c3f03a64c
9 files changed
+738
-16
No files matched your search
+30
@@ -30,6 +30,8 @@ from app.export import export_csv, export_json, export_anki_tsv, export_markdown
|
||||
from app.srs import calculate_sm2, generate_quiz_options, build_activity_heatmap, calculate_cefr_level
|
||||
from app.reader import parse_epub, parse_text, parse_pdf, count_words
|
||||
from app.ai import translate_sentence_ai, get_ollama_status
|
||||
from app.phrasal import detect_phrasal_verb
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -299,6 +301,7 @@ async def api_change_password(req: ChangePasswordRequest, user: dict = Depends(r
|
||||
async def api_lookup(
|
||||
term: Optional[str] = None,
|
||||
q: Optional[str] = None,
|
||||
context: Optional[str] = None,
|
||||
user: dict = Depends(require_user)
|
||||
):
|
||||
query_str = (term or q or "").strip()
|
||||
@@ -319,9 +322,36 @@ async def api_lookup(
|
||||
data["in_library"] = False
|
||||
data["library_card"] = None
|
||||
|
||||
# Multi-Word & Phrasal Verb Detection
|
||||
data["phrasal_verb"] = None
|
||||
if context:
|
||||
pv = detect_phrasal_verb(
|
||||
sentence=context,
|
||||
target_word=query_str,
|
||||
user_id=user["id"],
|
||||
conn=conn,
|
||||
)
|
||||
if pv and pv["term"].lower() != query_str.lower():
|
||||
data["phrasal_verb"] = pv
|
||||
|
||||
return data
|
||||
|
||||
|
||||
@app.get("/api/detect-phrasal-verb")
|
||||
async def api_detect_phrasal_verb(
|
||||
sentence: str = Query(..., min_length=1),
|
||||
word: str = Query(..., min_length=1),
|
||||
user: dict = Depends(require_user)
|
||||
):
|
||||
"""
|
||||
Analyzes sentence context around word to detect phrasal verbs, idioms, and collocations.
|
||||
"""
|
||||
with get_db() as conn:
|
||||
pv = detect_phrasal_verb(sentence=sentence, target_word=word, user_id=user["id"], conn=conn)
|
||||
return {"detected": bool(pv), "phrasal_verb": pv}
|
||||
|
||||
|
||||
|
||||
|
||||
@app.api_route("/api/audio", methods=["GET", "HEAD"])
|
||||
async def api_audio_proxy():
|
||||
|
||||
Reference in new issue
Block a user