@@ -0,0 +1,2160 @@
+import yaml%0Aimport requests%0Afrom os.path import join, dirname, abspath%0Afrom rdflib import Graph, Namespace, Literal%0A%0Abb_ont_url = ('https://raw.githubusercontent.com/BBN-E/Hume/master/resource/'%0A              'ontologies/hume_ontology.yaml')%0A%0Aeidos_ns = Namespace('https://github.com/clulab/eidos/wiki/JSON-LD/Grounding#')%0Aindra_ns = 'http://sorger.med.harvard.edu/indra/'%0Aindra_rel_ns = Namespace(indra_ns + 'relations/')%0Aisa = indra_rel_ns.term('isa')%0A%0Adef save_hierarchy(g, path):%0A    with open(path, 'wb') as out_file:%0A        g_bytes = g.serialize(format='nt')%0A        # Replace extra new lines in string and get rid of empty line at end%0A        g_bytes = g_bytes.replace(b'%5Cn%5Cn', b'%5Cn').strip()%0A        # Split into rows and sort%0A        rows = g_bytes.split(b'%5Cn')%0A        rows.sort()%0A        g_bytes = b'%5Cn'.join(rows)%0A        out_file.write(g_bytes)%0A%0A%0Adef get_term(node, prefix):%0A    node = node.replace(' ', '_')%0A    path = prefix + '/' + node if prefix else node%0A    return eidos_ns.term(path)%0A%0A%0Adef build_relations(G, node, tree, prefix):%0A    this_term = get_term(node, prefix)%0A    node = node.replace(' ', '_')%0A    if prefix is not None:%0A        prefix = prefix.replace(' ', '_')%0A    this_prefix = prefix + '/' + node if prefix else node%0A    for entry in tree:%0A        if isinstance(entry, str) and entry%5B0%5D != '_':%0A            child = entry%0A        elif isinstance(entry, dict):%0A            for child in entry.keys():%0A                if child%5B0%5D != '_' and child != 'examples' %5C%0A                   and any(isinstance(entry%5Bchild%5D, t) for t in %5Blist, dict%5D):%0A                    build_relations(G, child, entry%5Bchild%5D, this_prefix)%0A%0A        if child%5B0%5D != '_' and child != 'examples':%0A            child_term = get_term(child, this_prefix)%0A            rel = (child_term, isa, this_term)%0A            G.add(rel)%0A%0A%0Aif __name__ == '__main__':%0A    yml = requests.get(bb_ont_url).content%0A    root = yaml.load(yml)%0A    G = Graph()%0A    for top_entry in root:%0A        for node in top_entry.keys():%0A            build_relations(G, node, top_entry%5Bnode%5D, None)%0A    rdf_path = join(dirname(abspath(__file__)), 'bbn_ontology.rdf')%0A    save_hierarchy(G, rdf_path)

Create separate bbn ontology retriever.