delete empty file
This commit is contained in:
parent
dbc7207e21
commit
11fb2733e5
@ -18,4 +18,4 @@ user Hmmm, to może ten ze szpitalem jednak confirm(hotel=YY)
|
|||||||
system W jakim terminie chciałbyś dokonać rezerwacji? request(date)
|
system W jakim terminie chciałbyś dokonać rezerwacji? request(date)
|
||||||
user Od przyszłego poniedziałku do piątku inform(date=27.03-31.03)
|
user Od przyszłego poniedziałku do piątku inform(date=27.03-31.03)
|
||||||
system Dobrze w takim razie hotel YY na Kos dla dwóch osób, w terminie 27.03 do 31.03 expl-conf(hotel=YY, people=2, date=27.03-31.03, city=Kos)
|
system Dobrze w takim razie hotel YY na Kos dla dwóch osób, w terminie 27.03 do 31.03 expl-conf(hotel=YY, people=2, date=27.03-31.03, city=Kos)
|
||||||
system czy wszystko się zgadza? comfirm-domain
|
system czy wszystko się zgadza ? comfirm-domain
|
||||||
|
|
@ -1,14 +1,14 @@
|
|||||||
def remove_empty_lines(text):
|
def process_text(text, nazwisko_user, nazwisko_system):
|
||||||
lines = text.split('\n')
|
lines = text.split('\n')
|
||||||
|
result=[]
|
||||||
non_empty_lines = []
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip():
|
if nazwisko_system in line:
|
||||||
non_empty_lines.append(line)
|
result.append("system " + line.split(nazwisko_system, 1)[1].strip())
|
||||||
|
elif nazwisko_user in line:
|
||||||
return '\n'.join(non_empty_lines)
|
result.append("user " + line.split(nazwisko_user, 1)[1].strip())
|
||||||
|
else:
|
||||||
|
result.append(line)
|
||||||
|
return '\n'.join(result)
|
||||||
def join_lines(text):
|
def join_lines(text):
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
joined_lines = [lines[0]]
|
joined_lines = [lines[0]]
|
||||||
@ -20,32 +20,23 @@ def join_lines(text):
|
|||||||
joined_lines[-1] += " " + line
|
joined_lines[-1] += " " + line
|
||||||
|
|
||||||
return "\n".join(joined_lines)
|
return "\n".join(joined_lines)
|
||||||
|
def remove_empty_lines(text):
|
||||||
|
|
||||||
def process_text(text, nazwisko_user, nazwisko_system):
|
|
||||||
lines = text.split('\n')
|
lines = text.split('\n')
|
||||||
result = []
|
non_empty_lines = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if nazwisko_system in line:
|
if line.strip():
|
||||||
result.append("system " + line.split(nazwisko_system, 1)[1].strip())
|
non_empty_lines.append(line)
|
||||||
elif nazwisko_user in line:
|
|
||||||
result.append("user " + line.split(nazwisko_user, 1)[1].strip())
|
|
||||||
else:
|
|
||||||
result.append(line)
|
|
||||||
return '\n'.join(result)
|
|
||||||
|
|
||||||
|
return '\n'.join(non_empty_lines)
|
||||||
|
|
||||||
def read_tsv(file_path):
|
def read_tsv(file_path):
|
||||||
with open(file_path, 'r', encoding='utf-8') as tsv_file:
|
with open(file_path, 'r', encoding='utf-8') as tsv_file:
|
||||||
content = tsv_file.read()
|
content = tsv_file.read()
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
def write_tsv(file_path, content):
|
def write_tsv(file_path, content):
|
||||||
with open(file_path, 'w', encoding='utf-8') as tsv_file:
|
with open(file_path, 'w', encoding='utf-8') as tsv_file:
|
||||||
tsv_file.write(content)
|
tsv_file.write(content)
|
||||||
|
|
||||||
|
|
||||||
def replace_first_space_with_tab(text):
|
def replace_first_space_with_tab(text):
|
||||||
lines = text.split("\n")
|
lines = text.split("\n")
|
||||||
new_lines = []
|
new_lines = []
|
||||||
@ -57,8 +48,6 @@ def replace_first_space_with_tab(text):
|
|||||||
else:
|
else:
|
||||||
new_lines.append(line)
|
new_lines.append(line)
|
||||||
return "\n".join(new_lines)
|
return "\n".join(new_lines)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# wypelnic przed uruchomieniem
|
# wypelnic przed uruchomieniem
|
||||||
nazwisko_user = ""
|
nazwisko_user = ""
|
||||||
@ -66,11 +55,9 @@ if __name__ == '__main__':
|
|||||||
numer_user = ""
|
numer_user = ""
|
||||||
numer_system = ""
|
numer_system = ""
|
||||||
file_path = f"J:\PycharmProjects\systemy_dialogowe\data\dialog-{numer_system}-{numer_user}-01.tsv"
|
file_path = f"J:\PycharmProjects\systemy_dialogowe\data\dialog-{numer_system}-{numer_user}-01.tsv"
|
||||||
|
text = read_tsv(file_path )
|
||||||
text = read_tsv(file_path)
|
text = remove_empty_lines(text )
|
||||||
text = remove_empty_lines(text)
|
text = join_lines(text )
|
||||||
text = join_lines(text)
|
text = process_text(text, nazwisko_user, nazwisko_system )
|
||||||
text = process_text(text, nazwisko_user, nazwisko_system)
|
text = replace_first_space_with_tab(text )
|
||||||
text = replace_first_space_with_tab(text)
|
write_tsv(file_path, text )
|
||||||
write_tsv(file_path, text)
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user