Table Of Contents

Previous topic

lexicon.py

Next topic

lexiconvariable.py

This Page

lexiconlevel.py

class LexiconLevel(object):

Class for defining a single level of lexicon

def __init__(self, ns, elem, validator):

Parse an xml snippet containing level definition and construct a level instance.:

>>> from simo.builder.lexicon.lexiconlevel import LexiconLevel
>>> from lxml import etree
>>> xml = u'''<sublevel>
...             <name>comp_unit</name>
...             <type>static</type>
...             <num_vars>
...                 <variable>
...                     <name>BA</name>
...                     <description>Basal area</description>
...                 </variable>
...             </num_vars>
...             <cat_vars>
...                 <variable>
...                     <name>SC</name>
...                     <description>Site class</description>
...                     <values>
...                         <enum>
...                             <value>1</value>
...                             <description>Pine</description>
...                         </enum>
...                         <enum>
...                             <value>2</value>
...                             <description>Spruce</description>
...                         </enum>
...                     </values>
...                 </variable>
...             </cat_vars>
...             <text_vars>
...                <variable>
...                    <name>StandLabel</name>
...                    <description>Id text for the stand</description>
...                </variable>
...             </text_vars>
...         </sublevel>'''
>>> elem = etree.fromstring(xml)
>>> level = LexiconLevel('', elem, None)
>>> level.name
'comp_unit'
>>> level.type
'static'
>>> level.numerical  
set(['BA'])
>>> level.categorical  
set(['SC'])
>>> level.textual
set(['StandLabel'])
>>> var = level.variables['SC']
>>> var.name
'SC'
>>> var.minimum
>>> var.maximum
>>> var.values
{1.0: 'Pine', 2.0: 'Spruce'}
>>> var.desc
'Site class'