Click here to Skip to main content
15,891,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
New to programming :/

inside a software I have a value associated to a key. There are sometimes different variations of that key used (e.g., lens left, left lens, Lens_L, etc.). I use a script to evaluate that value associated with that key but have been hard coding each possible variation.

Can I create a list (or dictionary, collection, etc.) that I can call on in the script so that any variation of that key will be recognized? Instead of manually typing each variation in each script?

I also wonder if I could create a list of variations of a key and then call on that list in a dictionary assigned to the key? If so...could I call on the dictionary simply in a script to accept all variations of the desired key?

Thanks in advance.

What I have tried:

I have tried creating a hashtable but am under the impression I can only assign one value to each key in the hashtable. This is what I started creating before I realized I could only have one value in each key...

using System;
using System.Collections;

class Example
{
    public static void Main()
    {
        // create a hash table for structureSetAnatomicalArea

        Hashtable structureSetBrain = new Hashtable();

        // example brain structure set template
        structureSetBrain.Add('brain', 'Brain');
        structureSetBrain.Add('BrainStem', 'brainstem', 'brain stem', 'Brain Stem', 'Brainstem');
        structureSetBrain.Add('BrainStem+3mm', 'Brainstem+3mm', 'BS_3mm', 'BS_3', 'Brainstem_3', 'BrainStem_3', 'BrainStem_PRV', 'Brainstem_PRV', 'Brainstem PRV', 'BrainStem PRV')
        structureSetBrain.Add('Cerebellum', 'cerebellum');
        structureSetBrain.Add('Cerebrum', 'cerebrum');
        structureSetBrain.Add('Chiasm', 'chiasm', 'optic chiasm', 'Optic Chiasm', 'OpticChiasm');
        structureSetBrain.Add('CranialNerve', 'CN', 'Cranial Nerve', 'nerve_cranial', 'CranialNerves', 'cranial nerve');
        structureSetBrain.Add('CN_VII', 'CranialNerve7', 'Seventh Cranial Nerve', 'SeventhCN');
        structureSetBrain.Add('CN_VIII', 'CranialNerve8', 'Eighth Cranial Nerve', 'EighthCN');
        structureSetBrain.Add('Cochlea', 'cochlea');
        structureSetBrain.Add('Cochleas', 'cochleas');
        structureSetBrain.Add('Cochlea_L', 'Left Cochlea', 'Cochlea LT', 'Cochlea_LT', 'Cochlea_Left', 'cochlea_L', 'cochlea_LT', 'left cochlea', 'cochlea lt', 'cochlea_lt', 'cochlea_left');
        structureSetBrain.Add('Cochlea_R', 'Right Cochlea', 'Cochlea RT', 'Cochlea_RT', 'Cochlea_Right', 'cochlea_R', 'cochlea_RT', 'right cochlea', 'cochlea rt', 'cochlea_rt', 'cochlea_right');
        structureSetBrain.Add('Cornea', 'cornea');
        structureSetBrain.Add('Corneas', 'corneas');
        structureSetBrain.Add('Cornea_L', 'Left Cornea', 'Cornea LT', 'Cornea_LT', 'Cornea_Left', 'cornea_L', 'cornea_LT', 'left cornea', 'cornea lt', 'cornea_lt', 'cornea_left');
        structureSetBrain.Add('Cornea_R', 'Right Cornea', 'Cornea RT', 'Cornea_RT', 'Cornea_Right', 'cornea_R', 'cornea_RT', 'right cornea', 'cornea rt', 'cornea_rt', 'cornea_right');
        structureSetBrain.Add('Eye', 'eye', 'Globe', 'globe');
        structureSetBrain.Add('Eyes', 'eyes', 'Globes', 'globes');
        structureSetBrain.Add('Eye_L', 'Left Eye', 'Eye LT', 'Eye_LT', 'Eye_Left', 'eye_L', 'eye_LT', 'left eye', 'eye lt', 'eye_lt', 'eye_left', 'Globe_L', 'Left Globe', 'Globe LT', 'Globe_LT', 'Globe_Left', 'globe_L', 'globe_LT', 'left globe', 'globe lt', 'globe_lt', 'globe_left');
        structureSetBrain.Add('Eye_R', 'Right Eye', 'Eye RT', 'Eye_RT', 'Eye_Right', 'eye_R', 'eye_RT', 'right eye', 'eye rt', 'eye_rt', 'eye_right', 'Globe_R', 'Right Globe', 'Globe RT', 'Globe_RT', 'Globe_Right', 'globe_R', 'globe_RT', 'right globe', 'globe rt', 'globe_rt', 'globe_right');
        structureSetBrain.Add('FrontalLobe', 'frontalLobe', 'frontallobe', 'frontal lobe', 'Frontal_Lobe', 'frontal_lobe');
        structureSetBrain.Add('Hippocampus', 'hippocampus');
        structureSetBrain.Add('Hypothalamus', 'hypothalamus');
        structureSetBrain.Add('LacrimalGland', 'lacrimalgland', 'lacrimal gland');
        structureSetBrain.Add('LacrimalGlands', 'lacrimalglands', 'lacrimal glands');
        structureSetBrain.Add('Lacrimal_L', 'Left Lacrimal', 'Lacrimal LT', 'Lacrimal_LT', 'Lacrimal_Left', 'lacrimal_L', 'lacrimal_LT', 'left lacrimal', 'lacrimal lt', 'lacrimal_lt', 'lacrimal_left');
        structureSetBrain.Add('Lacrimal_R', 'Right Lacrimal', 'Lacrimal RT', 'Lacrimal_RT', 'Lacrimal_Right', 'lacrimal_R', 'lacrimal_RT', 'right lacrimal', 'lacrimal rt', 'lacrimal_rt', 'lacrimal_right');
        structureSetBrain.Add('Lens', 'lens');
        structureSetBrain.Add('Lenses', 'lenses');
        structureSetBrain.Add('Lens_L', 'Left Lens', 'Lens LT', 'Lens_LT', 'Lens_Left', 'lens_L', 'lens_LT', 'left lens', 'lens lt', 'lens_lt', 'lens_left');
        structureSetBrain.Add('Lens_R', 'Right Lens', 'Lens RT', 'Lens_RT', 'Lens_Right', 'lens_R', 'lens_RT', 'right lens', 'lens rt', 'lens_rt', 'lens_right');
        structureSetBrain.Add('OccipitalLobe', 'Occipital Lobe', 'occ lobe', 'occ_lobe', 'occipitalLobe', 'occLobe');
        structureSetBrain.Add('OpticNerve', 'Optic Nerve', 'optic nerve', 'opticNerve', 'Optic nerve');
        structureSetBrain.Add('OpticNerves', 'Optic Nerves', 'optic nerves', 'opticNerves', 'Optic nerves');
        structureSetBrain.Add('OpticNerve_L', 'OpticNerve_LT', 'opticnerve_L', 'opticnerve_LT', 'ON_L', 'ON_LT', 'ON_lt', 'ON_Left', 'ON_left', 'on_L', 'on_LT', 'on_left', 'on_Left');
        structureSetBrain.Add('OpticNerve_R', 'OpticNerve_RT', 'opticnerve_R', 'opticnerve_RT', 'ON_R', 'ON_RT', 'ON_rt', 'ON_Right', 'ON_right', 'on_R', 'on_RT', 'on_right', 'on_Right');
        structureSetBrain.Add('ParietalLobe', 'Parietal Lobe', 'parietallobe', 'parietalLobe', 'parLobe');
        structureSetBrain.Add('ParietLobe_L', 'ParLobe_L', 'ParietLobe_LT', 'ParLobe_LT', 'ParietLobe Lt', 'ParietLobe_Lt', 'ParietLobe_l', 'ParietLobe_lt, Parietal_L', 'Parietal_LT', 'Parietal_l', 'Parietal_lt', 'parlobe_L', 'parietlobe_LT', 'parlobe_LT', 'parietlobe_l', 'parietlobe_lt, parietal_L', 'parietal_LT', 'parietal_l', 'parietal_lt');
        structureSetBrain.Add('ParietLobe_R', 'ParLobe_R', 'ParietLobe_RT', 'ParLobe_RT', 'ParietLobe Rt', 'ParietLobe_Rt', 'ParietLobe_r', 'ParietLobe_rt, Parietal_R', 'Parietal_RT', 'Parietal_r', 'Parietal_rt', 'parlobe_R', 'parietlobe_RT', 'parlobe_RT', 'parietlobe_r', 'parietlobe_rt, parietal_R', 'parietal_RT', 'parietal_r', 'parietal_rt');
        structureSetBrain.Add('Pituitary', 'pituitary');
        structureSetBrain.Add('Retina', 'retina');
        structureSetBrain.Add('Retinae', 'Retinas', 'retinae', 'retinas');
        structureSetBrain.Add('Retina_L', 'Left Retina', 'Retina LT', 'Retina_LT', 'Retina Lt', 'Retina_Lt', 'Retina_Left', 'retina_L', 'retina_LT', 'left retina', 'retina lt', 'retina_lt', 'retina_left');
        structureSetBrain.Add('Retina_R', 'Right Retina', 'Retina RT', 'Retina_RT', 'Retina Rt', 'Retina_Rt', 'Retina_Right', 'retina_R', 'retina_RT', 'right retina', 'retina rt', 'retina_rt', 'retina_right');
        structureSetBrain.Add('SpinalCord', 'Spinal Cord', 'spinalcord', 'spinal cord', 'Cord', 'cord');
        structureSetBrain.Add('SpinalCord+5mm', 'spinalcord+5mm', 'Spinal Cord+5', 'Cord+5mm', 'cord+5mm', 'Cord PRV', 'cord PRV', 'cord_PRV', 'cord_5', 'cord_5mm', 'SpinalCord_5', 'SpinalCord_5mm', 'spinalcord_5');
        structureSetBrain.Add('TemporalLobe', 'Temporal Lobe', 'temporallobe', 'temporalLobe', 'tempLobe');
        structureSetBrain.Add('TempLobe_L', 'TempLobe_L', 'TempLobe_LT', 'TempLobe Lt', 'TempLobe_Lt', 'TempLobe_l', 'TempLobe_lt, Temporal_L', 'Temporal_LT', 'Temporal_l', 'Temporal_lt', 'templobe_L', 'templobe_LT', 'templobe_LT', 'templobe_l', 'templobe_lt, temporal_L', 'temporal_LT', 'temporal_l', 'temporal_lt');
        structureSetBrain.Add('TempLobe_R', 'TempLobe_R', 'TempLobe_RT', 'TempLobe Rt', 'TempLobe_Rt', 'TempLobe_r', 'TempLobe_rt, Temporal_R', 'Temporal_RT', 'Temporal_r', 'Temporal_rt', 'templobe_R', 'templobe_RT', 'templobe_RT', 'templobe_r', 'templobe_rt, temporal_R', 'temporal_RT', 'temporal_r', 'temporal_rt');
    }
}
}
Posted
Comments
Dave Kreskowiak 14-Jul-17 17:21pm    
Where is the input coming from that must be matched to this "dictionary"? Is it a file? A textbox on a page/form? User entered in some other software?

The easy way to eliminate free-form text is to use combo boxes or other structured input to maintain consistency.
Member 13310574 18-Jul-17 11:25am    
Thanks for your response!

I apologize for the lack of clarity. I think to state the problem more simply will help. So I work in a software program that assigns a numerical value to voxels in 3D datasets. Structures are created that dilenate portions of those datasets. The structures have a fundamental name e.g., spinal cord, but could be named a variety of ways e.g., SpinalCord, Cord, Spinal Cord, spinal cord, etc. [or for a more lateral structure , e.g., globe Lt, Globe_L, left globe, etc.]

We currently run a script that will search for the structure in the software that then creates a report with the values associated with each structure. I'd like to be able to create a dictionary or collection or module, etc. that will list each of the variable names for each structure that I can then call on in the script so that I won't have to hard code each of the variants each time. (and I imagine this would allow me to make edits to the lists instead of the code each time if necessary.)

Could I do this?
BillWoodruff 16-Jul-17 11:32am    
Dave's question about the source of the data is important !

You need to decide if you want a "flat" list of key-value pairs, or if you want some kind of tree/graph structure that embodies hierarchy. It appears to me you are dealing with a classification system here, a taxonomy. That suggests, to me, a simple tree structure. What do you think ?
Member 13310574 18-Jul-17 11:27am    
Thanks for your response! I tried to answer some of your questions above in my previous reply. I hope that helps clear up my problem.
Dave Kreskowiak 18-Jul-17 13:25pm    
No it doesn't. It appears as though you're allowing free-form text entry in whatever is generating these structures. Is this the case?

If so, that's a huge problem for you because a "dictionary" of any kind isn't going to pickup spelling errors. This would require some kind of fuzzy string matching, which isn't going to match 100% of the time.

So another question comes up. How accurate does your process have to be?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900