def get_childs(query_term="radiological finding"): tree = None s = {} path = root + '/Rx-thorax-automatic-captioning/' + filetree stream = open(path, "r") docs = yaml.load_all(stream, Loader=yaml.FullLoader) print("Starting to search " + query_term + " in the following trees:") for doc in docs: tree_root = DictImporter().import_(doc) print("\t" + tree_root.label) r = search.findall(tree_root, lambda node: node.label == query_term) if r: tree = RenderTree(r[0]) for pre, _, node in tree: CUI = None try: CUI = node.concept m = re.search('\((\w+)\)', CUI) if m: CUI = m.group(0).strip('(').strip(')') cui.add(CUI) except: pass s[node.label] = CUI if tree: t = str(tree.by_attr(lambda n: n.label + '\n')) st.sidebar.markdown("## Tree of child terms") st.sidebar.markdown(t) return s, t
if __name__ == '__main__': comp = field.CompositeField('TheComp') inta = field.IntField('a', 10, comp) intb = field.IntField('b', 20, comp) boolc = field.BoolField('c', True, comp) boold = field.BoolField('d', False, comp) floate = field.FloatField('e', 3.14, comp) compchild = field.CompositeField('ChildComp', None, comp) folder = field.FolderField('fo', '', compchild) file = field.FileField('fi', '', compchild) strg = field.StringField('g', 'abc', compchild) comboh = field.ComboboxField('h', 'T1', ['T1', 'T2', 'BOLD', 'DWI'], comp) renderer = RenderTree(comp) print(renderer) print(renderer.by_attr('value')) exporter = DictExporter(dictcls=OrderedDict) print(exporter.export(comp)) exporterj = JsonExporter() jstr = exporterj.export(comp) ## d = json.loads(jstr) ## importer = field.FieldImporter() ## comp2 = importer.import_(d) ## print(RenderTree(comp2)) print('=====') d = field.dump(comp)