entity.py
1 """ 2 Defines API paths for entity endpoints. 3 """ 4 5 from typing import List 6 7 from fastapi import APIRouter, Body 8 9 from .. import application 10 from ..route import EncodingAPIRoute 11 12 router = APIRouter(route_class=EncodingAPIRoute) 13 14 15 @router.get("/entity") 16 def entity(text: str): 17 """ 18 Applies a token classifier to text. 19 20 Args: 21 text: input text 22 23 Returns: 24 list of (entity, entity type, score) per text element 25 """ 26 27 return application.get().pipeline("entity", (text,)) 28 29 30 @router.post("/batchentity") 31 def batchentity(texts: List[str] = Body(...)): 32 """ 33 Applies a token classifier to text. 34 35 Args: 36 texts: list of text 37 38 Returns: 39 list of (entity, entity type, score) per text element 40 """ 41 42 return application.get().pipeline("entity", (texts,))