get_phrases is a Python function that accepts a sentence and returns its phrases as a list. It treats commas, semicolons, and colons as phrase separators. section 11.3.1
The function fits into a small decomposition of sentence analysis:
- get_phrases delegates the actual splitting to split_string, passing ',;:' as the separator characters. section 11.5.8
- average_sentence_complexity calls get_phrases for each sentence, counts the returned phrases, and averages those counts. section 11.5.9
- get_sentences and get_phrases share the same splitting pattern while using different punctuation sets. section 11.3.1
Splitting a sentence into phrases
get_phrases('Lustrous pearl, Rare, What a nice find') returns ['Lustrous pearl', 'Rare', 'What a nice find']. The function itself remains short because split_string handles the separator-based parsing. section 11.5.8
Listing 11.10 Return list of phrases from a sentence
def get_phrases(sentence):
'''
sentence is a sentence string.
Return a list of the phrases from sentence.
Phrases are separated by a ',', ';' or ':'.
>>> get_phrases('Lustrous pearl, Rare, What a nice find')
['Lustrous pearl', 'Rare', 'What a nice find']
'''
return split_string(sentence, ',;:') #1
Inspect the complete function definition, including its parameter description, separator rule, doctest example, and call to split_string. section 11.5.8
