[pylucene-dev] why isn't my custom
Similarityobjectchangingthebehavior?
Ofer Nave
ofer at smarter.com
Thu Mar 15 18:28:55 PST 2007
> -----Original Message-----
> From: pylucene-dev-bounces at osafoundation.org
> [mailto:pylucene-dev-bounces at osafoundation.org] On Behalf Of Pete
> Sent: Thursday, March 15, 2007 5:54 PM
> To: pylucene-dev at osafoundation.org
> Subject: Re: [pylucene-dev] why isn't my custom
> Similarityobjectchangingthebehavior?
>
> On Thursday March 15 2007 6:31 pm, Ofer Nave wrote:
>
> > class SimilaritySansTF(object):
> ...
> > def idf(self, term, searcher):
> > return self.super.idf(term, searcher)
> >
> > def idf(self, terms, searcher):
> > return self.super.idf(terms, searcher)
> >
> > def idf(self, docFreq, numDocs):
> > return self.super.idf(docFreq, numDocs)
>
> Python doesn't do signature-overloading. Your class is going
> to end up with the last definition of idf()
I knew Python didn't have signature overloading, but didn't know what would
happen when I defined the same function three times. Frankly, I was
surprised that it compiled without error. :) Thanks for the tip re last
definition being used.
> > So, that's definitely a step forward. However, I'm not
> very pleased
> > with my implementation, and I also have a host of new questions:
> >
> > 1) Did I implement the subclass wisely? I only wanted to override
> > tf(), but needed to implement many other methods in order
> to conform.
> > I also didn't want to have to recode the existing logic of the
> > superclass, and I didn't know how to properly call the super class
> > methods, so instead I instantiatied the superclass in __init__ and
> > delegated to it to calculate the answers for me. This works for
> > state-less classes, but would be problematic if I was subclassing a
> > class with state, where my subclass would have to share
> state with the superclass.
>
> Looks pretty much right to me - you might think about passing
> in self.super as an arg to __init__ instead.
Do you mean just to avoid the overhead of creating the inner
PyLucene.DefaultSimilarity() multiple times if SimilaritySansTF is created
several times?
> FWIW, if you're new to python, you picked about the single
> strangest package out there to start with. [0]
Don't I know it. :) Well, whatever doesn't kill you makes you stronger (or
gets you fired for taking too long).
-ofer
More information about the pylucene-dev
mailing list