Skip to content

Instantly share code, notes, and snippets.

@LLCampos
Last active November 6, 2016 12:46
Show Gist options
  • Save LLCampos/3d536f1160358b03008e548707deb355 to your computer and use it in GitHub Desktop.
Save LLCampos/3d536f1160358b03008e548707deb355 to your computer and use it in GitHub Desktop.
Given an OWL file of the RadLex ontology, extract all the class/terms preferred names into a file
from lxml import etree
radlex_tree = etree.parse('Radlex3.13.1.owl').getroot()
# Get all the term names of the Ontology, in a list.
all_terms = radlex_tree.xpath('//x:Preferred_name/text()',
namespaces={'x': radlex_tree.nsmap[None]})
with open('radlex_all_terms_names.txt', 'w') as f:
for term in all_terms:
f.write(term.encode('utf-8') + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment