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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:51:25+00:00 2026-06-13T19:51:25+00:00

(This question is with regards to string checking in general and not Natural Language

  • 0

(This question is with regards to string checking in general and not Natural Language Procesisng per se, but if you view it as an NLP problem, imagine it’s not a langauge that current analyzers can analye, for simplicity sake, i’ll use english strings as e.g.)

lets say there are only 6 possible form that a word can be realized in

  1. the initial letter being capitalized
  2. its plural form with an “s”
  3. its plural form with an “es”
  4. capitalized + “es”
  5. capitalized + “s”
  6. the basic form without plural or capitalization

let’s say i want to find the index of the 1st instance any form of the word coach occurs in a sentence, is there a simpler way of doing these 2 methods:

long if condition

sentence = "this is a sentence with the Coaches"
target = "coach"

print target.capitalize()

for j, i in enumerate(sentence.split(" ")):
  if i == target.capitalize() or i == target.capitalize()+"es" or \
     i == target.capitalize()+"s" or i == target+"es" or i==target+"s" or \
     i == target:
    print j

iterating try-except

variations = [target, target+"es", target+"s", target.capitalize()+"es",
target.capitalize()+"s", target.capitalize()]

ind = 0
for i in variations:
  try:
    j == sentence.split(" ").index(i)
    print j
  except ValueError:
    continue
  • 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-13T19:51:28+00:00Added an answer on June 13, 2026 at 7:51 pm

    I recommend having a look at the stem package of NLTK: http://nltk.org/api/nltk.stem.html

    Using it you can “remove morphological affixes from words, leaving only the word stem. Stemming algorithms aim to remove those affixes required for eg. grammatical role, tense, derivational morphology leaving only the stem of the word.”

    If your language is not covered by NLTK currently, you should consider extending NLTK. If you really need something simple and don’t bother about NLTK, then you should still write your code as a collection of small, easy to combine utility functions, for example:

    import string 
    
    def variation(stem, word):
        return word.lower() in [stem, stem + 'es', stem + 's']
    
    def variations(sentence, stem):
        sentence = cleanPunctuation(sentence).split()
        return ( (i, w) for i, w in enumerate(sentence) if variation(stem, w) )
    
    def cleanPunctuation(sentence):
        exclude = set(string.punctuation)
        return ''.join(ch for ch in sentence if ch not in exclude)
    
    def firstVariation(sentence, stem):
        for i, w  in variations(sentence, stem):
            return i, w
    
    sentence = "First coach, here another two coaches. Coaches are nice."
    
    print firstVariation(sentence, 'coach')
    
    # print all variations/forms of 'coach' found in the sentence:
    print "\n".join([str(i) + ' ' + w for i,w in variations(sentence, 'coach')])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand this question can be general but, specifically with regards to ASP.NET MVC,
This question is in regards to Mike Bostock's very exciting d3.js library in general,
I have just asked this question an hour ago but with regards to IE8
This is a question about setting our website's Language and Culture settings with regards
I am sorry if this question is double somewhere, I've searched but did not
I am solving this question on codechef ! It is a simple problem, but
This question is in regards to this blog entry. https://blog.stackoverflow.com/2008/07/easy-background-tasks-in-aspnet/ All the way at
I had posted a question in regards to this code. I found that JTextArea
I bumped into an additional question that I needed in regards to this: Using
I'm new to iPhone development, so apologies if this is a silly question, but

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.