本文整理汇总了Python中sentimentfinding.IOtools.readtextlines方法的典型用法代码示例。如果您正苦于以下问题:Python IOtools.readtextlines方法的具体用法?Python IOtools.readtextlines怎么用?Python IOtools.readtextlines使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sentimentfinding.IOtools
的用法示例。
在下文中一共展示了IOtools.readtextlines方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_resource_label
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def add_resource_label(matrixpath, datasetname, replacelabel=False, headers=True):
matrixlines = IOtools.readtextlines(matrixpath) # 1st item=fileid, lastitem=filecat.
newmatrix = []
if headers:
matrixlines = matrixlines[2:]
for instance in matrixlines:
items = instance.split()
fileid = items[0]
print instance,
path = datapath+os.sep+datasetname
foldernames = IOtools.getfoldernames_of_dir(datapath+os.sep+datasetname)
#print foldernames
for folder in foldernames:
allfileids = IOtools.getfilenames_of_dir(path+os.sep+folder, removeextension=False)
#print allfileids
if fileid in allfileids:
newspath = path+os.sep+folder+os.sep+fileid
resourcename = texter.getnewsmetadata(newspath, ["resource"])["resource"]
#print "## ",resourcename," ",type(instance)," ~~ ",instance
if replacelabel: items = items[:-1]
newmatrix.append(items +[resourcename])
break
return newmatrix
示例2: merge_word_lists
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def merge_word_lists(indirectory, outdirectory, outfilename):
fileids = IOtools.getfilenames_of_dir(indirectory, removeextension=False)
allwords = []
for fileid in fileids:
words = IOtools.readtextlines(indirectory+os.sep+fileid)
allwords.extend(words)
IOtools.todisc_list(outdirectory+os.sep+outfilename+".txt", allwords)
fdist = nltk.FreqDist(allwords)
IOtools.todisc_freqdist(outdirectory+os.sep+"weighted-"+outfilename+".txt", fdist)
'''
示例3: prepare_data
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def prepare_data(path, classlabels, header=False):
datapoints = IOtools.readtextlines(path)
X = []
Y = []
if header: datapoints = datapoints[1:]
for line in datapoints:
items = line.split()
classlabelindicing = classlabels[items[-1]] # class encoding
values = [float(val) for val in items[1:-1]]
X.append(values)
Y.append(classlabelindicing)
X = np.array(X)
Y = np.array(Y)
return X, Y
示例4: get_termdoc_matrix
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def get_termdoc_matrix(matrixpath):
lines = IOtools.readtextlines(matrixpath)
doclist = []
header = lines[0]
terms = header.split()
terms = map(lambda x : x.strip(), terms)
matrix = []
for i in range(1,len(lines)):
items = lines[i].split()
doclist.append(items[0])
values = [float(val) for val in items[1:-1]]
matrix.append(values)
return np.array(matrix), terms, doclist
'''
示例5: classification_results
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def classification_results(experimentname, resultfile, classlabeldecoding):
results = IOtools.readtextlines(IOtools.results_rootpath+os.sep+resultfile)
numofpoints = int(results[1].split(":")[1])
print results[2]," ",results[3]," ",numofpoints
predictions = results[3 : (numofpoints+3)]
print len(predictions)
confusionmatrix = np.zeros((len(classlabeldecoding), len(classlabeldecoding)))
for i,prediction in enumerate(predictions):
#items = prediction.split("\t")
items = re.split(r"\s+", prediction)
items = [str(item).strip() for item in items]
predicted = items[0]
actual = items[1]
print i," ",prediction," ~~ ",items
confusionmatrix[classlabeldecoding[predicted], classlabeldecoding[actual]] += 1
IOtools.todisc_matrix(confusionmatrix.tolist(), IOtools.matrixpath+os.sep+experimentname+"ConfMat.m")
# plot confusion matrix
xitems = [0 for i in range(len(classlabeldecoding))]
for k,v in classlabeldecoding.iteritems():
xitems[v] = k
classlabeldecoding.keys()
colors = plotter._get_colors(confusionmatrix.shape[0])
for k,v in classlabeldecoding.iteritems():
plotter.plot_line(xitems, confusionmatrix[v, :], linelabel=k, clr=colors[v])
print xitems," ",k," : ",v
plotter.plot_line(xitems, confusionmatrix.diagonal().tolist(), linelabel="target", clr="k")
plt.xlabel("actual")
plt.ylabel("predicted")
plt.legend()
plt.savefig(IOtools.img_output+os.sep+experimentname+"ConfMat.png")
plt.show()
示例6: read_wordlists
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def read_wordlists(self, inputpath, recordpath, labelwisefileidlist):
self.rootpath = recordpath
self.inputpath = inputpath
docroots = []
for label, fileids in labelwisefileidlist.iteritems():
for fileid in fileids:
docid = fileid
path = self.inputpath + os.sep + label + os.sep + fileid
words = IOtools.readtextlines(path)
words = texter.remove_endmarker(words, "(i)")
words = texter.remove_endmarker(words, "(ii)")
for root in words:
docroots.append((docid, root))
self.cfd_DocRoot = nltk.ConditionalFreqDist(docroots)
self.cfd_RootDoc = nltk.ConditionalFreqDist((word, fileid) for fileid in self.cfd_DocRoot.conditions()
for word in list(self.cfd_DocRoot[fileid]))
示例7: yapmak
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
if __name__ == "__main__":
#parseXML_phraseslexicon(phrasesxmlin, phrasestxtout)
#IOtools.mergetxtfiles(phrasestxtout, phrasestxtout+os.sep+"tr_phrases.txt")
#s = 'dedigini (veya soyledigini) yapmak (veya etmek)'
#s = "(birine) dedigini yapmak (veya soylemek) (kendi)"
s = "dedigini yapmak"
print editphrase(s)
allphrases = IOtools.readtextlines(phrasestxtout+os.sep+"tr_phrases.txt")
refinedphrases = []
for p in allphrases:
refinedphrases.append(editphrase(p))
IOtools.todisc_list(phrasestxtout+os.sep+"tr_phrasesEDIT.txt", refinedphrases)
'''
fname = "ADB_a.xml"
path = phrasespath + os.sep + fname
tree = ET.parse(path)
root = tree.getroot()
print root.findtext("name")
示例8: len
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
if __name__ == "__main__":
#getwordsandlemmasfromfile()
# intersect and differ categories
indirectory = "/home/dicle/Dicle/Tez/geziyakurdiproject/words/merged/"
outdirectory = indirectory
poswords = IOtools.readtextlines(indirectory+os.sep+"posRoot.txt")
negwords = IOtools.readtextlines(indirectory+os.sep+"negRoot.txt")
i = intersect_word_lists(poswords, negwords, outdirectory, "posneg_intersect")
pn = diff_word_lists(poswords, negwords, outdirectory, "pos-neg_diff")
np = diff_word_lists(negwords, poswords, outdirectory, "neg-pos_diff")
# report
numofcommons = len(set(i))
numofpos = len(set(poswords))
numofneg = len(set(negwords))
numofposdiff= len(set(pn))
numofnegdiff = len(set(np))
print "POS ratio"
print "numofcommon / numofPOS", str(float(numofcommons) / numofpos)
print "\nNEG ratio"
示例9: trydates
# 需要导入模块: from sentimentfinding import IOtools [as 别名]
# 或者: from sentimentfinding.IOtools import readtextlines [as 别名]
def trydates(brand, seedday=26, seedmonth=6, seedyear=2013, intervaldays=1):
rootlink = "http://t24.com.tr/media/papers/zoom/"
seeddate = datetime(seedyear, seedmonth, seedday)
for i in range(intervaldays):
seeddate = seeddate + timedelta(days=1)
strdate = seeddate.strftime('%Y-%m-%d')
imgname = brand + "_" + strdate + ".jpg"
print strdate, " ", imgname
'''
link = rootlink + "/" + imgname
dir = IOtools.ensure_dir(rootimgdir + os.sep + brand)
urllib.urlretrieve(link, dir + os.sep + imgname)
'''
def save_images(brandnames):
for brand in brandnames:
save_images_onebrand(brand)
if __name__ == "__main__":
brands = IOtools.readtextlines(rootdir + os.sep + "brandsselected.txt")
save_images(brands)
#trydates("")