def generateDic(filename): result = fileutil.readFileFromCSV(filename) themedDicName = "./data/themedic.in" sentimentDicName = "./data/sentimentdic.in" preDicName = "./data/predic.in" degreeDicName = "./data/degree.in" fileutil.deleteFileIfExist(themedDicName) fileutil.deleteFileIfExist(sentimentDicName) fileutil.deleteFileIfExist(preDicName) for r in result: sclist = r.sclist rowid = r.rowid for sc in sclist: thtext = sc.theme.text swtext = sc.word.text anls = sc.anls if r.text.find(swtext) == -1: l = len(swtext) for i in range(l): if r.text.find(swtext[:l - i]) != -1: fileutil.writeFile(preDicName, swtext[:l - i] + "\n") break fileutil.writeFile(themedDicName, thtext + "\n") fileutil.writeFile(sentimentDicName, swtext + " " + anls + "\n") print("Dictionaries generate succeed!")
def cutWordByCSVFile(self, filenamein, filenameout): rawdata = fileutil.readFileFromCSV(filenamein) fileutil.deleteFileIfExist(filenameout) result = "" totalProcess = len(rawdata) process = 0 for rd in rawdata: text = rd.text res = self.cutWord(text, 0, "") process = process + 1 self.showProcess(process, totalProcess) for r in res: result = result + r + " " result = result + "\n" fileutil.writeFile(filenameout, result)