views:

61

answers:

3

Simple and common tree like data structures

Data Structure example

Animated Cartoons have 4 extremities (arm, leg,limb..)
Human have 4 ext.
Insects have 6 ext.
Arachnids have 6 ext.

Animated Cartoons have 4 by extremity
Human have 5 by ext.
Insects have 1 by ext.
Arachnids have 1 by ext.

Some Kind of Implementation

Level/Table0 
              Quantity, Item
Level/Table1
              ItemName, Kingdom    
Level/Table2 
              Kingdom, NumberOfExtremities    
Level/Table3 
              ExtremityName, NumberOfFingers

Example Dataset

1 Homer Simpson, 1 Ralph Wiggum, 2 jon skeet, 3 Atomic ant, 2 Shelob (spider)

Querying.. "Number of fingers"

Number = 1*4*4 + 1*4*4 + 1*4*5 + 3*6*1 + 2*6*1 = 82 fingers (Let Jon be a Human)


I wonder if there is any tool for define it parseable for automatic create the inherited data, and drawing this kind of trees, (with the plus of making this kind of data access, if where posible..)

It could be drawn manually with for example FreeMind, but AFAIK it dont let you define datatype or structures to automatically create inherited branch of items, so it's really annoying to have to repeat and repeat a structure by copying (and with the risk of mistake). Repeated Work over Repeated Data, (an human running repeated code), it's a buggy feature.

So I would like to write the data in the correct language that let me reuse it for queries and visualization, if all data is in XML, or Java Classes, or in a Database File, etc.. there is some tool for viewing the tree and making the query?

PD : Creating nested folders in a filesystem and using Norton Commander in tree view, is not an option, I hope (just because It have to be builded manually)

+2  A: 

Your answer is mostly going to depend on what programming skills you already have and what skills you are willing to acquire. I can tell you what I would do with what I know.

I think for drawing trees you want a LaTeX package like qtree. If you don't like this one, there are a bunch of others out there. You'd have to write a script in whatever your favorite scripting language is to parse your input into the LaTeX code to generate the trees, but this could easily be done with less than 100 lines in most languages, if I properly understand your intentions. I would definitely recommend storing your data in an XML format using a library like Ruby's REXML, or whatever your favorite scripting language has.

If you are looking to generate more interactive trees, check out the Adobe Flex Framework. Again, if you don't like this specific framework, there are bunches of others out there (I recommend the blog FlowingData).

Hope this helps and I didn't miserably misunderstand your question.

David Hollman
+1 because you understood right, then your answer is to Create DataStructure in a First language (perhaps the one ready for answering the queries), then make an script in a Second Language for build the the LaTeX code output (Third language), it's a long path, but could work
Hernán Eche
I've found this one http://www.graphviz.org/, it's not a full solution, but would be an option to LaTeX
Hernán Eche
A: 

XML Schema Editor with visualization is perhaps what I am searching for

http://en.wikipedia.org/wiki/XML_Schema_Editor

checking it..

Hernán Eche
+1  A: 

Data structure that You are describing looks like it can fit in xml format. Take a look at Exist XML database, and if I can say so it is the most complete xml database. It comes with many tools to get you started fast ! like XQuery Sandbox option in admin http interface.

Example Dataset 1 Homer Simpson, 1 Ralph Wiggum, 2 jon skeet, 3 Atomic ant, 2 Shelob (spider)

I am assuming that there are 2 instances of jon skeet, 3 instances of Atomic ant and 2 instances of Shelob

Here is a XQuery example:

let $doc := 
<root>
    <definition>
        <AnimatedCartoons>
            <extremities>4</extremities>
            <fingers_per_ext>4</fingers_per_ext>
        </AnimatedCartoons>
        <Human>
            <extremities>4</extremities>
            <fingers_per_ext>5</fingers_per_ext>
        </Human>
        <Insects>
            <extremities>6</extremities>
            <fingers_per_ext>1</fingers_per_ext>
        </Insects>
        <Arachnids>
            <extremities>6</extremities>
            <fingers_per_ext>1</fingers_per_ext>
        </Arachnids>
    </definition>

    <subject><name>Homer Simpson</name><kind>AnimatedCartoons</kind></subject>
    <subject><name>Ralph Wiggum</name><kind>AnimatedCartoons</kind></subject>
    <subject><name>jon skeet</name><kind>Human</kind></subject>
    <subject><name>jon skeet</name><kind>Human</kind></subject>
    <subject><name>Atomic ant</name><kind>Insects</kind></subject>
    <subject><name>Atomic ant</name><kind>Insects</kind></subject>
    <subject><name>Atomic ant</name><kind>Insects</kind></subject>
    <subject><name>Shelob</name><kind>Arachnids</kind></subject>
    <subject><name>Shelob</name><kind>Arachnids</kind></subject>
</root>
let $definitions := $doc/definition/*
let $subjects := $doc/subject

(: here goes some query logic :)
let $fingers := fn:sum( 
    for $subject in $subjects
    return (
        for $x in $definitions
        where fn:name($x) = $subject/kind
        return $x/extremities * $x/fingers_per_ext
        )
    )
return $fingers
Alex
I saw XML is the path, the hierarchy of the data is more XML than relational db, but I am searching for a edit/visualizing tool that let me then do the queries. Something more, In my example there are four or at least three tables, you used just two, but well pehaps is to simplify your code, +1 anyway for the contribution!
Hernán Eche
Proper XML would look more like : <AnimatedCartoons extremities=4 fingers_per_ext=4 /> and <subject name="jon skeet" kind="Human" />
guigui42