forked from bradleecrockett/SentenceLength
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSentenceLength.py
More file actions
89 lines (68 loc) · 3.2 KB
/
SentenceLength.py
File metadata and controls
89 lines (68 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os
def findAverageSentence(filePath, delimiters, minLength):
file = open(filePath)
textInFile = file.read()
words = textInFile.split(" ")
# print(words)
# # Loop that discludes any words below minimum length - Alexie
# for word in words:
# if len(word) < int(minLength):
# words.remove(word)
# # End - Alexie
sentences = textInFile.split(".")
delimiters = delimiters.split()
#For every delimiter (symbol) loop through
for i in range(len(delimiters)):
delimiter = delimiters[i] #go through one delimiter at a time
if len(delimiters) > 0: #make sure there is delimiters
for j in range(len(sentences)):
if delimiter in sentences[j]: #go through each sentence and check if it contains the delimiter
additionalSentences = (sentences[j].split(str(delimiter)))
for sentence in additionalSentences:
sentences.append(sentence)
#Takes the split sentence which starts as a list(1 item) and turns it into
#two list elements in sentences(two list items)
#Ex: ["other sentence.", ["blah blah? yes."]](counts as 2 length)
#Turns into ["other sentence.", "blah blah", "yes."]](3 length for more accurate calculation)
sentences.remove(sentences[j])#fixes sentence number
sentences.remove("")
if (len(sentences) > 0):
aveSentenceLength = len(words) / len(sentences)
else:
aveSentenceLength = words
return int(round(aveSentenceLength, 0))
def main():
userFile = input("Enter the file path to the .txt file you wish to analyze.\n")
userDelimeters = input("Enter the characters (punctuation) that you want to be sentence delimiters separated by spaces.\n")
minLength = input("Enter the minimum length of a word (must be a positive integer).\n")
# Asks for a desired min average WPS
desiredLength = int(input("Is there a desired average WPS.\n"))
minLenPro = ""
for i in range(len(minLength)):
# print("1234567890".contains(minLength[i]))
if (minLength[i] in "1234567890") == False:
minLenPro = minLenPro + ""
else:
#
minLenPro = minLenPro + minLength[i]
# print(minLenPro)
# print("The average sentence length is", findAverageSentence(userFile, userDelimeters, minLength))
# #Checks if
# if (int(findAverageSentence(userFile, userDelimeters, minLength)) < desiredLength):
# print("The AWPS is lower than desired")
# elif (int(findAverageSentence(userFile, userDelimeters, minLength)) >= desiredLength):
# print("The AWPS meets your desired amount")
#
# minLenPro = minLenPro + minLength[i]
#if minLenPro == "":
# minLenPro = 3
# mlp = int(minLenPro)
#
#Dylan
if (findAverageSentence(userFile, userDelimeters, minLength) != desiredLength):
print("The average sentence length is", findAverageSentence(userFile, userDelimeters, minLength))
else:
print("You have the desired words per sentence of ", desiredLength)
#End Dylan
if __name__ == "__main__":
main()