Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double-counting the documents containing an item #10

Open
jianle4github opened this issue Dec 16, 2017 · 0 comments
Open

Double-counting the documents containing an item #10

jianle4github opened this issue Dec 16, 2017 · 0 comments

Comments

@jianle4github
Copy link

If an item, for example, "Bourqoqne" appears multiple times in a given document, "Coche-Dury Bourgogne Chardonay 2005, Bourgogne, France", your algorithm will append this same item into the IrIndex.index list and IrIndex.tf list multiple times. This multiple-append implementation distorts the calculation of total number of documents containing the given item in the following code:

idf = log( float( len(self.documents) ) / float( len(self.tf[term]) ) )

I changed the code from:

for term in terms:
if term not in self.index:
self.index[term] = []
self.tf[term] = []

        self.index[term].append(document_pos)
        self.tf[term].append(terms.count(term))

to:

for term in terms:
if term not in self.index:
self.index[term] = []
self.tf[term] = []

        if document_pos not in self.index[term]:
            self.index[term].append(document_pos)
            self.tf[term].append(terms.count(term))

by skipping the subsequent append operations if an item in conjunction with its containing document is already recorded inside an IrIndex object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant