本文整理匯總了Python中FileIO.readFile方法的典型用法代碼示例。如果您正苦於以下問題:Python FileIO.readFile方法的具體用法?Python FileIO.readFile怎麽用?Python FileIO.readFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類FileIO
的用法示例。
在下文中一共展示了FileIO.readFile方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test
# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import readFile [as 別名]
def test(testText, dictionary):
classCntTxt = FileIO.readFile('corpus\classCount.txt');
classCnt = {};
for line in classCntTxt.split('\n'):
statistics = line.split('\t');
if len(statistics) > 1:
classCnt[statistics[0]] = statistics[1];
return Classifier.naiveBayes(dictionary, classCnt, testText);
示例2: getBinTestText
# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import readFile [as 別名]
def getBinTestText(fileName) :
fileText = FileIO.readFile(fileName);
tokens = Tokenizer.tokenizer(fileText);
wordOccurence = {};
resultTokens = "";
for token in tokens.split("\n"):
if token not in wordOccurence:
wordOccurence[token] = 1;
resultTokens = resultTokens + token + "\n";
return resultTokens;
示例3: loadCorpus
# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import readFile [as 別名]
def loadCorpus(corpusName):
dictionary = {};
fileText = FileIO.readFile(corpusName);
for line in fileText.split('\n'):
words = line.split('\t');
if len(words) > 2:
if words[0] not in dictionary:
dictionary[words[0]] = {};
dictionary[words[0]][words[2]] = words[1];
return dictionary;
示例4: buildCorpus
# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import readFile [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..');
示例5: buildBinarizedCorpus
# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import readFile [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!!');
示例6: getTestText
# 需要導入模塊: import FileIO [as 別名]
# 或者: from FileIO import readFile [as 別名]
def getTestText(fileName):
testText = FileIO.readFile(fileName);
testText = Tokenizer.tokenizer(testText);
return testText;