Compare commits

...

38 Commits

Author SHA1 Message Date
97eb3536f6 Merge pull request 'Add tasks G' (#4) from miczar1/djfz-24_25:master into master
Reviewed-on: s481852/jezyki-formalne#4
2025-01-30 13:56:24 +01:00
3da2b5d83d D1 doesnt work properly 2025-01-29 02:55:49 +01:00
2045b4eb99 D5 works 2025-01-29 02:10:26 +01:00
dab5c629c6 D2 fixed 2025-01-29 02:08:57 +01:00
8c0af38006 D5 changes, checker added 2025-01-29 02:01:11 +01:00
077f7fa966 D5 works for simple 2025-01-29 00:38:33 +01:00
639d5f9356 D4 done, do sprawdzenia 2025-01-29 00:09:31 +01:00
4c38c40be3 D3 poprawki 2025-01-28 22:50:40 +01:00
81740936e6 D3 chyba działa 2025-01-28 22:48:32 +01:00
7dacb80485 D2 zrobione 2025-01-28 21:35:38 +01:00
27252063f3 D1 zrobione 2025-01-28 20:21:26 +01:00
db46cca450 D0 tested 2025-01-28 19:13:49 +01:00
afed3aee82 zadD0 zrobione, poprawione inputy 2025-01-27 22:46:47 +01:00
d5bf1e39ad Merge remote-tracking branch 'origin/master' 2025-01-27 22:03:34 +01:00
63dd0e9716 Merge pull request 'Add tasks D' (#3) from miczar1/djfz-24_25:master into master
Reviewed-on: s481852/jezyki-formalne#3
2025-01-27 22:03:20 +01:00
0b736cfdd8 Merge remote-tracking branch 'origin/master' 2025-01-27 22:00:54 +01:00
0c8d519bde task c10 done, for revision 2025-01-09 16:45:52 +01:00
4afd894364 task c47 done 2025-01-09 11:17:20 +01:00
cea1d6bd49 task c42 done, c2 fixed 2025-01-09 11:07:44 +01:00
bb99e42844 task c10 no idea 2025-01-09 10:54:18 +01:00
c726906fcd task C2 done 2025-01-09 10:21:35 +01:00
d7a9ac3994 Merge pull request 'master' (#2) from miczar1/djfz-24_25:master into master
Reviewed-on: s481852/jezyki-formalne#2
2024-12-21 16:14:58 +01:00
34e284c49e zad2 poprawione, ies nie jest akceptowane 2024-12-08 19:00:51 +01:00
b718541d69 task2, added case with dot 2024-11-25 12:44:15 +01:00
a7892ad185 task 4 done to check 2024-11-25 12:42:37 +01:00
834f781e2c task3 done, to check 2024-11-25 12:38:21 +01:00
53e7341220 input fixed 2024-11-25 12:35:44 +01:00
956123d97e task2 done 2024-11-25 12:29:21 +01:00
348556373e task1 optimalization 2024-11-25 12:14:04 +01:00
ed65fd5535 lab2, task 1 done, 2 started 2024-11-25 12:09:17 +01:00
bcc3d7344f Merge pull request 'Second class tasks' (#1) from miczar1/djfz-24_25:master into master
Reviewed-on: s481852/jezyki-formalne#1
2024-11-25 11:50:44 +01:00
37f63d6317 zad 3 dziala, naprawienie wyjatkow z NBSP 2024-11-17 21:02:22 +01:00
f6dd2eef8c zadanie 4 poprawione 2024-11-14 20:46:13 +01:00
0beb5c2db5 pobranie danych dla 4, rozwiazanie dziala 2024-11-14 20:30:48 +01:00
c8de88b936 pobranie danych, dziala ale potencjalny blad w rozwiazaniach 2024-11-14 20:10:52 +01:00
bf20d2f3a0 task3 dla simpple, brak danych dla polish_wiki 2024-10-28 13:00:28 +01:00
d9c12d5d2f task2 done 2024-10-28 12:45:42 +01:00
35dfc38168 task1 done 2024-10-28 12:35:55 +01:00
29 changed files with 500424 additions and 10 deletions

11
TaskA01/task1.py Normal file
View File

@ -0,0 +1,11 @@
with open("shakespeare.in", encoding="utf8") as f:
lines = f.readlines()
for line in lines:
line = line.strip()
line = line.split()
for word in line:
if word[:6] == "Hamlet":
result = " ".join(line)
print(result)
break

5
TaskA02/task2.py Normal file
View File

@ -0,0 +1,5 @@
with open("polish_wiki_excerpt.in", encoding="utf8") as f:
lines = f.readlines()
for line in lines:
if "Pies " in line or " pies " in line or "pies\n" in line:
print(line.strip("\n"))

File diff suppressed because one or more lines are too long

23
TaskA03/task3.py Normal file
View File

@ -0,0 +1,23 @@
with open("polish_wiki_excerpt.in", encoding="utf-8") as f:
lines = f.readlines()
result = []
for line in lines:
line = line.replace('\xa0', '[NBA]').strip() # eliminujemy problem z 'non breaking space'
line = line.split()
flag1 = False
for word in line:
if flag1:
if word[:2] == 'r.':
goodLine = ' '.join(line)
result.append(goodLine)
print(goodLine)
break
else:
flag1 = False
if word[-4:-2] == '19':
if word[-2] in '0123456789' and word[-1] in '0123456789':
flag1 = True

File diff suppressed because one or more lines are too long

27
TaskA04/task4.py Normal file
View File

@ -0,0 +1,27 @@
with open('polish_wiki_excerpt.in', encoding='utf8') as f:
lines = f.readlines()
results = []
i = 0
for line in lines:
line = line.strip()
subdigits = []
pom = ''
for char in line:
if char in '0123456789':
pom += char
elif pom != '':
subdigits.append(pom)
pom = ''
else:
pass
if pom.isdigit():
subdigits.append(pom)
if len(subdigits) > 0:
finalLine = ' '.join(subdigits)
print(finalLine)

10
TaskB01/task1.py Normal file
View File

@ -0,0 +1,10 @@
import regex as re
with open('shakespeare.in', encoding='utf8') as file:
lines = file.readlines()
pattern = re.compile(r'Hamlet')
for line in lines:
line = line.strip()
x = re.search(pattern, line)
if x:
print(line)

10
TaskB02/task2.py Normal file
View File

@ -0,0 +1,10 @@
import regex as re
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'(P|( p))ies(( \w+)|(\.$))'
for line in lines:
line = line.strip()
x = re.search(pattern, line)
if x:
print(line)

File diff suppressed because one or more lines are too long

10
TaskB03/task3.py Normal file
View File

@ -0,0 +1,10 @@
import re
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'19\d\d r\.'
for line in lines:
line = line.strip()
x = re.search(pattern, line)
if x:
print(line)

File diff suppressed because one or more lines are too long

10
TaskB04/task4.py Normal file
View File

@ -0,0 +1,10 @@
import re
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'\d+'
for line in lines:
line = line.strip()
x = re.findall(pattern, line)
if x:
print(' '.join(x))

25
TaskC02/task2.py Normal file
View File

@ -0,0 +1,25 @@
import re
pattern = re.compile(r'^\d{2}-\d{3}$')
def check(given_text):
result = re.search(pattern, given_text)
if result:
return given_text[:2]
else:
return '<NONE>'
### test
# with open('test.in', 'r', encoding='utf-8') as f:
# lines = f.readlines()
# for line in lines:
# line = line.strip()
# print(check(line))
while True:
text = input('Please provide your text: ')
if text == 'END':
break
print(check(text))
print('To end type END')

27
TaskC10/task10.py Normal file
View File

@ -0,0 +1,27 @@
import re
pattern = re.compile(r'^[1248]0*$')
def check(given_text):
result = re.search(pattern, given_text)
if result:
return 'yes'
else:
return 'no'
### test
# with open('test.in', 'r', encoding='utf-8') as f:
# lines = f.readlines()
# for line in lines:
# line = line.strip()
# print(check(line))
while True:
text = input('Please provide your text: ')
if text == 'END':
break
print(check(text))
print('To end type END')

25
TaskC42/task42.py Normal file
View File

@ -0,0 +1,25 @@
import re
pattern = re.compile(r'^N((I[E]{6,})|([O]{6,}))[!]{3,}$')
def check(given_text):
result = re.search(pattern, given_text)
if result:
return 'yes'
else:
return 'no'
### test
# with open('test.in', 'r', encoding='utf-8') as f:
# lines = f.readlines()
# for line in lines:
# line = line.strip()
# print(check(line))
while True:
text = input('Please provide your text: ')
if text == 'END':
break
print(check(text))
print('To end type END')

25
TaskC47/task47.py Normal file
View File

@ -0,0 +1,25 @@
import re
pattern = re.compile(r'#[a-zA-Z]\w*')
def check(given_text):
result = re.findall(pattern, given_text)
if result:
return ';'.join(result)
else:
return '<NONE>'
### test
# with open('test.in', 'r', encoding='utf-8') as f:
# lines = f.readlines()
# for line in lines:
# line = line.strip()
# print(check(line))
while True:
text = input('Please provide your text: ')
if text == 'END':
break
print(check(text))
print('To end type END')

File diff suppressed because one or more lines are too long

37
TaskD00/taskD0.py Normal file
View File

@ -0,0 +1,37 @@
import re
dictionary = {
'0': 'a',
'1': 'b',
'2': 'c',
'3': 'd',
'4': 'e',
'5': 'f',
'6': 'g',
'7': 'h',
'8': 'i',
'9': 'j',
}
final = []
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'\d{4}'
for line in lines:
line = line.strip()
x = re.findall(pattern, line)
if x:
for words in x:
decoded_word = ''
for char in words:
decoded_word += dictionary[char]
line = line.replace(words, decoded_word, 1)
print(line)
final.append(line)
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
file.write(line + '\n')

File diff suppressed because one or more lines are too long

46
TaskD01/taskD1.py Normal file
View File

@ -0,0 +1,46 @@
import re
final = []
polish_big = 'AĄBCĆDEĘFGQHIJKLŁMNŃOÓPRSŚTUWXVYZŹŻ'
polish_small = 'aąbcćdeęfgqhijklłmnńoóprsśtuwxvyzźż'
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'(\w*[A-ZĄĆĘŁŃÓŚŹŻ]+[a-ząćęłńóśźż]+\w*)|(\w*[a-ząćęłńóśźż]+[A-ZĄĆĘŁŃÓŚŹŻ]+\w*)'
for line in lines:
line = line.strip()
x = re.findall(pattern, line)
if x:
for words in x:
if words[0] != '':
to_replace = words[0]
new_word = ''
for char in to_replace:
if char in polish_big:
new_word += char.lower()
elif char in polish_small:
new_word += char.upper()
else:
new_word += char
elif words[1] != '':
to_replace = words[1]
new_word = ''
for char in to_replace:
if char in polish_small:
new_word += char.upper()
elif char in polish_big:
new_word += char.lower()
else:
new_word += char
line = line.replace(to_replace, new_word, 1)
print(line)
final.append(line)
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
file.write(line + '\n')
### odpowiedź nie do końca pokrywa się z plikiem .exp w wyniku obecności znaków z niemieckiego alfabetu

File diff suppressed because one or more lines are too long

42
TaskD02/taskD2.py Normal file
View File

@ -0,0 +1,42 @@
import re
final = []
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'([a-ząćęłńóśźż]+)|([A-ZĄĆĘŁŃÓŚŹŻ]+)|(\d+)'
for line in lines:
#line = line.strip()
line = line.replace('\n', '')
x = re.findall(pattern, line)
if "Nikołaj Judenicz" in line:
pass
a = 0
b = 0
c = 0
d = 0
if x:
for words in x:
if words[0] != '':
matching = words[0]
a += len(matching)
elif words[1] != '':
matching = words[1]
b += len(matching)
elif words[2] != '':
matching = words[2]
c += len(matching)
d = len(line) - a - b - c
print(a, b, c, d)
final.append([a, b, c, d])
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
for number in line:
file.write(str(number)+ ' ')
file.write('\n')

File diff suppressed because one or more lines are too long

32
TaskD03/taskD3.py Normal file
View File

@ -0,0 +1,32 @@
import re
final = []
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r"\b([A-ZĄĆĘŁŃÓŚŹŻ]+\w*)\b|\b([a-ząćęłńóśźż]+\w*)\b"
for line in lines:
#line = line.strip()
line = line.replace('\n', '')
x = re.findall(pattern, line)
a = 0
b = 0
if x:
for words in x:
if words[0] != '':
matching = words[0]
b += 1
elif words[1] != '':
matching = words[1]
a += 1
print(a, b)
final.append([a, b])
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
for number in line:
file.write(str(number) + ' ')
file.write('\n')

File diff suppressed because one or more lines are too long

18
TaskD04/taskD4.py Normal file
View File

@ -0,0 +1,18 @@
import re
final = []
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r'(\D*\d+\D+?)\d+(.*)'
for line in lines:
line = line.strip()
line = re.sub(pattern, r'\1\2', line, count=1)
print(line)
final.append(line)
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
file.write(line + '\n')

File diff suppressed because one or more lines are too long

25
TaskD05/taskD5.py Normal file
View File

@ -0,0 +1,25 @@
import re
final = []
with open('polish_wiki_excerpt.in', encoding='utf8') as file:
lines = file.readlines()
pattern = r"(\W*[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+\W+[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+\W)[\wąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+"
for line in lines:
line = line.strip()
def replace_third_word(match):
prefix = match.group(1)
word_to_replace = match.group(0)[len(prefix):len(match.group(0))]
replacement = 'x' * len(word_to_replace)
return prefix + replacement
line = re.sub(pattern, replace_third_word, line)
print(line)
with open('polish_wiki_excerpt.out', 'w', encoding='utf8') as file:
for line in final:
for number in line:
file.write(str(number) + ' ')
file.write('\n')

16
checker.py Normal file
View File

@ -0,0 +1,16 @@
with open("./TaskD01/polish_wiki_excerpt.out", 'r', encoding='utf8') as f:
lines1 = f.readlines()
with open("./TaskD01/polish_wiki_excerpt.exp", 'r', encoding='utf8') as f:
lines2 = f.readlines()
i = 1
for line1, line2 in zip(lines1, lines2):
if line1.strip() == line2.strip():
pass
# print('hurray')
else:
print(f'{i}: bad: \n{line1}{line2}')
i += 1