Implement auto-tagging (amenities, location features, condition/legal), content quality scoring with moderation integration, and FastAPI endpoints for single and batch text analysis. Uses underthesea for Vietnamese tokenization/POS when available, with regex fallback. Co-Authored-By: Paperclip <noreply@paperclip.ing>
28 lines
892 B
Python
28 lines
892 B
Python
from fastapi import APIRouter
|
|
|
|
from app.models.nlp import (
|
|
BatchAnalyzeRequest,
|
|
BatchAnalyzeResponse,
|
|
NLPAnalyzeRequest,
|
|
NLPAnalyzeResponse,
|
|
)
|
|
from app.services.nlp_service import nlp_service
|
|
|
|
router = APIRouter(prefix="/nlp", tags=["NLP"])
|
|
|
|
|
|
@router.post("/analyze", response_model=NLPAnalyzeResponse)
|
|
def analyze(req: NLPAnalyzeRequest) -> NLPAnalyzeResponse:
|
|
"""Analyze Vietnamese property description: auto-tag, quality score, tokenize."""
|
|
return nlp_service.analyze(req)
|
|
|
|
|
|
@router.post("/batch-analyze", response_model=BatchAnalyzeResponse)
|
|
def batch_analyze(req: BatchAnalyzeRequest) -> BatchAnalyzeResponse:
|
|
"""Batch analyze multiple property descriptions."""
|
|
results = [
|
|
nlp_service.analyze(NLPAnalyzeRequest(text=t, include_moderation=req.include_moderation))
|
|
for t in req.texts
|
|
]
|
|
return BatchAnalyzeResponse(results=results)
|