Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import pandas as pd
- import xmind
- from xmind.core.markerref import MarkerId
- xmind_file = 'intents.xmind'
- sample = [
- {'intent': 'General_intent1', 'count': 5},
- {'intent': 'General_intent2', 'count': 9},
- {'intent': 'General_intent2', 'count': 43},
- {'intent': 'Others_intent1', 'count': 16},
- {'intent': 'Others_intent2', 'count': 23}
- ]
- samples = pd.DataFrame(sample)
- # remove previous file if it exists.
- if os.path.exists(xmind_file):
- os.remove(xmind_file)
- x = xmind.load(xmind_file)
- sheet = x.getPrimarySheet()
- sheet.setTitle('Intents Summary')
- root = sheet.getRootTopic()
- root.setTitle('Intents')
- current_id = None
- for index, row in samples.iterrows():
- print('{} : {}'.format(row['intent'], row['count']))
- intent_topic = row['intent'].split('_')[0]
- intent = '{} ({})'.format(row['intent'].replace('{}_'.format(intent_topic), ''), row['count'])
- if intent_topic != current_id:
- topic = root.addSubTopic()
- current_id = intent_topic
- topic.setTitle(intent_topic)
- item = topic.addSubTopic()
- item.setTitle(intent)
- if row['count'] > 20:
- item.addMarker(MarkerId.starGreen)
- elif row['count'] < 10:
- item.addMarker(MarkerId.starRed)
- xmind.save(x, xmind_file)
- print('All done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement