47 lines
991 B
Python
47 lines
991 B
Python
|
|
import os
|
|
def read_file(filename):
|
|
try:
|
|
dir = os.getcwd() + '/jokar/Flair_NER'
|
|
file = open(dir+filename,"r")
|
|
except:
|
|
file = open('.' + filename,"r")
|
|
|
|
lines = []
|
|
content = file.read()
|
|
|
|
lines = content.split(' ')
|
|
# lines = content.splitlines()
|
|
|
|
file.close()
|
|
return lines
|
|
|
|
def write_file(filename, data):
|
|
try:
|
|
dir = os.getcwd() + '/jokar/Flair_NER'
|
|
file = open(dir+filename,"w")
|
|
except:
|
|
file = open('.' + filename,"w")
|
|
|
|
file.write(data)
|
|
|
|
file.close()
|
|
return lines
|
|
|
|
file = '/data/DATASET.txt'
|
|
|
|
lines = read_file(file)
|
|
len_s = []
|
|
index_s = []
|
|
for x, line in enumerate(lines):
|
|
a = len(line), x+1, line
|
|
len_s.append(a)
|
|
len_s.sort(reverse=True)
|
|
data = ''
|
|
for item in len_s:
|
|
if(item[0]> 500):
|
|
data = data + '+++++ ' + str(item[0]) + ' +++++' + '\n\n' + item[2] + '\n'
|
|
data = data + '#'*70 + '\n'
|
|
|
|
write_file('/data/test_data.txt', data)
|
|
print() |