in reply to modeling relationships

I sense some confusion -- you describe Perl data structures, yet you then show how they could also be represented in a database.

Assuming you're going to be dealing with a database, you could have a Person with the attributes name and place_of_work, if we make the assumption that a person has just a single place of work (that is, it's a one-to-one relationship).

There are a number of ways to set up the relationship where a Person has an assistant (who is also, no doubt, a Person), depending on how your universe is structured. If one Person could have one to many assistants, but each assistant would work for just one person, then you could point each assistant to a Person (usually done with an ID). If one Person could have just one assistant, then you could get away with a single pointer, from the Person to the assistant and/or vice versa. If you go the complicated route, and multiple Persons would share multiple assistants, then you'd have to go to a releationship table where Persons would be linked to the appropriate assistants.

I would stay away from thinking about implementation details (linked lists?) until you have a firm grasp of the data structure. The best possible way to implement this is definitely in a database, whether you use something light like SQLite, or go heavier with MySQL or PostgreSQL.

The advantage with using a database is that a) the data's stored somewhere safe, b) you can use SQL to pull out exactly what you want, and c) you can try various different architectures without tearing your hair out trying to debug an array of hashes containing more arrays ... you get the idea.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Replies are listed 'Best First'.
Re^2: modeling relationships
by punkish (Priest) on Feb 07, 2007 at 20:39 UTC
    I describe Perl data structures because I am able to wrap hashes around my entities. I try to represent them in a db because that is the first thing that comes to mind for persistent storage and rapid retrieval.

    In my OP, I have only described People. I could have entities that are Organizations, and either of these entities could have a multitude of properties. One of the key properties would be the relationship of these entitites to each other. So, a person (with its bundle of properties) could "works_at" an organization that "works_with" another organization that "employs" another person who is "married_to" another person who "works_at" the first organization, ad infinitum. The more I stare at this, the more it says, we are "RDF Triples." I want to semantically describe the agents and agencies in a community (of such agents and agencies), and I want to do so in a machine recognizable way.

    The rdbms is great for structured data, but fails miserably for open-ended, free-floating data structures such as this (I often wonder why an rdbms data store wasn't chosen for the ical reference).

    I am just starting to walk on this road, by I need the wisdom of monks to guide me as I start.

    --

    when small people start casting long shadows, it is time to go to bed