Click here to Skip to main content
11,813,557 members (46,398 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Python Python2.4
import sys, math, re
from operator import itemgetter
import math
#reading from test file
wF = open (r'C:\Craig\Data2\craiglist-file1.txt')
wordFile =
wordList = wordFile.upper()
wordList = wordFile.split()
#Reading from the keyword file
kWF = open('keywords.txt','r')
keywordFile =
KeywordList = keywordFile.upper()
keywordList = keywordFile.split()
word = 'k'
document = 'wordlist'
wordlist = 'w'

#total number of times terms occurs in file
def countTerm(word, document):
for k in keywordList:
    countTerm = 0
    for w in wordList:
        if k == w:
            countTerm = countTerm + 1
        if k == "the":
           print k, w, countTerm
    print k, countTerm

#total number of word in document
def wordfreq(wordList):
wordfreq = [wordList.count(p) for p in wordList]
dictionary = dict(zip(wordList, wordfreq))
count2 = 0
for t in wordList:
print 'total number of words', count2

#total number of file being processed
def docfreq(k, wF):
    count = 0
    for wordList in wF:
        if countTerm(k, w) > 0:
            count += 1
    return count
print countTerm
#docfreq = [wordList.count(z) for z in wF]
#dictionary = dict(zip(wF, docfreq))
#count3 = 1
#for j in wF:
    #count3 +=1
#print 'total number of document', count3
for n in range(0,len(keywordList)):
    print keywordList[n] wordfreq[n]/count2


# term frequency
# total number of times terms occurs in file / total number of word in document
#inverse document frequency
Posted 10-Dec-10 6:37am
Edited 10-Dec-10 6:46am
(no name)25.2K
HimanshuJoshi at 10-Dec-10 12:46pm
Added pre blocks.
HimanshuJoshi at 10-Dec-10 12:46pm
So what seems to be the problem?
Dave Kreskowiak at 10-Dec-10 13:40pm
Soooooooooooooooooooo...... did you have a question or did you just want to post a meaningless code snippet for everyone to completely ignore?
Keith Barrow at 12-Dec-10 7:15am
Nice code. What is the problem?
caisar oentoro at 6-Dec-13 4:01am
Well, no explanation about your code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Abhinav S 275
1 Palash Mondal_ 190
2 KrunalRohit 150
4 Manas_Kumar 115
0 OriginalGriff 3,877
1 KrunalRohit 2,526
2 Maciej Los 2,245
3 CPallini 2,240
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web03 | 2.8.151002.1 | Last Updated 10 Dec 2010
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100