33
44Returns the number of characters in `text`.
55"""
6- function characters (text:: String )
7- count:: Int = length (text)
8- return count
6+ function characters (text:: String ):: Int
7+ return Base. length (text)
8+ end
9+
10+ """
11+ characters_per_word(text::String)
12+
13+ Returns the number of characters per word or the average word length in `text`.
14+ """
15+ function characters_per_word (text:: String ):: Float64
16+ return characters (text) / words (text)
917end
1018
1119"""
1220 sentences(text::String)
1321
1422Returns the number of sentences in `text`.
1523"""
16- function sentences (text:: String )
17- count:: Int = length (split (text, [' .' , ' !' , ' ?' ]))
18- return count
24+ function sentences (text:: String ):: Int
25+ return Base. length (Base. split (text, [' .' , ' !' , ' ?' ]))
26+ end
27+
28+ """
29+ sentences_per_paragraph(text::String)
30+
31+ Returns the number of sentences per paragraph or the average paragraph length in `text`.
32+ """
33+ function sentences_per_paragraph (text:: String ):: Float64
34+ return sentences (text) / paragraphs (text)
1935end
2036
2137"""
2238 syllables(text::String)
2339
2440Returns the number of syllables in `text`.
2541"""
26- function syllables (text:: String )
42+ function syllables (text:: String ):: Int
2743 vowels:: String = " aeiou"
2844 count:: Int = 0
2945 in_vowel_sequence:: Bool = false
30- text:: String = lowercase (text)
46+ text:: String = Base . lowercase (text)
3147 for char in text
3248 if char in vowels
3349 if ! in_vowel_sequence
@@ -41,34 +57,49 @@ function syllables(text::String)
4157 return count
4258end
4359
60+ """
61+ syllables_per_word(text::String)
62+
63+ Returns the number of syllables per word or the average word length in `text`.
64+ """
65+ function syllables_per_word (text:: String ):: Float64
66+ return syllables (text) / words (text)
67+ end
68+
4469"""
4570 words(text::String)
4671
4772Returns the number of words in `text`.
4873"""
49- function words (text:: String )
50- count:: Int = length (split (text))
51- return count
74+ function words (text:: String ):: Int
75+ return Base. length (Base. split (text))
76+ end
77+
78+ """
79+ words_per_sentence(text::String)
80+
81+ Returns the number of words per sentence or the sentence length in `text`.
82+ """
83+ function words_per_sentence (text:: String ):: Float64
84+ return words (text) / sentences (text)
5285end
5386
5487"""
5588 lines(text::String)
5689
5790Returns the number of lines `text`.
5891"""
59- function lines (text:: String )
60- count:: Int = length (split (text, " \n " ))
61- return count
92+ function lines (text:: String ):: Int
93+ return Base. length (Base. split (text, " \n " ))
6294end
6395
6496"""
6597 paragraphs(text::String)
6698
6799Returns the number of paragraphs in `text`.
68100"""
69- function paragraphs (text:: String )
70- count:: Int = length (split (text, " \n\n " ))
71- return count
101+ function paragraphs (text:: String ):: Int
102+ return Base. length (Base. split (text, " \n\n " ))
72103end
73104
74105# Gunning Fog
77108
78109Returns the number of complex words (words with 3 or more syllables and not ending in "es", "ed", or "ing") in `text`.
79110"""
80- function complex_words (text:: String )
81- words:: Vector{String} = split (text)
111+ function complex_words (text:: String ):: Int
112+ words:: Vector{String} = Base . split (text)
82113 count:: Int = 0
83114 for word in words
84115 syllable_count:: Int = syllables (word)
85- if syllable_count >= 3 && ! any (x -> occursin (x, word), [' -' , " es" , " ed" , " ing" ])
116+ if syllable_count >= 3 && ! Base . any (x -> Base . occursin (x, word), [' -' , " es" , " ed" , " ing" ])
86117 count += 1
87118 end
88119 end
95126
96127Returns the number of words with 3 or more syllables in `text`.
97128"""
98- function polysyllabic_words (text:: String )
99- words:: Vector{String} = split (text)
129+ function polysyllabic_words (text:: String ):: Int
130+ words:: Vector{String} = Base . split (text)
100131 count:: Int = 0
101132 for word in words
102133 syllable_count = syllables (word)
121152Returns the number of words that are not in the specified `word_list` (either "dale-chall" or "spache") in `text`.
122153"""
123154function difficult_words (text:: String , word_list:: String )
124- lower_text:: String = lowercase (text)
125- words:: Vector{String} = split (lower_text)
155+ lower_text:: String = Base . lowercase (text)
156+ words:: Vector{String} = Base . split (lower_text)
126157 count:: Int = 0
127158
128159 dale_chall_txt:: String = Base. joinpath (Base. dirname (Base. @__FILE__ ), " dale-chall_word_list.txt" )
@@ -144,7 +175,7 @@ function difficult_words(text::String, word_list::String)
144175 end
145176 end
146177 else
147- error (" word_list must be 'dale-chall' or 'spache'" )
178+ Base . error (" word_list must be 'dale-chall' or 'spache'" )
148179 end
149180
150181 return count
0 commit comments