make_signature takes a text string and returns a five-number signature for authorship identification. It coordinates smaller feature functions instead of mixing all calculations into one large procedure. section 11.3 section 11.5.10
The signature contains these features:
- Average word length. section 11.5.10
- Different words divided by total words. section 11.5.10
- Words used exactly once divided by total words. section 11.5.10
- Average sentence length. section 11.5.10
- Average sentence complexity, measured through phrases in sentences. section 11.3.1 section 11.5.9
A numeric signature
Calling make_signature on “A pearl! Pearl! Lustrous pearl! Rare, what a nice find.” returns [4.1, 0.7, 0.5, 2.5, 1.25]. The function delegates each value to its corresponding feature function. section 11.5.10
Listing 11.12 Numeric signature for the text
def make_signature(text):
'''
The signature for text is a list of five elements:
average word length, different words divided by total words,
words used exactly once divided by total words,
average sentence length, and average sentence complexity.
Return the signature for text.
>>> make_signature('A pearl! Pearl! Lustrous pearl! \
Rare, what a nice find.')
[4.1, 0.7, 0.5, 2.5, 1.25]
'''
return [average_word_length(text), #1
different_to_total(text), #1
exactly_once_to_total(text), #1
average_sentence_length(text), #1
average_sentence_complexity(text)] #1
Inspect the complete function definition and its doctest example. section 11.5.10
