Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Design question about pretree classifier

1 view
Skip to first unread message

Julian

unread,
Dec 18, 2009, 11:38:22 AM12/18/09
to
Hello,

I've got a design problem for a classifier. To make it short: it maps
strings on strings.

Some strings have exactly one classification, some none and some more
than one.

There's a method classify(self, word) wich classifies a word. For the
first case there's no problem:

- one classification: return the value (it's a string)

But:

- none classification: return an exception or None? I think None is
better, hence its not an exception that there is no classification but
a defined state. What do you think?
- many classifications: what to do? retun a sequence of strings? raise
an exception and implement another method wich returns than the
classifications? what should I do here?

thanks for your answers!

Steve Holden

unread,
Dec 18, 2009, 12:59:38 PM12/18/09
to pytho...@python.org

Always return a list or tuple. For no classifications it should be
empty, for one classification it should have one element, ... , for N
classifications it should have N elements.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
UPCOMING EVENTS: http://holdenweb.eventbrite.com/

Julian

unread,
Dec 18, 2009, 2:25:09 PM12/18/09
to
On 18 Dez., 18:59, Steve Holden <st...@holdenweb.com> wrote:
> Julian wrote:
> > Hello,
>
> > I've got a design problem for a classifier. To make it short: it maps
> > strings on strings.
>
> > Some strings have exactly one classification, some none and some more
> > than one.
>
> > There's a method classify(self, word) wich classifies a word. For the
> > first case there's no problem:
>
> > - one classification: return the value (it's a string)
>
> > But:
>
> > - none classification: return an exception or None? I think None is
> > better, hence its not an exception that there is no classification but
> > a defined state. What do you think?
> > - many classifications: what to do? retun a sequence of strings? raise
> > an exception and implement another method wich returns than the
> > classifications? what should I do here?
>
> > thanks for your answers!
>
> Always return a list or tuple. For no classifications it should be
> empty, for one classification it should have one element, ... , for N
> classifications it should have N elements.
>

thanks, sounds simple and good!

Aahz

unread,
Jan 4, 2010, 8:35:24 PM1/4/10
to
In article <mailman.2090.1261159...@python.org>,

Steve Holden <st...@holdenweb.com> wrote:
>Julian wrote:
>>
>> But:
>>
>> - none classification: return an exception or None? I think None is
>> better, hence its not an exception that there is no classification but
>> a defined state. What do you think?
>> - many classifications: what to do? retun a sequence of strings? raise
>> an exception and implement another method wich returns than the
>> classifications? what should I do here?
>
>Always return a list or tuple. For no classifications it should be
>empty, for one classification it should have one element, ... , for N
>classifications it should have N elements.

Why not a set? If you're only going list classifications, a tuple or
list would be fine, but if you're going to probe classifications, you
should use something that isn't O(N).
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

Weinberg's Second Law: If builders built buildings the way programmers wrote
programs, then the first woodpecker that came along would destroy civilization.

0 new messages