Exemplo n.º 1
0
def test_pos_booleans():
    """Test POS boolean methods."""
    assert utils.is_adjective("ADJ")
    assert utils.is_adverb("ADV")
    assert utils.is_noun("NOUN")
    assert utils.is_noun("PROPN")
    assert utils.is_pronoun("PRON")
    assert utils.is_verb("VERB")
    assert utils.is_word("NOUN")
Exemplo n.º 2
0
def pronoun_noun_ratio(doc):
    """Compute Pronoun Noun ratio.

    This is an approximation of text complexity/readability, since pronouns
    are co-references to a proper noun or a noun. This is computed as the
    taking the ratio between third person pronouns and total nouns.

    :param doc: Text to be processed
    :type doc: Spacy doc
    :return: pronoun-noun ratio
    :rtype: float
    """
    noun_counter = 0
    third_person_pronouns = 0

    for token in doc:
        if is_noun(token.pos_):
            noun_counter += 1
        if is_pronoun(token.pos_) and THIRD_PERSON_LABEL in token.tag_:
            third_person_pronouns += 1

    return float(third_person_pronouns) / noun_counter