MCPcopy Index your code
hub / github.com/clips/pattern / chunked

Function chunked

pattern/text/tree.py:1021–1038  ·  view source on GitHub ↗

Returns a list of Chunk and Chink objects from the given sentence. Chink is a subclass of Chunk used for words that have Word.chunk == None (e.g., punctuation marks, conjunctions).

(sentence)

Source from the content-addressed store, hash-verified

1019# s.chunked(s) => [Chunk('black cats/NP'), Chink('and/O'), Chunk('white dogs/NP')]
1020
1021def chunked(sentence):
1022 """ Returns a list of Chunk and Chink objects from the given sentence.
1023 Chink is a subclass of Chunk used for words that have Word.chunk == None
1024 (e.g., punctuation marks, conjunctions).
1025 """
1026 # For example, to construct a training vector with the head of previous chunks as a feature.
1027 # Doing this with Sentence.chunks would discard the punctuation marks and conjunctions
1028 # (Sentence.chunks only yields Chunk objects), which amy be useful features.
1029 chunks = []
1030 for word in sentence:
1031 if word.chunk is not None:
1032 if len(chunks) == 0 or chunks[-1] != word.chunk:
1033 chunks.append(word.chunk)
1034 else:
1035 ch = Chink(sentence)
1036 ch.append(word.copy(ch))
1037 chunks.append(ch)
1038 return chunks
1039
1040#--- TEXT ------------------------------------------------------------------------------------------
1041

Callers 1

chunkedMethod · 0.85

Calls 4

lenFunction · 0.85
ChinkClass · 0.85
appendMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…