Skip to content

Instantly share code, notes, and snippets.

Last active Dec 2, 2015
What would you like to do?
Count number of labels in a Brain XML file (
#!/usr/bin/env python
Count number of labels in a Brain XML file
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:
idA = link.find('idA').text
idB = link.find('idB').text
if (idA == lab_guid) or (idB == lab_guid):
lab_count += 1
print('{}: {}'.format(label, lab_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment