import os import cfg import statistics wordSet = [] sentensesData = [] cwd = cfg.get_path() with open(cwd + 'words', 'r') as words: for word in words: # print(word) word = word.split('\t') word[0] = word[0].replace('\ufeff', '') word[1] = word[1].replace('\n', '') wordSet.append(word) with open(cwd + 'sentenses', 'r') as sentenses: for sentense in sentenses: sentense = sentense.replace('\n', '') sentensesData.append(sentense) wordSet.sort(key=lambda s: len(s[0]), reverse=True) # print(wordSet) newSentensesData = [] max_sentense = 0 for sentense in sentensesData: if len(sentense) > max_sentense: max_sentense = len(sentense) for sentense in sentensesData: points = 0
import os import cfg items = [] with open(cfg.get_path() + '131161_sentense', 'r') as sentenses_file: for sentense in sentenses_file: sentense = sentense.replace('\n', '') sentense = sentense.replace('\ufeff', '') sentense = sentense.split('-') items.append(sentense) # Check print(items[0]) print(len(items)) stns_file = open(cfg.get_path() + 'sentenses', 'a') answ_file = open(cfg.get_path() + 'answer', 'a') comparator = ['บวก', 'ลบ'] for item in items: ans = 2 if comparator[0] in item[1]: ans = 1 elif comparator[1] in item[1]: ans = 0 else: ans = 2 answ_file.write('{}\n'.format(ans)) stns_file.write('{}\n'.format(item[0]))
import numpy as np import os import cfg f = open(cfg.get_path() + 'words', 'w') words = [] chk = [] cwd = cfg.get_path() first = True with open(cwd + 'normal-word.txt', 'r') as norWord: for item in norWord: item = item.replace('\n', '') if not item in chk: words.append([item, 100 * np.random.uniform(0, 0.05)]) chk.append(item) first = True with open(cwd + 'negative-word', 'r') as negWord: for item in negWord: # print(item[0:len(item)-1]) item = item.replace('\n', '') if not item in chk: words.append([item, (-100 * np.random.uniform(0.5, 0.01))]) chk.append(item) first = True with open(cwd + 'positive-sentiment-words.txt', 'r') as posWord: for item in posWord: item = item.replace('\n', '') if not item in chk:
# for data in data_file: # if '\n' in data: # data = data[:-1] # tmp = data.split('\t') # for i in range(len(tmp)-1): # tmp[i] = float(tmp[i]) # tmp[len(tmp)-1] = int(tmp[len(tmp)-1]) # dataset.append(tmp) # print(dataset) # ans = [] # with open('answer', 'r') as ans_file: # for data in ans_file: # tmp = 0 # if '\n' in data: # tmp = data[:-1] # ans.append(int(tmp)) # print(ans) import json import cfg tmp = [] with open(cfg.get_path() + 'info', 'r') as fl: tmp = json.load(fl) print(tmp[0][0]['MLP-BP'][0]) print(tmp[1])