-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathconcatmentionmisc.py
More file actions
24 lines (19 loc) · 920 Bytes
/
concatmentionmisc.py
File metadata and controls
24 lines (19 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from udapi.core.block import Block
from collections import Counter
import re
class ConcatMentionMisc(Block):
"""All MISC attributes named MentionMisc_... are concatenated into MentionMisc"""
def process_tree(self,root):
for node in root.descendants_and_empty:
for attrname in list(node.misc):
matchObj = re.match('MentionMisc_([^[]+)((\[\d+\])?)',attrname)
if matchObj:
innerattrib = matchObj.group(1)
index = matchObj.group(2)
finalattr = 'MentionMisc'+index
value = node.misc[attrname].replace(",", "%2C")
if finalattr not in node.misc:
node.misc[finalattr] = f'{innerattrib}:{value}'
else:
node.misc[finalattr] += f',{innerattrib}:{value}'
del node.misc[attrname]