From fad6f557cbce234ae15b5f68bfbdcf3b28625384 Mon Sep 17 00:00:00 2001 From: IgnBys Date: Sun, 29 Oct 2023 10:11:56 +0100 Subject: [PATCH] TaskAO2 was ended --- TaskA02/TaskAO2.py | 31 -------------------- TaskA02/run.py | 70 +++++++++++++++++++++++++++++++++------------- 2 files changed, 50 insertions(+), 51 deletions(-) delete mode 100644 TaskA02/TaskAO2.py diff --git a/TaskA02/TaskAO2.py b/TaskA02/TaskAO2.py deleted file mode 100644 index f5275e9..0000000 --- a/TaskA02/TaskAO2.py +++ /dev/null @@ -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') \ No newline at end of file diff --git a/TaskA02/run.py b/TaskA02/run.py index d85ef4e..fcf4e56 100644 --- a/TaskA02/run.py +++ b/TaskA02/run.py @@ -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')