TaskAO2 was ended
This commit is contained in:
parent
c91aa0f040
commit
fad6f557cb
@ -1,31 +0,0 @@
|
||||
import re
|
||||
|
||||
|
||||
def openFile(fileName,piesArray1 = [' ', 'P', 'p', '('],
|
||||
piesArray2 = ['i', 'e', 's'],
|
||||
piesArray3 = ['\t', '\n', '.', ',', ';', '!', '?', ')']):
|
||||
with open(fileName, "r", encoding="utf-8") as file:
|
||||
file_contents = file.read()
|
||||
for row in file:
|
||||
piesArrayCounter = 0
|
||||
repCounter = 0
|
||||
counter = 0
|
||||
checkWord = ''
|
||||
for character in row:
|
||||
if character == ' ':
|
||||
checkWord+=character
|
||||
if counter == 0 and checkWord == ' ':
|
||||
if (character == 'P' or character == 'p'):
|
||||
counter +=1
|
||||
|
||||
|
||||
|
||||
|
||||
print('---------------------SHAKESPEARE.EXP--------------------------------------')
|
||||
openFile('shakespeare.exp')
|
||||
print('----------------------SHAKESPEARE.EXP-----------------------------------')
|
||||
openFile('shakespeare.in')
|
||||
print('------------------------SIMPLE.IN------------------------------------')
|
||||
openFile('simple.in')
|
||||
print('-----------------------SIMPLE.EXP--------------------------------------')
|
||||
openFile('simple.exp')
|
@ -1,30 +1,60 @@
|
||||
def openFile(fileName,piesArray = ['[Pp ]', 'i', 'e', 's', '[ \t\n.,;!?]']):
|
||||
def checkFirstSymbol(character):
|
||||
if character == 'P' or character == 'p' or character == ' ':
|
||||
return character
|
||||
else:
|
||||
return None
|
||||
|
||||
def checkLastSymbol(character):
|
||||
if (character == '\t'
|
||||
or character == '\n'
|
||||
or character == '.'
|
||||
or character == ','
|
||||
or character == ';'
|
||||
or character == '!'
|
||||
or character == ' '
|
||||
or character == '?'
|
||||
or character == ')'):
|
||||
return character
|
||||
else:
|
||||
return None
|
||||
def openFile(fileName):
|
||||
with open(fileName, "r", encoding="utf-8") as file:
|
||||
for row in file:
|
||||
repCounter = 0
|
||||
lastWordSymbol = ''
|
||||
counter = 0
|
||||
checkWord =[]
|
||||
checkWord = []
|
||||
for i in row:
|
||||
if i in piesArray[counter]:
|
||||
if i != ' ' or counter != 0:
|
||||
if lastWordSymbol == '' or lastWordSymbol == ' ':
|
||||
if i == 'P' or i=='p':
|
||||
checkWord+=i
|
||||
counter+=1
|
||||
if len(checkWord) >= 5:
|
||||
sum = 0
|
||||
for z in checkWord:
|
||||
if z in piesArray[sum]:
|
||||
sum +=1
|
||||
if sum ==4:
|
||||
checkWord = []
|
||||
counter = 0
|
||||
|
||||
repCounter += 1 # if in one row more than one Hamlet it will write the row only once
|
||||
if repCounter == 1:
|
||||
print(row.strip())
|
||||
lastWordSymbol = i
|
||||
|
||||
elif lastWordSymbol == checkFirstSymbol(lastWordSymbol):
|
||||
checkWord += i
|
||||
lastWordSymbol = i
|
||||
elif lastWordSymbol == 'i' and i=='e':
|
||||
checkWord += i
|
||||
lastWordSymbol = i
|
||||
elif lastWordSymbol == 'e' and i == 's':
|
||||
checkWord += i
|
||||
lastWordSymbol = i
|
||||
elif lastWordSymbol == 's' and i == checkLastSymbol(i):
|
||||
checkWord += i
|
||||
lastWordSymbol = i
|
||||
else:
|
||||
checkWord = []
|
||||
counter = 0
|
||||
checkWord=[]
|
||||
lastWordSymbol=''
|
||||
if (len(checkWord)>=5 and checkWord[0]==checkFirstSymbol(checkWord[0])
|
||||
and checkWord[1] == 'i'
|
||||
and checkWord[2] == 'e'
|
||||
and checkWord[3] == 's'
|
||||
and checkWord[4] == checkLastSymbol(checkWord[4])):
|
||||
print(row, end ='')
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
print('---------------------SHAKESPEARE.EXP--------------------------------------')
|
||||
openFile('polish_wiki_excerpt.exp')
|
||||
|
Loading…
Reference in New Issue
Block a user