当前位置: 首页>>代码示例>>Python>>正文


Python IOtools.readtextlines方法代码示例

本文整理汇总了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
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:30,代码来源:matrixhandler.py

示例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)
    '''
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:15,代码来源:articleanalysis.py

示例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
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:18,代码来源:classification.py

示例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
        
        
    '''
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:21,代码来源:termanalysis.py

示例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()
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:44,代码来源:classification.py

示例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]))
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:22,代码来源:documentsimilarity.py

示例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")
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:32,代码来源:parsexml.py

示例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"
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:33,代码来源:articleanalysis.py

示例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("")



 
    
开发者ID:dicleoztur,项目名称:subjectivity_detection,代码行数:28,代码来源:retrieveimages.py


注:本文中的sentimentfinding.IOtools.readtextlines方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。