Merge pull request #1287 from IamJeffG/feature/1226-more-complete-noun-chunks

Capture more noun chunks
This commit is contained in:
Matthew Honnibal 2017-09-08 07:59:10 +02:00 committed by GitHub
commit ddaff6ca56
2 changed files with 31 additions and 1 deletions

View File

@ -9,7 +9,7 @@ def english_noun_chunks(obj):
Detect base noun phrases from a dependency parse.
Works on both Doc and Span.
"""
labels = ['nsubj', 'dobj', 'nsubjpass', 'pcomp', 'pobj',
labels = ['nsubj', 'dobj', 'nsubjpass', 'pcomp', 'pobj', 'dative', 'appos',
'attr', 'ROOT']
doc = obj.doc # Ensure works on both Doc and Span.
np_deps = [doc.vocab.strings[label] for label in labels]

View File

@ -47,6 +47,36 @@ def test_parser_noun_chunks_pp_chunks(en_tokenizer):
assert chunks[1].text_with_ws == "another phrase "
def test_parser_noun_chunks_appositional_modifiers(en_tokenizer):
text = "Sam, my brother, arrived to the house."
heads = [5, -1, 1, -3, -4, 0, -1, 1, -2, -4]
tags = ['NNP', ',', 'PRP$', 'NN', ',', 'VBD', 'IN', 'DT', 'NN', '.']
deps = ['nsubj', 'punct', 'poss', 'appos', 'punct', 'ROOT', 'prep', 'det', 'pobj', 'punct']
tokens = en_tokenizer(text)
doc = get_doc(tokens.vocab, [t.text for t in tokens], tags=tags, deps=deps, heads=heads)
chunks = list(doc.noun_chunks)
assert len(chunks) == 3
assert chunks[0].text_with_ws == "Sam "
assert chunks[1].text_with_ws == "my brother "
assert chunks[2].text_with_ws == "the house "
def test_parser_noun_chunks_dative(en_tokenizer):
text = "She gave Bob a raise."
heads = [1, 0, -1, 1, -3, -4]
tags = ['PRP', 'VBD', 'NNP', 'DT', 'NN', '.']
deps = ['nsubj', 'ROOT', 'dative', 'det', 'dobj', 'punct']
tokens = en_tokenizer(text)
doc = get_doc(tokens.vocab, [t.text for t in tokens], tags=tags, deps=deps, heads=heads)
chunks = list(doc.noun_chunks)
assert len(chunks) == 3
assert chunks[0].text_with_ws == "She "
assert chunks[1].text_with_ws == "Bob "
assert chunks[2].text_with_ws == "a raise "
def test_parser_noun_chunks_standard_de(de_tokenizer):
text = "Eine Tasse steht auf dem Tisch."
heads = [1, 1, 0, -1, 1, -2, -4]