[Chicago-talk] Building a hierarchy

Jay Strauss me at heyjay.com
Wed Mar 16 10:16:35 PDT 2011


I guess I'm fumbling around for a good way to determine if I'm at a higher
or lower level.

The best I can come up with is to test each type and assign a number like:

<pseudo_code>
$level;
if ($index     == "upper roman") { $level = 0}
elsif ($index == "lower alpha") {level = 1}
elsif ($index == "lower roman" {$level = 2}
else ($index == "decimal" {$level = 3}

Then do math against the previous level
i.e.  $current_level - $previous_level
negative = move up to parent (n times)
equal = sibling
positive = child

to determine how to either recurse or how many calls to Tree::DAG_Node

It just seems brittle


On Wed, Mar 16, 2011 at 11:48 AM, David Young <davidy at nationalcycle.com>wrote:

> >> 2) how to traverse the array without knowing my indexes, i.e. go one
> level up, go one level down
>
> Should be pretty easy to implement using recursion.  If you come across a
> new line and it's a different "type" of prefix, recurse down if it looks
> like a lower level (a simple conditional or regex test), otherwise "return"
> to the previous level and let that level continue walking the hierarchy.
>
> ydy
>
> *David J. Young*
> IT Director
> * <http://www.nationalcycle.com> National Cycle, Inc.*
> *office +1-*708-343-0400 x103
> davidy at nationalcycle.com
>
>
>
> On Wed, Mar 16, 2011 at 11:31 AM, Jay Strauss <me at heyjay.com> wrote:
>
>> Hi,
>>
>> I need to build a hierarchy out of some data to load into a RDBMS.  The
>> data looks like below.  I need to convert it to more like:
>>
>> code, desc, parent_code
>>
>> (where code is like "193200000X")
>>
>> I'm struggling.
>>
>> I think I could do this in a rigid manner by saying I have 4 indexes or
>> levels:
>> upper case roman
>> lower case alpha
>> lower case roman
>> numeric
>>
>> and keeping track where I am, and I the parent one level above.
>>
>> I'd like to do it flexibly, without having to know how many levels in
>> advance (I get similarly structured data with # of levels and info from time
>> to time).
>>
>> But I don't know:
>>
>> 1) whats the best structure for this (I'm thinking an array of arrays)
>> 2) how to traverse the array without knowing my indexes, i.e. go one level
>> up, go one level down
>>
>> Can anyone suggest ways to skin this cat?
>>
>> Thanks
>> Jay
>>
>>
>> I. Individual or Groups (of Individuals)
>> a. Group
>> i. Multi-Specialty  - 193200000X
>> ii. Single Specialty  - 193400000X
>> b. Allopathic & Osteopathic Physicians
>> i. Allergy & Immunology - 207K00000X
>> 1. Allergy - 207KA0200X
>> 2. Clinical & Laboratory Immunology - 207KI0005X
>> ii. Anesthesiology - 207L00000X
>> 1. Addiction Medicine - 207LA0401X
>> 2. Critical Care Medicine - 207LC0200X
>> 3. Hospice and Palliative Medicine - 207LH0002X
>> 4. Pain Medicine - 207LP2900X
>> 5. Pediatric Anesthesiology - 207LP3000X
>> iii. Clinical Pharmacology - 208U00000X
>> iv. Colon & Rectal Surgery - 208C00000X
>> v. Dermatology - 207N00000X
>> 1. Clinical & Laboratory Dermatological Immunology - 207NI0002X
>> 2. Dermatopathology - 207ND0900X
>> 3. MOHS-Micrographic Surgery - 207ND0101X
>> 4. Pediatric Dermatology - 207NP0225X
>> 5. Procedural Dermatology - 207NS0135X
>> vi. Electrodiagnostic Medicine - 204R00000X
>> vii. Emergency Medicine - 207P00000X
>>
>> _______________________________________________
>> Chicago-talk mailing list
>> Chicago-talk at pm.org
>> http://mail.pm.org/mailman/listinfo/chicago-talk
>>
>
>
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20110316/8ca4f285/attachment-0001.html>


More information about the Chicago-talk mailing list