-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_utils.py
34 lines (31 loc) · 1.03 KB
/
index_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 16 16:04:48 2019
@author: leona
"""
#I actually didn't define function for this task but if we want to create the dict for like i indexes woukld be like this
def define(ranges):
dictionar = {}
k = 0
for i in ranges:
file1 = open("Cleantsv/filmclean-"+str(i)+'.tsv', encoding="utf8")
line = file1.read()# Use this to read file content as a stream:
#print(line)
words = line.split('\t')
wordssplitted1 = words[14].split()
wordssplitted2 = words[15].split()
#print(wordssplitted1, wordssplitted2)
for i in wordssplitted1:
#print(type(i))
if i not in dictionar:
dictionar[i] = str(k)
k = k+1
for i in wordssplitted2:
#print(type(i))
if i not in dictionar:
dictionar[i] = str(k)
k = k+1
#dictionar
import json
with open('Diction.json', 'w') as fp:
json.dump(dictionar, fp)