Last active
December 2, 2015 02:15
-
-
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/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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