Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9191759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:45:47+00:00 2026-06-17T20:45:47+00:00

When doing a word frequency count on my corpus, the results seem inacurate (are

  • 0

When doing a word frequency count on my corpus, the results seem inacurate (are not the most frequent words to my feeling, and the frequency count is only one or two) and some results show ‘as over\xe2’ and ‘\xad’. Can anyone help?

def toptenwords(mycorpus):
  mywords = mycorpus.words()
  nocapitals = [word.lower() for word in mywords] 
  filtered = [word for word in nocapitals if word not in stoplist]
  nopunctuation= [s.translate(None, string.punctuation) for s in filtered] 
  woordcounter = {}
     for word in nopunctuation:
        if word in wordcounter:
          woordcounter[word] += 1
        else:
          woordcounter[word] = 1
    frequentwords = sorted(wordcounter.iteritems(), key = itemgetter(1), reverse = True)
    top10 = frequentwords[:10]
    woord1 = frequentwords[1]
    woord2 = frequentwords[2]
    woord3 = frequentwords[3]
    woord4 = frequentwords[4]
    woord5 = frequentwords[5]
    woord6 = frequentwords[6]
    woord7 = frequentwords[7]
    woord8 = frequentwords[8]
    woord9 = frequentwords[9]
    woord10 = frequentwords[10]
    print "De 10 meest frequente woorden zijn: ", woord1, ",", woord2, ",", woord3, ",",    woord4, ",", woord5, ",", woord6, ",", woord7, ",", woord8, ",", woord9, "en", woord10

Code is originally in dutch, this is the NOT translated code:

def toptienwoorden(mycorpus):
   woorden = mycorpus.words()
   zonderhoofdletters = [word.lower() for word in woorden] 
   gefiltered = [word for word in zonderhoofdletters if word not in stoplijst] 
   geenleestekens = [s.translate(None, string.punctuation) for s in gefiltered] 
   woordteller = {}
   for word in geenleestekens:
      if word in woordteller:
         woordteller[word] += 1
      else:
         woordteller[word] = 1
  frequentewoorden = sorted(woordteller.iteritems(), key = itemgetter(1), reverse = True)
  top10 = frequentewoorden[:10]
  woord1 = frequentewoorden[1]
  woord2 = frequentewoorden[2]
  woord3 = frequentewoorden[3]
  woord4 = frequentewoorden[4]
  woord5 = frequentewoorden[5]
  woord6 = frequentewoorden[6]
  woord7 = frequentewoorden[7]
  woord8 = frequentewoorden[8]
  woord9 = frequentewoorden[9]
  woord10 = frequentewoorden[10]
  print "De 10 meest frequente woorden zijn: ", woord1, ",", woord2, ",", woord3, ",",    woord4, ",", woord5, ",", woord6, ",", woord7, ",", woord8, ",", woord9, "en", woord10
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:45:49+00:00Added an answer on June 17, 2026 at 8:45 pm

    Use a collections.Counter. It is perfect for counting the frequency of (hashable) items and it has a most_common method which can return the top ten most frequent items without you having to code the logic yourself:

    import string
    import collections
    
    
    def topNwords(mywords, N = 10, stoplist = set(), filtered = set()):
        # mywords = mycorpus.words()
        nocapitals = [word.lower() for word in mywords]
        filtered = [word for word in nocapitals if word not in stoplist]
        nopunctuation = [s.translate(None, string.punctuation) for s in filtered]
        woordcounter = collections.Counter(nopunctuation)
        top_ten = [word for word, freq in woordcounter.most_common(N)]
        return top_ten
    
    
    top_ten = topNwords('This is a test. It is only a test. In case of a real emergency'.split(), N = 10)
    print("De 10 meest frequente woorden zijn: {w}".format(w = ', '.join(top_ten)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does a set of functions doing exactly one word but differing in the name
I am doing a graduation project on Word Sense Disambiguation (WSD) I have one
I am using TinyMCE only to paste from word. What I am doing actually
CSS word-spacing property for input elements not working in Opera Am I doing something
I'm doing a mail-merge in Word 2010 with an Excel 2010 file as the
We are doing an app to manage and print Word, Excel, PowerPoint, and PDF
Does anyone have any experience with doing mail merge from Java on a word
In my project which I'm doing, I have to find if my word document
Just doing some research on searching for a character or word within a NSString
I'm currently doing enhancement on a vb.net project by using reference Interop.Microsoft.office.interop.word. Now i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.