@@ -0,0 +1,1514 @@
+import os%0Aimport sys%0Aimport xml.etree.ElementTree as ET%0Afrom rdflib import Graph, Namespace, Literal%0A%0A%0Atrips_ns = Namespace('http://trips.ihmc.us/concepts/')%0Aisa_rel = Namespace('http://trips.ihmc.us/relations/').term('isa')%0A%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 make_hierarchy(tree):%0A    g = Graph()%0A    concepts = tree.findall('concept')%0A    for concept in concepts:%0A        name = concept.attrib%5B'name'%5D.replace('ont::', '')%0A        if name == 'root':%0A            continue%0A        term = trips_ns.term(name)%0A        relations = concept.find(%22relation%5B@label='inherit'%5D%22)%0A        related_names = %5Brr.strip().replace('ont::', '') for rr%0A                        in relations.text.strip().split('%5Cn')%5D%0A        for related_name in related_names:%0A            related_term = trips_ns.term(related_name)%0A            g.add((term, isa_rel, related_term))%0A    return g%0A%0A%0Aif __name__ == '__main__':%0A    if len(sys.argv) %3C 2:%0A        print('Usage: python make_trips_ontology.py /path/to/trips-ont-dsl.xml')%0A        sys.exit()%0A    fname = sys.argv%5B1%5D%0A    tree = ET.parse(fname)%0A    g = make_hierarchy(tree)%0A    save_hierarchy(g, 'trips_ontology.rdf')%0A

Implement script to make TRIPS ontology