I know, it doesn't handle the case of infinately deep categories, but in some cases, using a form of notation may be the better alternative, partcularly if you're using faceted classification in a poly-heirarchy.

What we do in that case, is we assign each facet a letter, and we make sure that we emit the facets in a consistent order.

So, using your example:

A : habitat
  A1 : land animals
  A2 : aquatic animals
B : animal size
  B1 : small animal
  B2 : large animal
C : number of legs
  C0 : no legs
  C2 : 2 legs
  C4 : 4 legs
D : backbone?
  D1 : vertebrate
  D2 : invertebrate
    D2.1 : invertebrate w/ exoskeleton
    D2.2 : invertebrate w/out exoskeleton
E : diet
  E1 : carnivore
  E2 : herbavore

So, for instance, a dog might be (A1;B2;C4;D1;E1). Parents to that would be any of : (A1;B2;C4;D1) (A1;B2;C4;E1) (A1;B2;D1;E1) (A1;C4;D1;E1) or (B2;C4;D1;E1). A worm might be (A1;B2;C0;D2.2) (no E, as I don't think diet is significant in classifying them, but i could be wrong) Parents would be : (A1;B2;C0;D2) (A1;B2;D2.2) (A1;C0;D2.2) or (B2;C0;D2.2).

Now, to search this, we have to use SQL's 'LIKE' command, and we need to make sure that the notation is structured in a way to allow us to unambiguously specify a category. The easiest way is to end each classification within a facet with a dot (to make sure we're not matching 'A11' when we ask for 'A1'), and to prepend each facet in some delimiter (so we don't get facet AA when we want A):

  dog :  ;A1.;B2.;C4.;D1.;E1.
  worm:  ;A1.;B2.;C0.;D2.2.

If we want all land animals : category  LIKE '%;A1.%'

If we want all land animals with four legs: category  LIKE '%;A1.%;C4.%'

...

So -- the problems? Really hard to re-arrange after the fact. Benefits? Any depth or number of facets, provided you've allocated enough space for the notation ... of course, the notation can get rather large in complex systems, and it much less efficient to use than the other methods described above.


In reply to Re: database table advice by jhourcle
in thread database table advice by coldfingertips

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.