Spaces:
Runtime error
Runtime error
naveed-stockmark
commited on
Commit
•
709cde5
1
Parent(s):
5c0b561
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,22 +1,5 @@
|
|
1 |
-
import jsonlines
|
2 |
import json
|
3 |
|
4 |
-
def read_jsonlines(path):
|
5 |
-
with jsonlines.open(path) as reader:
|
6 |
-
lines = [obj for obj in reader]
|
7 |
-
return lines
|
8 |
-
|
9 |
-
def write_jsonlines(file, path):
|
10 |
-
with jsonlines.open(path, 'w') as writer:
|
11 |
-
writer.write_all(file)
|
12 |
-
|
13 |
-
def dump_json(file, path):
|
14 |
-
"""Save json object"""
|
15 |
-
|
16 |
-
with open(path, 'w', encoding='utf-8') as f:
|
17 |
-
json.dump(file, f, indent=4, ensure_ascii=False)
|
18 |
-
print("Saved json to path: " + str(path))
|
19 |
-
|
20 |
def load_json(path):
|
21 |
"""load json object"""
|
22 |
with open(path, 'rb') as f:
|
@@ -24,21 +7,6 @@ def load_json(path):
|
|
24 |
print("Loaded json from path: " + str(path))
|
25 |
return data
|
26 |
|
27 |
-
def split_w_delimiter(line, delimiter):
|
28 |
-
len_delimiter = len(delimiter)
|
29 |
-
|
30 |
-
sents = [sent for sent in line.split(delimiter) if sent.strip()]
|
31 |
-
|
32 |
-
if len(sents) == 0:
|
33 |
-
return []
|
34 |
-
|
35 |
-
if line[-len_delimiter:] == delimiter:
|
36 |
-
out = [sent + delimiter for sent in sents]
|
37 |
-
else:
|
38 |
-
out = [sent + delimiter for sent in sents[:-1]] + [sents[-1]]
|
39 |
-
|
40 |
-
return out
|
41 |
-
|
42 |
import difflib
|
43 |
|
44 |
def generate_diff_html(text_pairs, output_file=''):
|
|
|
|
|
1 |
import json
|
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
def load_json(path):
|
4 |
"""load json object"""
|
5 |
with open(path, 'rb') as f:
|
|
|
7 |
print("Loaded json from path: " + str(path))
|
8 |
return data
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
import difflib
|
11 |
|
12 |
def generate_diff_html(text_pairs, output_file=''):
|