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 9164227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:37:52+00:00 2026-06-17T14:37:52+00:00

I have a list of strings which are all verbs. I need to get

  • 0

I have a list of strings which are all verbs. I need to get the word frequencies for each verb, but I want to count verbs such as "want", "wants", "wanting" and "wanted" as one verb. Formally, a “verb” is defined as a set of 4 words that are of the form {X, Xs, Xed, Xing} or of the form {X, Xes, Xed, Xing} where X is the verb. How would I go about extracting verbs from the list such that I get "X" and a count of how many times the stem appears? I figured I could somehow use regex, however I’m new to regex and I am totally lost.

  • 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-17T14:37:54+00:00Added an answer on June 17, 2026 at 2:37 pm

    There is a library called nltk which has an insane array of functions for text processing. One of the subsets of functions are stemmers, which do just what you want (using algorithms/code developed by people with a lot of experience in the area). Here is the result using the Porter Stemming algorithm:

    In [3]: import nltk
    
    In [4]: verbs = ["want", "wants", "wanting", "wanted"]
    
    In [5]: for verb in verbs:
       ...:     print nltk.stem.porter.PorterStemmer().stem_word(verb)
       ...:     
    want
    want
    want
    want
    

    You could use this in conjunction with a defaultdict to do something like this (note: in Python 2.7+, a Counter would be equally useful/better):

    In [2]: from collections import defaultdict
    
    In [3]: from nltk.stem.porter import PorterStemmer
    
    In [4]: verbs = ["want", "wants", "wanting", "wanted", "running", "runs", "run"]
    
    In [5]: freq = defaultdict(int)
    
    In [6]: for verb in verbs:
       ...:     freq[PorterStemmer().stem_word(verb)] += 1
       ...:     
    
    In [7]: freq
    Out[7]: defaultdict(<type 'int'>, {'run': 3, 'want': 4})
    

    One thing to note: the stemmers aren’t perfect – for instance, adding ran to the above yields this as the result:

    defaultdict(<type 'int'>, {'ran': 1, 'run': 3, 'want': 4})
    

    However hopefully it will get you close to what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of strings from which I need to remove all elements
I have an ArrayList which get all it's entries as strings from DB List<Amthal>
I have a list of strings and with each string I want to check
I have a list of strings, each of which is an email formatted in
I have a list of strings (messages and urls) which I want to place
I have a list of items(i.e Strings) which I need to sort/filter. The end
Example of the problem If I have a list of valid option strings which
I have a simple list of strings, which may be of arbitrary length. I'd
I have the following code which utilises Guava's Files.readLines() method: List<String> strings = Lists.newArrayList();
I have a ListView which displays a list of string values. I want to

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.