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


Python FileIO.wrtieToFile方法代码示例

本文整理汇总了Python中FileIO.wrtieToFile方法的典型用法代码示例。如果您正苦于以下问题:Python FileIO.wrtieToFile方法的具体用法?Python FileIO.wrtieToFile怎么用?Python FileIO.wrtieToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FileIO的用法示例。


在下文中一共展示了FileIO.wrtieToFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import wrtieToFile [as 别名]
def main(trainMode, binarized, testDir, resultFile):
    dir1 = r'R:\masters\fall2013\COMP579A\project\aclImdb\train\pos';
    dir2 = r'R:\masters\fall2013\COMP579A\project\aclImdb\train\neg';
    corpusName = r'corpus\binCorpus.txt';
    if(not binarized):
        corpusName = r'corpus\corpus.txt';
    if(trainMode):
        if(binarized):
            buildBinarizedCorpus(dir1, corpusName);
            buildBinarizedCorpus(dir2, corpusName);
        else:
            buildCorpus(dir1, corpusName);
            buildCorpus(dir2, corpusName);
    
    dictionary = loadCorpus(corpusName);
    testText = '';
    print('test for dir' , testDir);
    for dir_entry in os.listdir(testDir):
        if binarized:
            testText = getBinTestText(os.path.join(testDir, dir_entry));
        else:
            testText = getTestText(os.path.join(testDir, dir_entry));
        result =test(testText, dictionary);
        FileIO.wrtieToFile(resultFile, 'a' ,"The file " + os.path.join(testDir, dir_entry) + " is classified as " + result + "\n");
    print("Done....");
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:27,代码来源:Analyzer.py

示例2: buildCorpus

# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import wrtieToFile [as 别名]
def buildCorpus(dirPath, corpusName):
    print('creating corpus!!');
    tagClass = fetchLabel(dirPath);
    classCnt = FileIO.countFiles(dirPath);
    dictionary = {};
    FileIO.wrtieToFile("corpus\classCount.txt", 'a', (tagClass + '\t' + str(classCnt) + '\n' ));
    for dir_entry in os.listdir(dirPath):
        text = FileIO.readFile(os.path.join(dirPath, dir_entry));
        text = Tokenizer.tokenizer(text);
        for token in text.split('\n'):
            if token not in dictionary:
                dictionary[token] = {};
            if tagClass not in dictionary[token]:
                dictionary[token][tagClass] = 0;
            dictionary[token][tagClass] = dictionary[token][tagClass] + 1;
    for key, value in dictionary.items():
        FileIO.wrtieToFile(corpusName, 'a', (key + '\t' + str(value[tagClass]) + '\t' + tagClass + '\n'));
    print('Corpus creation : Done..');
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:20,代码来源:Analyzer.py

示例3: buildBinarizedCorpus

# 需要导入模块: import FileIO [as 别名]
# 或者: from FileIO import wrtieToFile [as 别名]
def buildBinarizedCorpus(dirPath, corpusName):
    print('creating binarized corpus!!');
    tagClass = fetchLabel(dirPath);
    classCnt = FileIO.countFiles(dirPath);
    FileIO.wrtieToFile("corpus\classCount.txt", 'a', (tagClass + '\t' + str(classCnt) + '\n' ));
    corpusDict = {};
    for dir_entry in os.listdir(dirPath):
        fileTokens = {};
        text = FileIO.readFile(os.path.join(dirPath, dir_entry));
        text = Tokenizer.tokenizer(text);
        for token in text.split('\n'):
            if token not in fileTokens:
                fileTokens[token] = 1;
                if token not in corpusDict:
                    corpusDict[token] = {};
                    corpusDict[token][tagClass] = 1;
                else:
                    corpusDict[token][tagClass] = corpusDict[token][tagClass] + 1;
    for key, value in corpusDict.items():
        FileIO.wrtieToFile(corpusName, 'a', (key + '\t' + str(value[tagClass]) + '\t' + tagClass + '\n' ));
    print('binarized corpus creation done!!');
开发者ID:ambikab,项目名称:SentimentAnalysis,代码行数:23,代码来源:Analyzer.py


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