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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:49:29+00:00 2026-06-03T20:49:29+00:00

Jep still playing around with Python. I decided to try out Gensim, a tool

  • 0

Jep still playing around with Python.

I decided to try out Gensim, a tool to find out topics for a choosen word & context.

So I wondered how to find a word in a section of text and extract 20 words together with it (as in 10 words before that spectic word and 10 words after that specific word) then to save it together with other such extractions so Gensim could be run on it.

What seems to be hard for me is to find a way to extract the 10 before and after words when the choosen word is found. I played with nltk before and by just tokenizing the text into words or sentences it was easy to get hold of the sentences. Still getting those words or the sentences before and after that specific sentence seems hard for me to figure out how to do.

For those who are confused (it’s 1am here so I may be confusing) I’ll show it with an example:

As soon as it had finished, all her blood rushed to her heart, for she
was so angry to hear that Snow-White was yet living. “But now,”
thought she to herself, “will I make something which shall destroy her
completely.” Thus saying, she made a poisoned comb by arts which she
understood, and then, disguising herself, she took the form of an old
widow. She went over the seven hills to the house of the seven Dwarfs,
and[15] knocking at the door, called out, “Good wares to sell to-day!”

If we say the word is Snow-White then I’d want to get this part extracted:

her heart, for she was so angry to hear that Snow-White was yet living. “But now,”
thought she to herself, “will

10 word before and after Snow-White.

It is also cool enough to instead get the sentence before and after the sentence Snow-White appeared in if this can be done in nltk and is easier.

I mean whatever works best I shall be happy with one of the two solutions if someone could help me.

If this can be done with Gensim too…and that is easier, then I shall be happy with that too. So any of the 3 ways will be fine…I just want to try and see how this can be done because atm my head is blank.

  • 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-03T20:49:31+00:00Added an answer on June 3, 2026 at 8:49 pm
    text = """
    As soon as it had finished, all her blood rushed to her heart, for she was so angry to hear that Snow-White was yet living. "But now," thought she to herself, "will I make something which shall destroy her completely." Thus saying, she made a poisoned comb by arts which she understood, and then, disguising herself, she took the form of an old widow. She went over the seven hills to the house of the seven Dwarfs, and[15] knocking at the door, called out, "Good wares to sell to-day!"
    """
    spl = text.split()
    
    def ans(word):
        for ind, x in enumerate(spl):
           if x.strip(",'\".!") == word:
               break
        return " ".join(spl[ind-10:ind] + spl[ind:ind+11])
    
    
    >>> ans('Snow-White')
    her heart, for she was so angry to hear that Snow-White was yet living. "But now," thought she to herself, "will
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an array like this array 2 => string 'Member forum 1' 5
I wrote this utility function: public static <T> List<T> pluck(String fieldName, List list) throws
I'm looking for a relatively simpler (when compared with writing a parser) way to
I'm using a JEditorPane to display some HTML data, however any images that have
We are getting a NoSuchMethodError in the runtime. I just want to know do
I am having trouble with a HelloWorld Applet. Here is my Java code: package
Looking for a fast way to limit duplicates to a max of 2 when
I have been writing a chat app for android. I am implementing Google talk
For me the answer is currently: No, I would use iBatis, because NHibernate is
I have two tables in the clients mssql database. The first is a job

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.