Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: 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 = wF.read()
wordList = wordFile.upper()
wordList = wordFile.split()
 
#Reading from the keyword file
kWF = open('keywords.txt','r')
keywordFile = kWF.read()
KeywordList = keywordFile.upper()
keywordList = keywordFile.split()
 
word = 'k'
document = 'wordlist'
wordlist = 'w'
 

#total number of times terms occurs in file
def countTerm(word, document):
        return
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):
    return
wordfreq = [wordList.count(p) for p in wordList]
dictionary = dict(zip(wordList, wordfreq))
count2 = 0
for t in wordList:
    count2+=1
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 7:37am
Edited 10-Dec-10 7:46am
(no name)25.1K
v2
Comments
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 OriginalGriff 190
1 Jochen Arndt 165
2 PIEBALDconsult 150
3 BillWoodruff 148
4 DamithSL 140
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 10 Dec 2010
Copyright © CodeProject, 1999-2014
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