Ejemplo n.º 1
0
def analyze_article(articles: List[Article]):
    ents = []
    for article in articles:
        doc = nlp(article.content)
        for ent in doc.ents:
            ents.append({"text": ent.text, "label": ent.label_})
    return {"ents": ents}
Ejemplo n.º 2
0
def analyze_article4(article: Article):
    """example to  run ML model of input given by body

    """
    ents =[]
    doc = nlp(article.content)
    for ent in doc.ents:
        ents.append({"text":ent.text,"label":ent.label_})

    return {"message": article.content,"comments": article.comments, "ents": ents}
Ejemplo n.º 3
0
def analyze_article (article_id:int,q:str=None):
    """Eample of path variable as input, article_id is required and q is optional

    """
    # also convert string to integer as it expects an interger
    cnt =0
    if q:
        doc = nlp(q)
        cnt = len(doc.ents)

    return {"article_id":article_id, "q":q, "count": cnt }
Ejemplo n.º 4
0
def display_main(articles: List[Article]):
    ents = []
    comments = []
    for article in articles:
        for comment in article.comment:
            comments.append(comment.upper())

        doc = nlp(article.content)
        for ent in doc.ents:
            ents.append({"text": ent.text, "label": ent.label_})

    return {"comments": comments, "entities": ents}
Ejemplo n.º 5
0
def analyze_article5(articles: List[Article]):
    """example to  run *ML model* of **List of inputs**
        * comment1
        * comment2

    """
    ents =[]
    for article in articles:
        doc = nlp(article.content)
        for ent in doc.ents:
            ents.append({"text":ent.text,"label":ent.label_})

    return {"message": article.content,"comments": article.comments, "ents": ents}
Ejemplo n.º 6
0
def analyze_article(articles: List[Article]):
    """
    Analyze an article and extract entities with ⚡spaCy⚡

    Statistical models *will* have **errors**.

    * Extract entities
    * Display comments
    """
    ents = []
    for article in articles:
        doc = nlp(article.content)
        for ent in doc.ents:
            ents.append({"entity": ent.text, "label": ent.label_})

    return {"entities": ents}
Ejemplo n.º 7
0
def analyze_article(articles: List[Article]):
    """ Analyze an article and extract entities with 🌟 spaCy 🌟
    Statistical Models *will* have **errors**

    * Extract Entities
    * Scream Comments
    """
    ents=[]
    comments=[]

    for article in articles:
        for comment in article.comments:
            comments.append(comment.upper())
        doc = nlp(article.content)
        for ent in doc.ents:
            ents.append({"text":ent.text, "label":ent.label_})
    return{"ents":ents,"comments":comments}

    # return {"message":article.content,"comments":article.comments,"ents":ents}