On Thursday March 15 2007 9:28 pm, Ofer Nave wrote:
> > -----Original Message-----
> > From: [EMAIL PROTECTED]
> > [mailto:[EMAIL PROTECTED] On Behalf Of Pete
> > Sent: Thursday, March 15, 2007 5:54 PM
> > To: [email protected]
> > Subject: Re: [pylucene-dev] why isn't my custom
> > Similarityobjectchangingthebehavior?
> >
> > On Thursday March 15 2007 6:31 pm, Ofer Nave wrote:
> > 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.
There's no compilation - Python's entirely interpreted. Unless you have a
SyntaxError, the interpreter will let you write whatever code you want.
Including defining names multiple times, redefining
variables/functions/classes at runtime and referencing names that don't exist
(which'll throw an exception at runtime, when you actually hit that code).
> > 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?
No, just that's it a little more flexible - you could pass in some other
Similarity if you wanted to. Delegator pattern, or Wrapper, or whatever you
like to call it[0]. Overhead's not really an issue here, as you're gonna
create one of these things & pass it to your searcher.
I'd prolly do something like:
def __init__(self, similarity=None);
similarity=similarity or PyLucene.DefaultSimilarity()
assert isinstance(similarity, PyLucene.Similarity)
# should probably name this attr 'similarity', self.super looks weird,
# but that's just style
self.super=similarity
I may have some of the above names wrong, but you get the idea.
> > 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).
Heh. Good luck.
--Pete
[0] - FWIW, doing it this way is an oddity of PyLucene. In regular Python,
you'd just subclass & override the method in question.
--
Peter Fein || 773-575-0694 || [EMAIL PROTECTED]
http://www.pobox.com/~pfein/ || PGP: 0xCCF6AE6B
irc: [EMAIL PROTECTED] || jabber: [EMAIL PROTECTED]
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev