Skip to content

Instantly share code, notes, and snippets.

@kpsychas
Last active December 2, 2015 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kpsychas/3d94709909c24aa38e37 to your computer and use it in GitHub Desktop.
Save kpsychas/3d94709909c24aa38e37 to your computer and use it in GitHub Desktop.
Count number of labels in a Brain XML file (http://www.thebrain.com/)
#!/usr/bin/env python
'''
Count number of labels in a Brain XML file
(http://www.thebrain.com/)
'''
import xml.etree.ElementTree as ET
if __name__ == '__main__':
tree = ET.parse('MyBrain.xml')
root = tree.getroot()
thoughts = root.find('Thoughts').findall('Thought')
links = root.find('Links').findall('Link')
for thought in thoughts:
label = thought.find('label').text
if label is not None:
lab_guid = thought.find('guid').text
lab_count = 0
for link in links:
try:
idA = link.find('idA').text
idB = link.find('idB').text
if (idA == lab_guid) or (idB == lab_guid):
lab_count += 1
except:
pass
print('{}: {}'.format(label, lab_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment