Design question about pretree classifier

J

Julian

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!
 
S

Steve Holden

Julian said:
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.

regards
Steve
 
J

Julian

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!
 
A

Aahz

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top