Skip to content

Commit 03445fc

Browse files
committed
Some tweaking of functions
1 parent 5dab71e commit 03445fc

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

CompoundWordSplitter.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import enchant,sys
22

3+
# requires PyEnchant library
4+
35
# to be able to support Python 2 & 3
46
if sys.version_info[0] > 2:
57
unicode = str
68

79

810
def __concat(object1, object2):
11+
912
if isinstance(object1, str) or isinstance(object1, unicode):
1013
object1 = [object1]
1114
if isinstance(object2, str) or isinstance(object2, unicode):
@@ -14,10 +17,12 @@ def __concat(object1, object2):
1417

1518

1619
def __capitalize_first_char(word):
20+
1721
return word[0].upper() + word[1:]
1822

1923

20-
def split(word, language='en_us'):
24+
def __split(word, language='en_US'):
25+
2126
dictionary = enchant.Dict(language)
2227
max_index = len(word)
2328
for index, char in enumerate(word):
@@ -32,12 +37,12 @@ def split(word, language='en_us'):
3237
left_compound = __capitalize_first_char(left_compound)
3338
is_left_compound_valid_word = len(left_compound) > 1 and dictionary.check(left_compound)
3439
if is_left_compound_valid_word and \
35-
((not split(right_compound_1, language) == '' and not right_compound1_upper) or right_compound_1 == ''):
36-
return [compound for compound in __concat(left_compound, split(right_compound_1, language))\
40+
((not __split(right_compound_1, language) == '' and not right_compound1_upper) or right_compound_1 == ''):
41+
return [compound for compound in __concat(left_compound, __split(right_compound_1, language))\
3742
if not compound == '']
3843
elif is_left_compound_valid_word and word[max_index-index:max_index-index+1] == 's' and \
39-
((not split(right_compound_2, language) == '' and not right_compound2_upper) or right_compound_2 == ''):
40-
return [compound for compound in __concat(left_compound, split(right_compound_2, language))\
44+
((not __split(right_compound_2, language) == '' and not right_compound2_upper) or right_compound_2 == ''):
45+
return [compound for compound in __concat(left_compound, __split(right_compound_2, language))\
4146
if not compound == '']
4247
if not word == '' and dictionary.check(word):
4348
return word
@@ -47,4 +52,17 @@ def split(word, language='en_us'):
4752
return ''
4853

4954

50-
print(split("undertake"))
55+
def split(compound_word,language='en_US'):
56+
57+
words = compound_word.split('-')
58+
59+
simple_words = []
60+
61+
for word in words:
62+
result = __split(word, language)
63+
for val in result:
64+
simple_words.append(val)
65+
66+
return simple_words
67+
68+

SimpleSyllableCounter.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# NOTE: words ending with es, ed, and ing are not counted towards the total number of syllables
2+
13
def syllables(word):
24

35
# y can usually be considered as a syllable due to its pronunciation
@@ -13,6 +15,10 @@ def syllables(word):
1315
syllable_count = 0
1416
ends_with_vowel_flag = False
1517
last_letter = ""
18+
19+
# removing ing from the end of the word
20+
if 'ing' == word[-3:]:
21+
word = word[:-3]
1622

1723
for letter in word:
1824
if letter in vowels:
@@ -37,3 +43,4 @@ def syllables(word):
3743

3844
return syllable_count
3945

46+

0 commit comments

Comments
 (0)