3
3
4
4
Returns the number of characters in `text`.
5
5
"""
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)
9
17
end
10
18
11
19
"""
12
20
sentences(text::String)
13
21
14
22
Returns the number of sentences in `text`.
15
23
"""
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)
19
35
end
20
36
21
37
"""
22
38
syllables(text::String)
23
39
24
40
Returns the number of syllables in `text`.
25
41
"""
26
- function syllables (text:: String )
42
+ function syllables (text:: String ):: Int
27
43
vowels:: String = " aeiou"
28
44
count:: Int = 0
29
45
in_vowel_sequence:: Bool = false
30
- text:: String = lowercase (text)
46
+ text:: String = Base . lowercase (text)
31
47
for char in text
32
48
if char in vowels
33
49
if ! in_vowel_sequence
@@ -41,34 +57,49 @@ function syllables(text::String)
41
57
return count
42
58
end
43
59
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
+
44
69
"""
45
70
words(text::String)
46
71
47
72
Returns the number of words in `text`.
48
73
"""
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)
52
85
end
53
86
54
87
"""
55
88
lines(text::String)
56
89
57
90
Returns the number of lines `text`.
58
91
"""
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 " ))
62
94
end
63
95
64
96
"""
65
97
paragraphs(text::String)
66
98
67
99
Returns the number of paragraphs in `text`.
68
100
"""
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 " ))
72
103
end
73
104
74
105
# Gunning Fog
77
108
78
109
Returns the number of complex words (words with 3 or more syllables and not ending in "es", "ed", or "ing") in `text`.
79
110
"""
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)
82
113
count:: Int = 0
83
114
for word in words
84
115
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" ])
86
117
count += 1
87
118
end
88
119
end
95
126
96
127
Returns the number of words with 3 or more syllables in `text`.
97
128
"""
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)
100
131
count:: Int = 0
101
132
for word in words
102
133
syllable_count = syllables (word)
121
152
Returns the number of words that are not in the specified `word_list` (either "dale-chall" or "spache") in `text`.
122
153
"""
123
154
function 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)
126
157
count:: Int = 0
127
158
128
159
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)
144
175
end
145
176
end
146
177
else
147
- error (" word_list must be 'dale-chall' or 'spache'" )
178
+ Base . error (" word_list must be 'dale-chall' or 'spache'" )
148
179
end
149
180
150
181
return count
0 commit comments