liveBook · Manning

Get_phrases

As explained in Learn AI-Assisted Python Programming, Second Edition

get_phrases is a book-specific Python function that returns a list of phrases parsed from a sentence.

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

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Defines the interface and shows a delegated implementation, stopping short of explaining split_string internals.
Examples
Uses a comma-separated phrase example and an average-complexity example contrasting one phrase boundary.
What it assumes
Assumes split_string and get_sentences, while introducing phrase boundaries through a concrete punctuation rule.
What you can do after
Apply it via split_string to extract phrase lists and support average sentence-complexity calculations.
How it connects
Connects to split_string, get_sentences, average_sentence_complexity, and authorship identification.

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.