コード例 #1
0
def sentence_has_context(sentence) -> bool:
    if type(sentence) == spacy.tokens.Span:
        nlp = NLPConn.get_nlp_conn()
        sentence = nlp(sentence.string)

    sent_subjs = [t for t in sentence if t.dep_ == 'nsubj']
    return any([subj for subj in sent_subjs if subj.pos_ == "PROPN"])
コード例 #2
0
def get_has_contradictatory(sentence) -> int:
    if type(sentence) == spacy.tokens.Span:
        nlp = NLPConn.get_nlp_conn()
        sentence = nlp(sentence.string)

    contradictatory_matcher = ContradictatoryMatcher.get_contradicatory_matcher(
    )
    return int(any(contradictatory_matcher(sentence)))
def get_contradicatory_matcher():
    global matcher
    if matcher is None:
        nlp = NLPConn.get_nlp_conn()
        matcher = PhraseMatcher(nlp.vocab)
        patterns = [nlp.make_doc(phrase) for phrase in contradictatory_phrases]
        matcher.add("ContradictoryTokens", None, *patterns)
    return matcher
コード例 #4
0
=================
"""
import os

import spacy
from spacy.tokens import Span, Token

from trivia_generator.web_scraper import Article
from trivia_generator.web_scraper.WebScraper import get_page_by_random
from trivia_generator.TUnit import TUnit

from nlp_helpers import features
from nlp_helpers import NLPConn
from nlp_helpers import ContradictatoryMatcher

nlp = NLPConn.get_nlp_conn()
contradictatory_matcher = ContradictatoryMatcher.get_contradicatory_matcher()


def create_TUnits(article: Article) -> list:
    """Creates a list of TUnits from a Wikipedia article object.

    :param article: A Wikipedia article object.
    :type article: Article

    :returns: a list of TUnits created from article.
    """

    paragraphs = ' '.join(
        [para for para in article.content.splitlines() if para != ''])
    tunits = []
コード例 #5
0
def resolve_coreferences(content: str) -> str:
    nlp = NLPConn.get_nlp_conn()
    doc = nlp(content)
    resolved_coref = get_resolved(doc, doc._.coref_clusters)

    return resolved_coref