def execute(self):
     db = Db()
     l = text_to_list(self.file_contents)
     d = list_to_dict(l)
     db.update_word_counts(d, self.doc_type)
     db.update_doctype_count(self.count, self.doc_type)
     return self.count
 def execute(self):
     db = Db()
     l = text_to_list(self.file_contents)
     d = list_to_dict(l)
     db.update_word_counts(d, self.doc_type)
     db.update_doctype_count(self.count, self.doc_type)
     return self.count
Beispiel #3
0
	def learn_file(self, name, count):
		file_contents = None
		words_count = 0
		db = self.db
		try:
			f = open(name, 'r')
			file_contents = f.read()
			f.close()

			l = text_to_list(file_contents)
			d = list_to_dict(l)
			words_count = db.update_word_counts(d, self.doc_type)
			db.update_doctype_count(count, self.doc_type)

			print '>> TRAINING [ %s ]: %5d words learned from "%s"' % (self.doc_type, words_count, name)


		except Exception as e:
			raise ValueError(usage + '\nUnable to read specified file "%s", the error message was: %s' % (args[3], e))

		return words_count
from db import Db
import os, sys, string, re, csv
import collections
reload(sys)
sys.setdefaultencoding('utf8')
if sys.argv[1].lower() == 'p':
    textname = 'positive.csv'
    text = open(textname, 'rb')
elif sys.argv[1].lower() == 'n':
    textname = 'negative.csv'
    text = open(textname, 'rb')
else:
    print "Invalid Entry"
    sys.exit(True)
newl = file_to_list(text)
newd = list_to_dict(newl)
#word_dict = collections.OrderedDict(sorted(newd.items()))
#word_dict = sorted(newd,key=newd.__getitem__)
for word, count in sorted(
        newd.items(), key=lambda x: x[1], reverse=True
):  ###########################need to sort the list according to count here
    print word, count
#########pos or neg lai db ma rakhnu paryo#################
db = Db()
counts = db.get_doctype_counts()
#poscount = counts['p']
#negcount = counts['n']
if sys.argv[1].lower() == "p":
    db.update_words_count(newd, 'p')
    db.update_doctype_count(len(newd), 'p')
elif sys.argv[1].lower() == 'n':
Beispiel #5
0
def nepunigrams():
	unidict = list_to_dict(unilist)
	#word_dict = collections.OrderedDict(sorted(newd.items()))
	#word_dict = sorted(newd,key=newd.__getitem__)
	finaldict = sorted(unidict.items(),key=lambda x : x[1],reverse = True)
	return finaldict