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:
|
with open(fileName, "r", encoding="utf-8") as file:
|
||||||
for row in file:
|
for row in file:
|
||||||
repCounter = 0
|
lastWordSymbol = ''
|
||||||
counter = 0
|
counter = 0
|
||||||
checkWord = []
|
checkWord = []
|
||||||
for i in row:
|
for i in row:
|
||||||
if i in piesArray[counter]:
|
if lastWordSymbol == '' or lastWordSymbol == ' ':
|
||||||
if i != ' ' or counter != 0:
|
if i == 'P' or i=='p':
|
||||||
checkWord+=i
|
checkWord+=i
|
||||||
counter+=1
|
lastWordSymbol = i
|
||||||
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())
|
|
||||||
|
|
||||||
|
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:
|
else:
|
||||||
checkWord=[]
|
checkWord=[]
|
||||||
counter = 0
|
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--------------------------------------')
|
print('---------------------SHAKESPEARE.EXP--------------------------------------')
|
||||||
openFile('polish_wiki_excerpt.exp')
|
openFile('polish_wiki_excerpt.exp')
|
||||||
|
Loading…
Reference in New Issue
Block a user