@classmethod<EOL><INDENT>def _convert_to_dict(cls, term, replace_value_names=True):<DEDENT>
from collections import OrderedDict<EOL>if not term:<EOL><INDENT>return None<EOL><DEDENT>if term.children:<EOL><INDENT>d = OrderedDict()<EOL>for c in term.children:<EOL><INDENT>if c.child_property_type == '<STR_LIT>':<EOL><INDENT>d[c.record_term_lc] = cls._convert_to_dict(c, replace_value_names)<EOL><DEDENT>elif c.child_property_type == '<STR_LIT>':<EOL><INDENT>try:<EOL><INDENT>d[c.record_term_lc].append(cls._convert_to_dict(c, replace_value_names))<EOL><DEDENT>except (KeyError, AttributeError):<EOL><INDENT>d[c.record_term_lc] = [cls._convert_to_dict(c, replace_value_names)]<EOL><DEDENT><DEDENT>elif c.child_property_type == '<STR_LIT>': <EOL><INDENT>if c.record_term_lc in d:<EOL><INDENT>s = d[c.record_term_lc] + '<STR_LIT:U+0020>'<EOL><DEDENT>else:<EOL><INDENT>s = '<STR_LIT>'<EOL><DEDENT>d[c.record_term_lc] =s + (cls._convert_to_dict(c, replace_value_names) or '<STR_LIT>')<EOL><DEDENT>elif c.child_property_type == '<STR_LIT>':  <EOL><INDENT>d[c.record_term_lc] = d.get(c.record_term_lc, '<STR_LIT>') +  (cls._convert_to_dict(c,<EOL>replace_value_names)<EOL>or '<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>d[c.record_term_lc].append(cls._convert_to_dict(c, replace_value_names))<EOL><DEDENT>except KeyError:<EOL><INDENT>d[c.record_term_lc] = cls._convert_to_dict(c, replace_value_names)<EOL><DEDENT>except AttributeError as e:<EOL><INDENT>d[c.record_term_lc] = [d[c.record_term]] + [cls._convert_to_dict(c, replace_value_names)]<EOL><DEDENT><DEDENT><DEDENT>if term.value:<EOL><INDENT>if replace_value_names:<EOL><INDENT>d[term.term_value_name.lower()] = term.value<EOL><DEDENT>else:<EOL><INDENT>d['<STR_LIT>'] = term.value<EOL><DEDENT><DEDENT>return d<EOL><DEDENT>else:<EOL><INDENT>return term.value<EOL><DEDENT>
Converts a record heirarchy to nested dicts.

        :param term: Root term at which to start conversion