Modeling complex hierarchies

Posted by jdn on Stack Overflow See other posts from Stack Overflow or by jdn
Published on 2010-06-15T04:18:22Z Indexed on 2010/06/15 4:22 UTC
Read the original article Hit count: 293

Filed under:
|

To gain some experience, I am trying to make an expert system that can answer queries about the animal kingdom. However, I have run into a problem modeling the domain. I originally considered the animal kingdom hierarchy to be drawn like

-animal
  -bird
    -carnivore
     -hawk
    -herbivore
     -bluejay
  -mammals
   -carnivores
   -herbivores

This I figured would allow me to make queries easily like "give me all birds", but would be much more expensive to say "give me all carnivores", so I rewrote the hierarchy to look like:

-animal
  -carnivore
    -birds
     -hawk
    -mammals
     -xyz
  -herbivores
   -birds
     -bluejay
   -mammals

But now it will be much slower to query "give me all birds."

This is of course a simple example, but it got me thinking that I don't really know how to model complex relationships that are not so strictly hierarchical in nature in the context of writing an expert system to answer queries as stated above. A directed, cyclic graph seems like it could mathematically solve the problem, but storing this in a relational database and maintaining it (updates) would seem like a nightmare to me. I would like to know how people typically model such things. Explanations or pointers to resources to read further would be acceptable and appreciated.

© Stack Overflow or respective owner

Related posts about database

Related posts about expert-system