Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.30 KB | None | 0 0
  1. import os
  2.  
  3. import pandas as pd
  4. import xmind
  5. from xmind.core.markerref import MarkerId
  6.  
  7. xmind_file = 'intents.xmind'
  8.  
  9. sample = [
  10.     {'intent': 'General_intent1', 'count': 5},
  11.     {'intent': 'General_intent2', 'count': 9},
  12.     {'intent': 'General_intent2', 'count': 43},
  13.     {'intent': 'Others_intent1', 'count': 16},
  14.     {'intent': 'Others_intent2', 'count': 23}
  15. ]
  16.  
  17. samples = pd.DataFrame(sample)
  18.  
  19. # remove previous file if it exists.
  20. if os.path.exists(xmind_file):
  21.     os.remove(xmind_file)
  22.  
  23. x = xmind.load(xmind_file)
  24.  
  25. sheet = x.getPrimarySheet()
  26. sheet.setTitle('Intents Summary')
  27.  
  28. root = sheet.getRootTopic()
  29. root.setTitle('Intents')
  30.  
  31. current_id = None
  32. for index, row in samples.iterrows():
  33.     print('{} : {}'.format(row['intent'], row['count']))
  34.  
  35.     intent_topic = row['intent'].split('_')[0]
  36.     intent = '{} ({})'.format(row['intent'].replace('{}_'.format(intent_topic), ''), row['count'])
  37.  
  38.     if intent_topic != current_id:
  39.         topic = root.addSubTopic()
  40.         current_id = intent_topic
  41.         topic.setTitle(intent_topic)
  42.  
  43.     item = topic.addSubTopic()
  44.     item.setTitle(intent)
  45.  
  46.     if row['count'] > 20:
  47.         item.addMarker(MarkerId.starGreen)
  48.     elif row['count'] < 10:
  49.         item.addMarker(MarkerId.starRed)
  50.  
  51. xmind.save(x, xmind_file)
  52. print('All done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement