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

  • Home
  • SEARCH
  • 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 6877961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:39:53+00:00 2026-05-27T04:39:53+00:00

I am attempting to build a TokenStream from a Python Sequence. Just for fun

  • 0

I am attempting to build a TokenStream from a Python Sequence.
Just for fun I want to be able to pass my own Tokens directly to

pylucene.Field("MyField", MyTokenStream)

I tried to make “MyTokenStream” by…

terms = ['pant', 'on', 'ground', 'look', 'like', 'fool']
stream = pylucene.PythonTokenStream()
for t in terms:
  stream.addAttribute(pylucene.TermAttribute(t))

But unfortunately a wrapper for “TermAttribute” doesn’t exist, or for that matter any of the other Attribute classes in lucene so I get a NotImplemented error when calling them.

This doesn’t raise an exception – but I’m not not sure if it’s even setting the terms.

PythonTokenStream(terms)
  • 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-05-27T04:39:53+00:00Added an answer on May 27, 2026 at 4:39 am

    The Python* classes are designed to customize behavior by subclassing. In the case of TokenStream, the incrementToken method needs to be overridden.

    class MyTokenStream(lucene.PythonTokenStream):
        def __init__(self, terms):
            lucene.PythonTokenStream.__init__(self)
            self.terms = iter(terms)
            self.addAttribute(lucene.TermAttribute.class_)
        def incrementToken(self):
            for term in self.terms:
                self.getAttribute(lucene.TermAttribute.class_).setTermBuffer(term)
                return True
            return False
    
    mts = MyTokenStream(['pant', 'on', 'ground', 'look', 'like', 'fool'])
    while mts.incrementToken():
        print mts
    
    <MyTokenStream: (pant)>
    <MyTokenStream: (on)>
    <MyTokenStream: (ground)>
    <MyTokenStream: (look)>
    <MyTokenStream: (like)>
    <MyTokenStream: (fool)>
    

    The result of addAttribute could also be stored, obviating the need for getAttribute. My lupyne project has an example of that.

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

Sidebar

Related Questions

I'm attempting to build Python 2.6.2 from source on my Linux system. It has
I am attempting to build a simple method that creates an XML file from
I'm attempting to build a search stored procedure. I want to search multiple tables
I'm attempting to build a Rails application that uses Amazons S3 service. I'm able
I am attempting to build a rudimentary interpreter in Scheme, and I want to
Attempting to build .exe using py2exe: python setup.py py2exe , receiving error: ImportError: No
I'm attempting to build some C++ code that requires the Windows 7.0 SDK header
I'm attempting to build Firefox on my Windows Vista Ultimate machine. I keep getting
I am attempting to build a Java web project on NetBeans 6.8, but I
I'm attempting to build a project called DropThings but I am getting all these

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.