UCDP-AEC

Models and data for the UCDP Abstractive Event analysis Corpus paper
git clone https://esimon.eu/repos/UCDP-AEC.git
Log | Files | Refs | README | LICENSE

template_generate_ere.py (233033B)


      1 import sys
      2 import ipdb
      3 
      4 INPUT_STYLE_SET = ['event_type', 'event_type_sent', 'keywords', 'triggers', 'template']
      5 OUTPUT_STYLE_SET = ['trigger:sentence', 'argument:sentence']
      6 ROLE_PH_MAP = {
      7     'Person': 'somebody',
      8     'Entity': 'some people or some organization',
      9     'Defendant': 'somebody',
     10     'Prosecutor': 'some other',
     11     'Plaintiff': 'some other',
     12     'Artifact': 'something',
     13     'Destination': 'somewhere',
     14     'Origin': 'some place',
     15     'Agent': 'somebody or some organization',
     16     'Attacker': 'some attacker',
     17     'Target': 'some facility, someone, or some organization',
     18     'Victim': 'some victim',
     19     'Instrument': 'some way',
     20     'Thing': 'something',
     21     'Giver': 'someone',
     22     'Recipient': 'some other',
     23     'Org': 'some organization',
     24     'Audience': 'some publicity',
     25     'Place': 'somewhere',
     26     'Adjudicator': 'some adjudicator'
     27 }
     28 
     29 class eve_template_generator():
     30     def __init__(self, passage, triggers, roles, input_style, output_style, vocab, instance_base=False):
     31         """
     32         generate strctured information for events
     33         
     34         args:
     35             passage(List): a list of tokens
     36             triggers(List): a list of triggers
     37             roles(List): a list of Roles
     38             input_style(List): List of elements; elements belongs to INPUT_STYLE_SET
     39             input_style(List): List of elements; elements belongs to OUTPUT_STYLE_SET
     40             instance_base(Bool): if instance_base, we generate only one pair (use for trigger generation), else, we generate trigger_base (use for argument generation)
     41         """
     42         self.raw_passage = passage
     43         self.triggers = triggers
     44         self.roles = roles
     45         self.events = self.process_events(passage, triggers, roles)
     46         self.input_style = input_style
     47         self.output_style = output_style
     48         self.vocab = vocab
     49         self.event_templates = []
     50         if instance_base:
     51             for e_type in self.vocab['event_type_itos']:
     52                 theclass = getattr(sys.modules[__name__], e_type.replace(':', '_').replace('-', '_'), False)
     53                 if theclass:
     54                     self.event_templates.append(theclass(self.input_style, self.output_style, passage, e_type, self.events))
     55                 else:
     56                     print(e_type)
     57 
     58         else:
     59             for event in self.events:
     60                 theclass = getattr(sys.modules[__name__], event['event type'].replace(':', '_').replace('-', '_'), False)
     61                 assert theclass
     62                 self.event_templates.append(theclass(self.input_style, self.output_style, event['tokens'], event['event type'], event))
     63         self.data = [x.generate_pair(x.trigger_text) for x in self.event_templates]
     64         self.data = [x for x in self.data if x]
     65 
     66     def get_training_data(self):
     67         return self.data
     68 
     69     def process_events(self, passage, triggers, roles):
     70         """
     71         Given a list of token and event annotation, return a list of structured event
     72 
     73         structured_event:
     74         {
     75             'trigger text': str,
     76             'trigger span': (start, end),
     77             'event type': EVENT_TYPE(str),
     78             'arguments':{
     79                 ROLE_TYPE(str):[{
     80                     'argument text': str,
     81                     'argument span': (start, end)
     82                 }],
     83                 ROLE_TYPE(str):...,
     84                 ROLE_TYPE(str):....
     85             }
     86             'passage': PASSAGE
     87         }
     88         """
     89         
     90         events = {trigger: [] for trigger in triggers}
     91 
     92         for argument in roles:
     93             trigger = argument[0]
     94             events[trigger].append(argument)
     95         
     96         event_structures = []
     97         for trigger, arguments in events.items():
     98             eve_type = trigger[2]
     99             eve_text = ' '.join(passage[trigger[0]:trigger[1]])
    100             eve_span = (trigger[0], trigger[1])
    101             argus = {}
    102             for argument in arguments:
    103                 role_type = argument[1][2]
    104                 if role_type not in argus.keys():
    105                     argus[role_type] = []
    106                 argus[role_type].append({
    107                     'argument text': ' '.join(passage[argument[1][0]:argument[1][1]]),
    108                     'argument span': (argument[1][0], argument[1][1]),
    109                 })
    110             event_structures.append({
    111                 'trigger text': eve_text,
    112                 'trigger span': eve_span,
    113                 'event type': eve_type,
    114                 'arguments': argus,
    115                 'passage': ' '.join(passage),
    116                 'tokens': passage
    117             })
    118         return event_structures
    119 
    120 class event_template():
    121     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    122         self.input_style = input_style
    123         self.output_style = output_style
    124         self.output_template = self.get_output_template()
    125         self.passage = ' '.join(passage)
    126         self.tokens = passage
    127         self.event_type = event_type
    128         if gold_event is not None:
    129             self.gold_event = gold_event
    130             if isinstance(gold_event, list):
    131                 # instance base
    132                 self.trigger_text = " and ".join([x['trigger text'] for x in gold_event if x['event type']==event_type])
    133                 self.trigger_span = [x['trigger span'] for x in gold_event if x['event type']==event_type]
    134                 self.arguments = [x['arguments'] for x in gold_event if x['event type']==event_type]
    135             else:
    136                 # trigger base
    137                 self.trigger_text = gold_event['trigger text']
    138                 self.trigger_span = [gold_event['trigger span']]
    139                 self.arguments = [gold_event['arguments']]         
    140         else:
    141             self.gold_event = None
    142         
    143     @classmethod
    144     def get_keywords(self):
    145         pass
    146 
    147     def generate_pair(self, query_trigger):
    148         """
    149         Generate model input sentence and output sentence pair
    150         """
    151         input_str = self.generate_input_str(query_trigger)
    152         output_str, gold_sample = self.generate_output_str(query_trigger)
    153         return (input_str, output_str, self.gold_event, gold_sample, self.event_type, self.tokens)
    154 
    155     def generate_input_str(self, query_trigger):
    156         return None
    157 
    158     def generate_output_str(self, query_trigger):
    159         return (None, False)
    160 
    161     def decode(self, prediction):
    162         pass
    163 
    164     def evaluate(self, predict_output):
    165         assert self.gold_event is not None
    166         # categorize prediction
    167         pred_trigger = []
    168         pred_argument = []
    169         for pred in predict_output:
    170             if pred[1] == self.event_type:
    171                 pred_trigger.append(pred)
    172             else:
    173                 pred_argument.append(pred)
    174         # trigger score
    175         gold_tri_num = len(self.trigger_span)
    176         pred_tris = []
    177         for pred in pred_trigger:
    178             pred_span = self.predstr2span(pred[0])
    179             if pred_span[0] > -1:
    180                 pred_tris.append((pred_span[0], pred_span[1], pred[1]))
    181         pred_tri_num = len(pred_tris)
    182         match_tri = 0
    183         for pred in pred_tris:
    184             id_flag = False
    185             for gold_span in self.trigger_span:
    186                 if gold_span[0] == pred[0] and gold_span[1] == pred[1]:
    187                     id_flag = True
    188             match_tri += int(id_flag)
    189 
    190         # argument score
    191         converted_gold = self.get_converted_gold()
    192         gold_arg_num = len(converted_gold)
    193         pred_arg = []
    194         for pred in pred_argument:
    195             # find corresponding trigger
    196             pred_span = None
    197             if isinstance(self.gold_event, list):
    198                 # end2end case
    199                 try:
    200                     # we need this ``try'' because we cannot gurantee the model will be bug-free on the matching
    201                     cor_tri = pred_trigger[pred[2]['cor tri cnt']]
    202                     cor_tri_span = self.predstr2span(cor_tri[0])[0]
    203                     if cor_tri_span > -1:
    204                         pred_span = self.predstr2span(pred[0], cor_tri_span)
    205                     else:
    206                         continue
    207                 except Exception as e:
    208                     print(e)
    209             else:
    210                 # argument only case
    211                 pred_span = self.predstr2span(pred[0], self.trigger_span[0][0])
    212             if (pred_span is not None) and (pred_span[0] > -1):
    213                 pred_arg.append((pred_span[0], pred_span[1], pred[1]))
    214         pred_arg = list(set(pred_arg))
    215         pred_arg_num = len(pred_arg)
    216         
    217         target = converted_gold
    218         match_id = 0
    219         match_type = 0
    220         for pred in pred_arg:
    221             id_flag = False
    222             id_type = False
    223             for gold in target:
    224                 if gold[0]==pred[0] and gold[1]==pred[1]:
    225                     id_flag = True
    226                     if gold[2] == pred[2]:
    227                         id_type = True
    228                         break
    229             match_id += int(id_flag)
    230             match_type += int(id_type)
    231         return {
    232             'gold_tri_num': gold_tri_num, 
    233             'pred_tri_num': pred_tri_num,
    234             'match_tri_num': match_tri,
    235             'gold_arg_num': gold_arg_num,
    236             'pred_arg_num': pred_arg_num,
    237             'match_arg_id': match_id,
    238             'match_arg_cls': match_type
    239         }
    240     
    241     def get_converted_gold(self):
    242         converted_gold = []
    243         for argu in self.arguments:
    244             for arg_type, arg_list in argu.items():
    245                 for arg in arg_list:
    246                     converted_gold.append((arg['argument span'][0], arg['argument span'][1], arg_type))
    247         return list(set(converted_gold))
    248     
    249     def predstr2span(self, pred_str, trigger_idx=None):
    250         sub_words = [_.strip() for _ in pred_str.strip().lower().split()]
    251         candidates=[]
    252         for i in range(len(self.tokens)):
    253             j = 0
    254             while j < len(sub_words) and i+j < len(self.tokens):
    255                 if self.tokens[i+j].lower() == sub_words[j]:
    256                     j += 1
    257                 else:
    258                     break
    259             if j == len(sub_words):
    260                 candidates.append((i, i+len(sub_words)))
    261         if len(candidates) < 1:
    262             return -1, -1
    263         else:
    264             if trigger_idx is not None:
    265                 return sorted(candidates, key=lambda x: abs(trigger_idx-x[0]))[0]
    266             else:
    267                 return candidates[0]
    268 
    269 class Life_Be_Born(event_template):
    270 
    271     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    272         super().__init__(input_style, output_style, passage, event_type, gold_event)
    273     
    274     @classmethod
    275     def get_keywords(self):
    276         return ['born', 'birth', 'bore']
    277 
    278     def get_output_template(self):
    279         output_template = ''
    280         for o_style in OUTPUT_STYLE_SET:
    281             if o_style in self.output_style:
    282                 if o_style == 'trigger:sentence':
    283                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    284                 if o_style == 'argument:sentence':
    285                     output_template += ' \n {}'.format('somebody was born in somewhere.')
    286         return ('\n'.join(output_template.split('\n')[1:])).strip()
    287 
    288     def generate_input_str(self, query_trigger):
    289         input_str = self.passage
    290         for i_style in INPUT_STYLE_SET:
    291             if i_style in self.input_style:
    292                 if i_style == 'event_type':
    293                     input_str += ' \n {}'.format('life event, be-born sub-type')
    294                 if i_style == 'event_type_sent':
    295                     input_str += ' \n {}'.format('The event is related to life and someone is given birth to.')
    296                 if i_style == 'keywords':
    297                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    298                 if i_style == 'triggers':
    299                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    300                 if i_style == 'template':
    301                     input_str += ' \n {}'.format(self.output_template)
    302         
    303         return input_str
    304 
    305     def generate_output_str(self, query_trigger):
    306         assert self.gold_event is not None
    307         output_str = ''
    308         gold_sample = False
    309         for o_style in OUTPUT_STYLE_SET:
    310             if o_style in self.output_style:
    311                 if o_style == 'trigger:sentence':
    312                     if self.trigger_text != '':
    313                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    314                         gold_sample = True
    315                     else:
    316                         output_str += ' \n Event trigger is <Trigger>'
    317                 if o_style == 'argument:sentence':
    318                     output_texts = []
    319                     for argu in self.arguments:
    320                         filler = (
    321                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
    322                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
    323                         )
    324                         output_texts.append("{} was born in {}.".format(*filler))
    325                         gold_sample = True
    326                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    327 
    328         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    329         return (output_str, gold_sample)
    330 
    331     def decode(self, preds):
    332         output = []
    333         for cnt, pred in enumerate(preds.split('\n')):
    334             used_o_cnt = 0
    335             full_pred = pred.strip()
    336             for o_style in OUTPUT_STYLE_SET:
    337                 if o_style in self.output_style:
    338                     if o_style == 'trigger:sentence':
    339                         if used_o_cnt == cnt:
    340                             try:
    341                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    342                                 triggers = triggers.split(' and ')
    343                                 for t_cnt, t in enumerate(triggers):
    344                                     if t != '<Trigger>':
    345                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    346                             except:
    347                                 pass
    348                         used_o_cnt += 1
    349                     if o_style == 'argument:sentence':
    350                         if used_o_cnt == cnt:
    351                             try:
    352                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    353                                     person = prediction.split(' was born in ', 1)[0]
    354                                     person = person.split(' and ')
    355                                     place = prediction.split(' was born in ', 1)[1].rsplit('.', 1)[0]
    356                                     place = place.split(' and ')
    357                                     for arg in person:
    358                                         if arg != ROLE_PH_MAP['Person']:
    359                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
    360                                     for arg in place:
    361                                         if arg != ROLE_PH_MAP['Place']:
    362                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
    363                             except:
    364                                 pass
    365                         used_o_cnt += 1
    366                     
    367         return output
    368 
    369 class Life_Marry(event_template):
    370 
    371     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    372         super().__init__(input_style, output_style, passage, event_type, gold_event)
    373     
    374     @classmethod
    375     def get_keywords(self):
    376         return ['marry', 'marriage', 'married']
    377     
    378     def get_output_template(self):
    379         output_template = ''
    380         for o_style in OUTPUT_STYLE_SET:
    381             if o_style in self.output_style:
    382                 if o_style == 'trigger:sentence':
    383                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    384                 if o_style == 'argument:sentence':
    385                     output_template += ' \n {}'.format('somebody got married in somewhere.')
    386         return ('\n'.join(output_template.split('\n')[1:])).strip()
    387 
    388     def generate_input_str(self, query_trigger):
    389         input_str = self.passage
    390         for i_style in INPUT_STYLE_SET:
    391             if i_style in self.input_style:
    392                 if i_style == 'event_type':
    393                     input_str += ' \n {}'.format('life event, marry sub-type')
    394                 if i_style == 'event_type_sent':
    395                     input_str += ' \n {}'.format('The event is related to life and someone is married.')
    396                 if i_style == 'keywords':
    397                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    398                 if i_style == 'triggers':
    399                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    400                 if i_style == 'template':
    401                     input_str += ' \n {}'.format(self.output_template)
    402         return input_str
    403 
    404     def generate_output_str(self, query_trigger):
    405         assert self.gold_event is not None
    406         output_str = ''
    407         gold_sample = False
    408         for o_style in OUTPUT_STYLE_SET:
    409             if o_style in self.output_style:
    410                 if o_style == 'trigger:sentence':
    411                     if self.trigger_text != '':
    412                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    413                         gold_sample = True
    414                     else:
    415                         output_str += ' \n Event trigger is <Trigger>'
    416                 if o_style == 'argument:sentence':
    417                     output_texts = []
    418                     for argu in self.arguments:
    419                         filler = (
    420                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
    421                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
    422                         )
    423                         output_texts.append("{} got married in {}.".format(*filler))
    424                         gold_sample = True
    425                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    426         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    427         return (output_str, gold_sample)
    428 
    429     def decode(self, preds):
    430         output = []
    431         for cnt, pred in enumerate(preds.split('\n')):
    432             used_o_cnt = 0
    433             full_pred = pred.strip()
    434             for o_style in OUTPUT_STYLE_SET:
    435                 if o_style in self.output_style:
    436                     if o_style == 'trigger:sentence':
    437                         if used_o_cnt == cnt:
    438                             try:
    439                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    440                                 triggers = triggers.split(' and ')
    441                                 for t_cnt, t in enumerate(triggers):
    442                                     if t != '<Trigger>':
    443                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    444                             except:
    445                                     pass
    446                         used_o_cnt += 1
    447                     if o_style == 'argument:sentence':
    448                         if used_o_cnt == cnt:
    449                             try:
    450                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    451                                     person = prediction.split(' got married in ', 1)[0]
    452                                     person = person.split(' and ')
    453                                     place = prediction.split(' got married in ', 1)[1].rsplit('.', 1)[0]
    454                                     place = place.split(' and ')
    455                                     for arg in person:
    456                                         if arg != ROLE_PH_MAP['Person']:
    457                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
    458                                     for arg in place:
    459                                         if arg != ROLE_PH_MAP['Place']:
    460                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
    461                             except:
    462                                 pass
    463                         used_o_cnt += 1
    464         return output
    465     
    466 class Life_Divorce(event_template):
    467 
    468     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    469         super().__init__(input_style, output_style, passage, event_type, gold_event)
    470     
    471     @classmethod
    472     def get_keywords(self):
    473         return ['divorce', 'divorced', 'Divorce']
    474 
    475     def get_output_template(self):
    476         output_template = ''
    477         for o_style in OUTPUT_STYLE_SET:
    478             if o_style in self.output_style:
    479                 if o_style == 'trigger:sentence':
    480                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    481                 if o_style == 'argument:sentence':
    482                     output_template += ' \n {}'.format('somebody divorced in somewhere.')
    483         return ('\n'.join(output_template.split('\n')[1:])).strip()
    484 
    485     def generate_input_str(self, query_trigger):
    486         input_str = self.passage
    487         for i_style in INPUT_STYLE_SET:
    488             if i_style in self.input_style:
    489                 if i_style == 'event_type':
    490                     input_str += ' \n {}'.format('life event, divorce sub-type')
    491                 if i_style == 'event_type_sent':
    492                     input_str += ' \n {}'.format('The event is related to life and someone was divorced.')
    493                 if i_style == 'keywords':
    494                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    495                 if i_style == 'triggers':
    496                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    497                 if i_style == 'template':
    498                     input_str += ' \n {}'.format(self.output_template)
    499         
    500         return input_str
    501 
    502     def generate_output_str(self, query_trigger):
    503         assert self.gold_event is not None
    504         output_str = ''
    505         gold_sample = False
    506         for o_style in OUTPUT_STYLE_SET:
    507             if o_style in self.output_style:
    508                 if o_style == 'trigger:sentence':
    509                     if self.trigger_text != '':
    510                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    511                         gold_sample = True
    512                     else:
    513                         output_str += ' \n Event trigger is <Trigger>'
    514                 if o_style == 'argument:sentence':
    515                     output_texts = []
    516                     for argu in self.arguments:
    517                         filler = (
    518                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
    519                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
    520                         )
    521                         output_texts.append("{} divorced in {}.".format(*filler))
    522                         gold_sample = True
    523                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    524                 
    525         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    526         return (output_str, gold_sample)
    527 
    528     def decode(self, preds):
    529         output = []
    530         for cnt, pred in enumerate(preds.split('\n')):
    531             used_o_cnt = 0
    532             full_pred = pred.strip()
    533             for o_style in OUTPUT_STYLE_SET:
    534                 if o_style in self.output_style:
    535                     if o_style == 'trigger:sentence':
    536                         if used_o_cnt == cnt:
    537                             try:
    538                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    539                                 triggers = triggers.split(' and ')
    540                                 for t_cnt, t in enumerate(triggers):
    541                                     if t != '<Trigger>':
    542                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    543                             except:
    544                                 pass
    545                         used_o_cnt += 1
    546                     if o_style == 'argument:sentence':
    547                         if used_o_cnt == cnt:
    548                             try:
    549                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    550                                     person = prediction.split(' divorced in ', 1)[0]
    551                                     person = person.split(' and ')
    552                                     place = prediction.split(' divorced in ', 1)[1].rsplit('.', 1)[0]
    553                                     place = place.split(' and ')
    554                                     for arg in person:
    555                                         if arg != ROLE_PH_MAP['Person']:
    556                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
    557                                     for arg in place:
    558                                         if arg != ROLE_PH_MAP['Place']:
    559                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
    560                             except:
    561                                     pass
    562                         used_o_cnt += 1
    563                     
    564         return output
    565 
    566 class Life_Injure(event_template):
    567 
    568     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    569         super().__init__(input_style, output_style, passage, event_type, gold_event)
    570     
    571     @classmethod
    572     def get_keywords(self):
    573         return ['injure', 'wounded', 'hurt']
    574 
    575     def get_output_template(self):
    576         output_template = ''
    577         for o_style in OUTPUT_STYLE_SET:
    578             if o_style in self.output_style:
    579                 if o_style == 'trigger:sentence':
    580                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    581                 if o_style == 'argument:sentence':
    582                     output_template += ' \n {}'.format('somebody or some organization led to some victim injured by some way in somewhere.')
    583         return ('\n'.join(output_template.split('\n')[1:])).strip()
    584 
    585     def generate_input_str(self, query_trigger):
    586         input_str = self.passage
    587         for i_style in INPUT_STYLE_SET:
    588             if i_style in self.input_style:
    589                 if i_style == 'event_type':
    590                     input_str += ' \n {}'.format('life event, injure sub-type')
    591                 if i_style == 'event_type_sent':
    592                     input_str += ' \n {}'.format('The event is related to life and someone is injured.')
    593                 if i_style == 'keywords':
    594                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    595                 if i_style == 'triggers':
    596                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    597                 if i_style == 'template':
    598                     input_str += ' \n {}'.format(self.output_template)
    599         
    600         return input_str
    601 
    602     def generate_output_str(self, query_trigger):
    603         assert self.gold_event is not None
    604         output_str = ''
    605         gold_sample = False
    606         for o_style in OUTPUT_STYLE_SET:
    607             if o_style in self.output_style:
    608                 if o_style == 'trigger:sentence':
    609                     if self.trigger_text != '':
    610                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    611                         gold_sample = True
    612                     else:
    613                         output_str += ' \n Event trigger is <Trigger>'
    614                 if o_style == 'argument:sentence':
    615                     output_texts = []
    616                     for argu in self.arguments:
    617                         filler = (
    618                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
    619                             " and ".join([ a['argument text'] for a in argu['Victim']]) if "Victim" in argu.keys() else ROLE_PH_MAP['Victim'],
    620                             " and ".join([ a['argument text'] for a in argu['Instrument']]) if "Instrument" in argu.keys() else ROLE_PH_MAP['Instrument'],
    621                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
    622                         )
    623                         output_texts.append("{} led to {} injured by {} in {}.".format(*filler))
    624                         gold_sample = True
    625                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    626                 
    627         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    628         return (output_str, gold_sample)
    629 
    630     def decode(self, preds):
    631         output = []
    632         for cnt, pred in enumerate(preds.split('\n')):
    633             used_o_cnt = 0
    634             full_pred = pred.strip()
    635             for o_style in OUTPUT_STYLE_SET:
    636                 if o_style in self.output_style:
    637                     if o_style == 'trigger:sentence':
    638                         if used_o_cnt == cnt:
    639                             try:
    640                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    641                                 triggers = triggers.split(' and ')
    642                                 for t_cnt, t in enumerate(triggers):
    643                                     if t != '<Trigger>':
    644                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    645                             except:
    646                                 pass
    647                         used_o_cnt += 1
    648                     if o_style == 'argument:sentence':
    649                         if used_o_cnt == cnt:
    650                             try:
    651                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    652                                     agent = prediction.split(' led to ', 1)[0]
    653                                     agent = agent.split(' and ')
    654                                     victim = (prediction.split(' led to ', 1)[1]).split(' injured by ', 1)[0]
    655                                     victim = victim.split(' and ')
    656                                     instrument = ((prediction.split(' led to ', 1)[1]).split(' injured by ', 1)[1]).split(' in ', )[0]
    657                                     instrument = instrument.split(' and ')
    658                                     place = ((prediction.split(' led to ', 1)[1]).split(' injured by ', 1)[1]).split(' in ', 1)[1].rsplit('.',1)[0]
    659                                     place = place.split(' and ')
    660                                     for arg in agent:
    661                                         if arg != ROLE_PH_MAP['Agent']:
    662                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
    663                                     for arg in victim:
    664                                         if arg != ROLE_PH_MAP['Victim']:
    665                                             output.append((arg, 'Victim', {'cor tri cnt': a_cnt}))
    666                                     for arg in instrument:
    667                                         if arg != ROLE_PH_MAP['Instrument']:
    668                                             output.append((arg, 'Instrument', {'cor tri cnt': a_cnt}))                    
    669                                     for arg in place:
    670                                         if arg != ROLE_PH_MAP['Place']:
    671                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
    672                             except Exception as e:
    673                                 pass
    674                         used_o_cnt += 1
    675                     
    676         return output
    677 
    678 class Life_Die(event_template):
    679 
    680     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    681         super().__init__(input_style, output_style, passage, event_type, gold_event)
    682     
    683     @classmethod
    684     def get_keywords(self):
    685         return ['kill', 'death', 'hospitalized']
    686     
    687     def get_output_template(self):
    688         output_template = ''
    689         for o_style in OUTPUT_STYLE_SET:
    690             if o_style in self.output_style:
    691                 if o_style == 'trigger:sentence':
    692                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    693                 if o_style == 'argument:sentence':
    694                     output_template += ' \n {}'.format('somebody or some organization led to some victim died by some way in somewhere.')
    695         return ('\n'.join(output_template.split('\n')[1:])).strip()
    696 
    697     def generate_input_str(self, query_trigger):
    698         input_str = self.passage
    699         for i_style in INPUT_STYLE_SET:
    700             if i_style in self.input_style:
    701                 if i_style == 'event_type':
    702                     input_str += ' \n {}'.format('life event, die sub-type')
    703                 if i_style == 'event_type_sent':
    704                     input_str += ' \n {}'.format('The event is related to life and someone died.')
    705                 if i_style == 'keywords':
    706                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    707                 if i_style == 'triggers':
    708                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    709                 if i_style == 'template':
    710                     input_str += ' \n {}'.format(self.output_template)
    711         
    712         return input_str
    713 
    714     def generate_output_str(self, query_trigger):
    715         assert self.gold_event is not None
    716         output_str = ''
    717         gold_sample = False
    718         for o_style in OUTPUT_STYLE_SET:
    719             if o_style in self.output_style:
    720                 if o_style == 'trigger:sentence':
    721                     if self.trigger_text != '':
    722                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    723                         gold_sample = True
    724                     else:
    725                         output_str += ' \n Event trigger is <Trigger>'
    726                 if o_style == 'argument:sentence':
    727                     output_texts = []
    728                     for argu in self.arguments:
    729                         filler = (
    730                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
    731                             " and ".join([ a['argument text'] for a in argu['Victim']]) if "Victim" in argu.keys() else ROLE_PH_MAP['Victim'],
    732                             " and ".join([ a['argument text'] for a in argu['Instrument']]) if "Instrument" in argu.keys() else ROLE_PH_MAP['Instrument'],
    733                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
    734                         )
    735                         output_texts.append("{} led to {} died by {} in {}.".format(*filler))
    736                         gold_sample = True
    737                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    738                 
    739         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    740         return (output_str, gold_sample)
    741 
    742     def decode(self, preds):
    743         output = []
    744         for cnt, pred in enumerate(preds.split('\n')):
    745             used_o_cnt = 0
    746             full_pred = pred.strip()
    747             for o_style in OUTPUT_STYLE_SET:
    748                 if o_style in self.output_style:
    749                     if o_style == 'trigger:sentence':
    750                         if used_o_cnt == cnt:
    751                             try:
    752                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    753                                 triggers = triggers.split(' and ')
    754                                 for t_cnt, t in enumerate(triggers):
    755                                     if t != '<Trigger>':
    756                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    757                             except:
    758                                 pass
    759                         used_o_cnt += 1
    760                     if o_style == 'argument:sentence':
    761                         if used_o_cnt == cnt:
    762                             try:
    763                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    764                                     agent = prediction.split(' led to ', 1)[0]
    765                                     agent = agent.split(' and ')
    766                                     victim = (prediction.split(' led to ', 1)[1]).split(' died by ', 1)[0]
    767                                     victim = victim.split(' and ')
    768                                     instrument = ((prediction.split(' led to ', 1)[1]).split(' died by ', 1)[1]).split(' in ', )[0]
    769                                     instrument = instrument.split(' and ')
    770                                     place = ((prediction.split(' led to ', 1)[1]).split(' died by ', 1)[1]).split(' in ', 1)[1].rsplit('.',1)[0]
    771                                     place = place.split(' and ')
    772                                     for arg in agent:
    773                                         if arg != ROLE_PH_MAP['Agent']:
    774                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
    775                                     for arg in victim:
    776                                         if arg != ROLE_PH_MAP['Victim']:
    777                                             output.append((arg, 'Victim', {'cor tri cnt': a_cnt}))
    778                                     for arg in instrument:
    779                                         if arg != ROLE_PH_MAP['Instrument']:
    780                                             output.append((arg, 'Instrument', {'cor tri cnt': a_cnt}))         
    781                                     for arg in place:
    782                                         if arg != ROLE_PH_MAP['Place']:
    783                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
    784                             except Exception as e:
    785                                 pass
    786                         used_o_cnt += 1
    787         return output
    788 
    789 class Movement_Transport_Person(event_template):
    790 
    791     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    792         super().__init__(input_style, output_style, passage, event_type, gold_event)
    793     
    794     @classmethod
    795     def get_keywords(self):
    796         return ['travel', 'go', 'move']
    797     
    798     def get_output_template(self):
    799         output_template = ''
    800         for o_style in OUTPUT_STYLE_SET:
    801             if o_style in self.output_style:
    802                 if o_style == 'trigger:sentence':
    803                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    804                 if o_style == 'argument:sentence':
    805                     output_template += ' \n {}'.format('somebody was moved to somewhere from some place by some way. somebody or some organization was responsible for the movement.')
    806         return ('\n'.join(output_template.split('\n')[1:])).strip()
    807 
    808     def generate_input_str(self, query_trigger):
    809         input_str = self.passage
    810         for i_style in INPUT_STYLE_SET:
    811             if i_style in self.input_style:
    812                 if i_style == 'event_type':
    813                     input_str += ' \n {}'.format('movement event, transport person sub-type')
    814                 if i_style == 'event_type_sent':
    815                     input_str += ' \n {}'.format('The event is related to movement. The event occurs when a person moves or is moved from one place to another.')
    816                 if i_style == 'keywords':
    817                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    818                 if i_style == 'triggers':
    819                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    820                 if i_style == 'template':
    821                     input_str += ' \n {}'.format(self.output_template)
    822         
    823         return input_str
    824 
    825     def generate_output_str(self, query_trigger):
    826         assert self.gold_event is not None
    827         output_str = ''
    828         gold_sample = False
    829         for o_style in OUTPUT_STYLE_SET:
    830             if o_style in self.output_style:
    831                 if o_style == 'trigger:sentence':
    832                     if self.trigger_text != '':
    833                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    834                         gold_sample = True
    835                     else:
    836                         output_str += ' \n Event trigger is <Trigger>'
    837                 if o_style == 'argument:sentence':
    838                     output_texts = []
    839                     for argu in self.arguments:
    840                         filler = (
    841                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
    842                             " and ".join([ a['argument text'] for a in argu['Destination']]) if "Destination" in argu.keys() else ROLE_PH_MAP['Destination'],
    843                             " and ".join([ a['argument text'] for a in argu['Origin']]) if "Origin" in argu.keys() else ROLE_PH_MAP['Origin'],
    844                             " and ".join([ a['argument text'] for a in argu['Instrument']]) if "Instrument" in argu.keys() else ROLE_PH_MAP['Instrument'],
    845                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent']
    846                         )
    847                         output_texts.append("{} was moved to {} from {} by {}. {} was responsible for the movement.".format(*filler))
    848                         gold_sample = True
    849                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    850                 
    851         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    852         return (output_str, gold_sample)
    853 
    854     def decode(self, preds):
    855         output = []
    856         for cnt, pred in enumerate(preds.split('\n')):
    857             used_o_cnt = 0
    858             full_pred = pred.strip()
    859             for o_style in OUTPUT_STYLE_SET:
    860                 if o_style in self.output_style:
    861                     if o_style == 'trigger:sentence':
    862                         if used_o_cnt == cnt:
    863                             try:
    864                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    865                                 triggers = triggers.split(' and ')
    866                                 for t_cnt, t in enumerate(triggers):
    867                                     if t != '<Trigger>':
    868                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    869                             except:
    870                                 pass
    871                         used_o_cnt += 1
    872                     if o_style == 'argument:sentence':
    873                         if used_o_cnt == cnt:
    874                             try:
    875                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    876                                     artifact = prediction.split(' was moved to ', 1)[0]
    877                                     artifact = artifact.split(' and ')
    878                                     destination = (prediction.split(' was moved to ', 1)[1]).split(' from ', 1)[0]
    879                                     destination = destination.split(' and ')
    880                                     origin = ((prediction.split(' was moved to ', 1)[1]).split(' from ', 1)[1]).split(' by ', 1)[0]
    881                                     origin = origin.split(' and ')
    882                                     vehicle = (((prediction.split(' was moved to ', 1)[1]).split(' from ', 1)[1]).split(' by ', 1)[1]).split('.', 1)[0]
    883                                     vehicle = vehicle.split(' and ')
    884                                     remain = (((prediction.split(' was moved to ', 1)[1]).split(' from ', 1)[1]).split(' by ', 1)[1]).split('.', 1)[1]
    885                                     if 'was responsible for the movement' in remain:
    886                                         agent = (remain.split(' was responsible for the movement.')[0]).strip()
    887                                         agent = agent.split(' and ')
    888                                     else:
    889                                         agent = []
    890 
    891                                     for arg in agent:
    892                                         if arg != ROLE_PH_MAP['Agent']:
    893                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
    894                                     for arg in artifact:
    895                                         if arg != ROLE_PH_MAP['Person']:
    896                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
    897                                     for arg in destination:
    898                                         if arg != ROLE_PH_MAP['Destination']:
    899                                             output.append((arg, 'Destination', {'cor tri cnt': a_cnt}))          
    900                                     for arg in origin:
    901                                         if arg != ROLE_PH_MAP['Origin']:
    902                                             output.append((arg, 'Origin', {'cor tri cnt': a_cnt}))
    903                                     for arg in vehicle:
    904                                         if arg != ROLE_PH_MAP['Instrument']:
    905                                             output.append((arg, 'Instrument', {'cor tri cnt': a_cnt}))
    906                             except:
    907                                 pass
    908                         used_o_cnt += 1
    909                     
    910         return output
    911 
    912 class Movement_Transport_Artifact(event_template):
    913 
    914     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
    915         super().__init__(input_style, output_style, passage, event_type, gold_event)
    916 
    917     @classmethod
    918     def get_keywords(self):
    919         return ['export', 'deliver', 'send']
    920     
    921     def get_output_template(self):
    922         output_template = ''
    923         for o_style in OUTPUT_STYLE_SET:
    924             if o_style in self.output_style:
    925                 if o_style == 'trigger:sentence':
    926                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
    927                 if o_style == 'argument:sentence':
    928                     output_template += ' \n {}'.format('something was sent to somewhere from some place. somebody or some organization was responsible for the transport.')
    929         return ('\n'.join(output_template.split('\n')[1:])).strip()
    930 
    931     def generate_input_str(self, query_trigger):
    932         input_str = self.passage
    933         for i_style in INPUT_STYLE_SET:
    934             if i_style in self.input_style:
    935                 if i_style == 'event_type':
    936                     input_str += ' \n {}'.format('movement event, transport artifact sub-type')
    937                 if i_style == 'event_type_sent':
    938                     input_str += ' \n {}'.format('The event is related to movement. The event occurs when an artifact, like items or weapon, is moved from one place to another.')
    939                 if i_style == 'keywords':
    940                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
    941                 if i_style == 'triggers':
    942                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
    943                 if i_style == 'template':
    944                     input_str += ' \n {}'.format(self.output_template)
    945         
    946         return input_str
    947 
    948     def generate_output_str(self, query_trigger):
    949         assert self.gold_event is not None
    950         output_str = ''
    951         gold_sample = False
    952         for o_style in OUTPUT_STYLE_SET:
    953             if o_style in self.output_style:
    954                 if o_style == 'trigger:sentence':
    955                     if self.trigger_text != '':
    956                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
    957                         gold_sample = True
    958                     else:
    959                         output_str += ' \n Event trigger is <Trigger>'
    960                 if o_style == 'argument:sentence':
    961                     output_texts = []
    962                     for argu in self.arguments:
    963                         filler = (
    964                             " and ".join([ a['argument text'] for a in argu['Artifact']]) if "Artifact" in argu.keys() else ROLE_PH_MAP['Artifact'],
    965                             " and ".join([ a['argument text'] for a in argu['Destination']]) if "Destination" in argu.keys() else ROLE_PH_MAP['Destination'],
    966                             " and ".join([ a['argument text'] for a in argu['Origin']]) if "Origin" in argu.keys() else ROLE_PH_MAP['Origin'],
    967                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent']
    968                         )
    969                         output_texts.append("{} was sent to {} from {}. {} was responsible for the transport.".format(*filler))
    970                         gold_sample = True
    971                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
    972                 
    973         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
    974         return (output_str, gold_sample)
    975 
    976     def decode(self, preds):
    977         output = []
    978         for cnt, pred in enumerate(preds.split('\n')):
    979             used_o_cnt = 0
    980             full_pred = pred.strip()
    981             for o_style in OUTPUT_STYLE_SET:
    982                 if o_style in self.output_style:
    983                     if o_style == 'trigger:sentence':
    984                         if used_o_cnt == cnt:
    985                             try:
    986                                 triggers = full_pred.split('Event trigger is ', 1)[1]
    987                                 triggers = triggers.split(' and ')
    988                                 for t_cnt, t in enumerate(triggers):
    989                                     if t != '<Trigger>':
    990                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
    991                             except:
    992                                 pass
    993                         used_o_cnt += 1
    994                     if o_style == 'argument:sentence':
    995                         if used_o_cnt == cnt:
    996                             try:
    997                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
    998                                     artifact = prediction.split(' was sent to ', 1)[0]
    999                                     artifact = artifact.split(' and ')
   1000                                     destination = (prediction.split(' was sent to ', 1)[1]).split(' from ', 1)[0]
   1001                                     destination = destination.split(' and ')
   1002                                     origin = ((prediction.split(' was sent to ', 1)[1]).split(' from ', 1)[1]).split('. ', 1)[0]
   1003                                     origin = origin.split(' and ')
   1004 
   1005                                     remain = ((prediction.split(' was sent to ', 1)[1]).split(' from ', 1)[1]).split('. ', 1)[1]
   1006                                     if 'was responsible for the transport' in remain:
   1007                                         agent = (remain.split(' was responsible for the transport.')[0]).strip()
   1008                                         agent = agent.split(' and ')
   1009                                     else:
   1010                                         agent = []
   1011 
   1012                                     for arg in agent:
   1013                                         if arg != ROLE_PH_MAP['Agent']:
   1014                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   1015                                     for arg in artifact:
   1016                                         if arg != ROLE_PH_MAP['Artifact']:
   1017                                             output.append((arg, 'Artifact', {'cor tri cnt': a_cnt}))
   1018                                     for arg in destination:
   1019                                         if arg != ROLE_PH_MAP['Destination']:
   1020                                             output.append((arg, 'Destination', {'cor tri cnt': a_cnt}))          
   1021                                     for arg in origin:
   1022                                         if arg != ROLE_PH_MAP['Origin']:
   1023                                             output.append((arg, 'Origin', {'cor tri cnt': a_cnt}))
   1024                             except:
   1025                                 pass
   1026                         used_o_cnt += 1
   1027                     
   1028         return output
   1029 
   1030 class Transaction_Transfer_Ownership(event_template):
   1031 
   1032     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1033         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1034 
   1035     @classmethod
   1036     def get_keywords(self):
   1037         return ['sell', 'buy', 'acquire']
   1038 
   1039     def get_output_template(self):
   1040         output_template = ''
   1041         for o_style in OUTPUT_STYLE_SET:
   1042             if o_style in self.output_style:
   1043                 if o_style == 'trigger:sentence':
   1044                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1045                 if o_style == 'argument:sentence':
   1046                     output_template += ' \n {}'.format('The ownership of something from someone was transferred to some other at somewhere.')
   1047         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1048 
   1049     def generate_input_str(self, query_trigger):
   1050         input_str = self.passage
   1051         for i_style in INPUT_STYLE_SET:
   1052             if i_style in self.input_style:
   1053                 if i_style == 'event_type':
   1054                     input_str += ' \n {}'.format('transaction event, transfer ownership sub-type')
   1055                 if i_style == 'event_type_sent':
   1056                     input_str += ' \n {}'.format('The event is events refer to the buying, selling, loaning, borrowing, giving, receiving, bartering, stealing, or renting of physical items, assets,or organizations.')
   1057                 if i_style == 'keywords':
   1058                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1059                 if i_style == 'triggers':
   1060                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1061                 if i_style == 'template':
   1062                     input_str += ' \n {}'.format(self.output_template)
   1063         
   1064         return input_str
   1065 
   1066     def generate_output_str(self, query_trigger):
   1067         assert self.gold_event is not None
   1068         output_str = ''
   1069         gold_sample = False
   1070         for o_style in OUTPUT_STYLE_SET:
   1071             if o_style in self.output_style:
   1072                 if o_style == 'trigger:sentence':
   1073                     if self.trigger_text != '':
   1074                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1075                         gold_sample = True
   1076                     else:
   1077                         output_str += ' \n Event trigger is <Trigger>'
   1078                 if o_style == 'argument:sentence':
   1079                     output_texts = []
   1080                     for argu in self.arguments:
   1081                         buyer_list = []
   1082                         if "Beneficiary" in argu.keys():
   1083                             buyer_list.extend([ a['argument text'] for a in argu['Beneficiary']])
   1084                         if "Recipient" in argu.keys():
   1085                             buyer_list.extend([ a['argument text'] for a in argu['Recipient']])
   1086 
   1087                         filler = (
   1088                             " and ".join([ a['argument text'] for a in argu['Thing']]) if "Thing" in argu.keys() else ROLE_PH_MAP['Thing'],
   1089                             " and ".join([ a['argument text'] for a in argu['Giver']]) if "Giver" in argu.keys() else ROLE_PH_MAP['Giver'],                            
   1090                             " and ".join(buyer_list) if len(buyer_list)>0 else ROLE_PH_MAP['Recipient'],
   1091                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   1092                         )
   1093                         output_texts.append("The ownership of {} from {} was transferred to {} at {}.".format(*filler))
   1094                         gold_sample = True
   1095                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1096                 
   1097         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1098         return (output_str, gold_sample)
   1099 
   1100     def decode(self, preds):
   1101         output = []
   1102         for cnt, pred in enumerate(preds.split('\n')):
   1103             used_o_cnt = 0
   1104             full_pred = pred.strip()
   1105             for o_style in OUTPUT_STYLE_SET:
   1106                 if o_style in self.output_style:
   1107                     if o_style == 'trigger:sentence':
   1108                         if used_o_cnt == cnt:
   1109                             try:
   1110                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1111                                 triggers = triggers.split(' and ')
   1112                                 for t_cnt, t in enumerate(triggers):
   1113                                     if t != '<Trigger>':
   1114                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1115                             except:
   1116                                 pass
   1117                         used_o_cnt += 1
   1118                     if o_style == 'argument:sentence':
   1119                         if used_o_cnt == cnt:
   1120                             try:
   1121                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1122                                     thing = prediction.split(' from ', 1)[0].split('The ownership of ', 1)[1]
   1123                                     thing = thing.split(' and ')
   1124                                     remain = prediction.split(' from ', 1)[1]
   1125 
   1126                                     giver = remain.split(' was transferred to ', 1)[0]
   1127                                     giver = giver.split(' and ')
   1128                                     remain = remain.split(' was transferred to ', 1)[1]
   1129 
   1130                                     recipient = remain.split(' at ', 1)[0]
   1131                                     recipient = recipient.split(' and ')
   1132                                     remain = remain.split(' at ', 1)[1]
   1133 
   1134                                     place = remain.rsplit('.',1)[0]
   1135                                     place = place.split(' and ')
   1136 
   1137                                     for arg in thing:
   1138                                         if arg != ROLE_PH_MAP['Thing']:
   1139                                             output.append((arg, 'Thing', {'cor tri cnt': a_cnt}))
   1140                                     for arg in giver:
   1141                                         if arg != ROLE_PH_MAP['Giver']:
   1142                                             output.append((arg, 'Giver', {'cor tri cnt': a_cnt}))
   1143                                     for arg in recipient:
   1144                                         if arg != ROLE_PH_MAP['Recipient']:
   1145                                             output.append((arg, 'Recipient', {'cor tri cnt': a_cnt}))          
   1146                                     for arg in place:
   1147                                         if arg != ROLE_PH_MAP['Place']:
   1148                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   1149                             except Exception as e:
   1150                                 pass
   1151                         used_o_cnt += 1
   1152                     
   1153         return output
   1154 
   1155 class Transaction_Transfer_Money(event_template):
   1156 
   1157     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1158         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1159 
   1160     @classmethod
   1161     def get_keywords(self):
   1162         return ['pay', 'donation', 'loan']
   1163 
   1164     def get_output_template(self):
   1165         output_template = ''
   1166         for o_style in OUTPUT_STYLE_SET:
   1167             if o_style in self.output_style:
   1168                 if o_style == 'trigger:sentence':
   1169                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1170                 if o_style == 'argument:sentence':
   1171                     output_template += ' \n {}'.format('someone paid some other in somewhere.')
   1172         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1173 
   1174     def generate_input_str(self, query_trigger):
   1175         input_str = self.passage
   1176         for i_style in INPUT_STYLE_SET:
   1177             if i_style in self.input_style:
   1178                 if i_style == 'event_type':
   1179                     input_str += ' \n {}'.format('transaction event, transfer money sub-type')
   1180                 if i_style == 'event_type_sent':
   1181                     input_str += ' \n {}'.format('The event is related to transaction. The event occurs when someone is giving, receiving, borrowing, or lending money.')
   1182                 if i_style == 'keywords':
   1183                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1184                 if i_style == 'triggers':
   1185                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1186                 if i_style == 'template':
   1187                     input_str += ' \n {}'.format(self.output_template)
   1188         
   1189         return input_str
   1190 
   1191     def generate_output_str(self, query_trigger):
   1192         assert self.gold_event is not None
   1193         output_str = ''
   1194         gold_sample = False
   1195         for o_style in OUTPUT_STYLE_SET:
   1196             if o_style in self.output_style:
   1197                 if o_style == 'trigger:sentence':
   1198                     if self.trigger_text != '':
   1199                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1200                         gold_sample = True
   1201                     else:
   1202                         output_str += ' \n Event trigger is <Trigger>'
   1203                 if o_style == 'argument:sentence':
   1204                     output_texts = []
   1205                     for argu in self.arguments:
   1206                         recipient_list = []
   1207                         if "Recipient" in argu.keys():
   1208                             recipient_list.extend([ a['argument text'] for a in argu['Recipient']])
   1209                         if "Beneficiary" in argu.keys():
   1210                             recipient_list.extend([ a['argument text'] for a in argu['Beneficiary']])
   1211                         filler = (
   1212                             " and ".join([ a['argument text'] for a in argu['Giver']]) if "Giver" in argu.keys() else ROLE_PH_MAP['Giver'],
   1213                             " and ".join(recipient_list) if len(recipient_list)>0 else ROLE_PH_MAP['Recipient'],
   1214                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   1215                         )
   1216                         output_texts.append("{} paid {} in {}.".format(*filler))
   1217                         gold_sample = True
   1218                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1219                 
   1220         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1221         return (output_str, gold_sample)
   1222 
   1223     def decode(self, preds):
   1224         output = []
   1225         for cnt, pred in enumerate(preds.split('\n')):
   1226             used_o_cnt = 0
   1227             full_pred = pred.strip()
   1228             for o_style in OUTPUT_STYLE_SET:
   1229                 if o_style in self.output_style:
   1230                     if o_style == 'trigger:sentence':
   1231                         if used_o_cnt == cnt:
   1232                             try:
   1233                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1234                                 triggers = triggers.split(' and ')
   1235                                 for t_cnt, t in enumerate(triggers):
   1236                                     if t != '<Trigger>':
   1237                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1238                             except:
   1239                                 pass
   1240                         used_o_cnt += 1
   1241                     if o_style == 'argument:sentence':
   1242                         if used_o_cnt == cnt:
   1243                             try:
   1244                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1245                                     giver = prediction.split(' paid ', 1)[0]
   1246                                     giver = giver.split(' and ')
   1247                                     remain = prediction.split(' paid ', 1)[1]
   1248 
   1249                                     recipient = remain.split(' in ', 1)[0]
   1250                                     recipient = recipient.split(' and ')
   1251                                     remain = remain.split(' in ', 1)[1]
   1252 
   1253                                     place = remain.rsplit('.',1)[0]
   1254                                     place = place.split(' and ')
   1255 
   1256                                     for arg in giver:
   1257                                         if arg != ROLE_PH_MAP['Giver']:
   1258                                             output.append((arg, 'Giver', {'cor tri cnt': a_cnt}))
   1259                                     for arg in recipient:
   1260                                         if arg != ROLE_PH_MAP['Recipient']:
   1261                                             output.append((arg, 'Recipient', {'cor tri cnt': a_cnt}))          
   1262                                     for arg in place:
   1263                                         if arg != ROLE_PH_MAP['Place']:
   1264                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   1265                             except:
   1266                                 pass
   1267                         used_o_cnt += 1
   1268                     
   1269         return output
   1270 
   1271 class Transaction_Transaction(event_template):
   1272     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1273         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1274 
   1275     @classmethod
   1276     def get_keywords(self):
   1277         return ['receive', 'give', 'get']
   1278 
   1279     def get_output_template(self):
   1280         output_template = ''
   1281         for o_style in OUTPUT_STYLE_SET:
   1282             if o_style in self.output_style:
   1283                 if o_style == 'trigger:sentence':
   1284                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1285                 if o_style == 'argument:sentence':
   1286                     output_template += ' \n {}'.format('someone give some things to some other in somewhere.')
   1287         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1288 
   1289     def generate_input_str(self, query_trigger):
   1290         input_str = self.passage
   1291         for i_style in INPUT_STYLE_SET:
   1292             if i_style in self.input_style:
   1293                 if i_style == 'event_type':
   1294                     input_str += ' \n {}'.format('transaction event, transaction sub-type')
   1295                 if i_style == 'event_type_sent':
   1296                     input_str += ' \n {}'.format('The event is related to transaction. The event occurs when someone is giving, receiving, borrowing, or lending something when you cannot tell whether it is money or an asset in the context.')
   1297                 if i_style == 'keywords':
   1298                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1299                 if i_style == 'triggers':
   1300                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1301                 if i_style == 'template':
   1302                     input_str += ' \n {}'.format(self.output_template)
   1303         
   1304         return input_str
   1305 
   1306     def generate_output_str(self, query_trigger):
   1307         assert self.gold_event is not None
   1308         output_str = ''
   1309         gold_sample = False
   1310         for o_style in OUTPUT_STYLE_SET:
   1311             if o_style in self.output_style:
   1312                 if o_style == 'trigger:sentence':
   1313                     if self.trigger_text != '':
   1314                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1315                         gold_sample = True
   1316                     else:
   1317                         output_str += ' \n Event trigger is <Trigger>'
   1318                 if o_style == 'argument:sentence':
   1319                     output_texts = []
   1320                     for argu in self.arguments:
   1321                         recipient_list = []
   1322                         if "Recipient" in argu.keys():
   1323                             recipient_list.extend([ a['argument text'] for a in argu['Recipient']])
   1324                         if "Beneficiary" in argu.keys():
   1325                             recipient_list.extend([ a['argument text'] for a in argu['Beneficiary']])
   1326                         filler = (
   1327                             " and ".join([ a['argument text'] for a in argu['Giver']]) if "Giver" in argu.keys() else ROLE_PH_MAP['Giver'],
   1328                             " and ".join(recipient_list) if len(recipient_list)>0 else ROLE_PH_MAP['Recipient'],
   1329                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   1330                         )
   1331                         output_texts.append("{} give some things to {} in {}.".format(*filler))
   1332                         gold_sample = True
   1333                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1334                 
   1335         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1336         return (output_str, gold_sample)
   1337 
   1338     def decode(self, preds):
   1339         output = []
   1340         for cnt, pred in enumerate(preds.split('\n')):
   1341             used_o_cnt = 0
   1342             full_pred = pred.strip()
   1343             for o_style in OUTPUT_STYLE_SET:
   1344                 if o_style in self.output_style:
   1345                     if o_style == 'trigger:sentence':
   1346                         if used_o_cnt == cnt:
   1347                             try:
   1348                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1349                                 triggers = triggers.split(' and ')
   1350                                 for t_cnt, t in enumerate(triggers):
   1351                                     if t != '<Trigger>':
   1352                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1353                             except:
   1354                                 pass
   1355                         used_o_cnt += 1
   1356                     if o_style == 'argument:sentence':
   1357                         if used_o_cnt == cnt:
   1358                             try:
   1359                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1360                                     giver = prediction.split(' give some things to ', 1)[0]
   1361                                     giver = giver.split(' and ')
   1362                                     remain = prediction.split(' give some things to', 1)[1]
   1363 
   1364                                     recipient = remain.split(' in ', 1)[0]
   1365                                     recipient = recipient.split(' and ')
   1366                                     remain = remain.split(' in ', 1)[1]
   1367 
   1368                                     place = remain.rsplit('.',1)[0]
   1369                                     place = place.split(' and ')
   1370 
   1371                                     for arg in giver:
   1372                                         if arg != ROLE_PH_MAP['Giver']:
   1373                                             output.append((arg, 'Giver', {'cor tri cnt': a_cnt}))
   1374                                     for arg in recipient:
   1375                                         if arg != ROLE_PH_MAP['Recipient']:
   1376                                             output.append((arg, 'Recipient', {'cor tri cnt': a_cnt}))          
   1377                                     for arg in place:
   1378                                         if arg != ROLE_PH_MAP['Place']:
   1379                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   1380                             except:
   1381                                 pass
   1382                         used_o_cnt += 1
   1383                     
   1384         return output
   1385 
   1386 class Business_Start_Org(event_template):
   1387 
   1388     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1389         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1390 
   1391     @classmethod
   1392     def get_keywords(self):
   1393         return ['founded', 'create', 'launch']
   1394 
   1395     def get_output_template(self):
   1396         output_template = ''
   1397         for o_style in OUTPUT_STYLE_SET:
   1398             if o_style in self.output_style:
   1399                 if o_style == 'trigger:sentence':
   1400                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1401                 if o_style == 'argument:sentence':
   1402                     output_template += ' \n {}'.format('somebody or some organization launched some organization in somewhere.')
   1403         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1404 
   1405     def generate_input_str(self, query_trigger):
   1406         input_str = self.passage
   1407         for i_style in INPUT_STYLE_SET:
   1408             if i_style in self.input_style:
   1409                 if i_style == 'event_type':
   1410                     input_str += ' \n {}'.format('business event, start organization sub-type')
   1411                 if i_style == 'event_type_sent':
   1412                     input_str += ' \n {}'.format('The event is related to a new organization being created.')
   1413                 if i_style == 'keywords':
   1414                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1415                 if i_style == 'triggers':
   1416                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1417                 if i_style == 'template':
   1418                     input_str += ' \n {}'.format(self.output_template)
   1419         
   1420         return input_str
   1421 
   1422     def generate_output_str(self, query_trigger):
   1423         assert self.gold_event is not None
   1424         output_str = ''
   1425         gold_sample = False
   1426         for o_style in OUTPUT_STYLE_SET:
   1427             if o_style in self.output_style:
   1428                 if o_style == 'trigger:sentence':
   1429                     if self.trigger_text != '':
   1430                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1431                         gold_sample = True
   1432                     else:
   1433                         output_str += ' \n Event trigger is <Trigger>'
   1434                 if o_style == 'argument:sentence':
   1435                     output_texts = []
   1436                     for argu in self.arguments:
   1437                         filler = (
   1438                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
   1439                             " and ".join([ a['argument text'] for a in argu['Org']]) if "Org" in argu.keys() else ROLE_PH_MAP['Org'],
   1440                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   1441                         )
   1442                         output_texts.append("{} launched {} in {}.".format(*filler))
   1443                         gold_sample = True
   1444                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1445         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1446         return (output_str, gold_sample)
   1447 
   1448     def decode(self, preds):
   1449         output = []
   1450         for cnt, pred in enumerate(preds.split('\n')):
   1451             used_o_cnt = 0
   1452             full_pred = pred.strip()
   1453             for o_style in OUTPUT_STYLE_SET:
   1454                 if o_style in self.output_style:
   1455                     if o_style == 'trigger:sentence':
   1456                         if used_o_cnt == cnt:
   1457                             try:
   1458                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1459                                 triggers = triggers.split(' and ')
   1460                                 for t_cnt, t in enumerate(triggers):
   1461                                     if t != '<Trigger>':
   1462                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1463                             except:
   1464                                 pass
   1465                         used_o_cnt += 1
   1466                     if o_style == 'argument:sentence':
   1467                         if used_o_cnt == cnt:
   1468                             try:
   1469                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1470                                     agent = prediction.split(' launched ', 1)[0]
   1471                                     agent = agent.split(' and ')
   1472                                     remain = prediction.split(' launched ', 1)[1]
   1473 
   1474                                     org = remain.split(' in ', 1)[0]
   1475                                     org = org.split(' and ')
   1476                                     remain = remain.split(' in ', 1)[1]
   1477 
   1478                                     place = remain.rsplit('.',1)[0]
   1479                                     place = place.split(' and ')
   1480                                     for arg in agent:
   1481                                         if arg != ROLE_PH_MAP['Agent']:
   1482                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   1483                                     for arg in org:
   1484                                         if arg != ROLE_PH_MAP['Org']:
   1485                                             output.append((arg, 'Org', {'cor tri cnt': a_cnt}))                  
   1486                                     for arg in place:
   1487                                         if arg != ROLE_PH_MAP['Place']:
   1488                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   1489                             except:
   1490                                 pass
   1491                         used_o_cnt += 1
   1492                     
   1493         return output
   1494 
   1495 class Business_Merge_Org(event_template):
   1496 
   1497     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1498         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1499 
   1500     @classmethod
   1501     def get_keywords(self):
   1502         return ['merge', 'merging', 'merger']
   1503 
   1504     def get_output_template(self):
   1505         output_template = ''
   1506         for o_style in OUTPUT_STYLE_SET:
   1507             if o_style in self.output_style:
   1508                 if o_style == 'trigger:sentence':
   1509                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1510                 if o_style == 'argument:sentence':
   1511                     output_template += ' \n {}'.format('some organization was merged.')
   1512         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1513 
   1514     def generate_input_str(self, query_trigger):
   1515         input_str = self.passage
   1516         for i_style in INPUT_STYLE_SET:
   1517             if i_style in self.input_style:
   1518                 if i_style == 'event_type':
   1519                     input_str += ' \n {}'.format('business event, merge organization sub-type')
   1520                 if i_style == 'event_type_sent':
   1521                     input_str += ' \n {}'.format('The event is related to two or more organization coming together to form a new organization.')
   1522                 if i_style == 'keywords':
   1523                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1524                 if i_style == 'triggers':
   1525                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1526                 if i_style == 'template':
   1527                     input_str += ' \n {}'.format(self.output_template)
   1528         
   1529         return input_str
   1530 
   1531     def generate_output_str(self, query_trigger):
   1532         assert self.gold_event is not None
   1533         output_str = ''
   1534         gold_sample = False
   1535         for o_style in OUTPUT_STYLE_SET:
   1536             if o_style in self.output_style:
   1537                 if o_style == 'trigger:sentence':
   1538                     if self.trigger_text != '':
   1539                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1540                         gold_sample = True
   1541                     else:
   1542                         output_str += ' \n Event trigger is <Trigger>'
   1543                 if o_style == 'argument:sentence':
   1544                     output_texts = []
   1545                     for argu in self.arguments:
   1546                         filler = (
   1547                             " and ".join([ a['argument text'] for a in argu['Org']]) if "Org" in argu.keys() else ROLE_PH_MAP['Org']
   1548                         )
   1549                         output_texts.append("{} was merged.".format(filler))
   1550                         gold_sample = True
   1551                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1552                 
   1553         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1554         return (output_str, gold_sample)
   1555 
   1556     def decode(self, preds):
   1557         output = []
   1558         for cnt, pred in enumerate(preds.split('\n')):
   1559             used_o_cnt = 0
   1560             full_pred = pred.strip()
   1561             for o_style in OUTPUT_STYLE_SET:
   1562                 if o_style in self.output_style:
   1563                     if o_style == 'trigger:sentence':
   1564                         if used_o_cnt == cnt:
   1565                             try:
   1566                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1567                                 triggers = triggers.split(' and ')
   1568                                 for t_cnt, t in enumerate(triggers):
   1569                                     if t != '<Trigger>':
   1570                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1571                             except:
   1572                                 pass
   1573                         used_o_cnt += 1
   1574                     if o_style == 'argument:sentence':
   1575                         if used_o_cnt == cnt:
   1576                             try:
   1577                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1578                                     org = prediction.split(' was merged.', 1)[0]
   1579                                     org = org.split(' and ')
   1580                                     for arg in org:
   1581                                         if arg != ROLE_PH_MAP['Org']:
   1582                                             output.append((arg, 'Org', {'cor tri cnt': a_cnt}))                  
   1583                             except:
   1584                                 pass
   1585                         used_o_cnt += 1
   1586                     
   1587         return output
   1588 
   1589 class Business_Declare_Bankruptcy(event_template):
   1590 
   1591     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1592         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1593 
   1594     @classmethod
   1595     def get_keywords(self):
   1596         return ['bankruptcy', 'bankrupt', 'Bankruptcy']
   1597 
   1598     def get_output_template(self):
   1599         output_template = ''
   1600         for o_style in OUTPUT_STYLE_SET:
   1601             if o_style in self.output_style:
   1602                 if o_style == 'trigger:sentence':
   1603                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1604                 if o_style == 'argument:sentence':
   1605                     output_template += ' \n {}'.format('some organization declared bankruptcy.')
   1606         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1607 
   1608     def generate_input_str(self, query_trigger):
   1609         input_str = self.passage
   1610         for i_style in INPUT_STYLE_SET:
   1611             if i_style in self.input_style:
   1612                 if i_style == 'event_type':
   1613                     input_str += ' \n {}'.format('business event, declare bankruptcy sub-type')
   1614                 if i_style == 'event_type_sent':
   1615                     input_str += ' \n {}'.format('The event is related to some organization declaring bankruptcy.')
   1616                 if i_style == 'keywords':
   1617                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1618                 if i_style == 'triggers':
   1619                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1620                 if i_style == 'template':
   1621                     input_str += ' \n {}'.format(self.output_template)
   1622         
   1623         return input_str
   1624 
   1625     def generate_output_str(self, query_trigger):
   1626         assert self.gold_event is not None
   1627         output_str = ''
   1628         gold_sample = False
   1629         for o_style in OUTPUT_STYLE_SET:
   1630             if o_style in self.output_style:
   1631                 if o_style == 'trigger:sentence':
   1632                     if self.trigger_text != '':
   1633                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1634                         gold_sample = True
   1635                     else:
   1636                         output_str += ' \n Event trigger is <Trigger>'
   1637                 if o_style == 'argument:sentence':
   1638                     output_texts = []
   1639                     for argu in self.arguments:
   1640                         filler = (
   1641                             " and ".join([ a['argument text'] for a in argu['Org']]) if "Org" in argu.keys() else ROLE_PH_MAP['Org']
   1642                         )
   1643                         output_texts.append("{} declared bankruptcy.".format(filler))
   1644                         gold_sample = True
   1645                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1646                 
   1647         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1648         return (output_str, gold_sample)
   1649 
   1650     def decode(self, preds):
   1651         output = []
   1652         for cnt, pred in enumerate(preds.split('\n')):
   1653             used_o_cnt = 0
   1654             full_pred = pred.strip()
   1655             for o_style in OUTPUT_STYLE_SET:
   1656                 if o_style in self.output_style:
   1657                     if o_style == 'trigger:sentence':
   1658                         if used_o_cnt == cnt:
   1659                             try:
   1660                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1661                                 triggers = triggers.split(' and ')
   1662                                 for t_cnt, t in enumerate(triggers):
   1663                                     if t != '<Trigger>':
   1664                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1665                             except:
   1666                                 pass
   1667                         used_o_cnt += 1
   1668                     if o_style == 'argument:sentence':
   1669                         if used_o_cnt == cnt:
   1670                             try:
   1671                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1672                                     org = prediction.split(' declared bankruptcy.', 1)[0]
   1673                                     org = org.split(' and ')
   1674                                     for arg in org:
   1675                                         if arg != ROLE_PH_MAP['Org']:
   1676                                             output.append((arg, 'Org', {'cor tri cnt': a_cnt}))                  
   1677                             except:
   1678                                 pass
   1679                         used_o_cnt += 1
   1680                     
   1681         return output
   1682 
   1683 class Business_End_Org(event_template):
   1684 
   1685     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1686         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1687     
   1688     @classmethod
   1689     def get_keywords(self):
   1690         return ['dissolve', 'disbanded', 'close'] 
   1691 
   1692     def get_output_template(self):
   1693         output_template = ''
   1694         for o_style in OUTPUT_STYLE_SET:
   1695             if o_style in self.output_style:
   1696                 if o_style == 'trigger:sentence':
   1697                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1698                 if o_style == 'argument:sentence':
   1699                     output_template += ' \n {}'.format('some organization dissolved.')
   1700         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1701 
   1702     def generate_input_str(self, query_trigger):
   1703         input_str = self.passage
   1704         for i_style in INPUT_STYLE_SET:
   1705             if i_style in self.input_style:
   1706                 if i_style == 'event_type':
   1707                     input_str += ' \n {}'.format('business event, end organization sub-type')
   1708                 if i_style == 'event_type_sent':
   1709                     input_str += ' \n {}'.format('The event is related to some organization ceasing to exist.')
   1710                 if i_style == 'keywords':
   1711                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1712                 if i_style == 'triggers':
   1713                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1714                 if i_style == 'template':
   1715                     input_str += ' \n {}'.format(self.output_template)
   1716         
   1717         return input_str
   1718 
   1719     def generate_output_str(self, query_trigger):
   1720         assert self.gold_event is not None
   1721         output_str = ''
   1722         gold_sample = False
   1723         for o_style in OUTPUT_STYLE_SET:
   1724             if o_style in self.output_style:
   1725                 if o_style == 'trigger:sentence':
   1726                     if self.trigger_text != '':
   1727                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1728                         gold_sample = True
   1729                     else:
   1730                         output_str += ' \n Event trigger is <Trigger>'
   1731                 if o_style == 'argument:sentence':
   1732                     output_texts = []
   1733                     for argu in self.arguments:
   1734                         filler = (
   1735                             " and ".join([ a['argument text'] for a in argu['Org']]) if "Org" in argu.keys() else ROLE_PH_MAP['Org']
   1736                         )
   1737                         output_texts.append("{} dissolved.".format(filler))
   1738                         gold_sample = True
   1739                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1740                 
   1741         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1742         return (output_str, gold_sample)
   1743 
   1744     def decode(self, preds):
   1745         output = []
   1746         for cnt, pred in enumerate(preds.split('\n')):
   1747             used_o_cnt = 0
   1748             full_pred = pred.strip()
   1749             for o_style in OUTPUT_STYLE_SET:
   1750                 if o_style in self.output_style:
   1751                     if o_style == 'trigger:sentence':
   1752                         if used_o_cnt == cnt:
   1753                             try:
   1754                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1755                                 triggers = triggers.split(' and ')
   1756                                 for t_cnt, t in enumerate(triggers):
   1757                                     if t != '<Trigger>':
   1758                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1759                             except:
   1760                                 pass
   1761                         used_o_cnt += 1
   1762                     if o_style == 'argument:sentence':
   1763                         if used_o_cnt == cnt:
   1764                             try:
   1765                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1766                                     org = prediction.split(' dissolved.', 1)[0]
   1767                                     org = org.split(' and ')
   1768                                     for arg in org:
   1769                                         if arg != ROLE_PH_MAP['Org']:
   1770                                             output.append((arg, 'Org', {'cor tri cnt': a_cnt}))                  
   1771                             except:
   1772                                 pass
   1773                         used_o_cnt += 1
   1774                     
   1775         return output
   1776 
   1777 class Conflict_Attack(event_template):
   1778 
   1779     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1780         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1781 
   1782     @classmethod
   1783     def get_keywords(self):
   1784         return ['war', 'attack', 'terrorism']
   1785 
   1786     def get_output_template(self):
   1787         output_template = ''
   1788         for o_style in OUTPUT_STYLE_SET:
   1789             if o_style in self.output_style:
   1790                 if o_style == 'trigger:sentence':
   1791                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1792                 if o_style == 'argument:sentence':
   1793                     output_template += ' \n {}'.format('some attacker attacked some facility, someone, or some organization by some way in somewhere.')
   1794         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1795 
   1796     def generate_input_str(self, query_trigger):
   1797         input_str = self.passage
   1798         for i_style in INPUT_STYLE_SET:
   1799             if i_style in self.input_style:
   1800                 if i_style == 'event_type':
   1801                     input_str += ' \n {}'.format('conflict event, attack sub-type')
   1802                 if i_style == 'event_type_sent':
   1803                     input_str += ' \n {}'.format('The event is related to conflict and some violent physical act.')
   1804                 if i_style == 'keywords':
   1805                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1806                 if i_style == 'triggers':
   1807                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1808                 if i_style == 'template':
   1809                     input_str += ' \n {}'.format(self.output_template)
   1810         
   1811         return input_str
   1812 
   1813     def generate_output_str(self, query_trigger):
   1814         assert self.gold_event is not None
   1815         output_str = ''
   1816         gold_sample = False
   1817         for o_style in OUTPUT_STYLE_SET:
   1818             if o_style in self.output_style:
   1819                 if o_style == 'trigger:sentence':
   1820                     if self.trigger_text != '':
   1821                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1822                         gold_sample = True
   1823                     else:
   1824                         output_str += ' \n Event trigger is <Trigger>'
   1825                 if o_style == 'argument:sentence':
   1826                     output_texts = []
   1827                     for argu in self.arguments:
   1828                         attacker_list = []
   1829                         if "Attacker" in argu.keys():
   1830                             attacker_list.extend([ a['argument text'] for a in argu['Attacker']])
   1831                         if "Agent" in argu.keys():
   1832                             attacker_list.extend([ a['argument text'] for a in argu['Agent']])  
   1833                         filler = (
   1834                             " and ".join(attacker_list) if len(attacker_list)>0 else ROLE_PH_MAP['Attacker'],
   1835                             " and ".join([ a['argument text'] for a in argu['Target']]) if "Target" in argu.keys() else ROLE_PH_MAP['Target'],
   1836                             " and ".join([ a['argument text'] for a in argu['Instrument']]) if "Instrument" in argu.keys() else ROLE_PH_MAP['Instrument'],
   1837                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   1838                         )
   1839                         output_texts.append("{} attacked {} by {} in {}.".format(*filler))
   1840                         gold_sample = True
   1841                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1842                 
   1843         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1844         return (output_str, gold_sample)
   1845 
   1846     def decode(self, preds):
   1847         output = []
   1848         for cnt, pred in enumerate(preds.split('\n')):
   1849             used_o_cnt = 0
   1850             full_pred = pred.strip()
   1851             for o_style in OUTPUT_STYLE_SET:
   1852                 if o_style in self.output_style:
   1853                     if o_style == 'trigger:sentence':
   1854                         if used_o_cnt == cnt:
   1855                             try:
   1856                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1857                                 triggers = triggers.split(' and ')
   1858                                 for t_cnt, t in enumerate(triggers):
   1859                                     if t != '<Trigger>':
   1860                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1861                             except Exception as e:
   1862                                 #print(e)
   1863                                 pass
   1864                         used_o_cnt += 1
   1865                     if o_style == 'argument:sentence':
   1866                         if used_o_cnt == cnt:
   1867                             try:
   1868                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1869                                     attack = prediction.split(' attacked ', 1)[0]
   1870                                     attack = attack.split(' and ')
   1871                                     remain = prediction.split(' attacked ', 1)[1]
   1872 
   1873                                     target = remain.split(' by ', 1)[0]
   1874                                     target = target.split(' and ')
   1875                                     remain = remain.split(' by ', 1)[1]
   1876 
   1877                                     instrument = remain.split(' in ', 1)[0]
   1878                                     instrument = instrument.split(' and ')
   1879                                     remain = remain.split(' in ', 1)[1]
   1880 
   1881                                     place = remain.rsplit('.',1)[0]
   1882                                     place = place.split(' and ')
   1883                                     for arg in attack:
   1884                                         if arg != ROLE_PH_MAP['Attacker']:
   1885                                             output.append((arg, 'Attacker', {'cor tri cnt': a_cnt}))
   1886                                     for arg in target:
   1887                                         if arg != ROLE_PH_MAP['Target']:
   1888                                             output.append((arg, 'Target', {'cor tri cnt': a_cnt}))
   1889                                     for arg in instrument:
   1890                                         if arg != ROLE_PH_MAP['Instrument']:
   1891                                             output.append((arg, 'Instrument', {'cor tri cnt': a_cnt}))                    
   1892                                     for arg in place:
   1893                                         if arg != ROLE_PH_MAP['Place']:
   1894                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   1895                             except:
   1896                                 pass
   1897                         used_o_cnt += 1
   1898                     
   1899         return output
   1900 
   1901 class Conflict_Demonstrate(event_template):
   1902     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   1903         super().__init__(input_style, output_style, passage, event_type, gold_event)
   1904 
   1905     @classmethod
   1906     def get_keywords(self):
   1907         return ['riot', 'protest', 'demonstrate']
   1908 
   1909     def get_output_template(self):
   1910         output_template = ''
   1911         for o_style in OUTPUT_STYLE_SET:
   1912             if o_style in self.output_style:
   1913                 if o_style == 'trigger:sentence':
   1914                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   1915                 if o_style == 'argument:sentence':
   1916                     output_template += ' \n {}'.format('some people or some organization protest at somewhere.')
   1917         return ('\n'.join(output_template.split('\n')[1:])).strip()
   1918 
   1919     def generate_input_str(self, query_trigger):
   1920         input_str = self.passage
   1921         for i_style in INPUT_STYLE_SET:
   1922             if i_style in self.input_style:
   1923                 if i_style == 'event_type':
   1924                     input_str += ' \n {}'.format('conflict event, demonstrate sub-type')
   1925                 if i_style == 'event_type_sent':
   1926                     input_str += ' \n {}'.format('The event is related to a large number of people coming together to protest.')
   1927                 if i_style == 'keywords':
   1928                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   1929                 if i_style == 'triggers':
   1930                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   1931                 if i_style == 'template':
   1932                     input_str += ' \n {}'.format(self.output_template)
   1933         
   1934         return input_str
   1935 
   1936     def generate_output_str(self, query_trigger):
   1937         assert self.gold_event is not None
   1938         output_str = ''
   1939         gold_sample = False
   1940         for o_style in OUTPUT_STYLE_SET:
   1941             if o_style in self.output_style:
   1942                 if o_style == 'trigger:sentence':
   1943                     if self.trigger_text != '':
   1944                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   1945                         gold_sample = True
   1946                     else:
   1947                         output_str += ' \n Event trigger is <Trigger>'
   1948                 if o_style == 'argument:sentence':
   1949                     output_texts = []
   1950                     for argu in self.arguments:
   1951                         filler = (
   1952                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   1953                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   1954                         )
   1955                         output_texts.append("{} protest at {}.".format(*filler))
   1956                         gold_sample = True
   1957                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   1958         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   1959         return (output_str, gold_sample)
   1960 
   1961     def decode(self, preds):
   1962         output = []
   1963         for cnt, pred in enumerate(preds.split('\n')):
   1964             used_o_cnt = 0
   1965             full_pred = pred.strip()
   1966             for o_style in OUTPUT_STYLE_SET:
   1967                 if o_style in self.output_style:
   1968                     if o_style == 'trigger:sentence':
   1969                         if used_o_cnt == cnt:
   1970                             try:
   1971                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   1972                                 triggers = triggers.split(' and ')
   1973                                 for t_cnt, t in enumerate(triggers):
   1974                                     if t != '<Trigger>':
   1975                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   1976                             except:
   1977                                 pass
   1978                         used_o_cnt += 1
   1979                     if o_style == 'argument:sentence':
   1980                         if used_o_cnt == cnt:
   1981                             try:
   1982                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   1983                                     entity = prediction.split(' protest at ', 1)[0]
   1984                                     entity = entity.split(' and ')
   1985                                     remain = prediction.split(' protest at ', 1)[1]
   1986 
   1987                                     place = remain.rsplit('.',1)[0]
   1988                                     place = place.split(' and ')
   1989                                     for arg in entity:
   1990                                         if arg != ROLE_PH_MAP['Entity']:
   1991                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   1992                                     for arg in place:
   1993                                         if arg != ROLE_PH_MAP['Place']:
   1994                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   1995                             except:
   1996                                 pass                                    
   1997                         used_o_cnt += 1
   1998                     
   1999         return output
   2000 
   2001 class Contact_Meet(event_template):
   2002     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2003         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2004 
   2005     @classmethod
   2006     def get_keywords(self):
   2007         return ['meeting', 'met', 'summit']
   2008 
   2009     def get_output_template(self):
   2010         output_template = ''
   2011         for o_style in OUTPUT_STYLE_SET:
   2012             if o_style in self.output_style:
   2013                 if o_style == 'trigger:sentence':
   2014                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2015                 if o_style == 'argument:sentence':
   2016                     output_template += ' \n {}'.format('some people or some organization met at somewhere.')
   2017         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2018 
   2019     def generate_input_str(self, query_trigger):
   2020         input_str = self.passage
   2021         for i_style in INPUT_STYLE_SET:
   2022             if i_style in self.input_style:
   2023                 if i_style == 'event_type':
   2024                     input_str += ' \n {}'.format('contact event, meet sub-type')
   2025                 if i_style == 'event_type_sent':
   2026                     input_str += ' \n {}'.format('The event is related to a group of people meeting and interacting with one another face-to-face.')
   2027                 if i_style == 'keywords':
   2028                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2029                 if i_style == 'triggers':
   2030                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2031                 if i_style == 'template':
   2032                     input_str += ' \n {}'.format(self.output_template)
   2033         
   2034         return input_str
   2035 
   2036     def generate_output_str(self, query_trigger):
   2037         assert self.gold_event is not None
   2038         output_str = ''
   2039         gold_sample = False
   2040         for o_style in OUTPUT_STYLE_SET:
   2041             if o_style in self.output_style:
   2042                 if o_style == 'trigger:sentence':
   2043                     if self.trigger_text != '':
   2044                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2045                         gold_sample = True
   2046                     else:
   2047                         output_str += ' \n Event trigger is <Trigger>'
   2048                 if o_style == 'argument:sentence':
   2049                     output_texts = []
   2050                     for argu in self.arguments:
   2051                         filler = (
   2052                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   2053                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2054                         )
   2055                         output_texts.append("{} met at {}.".format(*filler))
   2056                         gold_sample = True
   2057                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2058                 
   2059         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2060         return (output_str, gold_sample)
   2061 
   2062     def decode(self, preds):
   2063         output = []
   2064         for cnt, pred in enumerate(preds.split('\n')):
   2065             used_o_cnt = 0
   2066             full_pred = pred.strip()
   2067             for o_style in OUTPUT_STYLE_SET:
   2068                 if o_style in self.output_style:
   2069                     if o_style == 'trigger:sentence':
   2070                         if used_o_cnt == cnt:
   2071                             try:
   2072                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2073                                 triggers = triggers.split(' and ')
   2074                                 for t_cnt, t in enumerate(triggers):
   2075                                     if t != '<Trigger>':
   2076                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2077                             except:
   2078                                 pass
   2079                         used_o_cnt += 1
   2080                     if o_style == 'argument:sentence':
   2081                         if used_o_cnt == cnt:
   2082                             try:
   2083                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2084                                     entity = prediction.split(' met at ', 1)[0]
   2085                                     entity = entity.split(' and ')
   2086                                     remain = prediction.split(' met at ', 1)[1]
   2087 
   2088                                     place = remain.rsplit('.',1)[0]
   2089                                     place = place.split(' and ')
   2090                                     for arg in entity:
   2091                                         if arg != ROLE_PH_MAP['Entity']:
   2092                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   2093                                     for arg in place:
   2094                                         if arg != ROLE_PH_MAP['Place']:
   2095                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2096                             except:
   2097                                 pass                                    
   2098                         used_o_cnt += 1
   2099                     
   2100         return output
   2101 
   2102 class Contact_Correspondence(event_template):
   2103     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2104         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2105 
   2106     @classmethod
   2107     def get_keywords(self):
   2108         return ['call', 'teleconference', 'e-mail']
   2109 
   2110     def get_output_template(self):
   2111         output_template = ''
   2112         for o_style in OUTPUT_STYLE_SET:
   2113             if o_style in self.output_style:
   2114                 if o_style == 'trigger:sentence':
   2115                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2116                 if o_style == 'argument:sentence':
   2117                     output_template += ' \n {}'.format('some people or some organization contacted each other at somewhere.')
   2118         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2119 
   2120     def generate_input_str(self, query_trigger):
   2121         input_str = self.passage
   2122         for i_style in INPUT_STYLE_SET:
   2123             if i_style in self.input_style:
   2124                 if i_style == 'event_type':
   2125                     input_str += ' \n {}'.format('contact event, correspondence sub-type')
   2126                 if i_style == 'event_type_sent':
   2127                     input_str += ' \n {}'.format('The event happens when a face‐to‐face meeting between sender and receiver is not explicitly stated. This includes written, phone, or electronic communication.')
   2128                 if i_style == 'keywords':
   2129                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2130                 if i_style == 'triggers':
   2131                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2132                 if i_style == 'template':
   2133                     input_str += ' \n {}'.format(self.output_template)
   2134         
   2135         return input_str
   2136 
   2137     def generate_output_str(self, query_trigger):
   2138         assert self.gold_event is not None
   2139         output_str = ''
   2140         gold_sample = False
   2141         for o_style in OUTPUT_STYLE_SET:
   2142             if o_style in self.output_style:
   2143                 if o_style == 'trigger:sentence':
   2144                     if self.trigger_text != '':
   2145                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2146                         gold_sample = True
   2147                     else:
   2148                         output_str += ' \n Event trigger is <Trigger>'
   2149                 if o_style == 'argument:sentence':
   2150                     output_texts = []
   2151                     for argu in self.arguments:
   2152                         filler = (
   2153                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   2154                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2155                         )
   2156                         output_texts.append("{} contacted each other at {}.".format(*filler))
   2157                         gold_sample = True
   2158                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2159                 
   2160         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2161         return (output_str, gold_sample)
   2162 
   2163     def decode(self, preds):
   2164         output = []
   2165         for cnt, pred in enumerate(preds.split('\n')):
   2166             used_o_cnt = 0
   2167             full_pred = pred.strip()
   2168             for o_style in OUTPUT_STYLE_SET:
   2169                 if o_style in self.output_style:
   2170                     if o_style == 'trigger:sentence':
   2171                         if used_o_cnt == cnt:
   2172                             try:
   2173                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2174                                 triggers = triggers.split(' and ')
   2175                                 for t_cnt, t in enumerate(triggers):
   2176                                     if t != '<Trigger>':
   2177                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2178                             except:
   2179                                 pass
   2180                         used_o_cnt += 1
   2181                     if o_style == 'argument:sentence':
   2182                         if used_o_cnt == cnt:
   2183                             try:
   2184                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2185                                     entity = prediction.split(' contacted each other at ', 1)[0]
   2186                                     entity = entity.split(' and ')
   2187                                     remain = prediction.split(' contacted each other at ', 1)[1]
   2188 
   2189                                     place = remain.rsplit('.',1)[0]
   2190                                     place = place.split(' and ')
   2191                                     for arg in entity:
   2192                                         if arg != ROLE_PH_MAP['Entity']:
   2193                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   2194                                     for arg in place:
   2195                                         if arg != ROLE_PH_MAP['Place']:
   2196                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2197                             except:
   2198                                 pass                                   
   2199                         used_o_cnt += 1
   2200                     
   2201         return output
   2202 
   2203 class Contact_Broadcast(event_template):
   2204     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2205         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2206 
   2207     @classmethod
   2208     def get_keywords(self):
   2209         return ['statement', 'announce', 'say']
   2210 
   2211     def get_output_template(self):
   2212         output_template = ''
   2213         for o_style in OUTPUT_STYLE_SET:
   2214             if o_style in self.output_style:
   2215                 if o_style == 'trigger:sentence':
   2216                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2217                 if o_style == 'argument:sentence':
   2218                     output_template += ' \n {}'.format('some people or some organization made announcement to some publicity at somewhere.')
   2219         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2220 
   2221     def generate_input_str(self, query_trigger):
   2222         input_str = self.passage
   2223         for i_style in INPUT_STYLE_SET:
   2224             if i_style in self.input_style:
   2225                 if i_style == 'event_type':
   2226                     input_str += ' \n {}'.format('contact event, broadcast sub-type')
   2227                 if i_style == 'event_type_sent':
   2228                     input_str += ' \n {}'.format('The event happens when a person or an organization contact with the media and other publicity or announcement conference.')
   2229                 if i_style == 'keywords':
   2230                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2231                 if i_style == 'triggers':
   2232                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2233                 if i_style == 'template':
   2234                     input_str += ' \n {}'.format(self.output_template)
   2235         
   2236         return input_str
   2237 
   2238     def generate_output_str(self, query_trigger):
   2239         assert self.gold_event is not None
   2240         output_str = ''
   2241         gold_sample = False
   2242         for o_style in OUTPUT_STYLE_SET:
   2243             if o_style in self.output_style:
   2244                 if o_style == 'trigger:sentence':
   2245                     if self.trigger_text != '':
   2246                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2247                         gold_sample = True
   2248                     else:
   2249                         output_str += ' \n Event trigger is <Trigger>'
   2250                 if o_style == 'argument:sentence':
   2251                     output_texts = []
   2252                     for argu in self.arguments:
   2253                         filler = (
   2254                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   2255                             " and ".join([ a['argument text'] for a in argu['Audience']]) if "Audience" in argu.keys() else ROLE_PH_MAP['Audience'],
   2256                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2257                         )
   2258                         output_texts.append("{} made announcement to {} at {}.".format(*filler))
   2259                         gold_sample = True
   2260                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2261                 
   2262         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2263         return (output_str, gold_sample)
   2264 
   2265     def decode(self, preds):
   2266         output = []
   2267         for cnt, pred in enumerate(preds.split('\n')):
   2268             used_o_cnt = 0
   2269             full_pred = pred.strip()
   2270             for o_style in OUTPUT_STYLE_SET:
   2271                 if o_style in self.output_style:
   2272                     if o_style == 'trigger:sentence':
   2273                         if used_o_cnt == cnt:
   2274                             try:
   2275                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2276                                 triggers = triggers.split(' and ')
   2277                                 for t_cnt, t in enumerate(triggers):
   2278                                     if t != '<Trigger>':
   2279                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2280                             except:
   2281                                 pass
   2282                         used_o_cnt += 1
   2283                     if o_style == 'argument:sentence':
   2284                         if used_o_cnt == cnt:
   2285                             try:
   2286                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2287                                     entity = prediction.split(' made announcement to ', 1)[0]
   2288                                     entity = entity.split(' and ')
   2289                                     remain = prediction.split(' made announcement to ', 1)[1]
   2290 
   2291                                     audience = remain.split(' at ', 1)[0]
   2292                                     audience = audience.split(' and ')
   2293                                     remain = remain.split(' at ', 1)[1]
   2294 
   2295                                     place = remain.rsplit('.',1)[0]
   2296                                     place = place.split(' and ')
   2297                                     for arg in entity:
   2298                                         if arg != ROLE_PH_MAP['Entity']:
   2299                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   2300                                     for arg in audience:
   2301                                         if arg != ROLE_PH_MAP['Audience']:
   2302                                             output.append((arg, 'Audience', {'cor tri cnt': a_cnt}))
   2303                                     for arg in place:
   2304                                         if arg != ROLE_PH_MAP['Place']:
   2305                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2306                             except:
   2307                                 pass                                   
   2308                         used_o_cnt += 1
   2309                     
   2310         return output
   2311 
   2312 class Contact_Contact(event_template):
   2313     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2314         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2315 
   2316     @classmethod
   2317     def get_keywords(self):
   2318         return ['said', 'talk', 'tell']
   2319 
   2320     def get_output_template(self):
   2321         output_template = ''
   2322         for o_style in OUTPUT_STYLE_SET:
   2323             if o_style in self.output_style:
   2324                 if o_style == 'trigger:sentence':
   2325                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2326                 if o_style == 'argument:sentence':
   2327                     output_template += ' \n {}'.format('some people or some organization talked to each other at somewhere.')
   2328         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2329 
   2330     def generate_input_str(self, query_trigger):
   2331         input_str = self.passage
   2332         for i_style in INPUT_STYLE_SET:
   2333             if i_style in self.input_style:
   2334                 if i_style == 'event_type':
   2335                     input_str += ' \n {}'.format('contact event, contact sub-type')
   2336                 if i_style == 'event_type_sent':
   2337                     input_str += ' \n {}'.format('The event happens when there is no explicit mention of contact ways of communication.')
   2338                 if i_style == 'keywords':
   2339                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2340                 if i_style == 'triggers':
   2341                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2342                 if i_style == 'template':
   2343                     input_str += ' \n {}'.format(self.output_template)
   2344         
   2345         return input_str
   2346 
   2347     def generate_output_str(self, query_trigger):
   2348         assert self.gold_event is not None
   2349         output_str = ''
   2350         gold_sample = False
   2351         for o_style in OUTPUT_STYLE_SET:
   2352             if o_style in self.output_style:
   2353                 if o_style == 'trigger:sentence':
   2354                     if self.trigger_text != '':
   2355                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2356                         gold_sample = True
   2357                     else:
   2358                         output_str += ' \n Event trigger is <Trigger>'
   2359                 if o_style == 'argument:sentence':
   2360                     output_texts = []
   2361                     for argu in self.arguments:
   2362                         filler = (
   2363                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   2364                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2365                         )
   2366                         output_texts.append("{} talked to each other at {}.".format(*filler))
   2367                         gold_sample = True
   2368                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2369                 
   2370         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2371         return (output_str, gold_sample)
   2372 
   2373     def decode(self, preds):
   2374         output = []
   2375         for cnt, pred in enumerate(preds.split('\n')):
   2376             used_o_cnt = 0
   2377             full_pred = pred.strip()
   2378             for o_style in OUTPUT_STYLE_SET:
   2379                 if o_style in self.output_style:
   2380                     if o_style == 'trigger:sentence':
   2381                         if used_o_cnt == cnt:
   2382                             try:
   2383                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2384                                 triggers = triggers.split(' and ')
   2385                                 for t_cnt, t in enumerate(triggers):
   2386                                     if t != '<Trigger>':
   2387                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2388                             except:
   2389                                 pass
   2390                         used_o_cnt += 1
   2391                     if o_style == 'argument:sentence':
   2392                         if used_o_cnt == cnt:
   2393                             try:
   2394                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2395                                     entity = prediction.split(' talked to each other at ', 1)[0]
   2396                                     entity = entity.split(' and ')
   2397                                     remain = prediction.split(' talked to each other at ', 1)[1]
   2398 
   2399                                     place = remain.rsplit('.',1)[0]
   2400                                     place = place.split(' and ')
   2401                                     for arg in entity:
   2402                                         if arg != ROLE_PH_MAP['Entity']:
   2403                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   2404                                     for arg in place:
   2405                                         if arg != ROLE_PH_MAP['Place']:
   2406                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2407                             except:
   2408                                 pass                                   
   2409                         used_o_cnt += 1
   2410                     
   2411         return output
   2412 
   2413 class Manufacture_Artifact(event_template):
   2414     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2415         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2416     
   2417     @classmethod
   2418     def get_keywords(self):
   2419         return ['develop', 'produce', 'construct']
   2420     
   2421     def get_output_template(self):
   2422         output_template = ''
   2423         for o_style in OUTPUT_STYLE_SET:
   2424             if o_style in self.output_style:
   2425                 if o_style == 'trigger:sentence':
   2426                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2427                 if o_style == 'argument:sentence':
   2428                     output_template += ' \n {}'.format('something was built by somebody or some organization in somewhere.')
   2429         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2430 
   2431     def generate_input_str(self, query_trigger):
   2432         input_str = self.passage
   2433         for i_style in INPUT_STYLE_SET:
   2434             if i_style in self.input_style:
   2435                 if i_style == 'event_type':
   2436                     input_str += ' \n {}'.format('manufacture event, artifact sub-type')
   2437                 if i_style == 'event_type_sent':
   2438                     input_str += ' \n {}'.format('The event occurs whenever a person or an organization builds or manufactures a facility or a weapon, etc.')
   2439                 if i_style == 'keywords':
   2440                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2441                 if i_style == 'triggers':
   2442                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2443                 if i_style == 'template':
   2444                     input_str += ' \n {}'.format(self.output_template)
   2445         
   2446         return input_str
   2447 
   2448     def generate_output_str(self, query_trigger):
   2449         assert self.gold_event is not None
   2450         output_str = ''
   2451         gold_sample = False
   2452         for o_style in OUTPUT_STYLE_SET:
   2453             if o_style in self.output_style:
   2454                 if o_style == 'trigger:sentence':
   2455                     if self.trigger_text != '':
   2456                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2457                         gold_sample = True
   2458                     else:
   2459                         output_str += ' \n Event trigger is <Trigger>'
   2460                 if o_style == 'argument:sentence':
   2461                     output_texts = []
   2462                     for argu in self.arguments:
   2463                         filler = (
   2464                             " and ".join([ a['argument text'] for a in argu['Artifact']]) if "Artifact" in argu.keys() else ROLE_PH_MAP['Artifact'],
   2465                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
   2466                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2467                         )
   2468                         output_texts.append("{} was built by {} in {}.".format(*filler))
   2469                         gold_sample = True
   2470                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2471                 
   2472         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2473         return (output_str, gold_sample)
   2474 
   2475     def decode(self, preds):
   2476         output = []
   2477         for cnt, pred in enumerate(preds.split('\n')):
   2478             used_o_cnt = 0
   2479             full_pred = pred.strip()
   2480             for o_style in OUTPUT_STYLE_SET:
   2481                 if o_style in self.output_style:
   2482                     if o_style == 'trigger:sentence':
   2483                         if used_o_cnt == cnt:
   2484                             try:
   2485                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2486                                 triggers = triggers.split(' and ')
   2487                                 for t_cnt, t in enumerate(triggers):
   2488                                     if t != '<Trigger>':
   2489                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2490                             except:
   2491                                 pass
   2492                         used_o_cnt += 1
   2493                     if o_style == 'argument:sentence':
   2494                         if used_o_cnt == cnt:
   2495                             try:
   2496                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2497                                     artifact = prediction.split(' was built by ', 1)[0]
   2498                                     artifact = artifact.split(' and ')
   2499                                     remain = prediction.split(' was built by ', 1)[1]
   2500 
   2501                                     agent = remain.split(' in ', 1)[0]
   2502                                     agent = agent.split(' and ')
   2503                                     remain = remain.split(' in ', 1)[1]
   2504 
   2505                                     place = remain.rsplit('.', 1)[0]
   2506                                     place = place.split(' and ')
   2507 
   2508                                     for arg in agent:
   2509                                         if arg != ROLE_PH_MAP['Agent']:
   2510                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   2511                                     for arg in artifact:
   2512                                         if arg != ROLE_PH_MAP['Artifact']:
   2513                                             output.append((arg, 'Artifact', {'cor tri cnt': a_cnt}))
   2514                                     for arg in place:
   2515                                         if arg != ROLE_PH_MAP['Place']:
   2516                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2517                             except Exception as e:
   2518                                 pass
   2519                         used_o_cnt += 1
   2520                     
   2521         return output
   2522 
   2523 class Personnel_Start_Position(event_template):
   2524 
   2525     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2526         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2527 
   2528     @classmethod
   2529     def get_keywords(self):
   2530         return ['hire', 'appoint', 'join']
   2531 
   2532     def get_output_template(self):
   2533         output_template = ''
   2534         for o_style in OUTPUT_STYLE_SET:
   2535             if o_style in self.output_style:
   2536                 if o_style == 'trigger:sentence':
   2537                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2538                 if o_style == 'argument:sentence':
   2539                     output_template += ' \n {}'.format('somebody got new job and was hired by some people or some organization in somewhere.')
   2540         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2541 
   2542     def generate_input_str(self, query_trigger):
   2543         input_str = self.passage
   2544         for i_style in INPUT_STYLE_SET:
   2545             if i_style in self.input_style:
   2546                 if i_style == 'event_type':
   2547                     input_str += ' \n {}'.format('personnel event, start position sub-type')
   2548                 if i_style == 'event_type_sent':
   2549                     input_str += ' \n {}'.format('The event is related to a person begins working for an organization or a hiring manager.')
   2550                 if i_style == 'keywords':
   2551                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2552                 if i_style == 'triggers':
   2553                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2554                 if i_style == 'template':
   2555                     input_str += ' \n {}'.format(self.output_template)
   2556         
   2557         return input_str
   2558 
   2559     def generate_output_str(self, query_trigger):
   2560         assert self.gold_event is not None
   2561         output_str = ''
   2562         gold_sample = False
   2563         for o_style in OUTPUT_STYLE_SET:
   2564             if o_style in self.output_style:
   2565                 if o_style == 'trigger:sentence':
   2566                     if self.trigger_text != '':
   2567                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2568                         gold_sample = True
   2569                     else:
   2570                         output_str += ' \n Event trigger is <Trigger>'
   2571                 if o_style == 'argument:sentence':
   2572                     output_texts = []
   2573                     for argu in self.arguments:
   2574                         filler = (
   2575                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   2576                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   2577                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2578                         )
   2579                         output_texts.append("{} got new job and was hired by {} in {}.".format(*filler))
   2580                         gold_sample = True
   2581                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2582         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2583         return (output_str, gold_sample)
   2584 
   2585     def decode(self, preds):
   2586         output = []
   2587         for cnt, pred in enumerate(preds.split('\n')):
   2588             used_o_cnt = 0
   2589             full_pred = pred.strip()
   2590             for o_style in OUTPUT_STYLE_SET:
   2591                 if o_style in self.output_style:
   2592                     if o_style == 'trigger:sentence':
   2593                         if used_o_cnt == cnt:
   2594                             try:
   2595                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2596                                 triggers = triggers.split(' and ')
   2597                                 for t_cnt, t in enumerate(triggers):
   2598                                     if t != '<Trigger>':
   2599                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2600                             except:
   2601                                 pass
   2602                         used_o_cnt += 1
   2603                     if o_style == 'argument:sentence':
   2604                         if used_o_cnt == cnt:
   2605                             try:
   2606                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2607                                     person = prediction.split(' got new job and was hired by ', 1)[0]
   2608                                     person = person.split(' and ')
   2609                                     remain = prediction.split(' got new job and was hired by ', 1)[1]
   2610 
   2611                                     entity = remain.split(' in ', 1)[0]
   2612                                     entity = entity.split(' and ')
   2613                                     remain = remain.split(' in ', 1)[1]
   2614 
   2615                                     place = remain.rsplit('.',1)[0]
   2616                                     place = place.split(' and ')
   2617                                     for arg in person:
   2618                                         if arg != ROLE_PH_MAP['Person']:
   2619                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   2620                                     for arg in entity:
   2621                                         if arg != ROLE_PH_MAP['Entity']:
   2622                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   2623                                     for arg in place:
   2624                                         if arg != ROLE_PH_MAP['Place']:
   2625                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2626                             except:
   2627                                 pass
   2628                         used_o_cnt += 1
   2629         return output
   2630 
   2631 class Personnel_End_Position(event_template):
   2632 
   2633     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2634         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2635 
   2636     @classmethod
   2637     def get_keywords(self):
   2638         return ['former', 'laid off', 'fired']
   2639 
   2640     def get_output_template(self):
   2641         output_template = ''
   2642         for o_style in OUTPUT_STYLE_SET:
   2643             if o_style in self.output_style:
   2644                 if o_style == 'trigger:sentence':
   2645                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2646                 if o_style == 'argument:sentence':
   2647                     output_template += ' \n {}'.format('somebody stopped working for some people or some organization at somewhere.')
   2648         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2649 
   2650     def generate_input_str(self, query_trigger):
   2651         input_str = self.passage
   2652         for i_style in INPUT_STYLE_SET:
   2653             if i_style in self.input_style:
   2654                 if i_style == 'event_type':
   2655                     input_str += ' \n {}'.format('personnel event, end position sub-type')
   2656                 if i_style == 'event_type_sent':
   2657                     input_str += ' \n {}'.format('The event is related to a person stops working for an organization or a hiring manager.')
   2658                 if i_style == 'keywords':
   2659                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2660                 if i_style == 'triggers':
   2661                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2662                 if i_style == 'template':
   2663                     input_str += ' \n {}'.format(self.output_template)
   2664         
   2665         return input_str
   2666 
   2667     def generate_output_str(self, query_trigger):
   2668         assert self.gold_event is not None
   2669         output_str = ''
   2670         gold_sample = False
   2671         for o_style in OUTPUT_STYLE_SET:
   2672             if o_style in self.output_style:
   2673                 if o_style == 'trigger:sentence':
   2674                     if self.trigger_text != '':
   2675                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2676                         gold_sample = True
   2677                     else:
   2678                         output_str += ' \n Event trigger is <Trigger>'
   2679                 if o_style == 'argument:sentence':
   2680                     output_texts = []
   2681                     for argu in self.arguments:
   2682                         filler = (
   2683                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   2684                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   2685                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2686                         )
   2687                         output_texts.append("{} stopped working for {} at {}.".format(*filler))
   2688                         gold_sample = True
   2689                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2690         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2691         return (output_str, gold_sample)
   2692 
   2693     def decode(self, preds):
   2694         output = []
   2695         for cnt, pred in enumerate(preds.split('\n')):
   2696             used_o_cnt = 0
   2697             full_pred = pred.strip()
   2698             for o_style in OUTPUT_STYLE_SET:
   2699                 if o_style in self.output_style:
   2700                     if o_style == 'trigger:sentence':
   2701                         if used_o_cnt == cnt:
   2702                             try:
   2703                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2704                                 triggers = triggers.split(' and ')
   2705                                 for t_cnt, t in enumerate(triggers):
   2706                                     if t != '<Trigger>':
   2707                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2708                             except:
   2709                                 pass
   2710                         used_o_cnt += 1
   2711                     if o_style == 'argument:sentence':
   2712                         if used_o_cnt == cnt:
   2713                             try:
   2714                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2715                                     person = prediction.split(' stopped working for ', 1)[0]
   2716                                     person = person.split(' and ')
   2717                                     remain = prediction.split(' stopped working for ', 1)[1]
   2718 
   2719                                     entity = remain.split(' at ', 1)[0]
   2720                                     entity = entity.split(' and ')
   2721                                     remain = remain.split(' at ', 1)[1]
   2722 
   2723                                     place = remain.rsplit('.',1)[0]
   2724                                     place = place.split(' and ')
   2725                                     for arg in person:
   2726                                         if arg != ROLE_PH_MAP['Person']:
   2727                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   2728                                     for arg in entity:
   2729                                         if arg != ROLE_PH_MAP['Entity']:
   2730                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   2731                                     for arg in place:
   2732                                         if arg != ROLE_PH_MAP['Place']:
   2733                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2734                             except:
   2735                                 pass
   2736                         used_o_cnt += 1
   2737         return output
   2738 
   2739 class Personnel_Nominate(event_template):
   2740 
   2741     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2742         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2743 
   2744     @classmethod
   2745     def get_keywords(self):
   2746         return ['named', 'nomination', 'nominate']
   2747 
   2748     def get_output_template(self):
   2749         output_template = ''
   2750         for o_style in OUTPUT_STYLE_SET:
   2751             if o_style in self.output_style:
   2752                 if o_style == 'trigger:sentence':
   2753                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2754                 if o_style == 'argument:sentence':
   2755                     output_template += ' \n {}'.format('somebody was nominated by somebody or some organization to do a job.')
   2756         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2757 
   2758     def generate_input_str(self, query_trigger):
   2759         input_str = self.passage
   2760         for i_style in INPUT_STYLE_SET:
   2761             if i_style in self.input_style:
   2762                 if i_style == 'event_type':
   2763                     input_str += ' \n {}'.format('personnel event, nominate position sub-type')
   2764                 if i_style == 'event_type_sent':
   2765                     input_str += ' \n {}'.format('The event is related to a person being nominated for a position.')
   2766                 if i_style == 'keywords':
   2767                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2768                 if i_style == 'triggers':
   2769                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2770                 if i_style == 'template':
   2771                     input_str += ' \n {}'.format(self.output_template)
   2772         
   2773         return input_str
   2774 
   2775     def generate_output_str(self, query_trigger):
   2776         assert self.gold_event is not None
   2777         output_str = ''
   2778         gold_sample = False
   2779         for o_style in OUTPUT_STYLE_SET:
   2780             if o_style in self.output_style:
   2781                 if o_style == 'trigger:sentence':
   2782                     if self.trigger_text != '':
   2783                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2784                         gold_sample = True
   2785                     else:
   2786                         output_str += ' \n Event trigger is <Trigger>'
   2787                 if o_style == 'argument:sentence':
   2788                     output_texts = []
   2789                     for argu in self.arguments:
   2790                         filler = (
   2791                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   2792                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent']
   2793                         )
   2794                         output_texts.append("{} was nominated by {} to do a job.".format(*filler))
   2795                         gold_sample = True
   2796                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2797         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2798         return (output_str, gold_sample)
   2799 
   2800     def decode(self, preds):
   2801         output = []
   2802         for cnt, pred in enumerate(preds.split('\n')):
   2803             used_o_cnt = 0
   2804             full_pred = pred.strip()
   2805             for o_style in OUTPUT_STYLE_SET:
   2806                 if o_style in self.output_style:
   2807                     if o_style == 'trigger:sentence':
   2808                         if used_o_cnt == cnt:
   2809                             try:
   2810                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2811                                 triggers = triggers.split(' and ')
   2812                                 for t_cnt, t in enumerate(triggers):
   2813                                     if t != '<Trigger>':
   2814                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2815                             except:
   2816                                 pass
   2817                         used_o_cnt += 1
   2818                     if o_style == 'argument:sentence':
   2819                         if used_o_cnt == cnt:
   2820                             try:
   2821                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2822                                     person = prediction.split(' was nominated by ', 1)[0]
   2823                                     person = person.split(' and ')
   2824                                     remain = prediction.split(' was nominated by ', 1)[1]
   2825 
   2826                                     agent = remain.rsplit(' to do a job.',1)[0]
   2827                                     agent = agent.split(' and ')
   2828                                     for arg in person:
   2829                                         if arg != ROLE_PH_MAP['Person']:
   2830                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   2831                                     for arg in agent:
   2832                                         if arg != ROLE_PH_MAP['Agent']:
   2833                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   2834                             except:
   2835                                 pass
   2836                         used_o_cnt += 1
   2837         return output
   2838 
   2839 class Personnel_Elect(event_template):
   2840 
   2841     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2842         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2843     
   2844     @classmethod
   2845     def get_keywords(self):
   2846         return ['election', 'elect', 'elected']
   2847 
   2848     def get_output_template(self):
   2849         output_template = ''
   2850         for o_style in OUTPUT_STYLE_SET:
   2851             if o_style in self.output_style:
   2852                 if o_style == 'trigger:sentence':
   2853                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2854                 if o_style == 'argument:sentence':
   2855                     output_template += ' \n {}'.format('somebody was elected a position, and the election was voted by somebody or some organization in somewhere.')
   2856         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2857 
   2858     def generate_input_str(self, query_trigger):
   2859         input_str = self.passage
   2860         for i_style in INPUT_STYLE_SET:
   2861             if i_style in self.input_style:
   2862                 if i_style == 'event_type':
   2863                     input_str += ' \n {}'.format('personnel event, elect position sub-type')
   2864                 if i_style == 'event_type_sent':
   2865                     input_str += ' \n {}'.format('The event is related to a candidate wins an election.')
   2866                 if i_style == 'keywords':
   2867                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2868                 if i_style == 'triggers':
   2869                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2870                 if i_style == 'template':
   2871                     input_str += ' \n {}'.format(self.output_template)
   2872         
   2873         return input_str
   2874 
   2875     def generate_output_str(self, query_trigger):
   2876         assert self.gold_event is not None
   2877         output_str = ''
   2878         gold_sample = False
   2879         for o_style in OUTPUT_STYLE_SET:
   2880             if o_style in self.output_style:
   2881                 if o_style == 'trigger:sentence':
   2882                     if self.trigger_text != '':
   2883                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2884                         gold_sample = True
   2885                     else:
   2886                         output_str += ' \n Event trigger is <Trigger>'
   2887                 if o_style == 'argument:sentence':
   2888                     output_texts = []
   2889                     for argu in self.arguments:
   2890                         filler = (
   2891                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   2892                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
   2893                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   2894                         )
   2895                         output_texts.append("{} was elected a position, and the election was voted by {} in {}.".format(*filler))
   2896                         gold_sample = True
   2897                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   2898         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   2899         return (output_str, gold_sample)
   2900 
   2901     def decode(self, preds):
   2902         output = []
   2903         for cnt, pred in enumerate(preds.split('\n')):
   2904             used_o_cnt = 0
   2905             full_pred = pred.strip()
   2906             for o_style in OUTPUT_STYLE_SET:
   2907                 if o_style in self.output_style:
   2908                     if o_style == 'trigger:sentence':
   2909                         if used_o_cnt == cnt:
   2910                             try:
   2911                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   2912                                 triggers = triggers.split(' and ')
   2913                                 for t_cnt, t in enumerate(triggers):
   2914                                     if t != '<Trigger>':
   2915                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   2916                             except:
   2917                                 pass
   2918                         used_o_cnt += 1
   2919                     if o_style == 'argument:sentence':
   2920                         if used_o_cnt == cnt:
   2921                             try:
   2922                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   2923                                     person = prediction.split(' was elected a position, and the election was voted by ', 1)[0]
   2924                                     person = person.split(' and ')
   2925                                     remain = prediction.split(' was elected a position, and the election was voted by ', 1)[1]
   2926 
   2927                                     entity = remain.split(' in ', 1)[0]
   2928                                     entity = entity.split(' and ')
   2929                                     remain = remain.split(' in ', 1)[1]
   2930 
   2931                                     place = remain.rsplit('.',1)[0]
   2932                                     place = place.split(' and ')
   2933                                     for arg in person:
   2934                                         if arg != ROLE_PH_MAP['Person']:
   2935                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   2936                                     for arg in entity:
   2937                                         if arg != ROLE_PH_MAP['Agent']:
   2938                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   2939                                     for arg in place:
   2940                                         if arg != ROLE_PH_MAP['Place']:
   2941                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   2942                             except:
   2943                                 pass
   2944                         used_o_cnt += 1
   2945         return output
   2946 
   2947 class Justice_Arrest_Jail(event_template):
   2948 
   2949     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   2950         super().__init__(input_style, output_style, passage, event_type, gold_event)
   2951 
   2952     @classmethod
   2953     def get_keywords(self):
   2954         return ['arrest', 'jail', 'detained']
   2955     
   2956     def get_output_template(self):
   2957         output_template = ''
   2958         for o_style in OUTPUT_STYLE_SET:
   2959             if o_style in self.output_style:
   2960                 if o_style == 'trigger:sentence':
   2961                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   2962                 if o_style == 'argument:sentence':
   2963                     output_template += ' \n {}'.format('somebody was sent to jailed or arrested by somebody or some organization in somewhere.')
   2964         return ('\n'.join(output_template.split('\n')[1:])).strip()
   2965 
   2966     def generate_input_str(self, query_trigger):
   2967         input_str = self.passage
   2968         for i_style in INPUT_STYLE_SET:
   2969             if i_style in self.input_style:
   2970                 if i_style == 'event_type':
   2971                     input_str += ' \n {}'.format('justice event, arrest jail sub-type')
   2972                 if i_style == 'event_type_sent':
   2973                     input_str += ' \n {}'.format('The event is related to a person getting arrested or a person being sent to jail.')
   2974                 if i_style == 'keywords':
   2975                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   2976                 if i_style == 'triggers':
   2977                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   2978                 if i_style == 'template':
   2979                     input_str += ' \n {}'.format(self.output_template)
   2980         
   2981         return input_str
   2982 
   2983     def generate_output_str(self, query_trigger):
   2984         assert self.gold_event is not None
   2985         output_str = ''
   2986         gold_sample = False
   2987         for o_style in OUTPUT_STYLE_SET:
   2988             if o_style in self.output_style:
   2989                 if o_style == 'trigger:sentence':
   2990                     if self.trigger_text != '':
   2991                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   2992                         gold_sample = True
   2993                     else:
   2994                         output_str += ' \n Event trigger is <Trigger>'
   2995                 if o_style == 'argument:sentence':
   2996                     output_texts = []
   2997                     for argu in self.arguments:
   2998                         filler = (
   2999                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   3000                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
   3001                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   3002                         )
   3003                         output_texts.append("{} was sent to jailed or arrested by {} in {}.".format(*filler))
   3004                         gold_sample = True
   3005                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3006         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3007         return (output_str, gold_sample)
   3008 
   3009     def decode(self, preds):
   3010         output = []
   3011         for cnt, pred in enumerate(preds.split('\n')):
   3012             used_o_cnt = 0
   3013             full_pred = pred.strip()
   3014             for o_style in OUTPUT_STYLE_SET:
   3015                 if o_style in self.output_style:
   3016                     if o_style == 'trigger:sentence':
   3017                         if used_o_cnt == cnt:
   3018                             try:
   3019                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3020                                 triggers = triggers.split(' and ')
   3021                                 for t_cnt, t in enumerate(triggers):
   3022                                     if t != '<Trigger>':
   3023                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3024                             except:
   3025                                 pass
   3026                         used_o_cnt += 1
   3027                     if o_style == 'argument:sentence':
   3028                         if used_o_cnt == cnt:
   3029                             try:
   3030                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3031                                     person = prediction.split(' was sent to jailed or arrested by ', 1)[0]
   3032                                     person = person.split(' and ')
   3033                                     remain = prediction.split(' was sent to jailed or arrested by ', 1)[1]
   3034 
   3035                                     agent = remain.split(' in ', 1)[0]
   3036                                     agent = agent.split(' and ')
   3037                                     remain = remain.split(' in ', 1)[1]
   3038 
   3039                                     place = remain.rsplit('.',1)[0]
   3040                                     place = place.split(' and ')
   3041                                     for arg in person:
   3042                                         if arg != ROLE_PH_MAP['Person']:
   3043                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   3044                                     for arg in agent:
   3045                                         if arg != ROLE_PH_MAP['Agent']:
   3046                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   3047                                     for arg in place:
   3048                                         if arg != ROLE_PH_MAP['Place']:
   3049                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3050                             except Exception as e:
   3051                                 pass
   3052                         used_o_cnt += 1
   3053         return output
   3054 
   3055 class Justice_Release_Parole(event_template):
   3056 
   3057     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3058         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3059 
   3060     @classmethod
   3061     def get_keywords(self):
   3062         return ['parole', 'release', 'free']
   3063 
   3064     def get_output_template(self):
   3065         output_template = ''
   3066         for o_style in OUTPUT_STYLE_SET:
   3067             if o_style in self.output_style:
   3068                 if o_style == 'trigger:sentence':
   3069                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3070                 if o_style == 'argument:sentence':
   3071                     output_template += ' \n {}'.format('somebody was released by somebody or some organization from somewhere.')
   3072         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3073 
   3074     def generate_input_str(self, query_trigger):
   3075         input_str = self.passage
   3076         for i_style in INPUT_STYLE_SET:
   3077             if i_style in self.input_style:
   3078                 if i_style == 'event_type':
   3079                     input_str += ' \n {}'.format('justice event, release parole sub-type')
   3080                 if i_style == 'event_type_sent':
   3081                     input_str += ' \n {}'.format("The event is related to an end to someone's custody in prison.")
   3082                 if i_style == 'keywords':
   3083                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3084                 if i_style == 'triggers':
   3085                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3086                 if i_style == 'template':
   3087                     input_str += ' \n {}'.format(self.output_template)
   3088         
   3089         return input_str
   3090 
   3091     def generate_output_str(self, query_trigger):
   3092         assert self.gold_event is not None
   3093         output_str = ''
   3094         gold_sample = False
   3095         for o_style in OUTPUT_STYLE_SET:
   3096             if o_style in self.output_style:
   3097                 if o_style == 'trigger:sentence':
   3098                     if self.trigger_text != '':
   3099                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3100                         gold_sample = True
   3101                     else:
   3102                         output_str += ' \n Event trigger is <Trigger>'
   3103                 if o_style == 'argument:sentence':
   3104                     output_texts = []
   3105                     for argu in self.arguments:
   3106                         filler = (
   3107                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   3108                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
   3109                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   3110                         )
   3111                         output_texts.append("{} was released by {} from {}.".format(*filler))
   3112                         gold_sample = True
   3113                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3114         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3115         return (output_str, gold_sample)
   3116 
   3117     def decode(self, preds):
   3118         output = []
   3119         for cnt, pred in enumerate(preds.split('\n')):
   3120             used_o_cnt = 0
   3121             full_pred = pred.strip()
   3122             for o_style in OUTPUT_STYLE_SET:
   3123                 if o_style in self.output_style:
   3124                     if o_style == 'trigger:sentence':
   3125                         if used_o_cnt == cnt:
   3126                             try:
   3127                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3128                                 triggers = triggers.split(' and ')
   3129                                 for t_cnt, t in enumerate(triggers):
   3130                                     if t != '<Trigger>':
   3131                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3132                             except:
   3133                                 pass
   3134                         used_o_cnt += 1
   3135                     if o_style == 'argument:sentence':
   3136                         if used_o_cnt == cnt:
   3137                             try:
   3138                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3139                                     person = prediction.split(' was released by ', 1)[0]
   3140                                     person = person.split(' and ')
   3141                                     remain = prediction.split(' was released by ', 1)[1]
   3142 
   3143                                     entity = remain.split(' from ', 1)[0]
   3144                                     entity = entity.split(' and ')
   3145                                     remain = remain.split(' from ', 1)[1]
   3146 
   3147                                     place = remain.rsplit('.',1)[0]
   3148                                     place = place.split(' and ')
   3149                                     for arg in person:
   3150                                         if arg != ROLE_PH_MAP['Person']:
   3151                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   3152                                     for arg in entity:
   3153                                         if arg != ROLE_PH_MAP['Agent']:
   3154                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   3155                                     for arg in place:
   3156                                         if arg != ROLE_PH_MAP['Place']:
   3157                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3158                             except:
   3159                                 pass
   3160                         used_o_cnt += 1
   3161         return output
   3162 
   3163 class Justice_Trial_Hearing(event_template):
   3164 
   3165     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3166         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3167     
   3168     @classmethod
   3169     def get_keywords(self):
   3170         return ['trial', 'hearing', 'proceeding']    
   3171     
   3172     def get_output_template(self):
   3173         output_template = ''
   3174         for o_style in OUTPUT_STYLE_SET:
   3175             if o_style in self.output_style:
   3176                 if o_style == 'trigger:sentence':
   3177                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3178                 if o_style == 'argument:sentence':
   3179                     output_template += ' \n {}'.format('somebody, prosecuted by some other, faced a trial in somewhere. The hearing was judged by some adjudicator.')
   3180         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3181 
   3182     def generate_input_str(self, query_trigger):
   3183         input_str = self.passage
   3184         for i_style in INPUT_STYLE_SET:
   3185             if i_style in self.input_style:
   3186                 if i_style == 'event_type':
   3187                     input_str += ' \n {}'.format('justice event, trial hearing sub-type')
   3188                 if i_style == 'event_type_sent':
   3189                     input_str += ' \n {}'.format("The event is related to a trial or hearing for someone.")
   3190                 if i_style == 'keywords':
   3191                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3192                 if i_style == 'triggers':
   3193                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3194                 if i_style == 'template':
   3195                     input_str += ' \n {}'.format(self.output_template)
   3196         return input_str
   3197 
   3198     def generate_output_str(self, query_trigger):
   3199         assert self.gold_event is not None
   3200         output_str = ''
   3201         gold_sample = False
   3202         for o_style in OUTPUT_STYLE_SET:
   3203             if o_style in self.output_style:
   3204                 if o_style == 'trigger:sentence':
   3205                     if self.trigger_text != '':
   3206                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3207                         gold_sample = True
   3208                     else:
   3209                         output_str += ' \n Event trigger is <Trigger>'
   3210                 if o_style == 'argument:sentence':
   3211                     output_texts = []
   3212                     for argu in self.arguments:
   3213                         filler = (
   3214                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   3215                             " and ".join([ a['argument text'] for a in argu['Prosecutor']]) if "Prosecutor" in argu.keys() else ROLE_PH_MAP['Prosecutor'],
   3216                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   3217                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   3218                         )
   3219                         output_texts.append("{}, prosecuted by {}, faced a trial in {}. The hearing was judged by {}.".format(*filler))
   3220                         gold_sample = True
   3221                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3222         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3223         return (output_str, gold_sample)
   3224 
   3225     def decode(self, preds):
   3226         output = []
   3227         for cnt, pred in enumerate(preds.split('\n')):
   3228             used_o_cnt = 0
   3229             full_pred = pred.strip()
   3230             for o_style in OUTPUT_STYLE_SET:
   3231                 if o_style in self.output_style:
   3232                     if o_style == 'trigger:sentence':
   3233                         if used_o_cnt == cnt:
   3234                             try:
   3235                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3236                                 triggers = triggers.split(' and ')
   3237                                 for t_cnt, t in enumerate(triggers):
   3238                                     if t != '<Trigger>':
   3239                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3240                             except:
   3241                                 pass
   3242                         used_o_cnt += 1
   3243                     if o_style == 'argument:sentence':
   3244                         if used_o_cnt == cnt:
   3245                             try:
   3246                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3247                                     defendant = prediction.split(', prosecuted by ', 1)[0]
   3248                                     defendant = defendant.split(' and ')
   3249                                     remain = prediction.split(', prosecuted by ', 1)[1]
   3250 
   3251                                     prosecutor = remain.split(', faced a trial in ', 1)[0]
   3252                                     prosecutor = prosecutor.split(' and ')
   3253                                     remain = remain.split(', faced a trial in ', 1)[1]
   3254 
   3255                                     place = remain.split('. The hearing was judged by ', 1)[0]
   3256                                     place = place.split(' and ')
   3257                                     remain = remain.split('. The hearing was judged by ', 1)[1]
   3258 
   3259                                     adjudicator = remain.rsplit('.',1)[0]
   3260                                     adjudicator = adjudicator.split(' and ')
   3261                                     for arg in defendant:
   3262                                         if arg != ROLE_PH_MAP['Defendant']:
   3263                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   3264                                     for arg in prosecutor:
   3265                                         if arg != ROLE_PH_MAP['Prosecutor']:
   3266                                             output.append((arg, 'Prosecutor', {'cor tri cnt': a_cnt}))
   3267                                     for arg in place:
   3268                                         if arg != ROLE_PH_MAP['Place']:
   3269                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3270                                     for arg in adjudicator:
   3271                                         if arg != ROLE_PH_MAP['Adjudicator']:
   3272                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   3273                             except Exception as e:
   3274                                 pass
   3275                         used_o_cnt += 1
   3276         return output
   3277 
   3278 class Justice_Charge_Indict(event_template):
   3279 
   3280     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3281         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3282 
   3283     @classmethod
   3284     def get_keywords(self):
   3285         return ['indict', 'charged', 'accused']
   3286 
   3287     def get_output_template(self):
   3288         output_template = ''
   3289         for o_style in OUTPUT_STYLE_SET:
   3290             if o_style in self.output_style:
   3291                 if o_style == 'trigger:sentence':
   3292                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3293                 if o_style == 'argument:sentence':
   3294                     output_template += ' \n {}'.format('somebody was charged by some other in somewhere. The adjudication was judged by some adjudicator.')
   3295         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3296 
   3297     def generate_input_str(self, query_trigger):
   3298         input_str = self.passage
   3299         for i_style in INPUT_STYLE_SET:
   3300             if i_style in self.input_style:
   3301                 if i_style == 'event_type':
   3302                     input_str += ' \n {}'.format('justice event, charge indict sub-type')
   3303                 if i_style == 'event_type_sent':
   3304                     input_str += ' \n {}'.format("The event is related to someone or some organization being accused of a crime.")
   3305                 if i_style == 'keywords':
   3306                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3307                 if i_style == 'triggers':
   3308                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3309                 if i_style == 'template':
   3310                     input_str += ' \n {}'.format(self.output_template)
   3311         return input_str
   3312 
   3313     def generate_output_str(self, query_trigger):
   3314         assert self.gold_event is not None
   3315         output_str = ''
   3316         gold_sample = False
   3317         for o_style in OUTPUT_STYLE_SET:
   3318             if o_style in self.output_style:
   3319                 if o_style == 'trigger:sentence':
   3320                     if self.trigger_text != '':
   3321                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3322                         gold_sample = True
   3323                     else:
   3324                         output_str += ' \n Event trigger is <Trigger>'
   3325                 if o_style == 'argument:sentence':
   3326                     output_texts = []
   3327                     for argu in self.arguments:
   3328                         filler = (
   3329                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   3330                             " and ".join([ a['argument text'] for a in argu['Prosecutor']]) if "Prosecutor" in argu.keys() else ROLE_PH_MAP['Prosecutor'],
   3331                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   3332                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   3333                         )
   3334                         output_texts.append("{} was charged by {} in {}. The adjudication was judged by {}.".format(*filler))
   3335                         gold_sample = True
   3336                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3337         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3338         return (output_str, gold_sample)
   3339 
   3340     def decode(self, preds):
   3341         output = []
   3342         for cnt, pred in enumerate(preds.split('\n')):
   3343             used_o_cnt = 0
   3344             full_pred = pred.strip()
   3345             for o_style in OUTPUT_STYLE_SET:
   3346                 if o_style in self.output_style:
   3347                     if o_style == 'trigger:sentence':
   3348                         if used_o_cnt == cnt:
   3349                             try:
   3350                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3351                                 triggers = triggers.split(' and ')
   3352                                 for t_cnt, t in enumerate(triggers):
   3353                                     if t != '<Trigger>':
   3354                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3355                             except:
   3356                                 pass
   3357                         used_o_cnt += 1
   3358                     if o_style == 'argument:sentence':
   3359                         if used_o_cnt == cnt:
   3360                             try:
   3361                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3362                                     defendant = prediction.split(' was charged by ', 1)[0]
   3363                                     defendant = defendant.split(' and ')
   3364                                     remain = prediction.split(' was charged by ', 1)[1]
   3365 
   3366                                     prosecutor = remain.split(' in ', 1)[0]
   3367                                     prosecutor = prosecutor.split(' and ')
   3368                                     remain = remain.split(' in ', 1)[1]
   3369 
   3370                                     place = remain.split('. The adjudication was judged by ', 1)[0]
   3371                                     place = place.split(' and ')
   3372                                     remain = remain.split('. The adjudication was judged by ', 1)[1]
   3373 
   3374                                     adjudicator = remain.rsplit('.',1)[0]
   3375                                     adjudicator = adjudicator.split(' and ')
   3376                                     for arg in defendant:
   3377                                         if arg != ROLE_PH_MAP['Defendant']:
   3378                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   3379                                     for arg in prosecutor:
   3380                                         if arg != ROLE_PH_MAP['Prosecutor']:
   3381                                             output.append((arg, 'Prosecutor', {'cor tri cnt': a_cnt}))
   3382                                     for arg in place:
   3383                                         if arg != ROLE_PH_MAP['Place']:
   3384                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3385                                     for arg in adjudicator:
   3386                                         if arg != ROLE_PH_MAP['Adjudicator']:
   3387                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   3388                             except:
   3389                                 pass
   3390                         used_o_cnt += 1
   3391         return output
   3392 
   3393 class Justice_Sue(event_template):
   3394 
   3395     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3396         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3397 
   3398     @classmethod
   3399     def get_keywords(self):
   3400         return ['sue', 'lawsuit', 'suit']
   3401 
   3402     def get_output_template(self):
   3403         output_template = ''
   3404         for o_style in OUTPUT_STYLE_SET:
   3405             if o_style in self.output_style:
   3406                 if o_style == 'trigger:sentence':
   3407                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3408                 if o_style == 'argument:sentence':
   3409                     output_template += ' \n {}'.format('somebody was sued by some other in somewhere. The adjudication was judged by some adjudicator.')
   3410         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3411 
   3412     def generate_input_str(self, query_trigger):
   3413         input_str = self.passage
   3414         for i_style in INPUT_STYLE_SET:
   3415             if i_style in self.input_style:
   3416                 if i_style == 'event_type':
   3417                     input_str += ' \n {}'.format('justice event, sue sub-type')
   3418                 if i_style == 'event_type_sent':
   3419                     input_str += ' \n {}'.format("The event is related to a court proceeding that has been initiated and someone sue the other.")
   3420                 if i_style == 'keywords':
   3421                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3422                 if i_style == 'triggers':
   3423                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3424                 if i_style == 'template':
   3425                     input_str += ' \n {}'.format(self.output_template)
   3426         return input_str
   3427 
   3428     def generate_output_str(self, query_trigger):
   3429         assert self.gold_event is not None
   3430         output_str = ''
   3431         gold_sample = False
   3432         for o_style in OUTPUT_STYLE_SET:
   3433             if o_style in self.output_style:
   3434                 if o_style == 'trigger:sentence':
   3435                     if self.trigger_text != '':
   3436                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3437                         gold_sample = True
   3438                     else:
   3439                         output_str += ' \n Event trigger is <Trigger>'
   3440                 if o_style == 'argument:sentence':
   3441                     output_texts = []
   3442                     for argu in self.arguments:
   3443                         filler = (
   3444                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   3445                             " and ".join([ a['argument text'] for a in argu['Plaintiff']]) if "Plaintiff" in argu.keys() else ROLE_PH_MAP['Plaintiff'],
   3446                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   3447                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   3448                         )
   3449                         output_texts.append("{} was sued by {} in {}. The adjudication was judged by {}.".format(*filler))
   3450                         gold_sample = True
   3451                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3452         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3453         return (output_str, gold_sample)
   3454 
   3455     def decode(self, preds):
   3456         output = []
   3457         for cnt, pred in enumerate(preds.split('\n')):
   3458             used_o_cnt = 0
   3459             full_pred = pred.strip()
   3460             for o_style in OUTPUT_STYLE_SET:
   3461                 if o_style in self.output_style:
   3462                     if o_style == 'trigger:sentence':
   3463                         if used_o_cnt == cnt:
   3464                             try:
   3465                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3466                                 triggers = triggers.split(' and ')
   3467                                 for t_cnt, t in enumerate(triggers):
   3468                                     if t != '<Trigger>':
   3469                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3470                             except:
   3471                                 pass
   3472                         used_o_cnt += 1
   3473                     if o_style == 'argument:sentence':
   3474                         if used_o_cnt == cnt:
   3475                             try:
   3476                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3477                                     defendant = prediction.split(' was sued by ', 1)[0]
   3478                                     defendant = defendant.split(' and ')
   3479                                     remain = prediction.split(' was sued by ', 1)[1]
   3480 
   3481                                     plaintiff = remain.split(' in ', 1)[0]
   3482                                     plaintiff = plaintiff.split(' and ')
   3483                                     remain = remain.split(' in ', 1)[1]
   3484 
   3485                                     place = remain.split('. The adjudication was judged by ', 1)[0]
   3486                                     place = place.split(' and ')
   3487                                     remain = remain.split('. The adjudication was judged by ', 1)[1]
   3488 
   3489                                     adjudicator = remain.rsplit('.',1)[0]
   3490                                     adjudicator = adjudicator.split(' and ')
   3491                                     for arg in defendant:
   3492                                         if arg != ROLE_PH_MAP['Defendant']:
   3493                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   3494                                     for arg in plaintiff:
   3495                                         if arg != ROLE_PH_MAP['Plaintiff']:
   3496                                             output.append((arg, 'Plaintiff', {'cor tri cnt': a_cnt}))
   3497                                     for arg in place:
   3498                                         if arg != ROLE_PH_MAP['Place']:
   3499                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3500                                     for arg in adjudicator:
   3501                                         if arg != ROLE_PH_MAP['Adjudicator']:
   3502                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   3503                             except:
   3504                                 pass
   3505                         used_o_cnt += 1
   3506         return output
   3507 
   3508 class Justice_Convict(event_template):
   3509 
   3510     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3511         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3512 
   3513     @classmethod
   3514     def get_keywords(self):
   3515         return ['convicted', 'guilty', 'verdict']
   3516 
   3517     def get_output_template(self):
   3518         output_template = ''
   3519         for o_style in OUTPUT_STYLE_SET:
   3520             if o_style in self.output_style:
   3521                 if o_style == 'trigger:sentence':
   3522                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3523                 if o_style == 'argument:sentence':
   3524                     output_template += ' \n {}'.format('somebody was convicted of a crime in somewhere. The adjudication was judged by some adjudicator.')
   3525         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3526 
   3527     def generate_input_str(self, query_trigger):
   3528         input_str = self.passage
   3529         for i_style in INPUT_STYLE_SET:
   3530             if i_style in self.input_style:
   3531                 if i_style == 'event_type':
   3532                     input_str += ' \n {}'.format('justice event, convict sub-type')
   3533                 if i_style == 'event_type_sent':
   3534                     input_str += ' \n {}'.format("The event is related to someone being found guilty of a crime.")
   3535                 if i_style == 'keywords':
   3536                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3537                 if i_style == 'triggers':
   3538                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3539                 if i_style == 'template':
   3540                     input_str += ' \n {}'.format(self.output_template)
   3541         return input_str
   3542 
   3543     def generate_output_str(self, query_trigger):
   3544         assert self.gold_event is not None
   3545         output_str = ''
   3546         gold_sample = False
   3547         for o_style in OUTPUT_STYLE_SET:
   3548             if o_style in self.output_style:
   3549                 if o_style == 'trigger:sentence':
   3550                     if self.trigger_text != '':
   3551                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3552                         gold_sample = True
   3553                     else:
   3554                         output_str += ' \n Event trigger is <Trigger>'
   3555                 if o_style == 'argument:sentence':
   3556                     output_texts = []
   3557                     for argu in self.arguments:
   3558                         filler = (
   3559                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   3560                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   3561                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   3562                         )
   3563                         output_texts.append("{} was convicted of a crime in {}. The adjudication was judged by {}.".format(*filler))
   3564                         gold_sample = True
   3565                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3566         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3567         return (output_str, gold_sample)
   3568 
   3569     def decode(self, preds):
   3570         output = []
   3571         for cnt, pred in enumerate(preds.split('\n')):
   3572             used_o_cnt = 0
   3573             full_pred = pred.strip()
   3574             for o_style in OUTPUT_STYLE_SET:
   3575                 if o_style in self.output_style:
   3576                     if o_style == 'trigger:sentence':
   3577                         if used_o_cnt == cnt:
   3578                             try:
   3579                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3580                                 triggers = triggers.split(' and ')
   3581                                 for t_cnt, t in enumerate(triggers):
   3582                                     if t != '<Trigger>':
   3583                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3584                             except:
   3585                                 pass
   3586                         used_o_cnt += 1
   3587                     if o_style == 'argument:sentence':
   3588                         if used_o_cnt == cnt:
   3589                             try:
   3590                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3591                                     defendant = prediction.split(' was convicted of a crime in ', 1)[0]
   3592                                     defendant = defendant.split(' and ')
   3593                                     remain = prediction.split(' was convicted of a crime in ', 1)[1]
   3594 
   3595                                     place = remain.split('. The adjudication was judged by ', 1)[0]
   3596                                     place = place.split(' and ')
   3597                                     remain = remain.split('. The adjudication was judged by ', 1)[1]
   3598 
   3599                                     adjudicator = remain.rsplit('.',1)[0]
   3600                                     adjudicator = adjudicator.split(' and ')
   3601                                     for arg in defendant:
   3602                                         if arg != ROLE_PH_MAP['Defendant']:
   3603                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   3604                                     for arg in place:
   3605                                         if arg != ROLE_PH_MAP['Place']:
   3606                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3607                                     for arg in adjudicator:
   3608                                         if arg != ROLE_PH_MAP['Adjudicator']:
   3609                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   3610                             except:
   3611                                 pass
   3612                         used_o_cnt += 1
   3613         return output
   3614 
   3615 class Justice_Sentence(event_template):
   3616     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3617         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3618 
   3619     @classmethod
   3620     def get_keywords(self):
   3621         return ['sentenced', 'sentencing', 'sentence']
   3622 
   3623     def get_output_template(self):
   3624         output_template = ''
   3625         for o_style in OUTPUT_STYLE_SET:
   3626             if o_style in self.output_style:
   3627                 if o_style == 'trigger:sentence':
   3628                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3629                 if o_style == 'argument:sentence':
   3630                     output_template += ' \n {}'.format('somebody was sentenced to punishment in somewhere. The adjudication was judged by some adjudicator.')
   3631         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3632 
   3633     def generate_input_str(self, query_trigger):
   3634         input_str = self.passage
   3635         for i_style in INPUT_STYLE_SET:
   3636             if i_style in self.input_style:
   3637                 if i_style == 'event_type':
   3638                     input_str += ' \n {}'.format('justice event, sentence sub-type')
   3639                 if i_style == 'event_type_sent':
   3640                     input_str += ' \n {}'.format("The event is related to someone being sentences to punishment because of a crime.")
   3641                 if i_style == 'keywords':
   3642                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3643                 if i_style == 'triggers':
   3644                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3645                 if i_style == 'template':
   3646                     input_str += ' \n {}'.format(self.output_template)
   3647         return input_str
   3648 
   3649     def generate_output_str(self, query_trigger):
   3650         assert self.gold_event is not None
   3651         output_str = ''
   3652         gold_sample = False
   3653         for o_style in OUTPUT_STYLE_SET:
   3654             if o_style in self.output_style:
   3655                 if o_style == 'trigger:sentence':
   3656                     if self.trigger_text != '':
   3657                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3658                         gold_sample = True
   3659                     else:
   3660                         output_str += ' \n Event trigger is <Trigger>'
   3661                 if o_style == 'argument:sentence':
   3662                     output_texts = []
   3663                     for argu in self.arguments:
   3664                         filler = (
   3665                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   3666                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   3667                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   3668                         )
   3669                         output_texts.append("{} was sentenced to punishment in {}. The adjudication was judged by {}.".format(*filler))
   3670                         gold_sample = True
   3671                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3672         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3673         return (output_str, gold_sample)
   3674 
   3675     def decode(self, preds):
   3676         output = []
   3677         for cnt, pred in enumerate(preds.split('\n')):
   3678             used_o_cnt = 0
   3679             full_pred = pred.strip()
   3680             for o_style in OUTPUT_STYLE_SET:
   3681                 if o_style in self.output_style:
   3682                     if o_style == 'trigger:sentence':
   3683                         if used_o_cnt == cnt:
   3684                             try:
   3685                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3686                                 triggers = triggers.split(' and ')
   3687                                 for t_cnt, t in enumerate(triggers):
   3688                                     if t != '<Trigger>':
   3689                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3690                             except:
   3691                                 pass
   3692                         used_o_cnt += 1
   3693                     if o_style == 'argument:sentence':
   3694                         if used_o_cnt == cnt:
   3695                             try:
   3696                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3697                                     defendant = prediction.split(' was sentenced to punishment in ', 1)[0]
   3698                                     defendant = defendant.split(' and ')
   3699                                     remain = prediction.split(' was sentenced to punishment in ', 1)[1]
   3700 
   3701                                     place = remain.split('. The adjudication was judged by ', 1)[0]
   3702                                     place = place.split(' and ')
   3703                                     remain = remain.split('. The adjudication was judged by ', 1)[1]
   3704 
   3705                                     adjudicator = remain.rsplit('.',1)[0]
   3706                                     adjudicator = adjudicator.split(' and ')
   3707                                     for arg in defendant:
   3708                                         if arg != ROLE_PH_MAP['Defendant']:
   3709                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   3710                                     for arg in place:
   3711                                         if arg != ROLE_PH_MAP['Place']:
   3712                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3713                                     for arg in adjudicator:
   3714                                         if arg != ROLE_PH_MAP['Adjudicator']:
   3715                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   3716                             except:
   3717                                 pass
   3718                         used_o_cnt += 1
   3719         return output
   3720 
   3721 class Justice_Fine(event_template):
   3722     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3723         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3724 
   3725     @classmethod
   3726     def get_keywords(self):
   3727         return ['fine', 'fined', 'payouts']
   3728 
   3729     def get_output_template(self):
   3730         output_template = ''
   3731         for o_style in OUTPUT_STYLE_SET:
   3732             if o_style in self.output_style:
   3733                 if o_style == 'trigger:sentence':
   3734                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3735                 if o_style == 'argument:sentence':
   3736                     output_template += ' \n {}'.format('some people or some organization in somewhere was ordered by some adjudicator to pay a fine.')
   3737         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3738 
   3739     def generate_input_str(self, query_trigger):
   3740         input_str = self.passage
   3741         for i_style in INPUT_STYLE_SET:
   3742             if i_style in self.input_style:
   3743                 if i_style == 'event_type':
   3744                     input_str += ' \n {}'.format('justice event, fine sub-type')
   3745                 if i_style == 'event_type_sent':
   3746                     input_str += ' \n {}'.format("The event is related to someone being issued a financial punishment.")
   3747                 if i_style == 'keywords':
   3748                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3749                 if i_style == 'triggers':
   3750                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3751                 if i_style == 'template':
   3752                     input_str += ' \n {}'.format(self.output_template)
   3753         return input_str
   3754 
   3755     def generate_output_str(self, query_trigger):
   3756         assert self.gold_event is not None
   3757         output_str = ''
   3758         gold_sample = False
   3759         for o_style in OUTPUT_STYLE_SET:
   3760             if o_style in self.output_style:
   3761                 if o_style == 'trigger:sentence':
   3762                     if self.trigger_text != '':
   3763                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3764                         gold_sample = True
   3765                     else:
   3766                         output_str += ' \n Event trigger is <Trigger>'
   3767                 if o_style == 'argument:sentence':
   3768                     output_texts = []
   3769                     for argu in self.arguments:
   3770                         filler = (
   3771                             " and ".join([ a['argument text'] for a in argu['Entity']]) if "Entity" in argu.keys() else ROLE_PH_MAP['Entity'],
   3772                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   3773                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   3774                         )
   3775                         output_texts.append("{} in {} was ordered by {} to pay a fine.".format(*filler))
   3776                         gold_sample = True
   3777                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3778         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3779         return (output_str, gold_sample)
   3780 
   3781     def decode(self, preds):
   3782         output = []
   3783         for cnt, pred in enumerate(preds.split('\n')):
   3784             used_o_cnt = 0
   3785             full_pred = pred.strip()
   3786             for o_style in OUTPUT_STYLE_SET:
   3787                 if o_style in self.output_style:
   3788                     if o_style == 'trigger:sentence':
   3789                         if used_o_cnt == cnt:
   3790                             try:
   3791                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3792                                 triggers = triggers.split(' and ')
   3793                                 for t_cnt, t in enumerate(triggers):
   3794                                     if t != '<Trigger>':
   3795                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3796                             except:
   3797                                 pass
   3798                         used_o_cnt += 1
   3799                     if o_style == 'argument:sentence':
   3800                         if used_o_cnt == cnt:
   3801                             try:
   3802                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3803                                     entity = prediction.split(' in ', 1)[0]
   3804                                     entity = entity.split(' and ')
   3805                                     remain = prediction.split(' in ', 1)[1]
   3806 
   3807                                     place = remain.split(' was ordered by ', 1)[0]
   3808                                     place = place.split(' and ')
   3809                                     remain = remain.split(' was ordered by ', 1)[1]
   3810 
   3811                                     adjudicator = remain.rsplit(' to pay a fine.',1)[0]
   3812                                     adjudicator = adjudicator.split(' and ')
   3813                                     for arg in entity:
   3814                                         if arg != ROLE_PH_MAP['Entity']:
   3815                                             output.append((arg, 'Entity', {'cor tri cnt': a_cnt}))
   3816                                     for arg in place:
   3817                                         if arg != ROLE_PH_MAP['Place']:
   3818                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3819                                     for arg in adjudicator:
   3820                                         if arg != ROLE_PH_MAP['Adjudicator']:
   3821                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   3822                             except Exception as e:
   3823                                 pass
   3824                         used_o_cnt += 1
   3825         return output
   3826 
   3827 class Justice_Execute(event_template):
   3828     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3829         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3830 
   3831     @classmethod
   3832     def get_keywords(self):
   3833         return ['execution', 'executed', 'execute']
   3834 
   3835     def get_output_template(self):
   3836         output_template = ''
   3837         for o_style in OUTPUT_STYLE_SET:
   3838             if o_style in self.output_style:
   3839                 if o_style == 'trigger:sentence':
   3840                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3841                 if o_style == 'argument:sentence':
   3842                     output_template += ' \n {}'.format('somebody was executed by somebody or some organization at somewhere.')
   3843         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3844 
   3845     def generate_input_str(self, query_trigger):
   3846         input_str = self.passage
   3847         for i_style in INPUT_STYLE_SET:
   3848             if i_style in self.input_style:
   3849                 if i_style == 'event_type':
   3850                     input_str += ' \n {}'.format('justice event, execute sub-type')
   3851                 if i_style == 'event_type_sent':
   3852                     input_str += ' \n {}'.format("The event is related to someone being executed to death.")
   3853                 if i_style == 'keywords':
   3854                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3855                 if i_style == 'triggers':
   3856                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3857                 if i_style == 'template':
   3858                     input_str += ' \n {}'.format(self.output_template)
   3859         return input_str
   3860 
   3861     def generate_output_str(self, query_trigger):
   3862         assert self.gold_event is not None
   3863         output_str = ''
   3864         gold_sample = False
   3865         for o_style in OUTPUT_STYLE_SET:
   3866             if o_style in self.output_style:
   3867                 if o_style == 'trigger:sentence':
   3868                     if self.trigger_text != '':
   3869                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3870                         gold_sample = True
   3871                     else:
   3872                         output_str += ' \n Event trigger is <Trigger>'
   3873                 if o_style == 'argument:sentence':
   3874                     output_texts = []
   3875                     for argu in self.arguments:
   3876                         filler = (
   3877                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   3878                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent'],
   3879                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place']
   3880                         )
   3881                         output_texts.append("{} was executed by {} at {}.".format(*filler))
   3882                         gold_sample = True
   3883                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3884         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3885         return (output_str, gold_sample)
   3886 
   3887     def decode(self, preds):
   3888         output = []
   3889         for cnt, pred in enumerate(preds.split('\n')):
   3890             used_o_cnt = 0
   3891             full_pred = pred.strip()
   3892             for o_style in OUTPUT_STYLE_SET:
   3893                 if o_style in self.output_style:
   3894                     if o_style == 'trigger:sentence':
   3895                         if used_o_cnt == cnt:
   3896                             try:
   3897                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   3898                                 triggers = triggers.split(' and ')
   3899                                 for t_cnt, t in enumerate(triggers):
   3900                                     if t != '<Trigger>':
   3901                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   3902                             except:
   3903                                 pass
   3904                         used_o_cnt += 1
   3905                     if o_style == 'argument:sentence':
   3906                         if used_o_cnt == cnt:
   3907                             try:
   3908                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   3909                                     person = prediction.split(' was executed by ', 1)[0]
   3910                                     person = person.split(' and ')
   3911                                     remain = prediction.split(' was executed by ', 1)[1]
   3912 
   3913                                     agent = remain.split(' at ', 1)[0]
   3914                                     agent = agent.split(' and ')
   3915                                     remain = remain.split(' at ', 1)[1]
   3916 
   3917                                     place = remain.rsplit('.',1)[0]
   3918                                     place = place.split(' and ')
   3919                                     for arg in person:
   3920                                         if arg != ROLE_PH_MAP['Person']:
   3921                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   3922                                     for arg in place:
   3923                                         if arg != ROLE_PH_MAP['Place']:
   3924                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   3925                                     for arg in agent:
   3926                                         if arg != ROLE_PH_MAP['Agent']:
   3927                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   3928                             except:
   3929                                 pass
   3930                         used_o_cnt += 1
   3931         return output
   3932             
   3933 class Justice_Extradite(event_template):
   3934     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   3935         super().__init__(input_style, output_style, passage, event_type, gold_event)
   3936 
   3937     @classmethod
   3938     def get_keywords(self):
   3939         return ['extradition', 'extradited', 'extraditing']
   3940 
   3941     def get_output_template(self):
   3942         output_template = ''
   3943         for o_style in OUTPUT_STYLE_SET:
   3944             if o_style in self.output_style:
   3945                 if o_style == 'trigger:sentence':
   3946                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   3947                 if o_style == 'argument:sentence':
   3948                     output_template += ' \n {}'.format('somebody was extradicted to somewhere from some place. somebody or some organization was responsible for the extradition.')
   3949         return ('\n'.join(output_template.split('\n')[1:])).strip()
   3950 
   3951     def generate_input_str(self, query_trigger):
   3952         input_str = self.passage
   3953         for i_style in INPUT_STYLE_SET:
   3954             if i_style in self.input_style:
   3955                 if i_style == 'event_type':
   3956                     input_str += ' \n {}'.format('justice event, extradite sub-type')
   3957                 if i_style == 'event_type_sent':
   3958                     input_str += ' \n {}'.format('The event is related to justice. The event occurs when a person was extradited from one place to another place.')
   3959                 if i_style == 'keywords':
   3960                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   3961                 if i_style == 'triggers':
   3962                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   3963                 if i_style == 'template':
   3964                     input_str += ' \n {}'.format(self.output_template)
   3965         
   3966         return input_str
   3967 
   3968     def generate_output_str(self, query_trigger):
   3969         assert self.gold_event is not None
   3970         output_str = ''
   3971         gold_sample = False
   3972         for o_style in OUTPUT_STYLE_SET:
   3973             if o_style in self.output_style:
   3974                 if o_style == 'trigger:sentence':
   3975                     if self.trigger_text != '':
   3976                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   3977                         gold_sample = True
   3978                     else:
   3979                         output_str += ' \n Event trigger is <Trigger>'
   3980                 if o_style == 'argument:sentence':
   3981                     output_texts = []
   3982                     for argu in self.arguments:
   3983                         filler = (
   3984                             " and ".join([ a['argument text'] for a in argu['Person']]) if "Person" in argu.keys() else ROLE_PH_MAP['Person'],
   3985                             " and ".join([ a['argument text'] for a in argu['Destination']]) if "Destination" in argu.keys() else ROLE_PH_MAP['Destination'],
   3986                             " and ".join([ a['argument text'] for a in argu['Origin']]) if "Origin" in argu.keys() else ROLE_PH_MAP['Origin'],
   3987                             " and ".join([ a['argument text'] for a in argu['Agent']]) if "Agent" in argu.keys() else ROLE_PH_MAP['Agent']
   3988                         )
   3989                         output_texts.append("{} was extradicted to {} from {}. {} was responsible for the extradition.".format(*filler))
   3990                         gold_sample = True
   3991                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   3992         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   3993         return (output_str, gold_sample)
   3994 
   3995     def decode(self, preds):
   3996         output = []
   3997         for cnt, pred in enumerate(preds.split('\n')):
   3998             used_o_cnt = 0
   3999             full_pred = pred.strip()
   4000             for o_style in OUTPUT_STYLE_SET:
   4001                 if o_style in self.output_style:
   4002                     if o_style == 'trigger:sentence':
   4003                         if used_o_cnt == cnt:
   4004                             try:
   4005                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   4006                                 triggers = triggers.split(' and ')
   4007                                 for t_cnt, t in enumerate(triggers):
   4008                                     if t != '<Trigger>':
   4009                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   4010                             except:
   4011                                 pass
   4012                         used_o_cnt += 1
   4013                     if o_style == 'argument:sentence':
   4014                         if used_o_cnt == cnt:
   4015                             try:
   4016                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   4017                                     person = prediction.split(' was extradicted to ')[0]
   4018                                     person = person.split(' and ')
   4019 
   4020                                     destination = (prediction.split(' was extradicted to ')[1]).split(' from ')[0]
   4021                                     destination = destination.split(' and ')
   4022 
   4023                                     origin = ((prediction.split(' was extradicted to ')[1]).split(' from ')[1]).split('.', 1)[0]
   4024                                     origin = origin.split(' and ')
   4025 
   4026                                     remain = ((prediction.split(' was extradicted to ')[1]).split(' from ')[1]).split('.', 1)[1]
   4027 
   4028                                     if 'was responsible for' in remain:
   4029                                         agent = (remain.split(' was responsible for the extradition.')[0]).strip()
   4030                                         agent = agent.split(' and ')
   4031                                     else:
   4032                                         agent = []
   4033 
   4034                                     for arg in agent:
   4035                                         if arg != ROLE_PH_MAP['Agent']:
   4036                                             output.append((arg, 'Agent', {'cor tri cnt': a_cnt}))
   4037                                     for arg in person:
   4038                                         if arg != ROLE_PH_MAP['Person']:
   4039                                             output.append((arg, 'Person', {'cor tri cnt': a_cnt}))
   4040                                     for arg in destination:
   4041                                         if arg != ROLE_PH_MAP['Destination']:
   4042                                             output.append((arg, 'Destination', {'cor tri cnt': a_cnt}))          
   4043                                     for arg in origin:
   4044                                         if arg != ROLE_PH_MAP['Origin']:
   4045                                             output.append((arg, 'Origin', {'cor tri cnt': a_cnt}))
   4046                             except:
   4047                                 pass
   4048                         used_o_cnt += 1
   4049         return output
   4050 
   4051 class Justice_Acquit(event_template):
   4052     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   4053         super().__init__(input_style, output_style, passage, event_type, gold_event)
   4054 
   4055     @classmethod
   4056     def get_keywords(self):
   4057         return ['acquitted', 'acquittal', 'acquit']
   4058 
   4059     def get_output_template(self):
   4060         output_template = ''
   4061         for o_style in OUTPUT_STYLE_SET:
   4062             if o_style in self.output_style:
   4063                 if o_style == 'trigger:sentence':
   4064                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   4065                 if o_style == 'argument:sentence':
   4066                     output_template += ' \n {}'.format('somebody was acquitted of the charges by some adjudicator.')
   4067         return ('\n'.join(output_template.split('\n')[1:])).strip()
   4068 
   4069     def generate_input_str(self, query_trigger):
   4070         input_str = self.passage
   4071         for i_style in INPUT_STYLE_SET:
   4072             if i_style in self.input_style:
   4073                 if i_style == 'event_type':
   4074                     input_str += ' \n {}'.format('justice event, acquit sub-type')
   4075                 if i_style == 'event_type_sent':
   4076                     input_str += ' \n {}'.format("The event is related to someone being acquitted.")
   4077                 if i_style == 'keywords':
   4078                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   4079                 if i_style == 'triggers':
   4080                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   4081                 if i_style == 'template':
   4082                     input_str += ' \n {}'.format(self.output_template)
   4083         return input_str
   4084 
   4085     def generate_output_str(self, query_trigger):
   4086         assert self.gold_event is not None
   4087         output_str = ''
   4088         gold_sample = False
   4089         for o_style in OUTPUT_STYLE_SET:
   4090             if o_style in self.output_style:
   4091                 if o_style == 'trigger:sentence':
   4092                     if self.trigger_text != '':
   4093                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   4094                         gold_sample = True
   4095                     else:
   4096                         output_str += ' \n Event trigger is <Trigger>'
   4097                 if o_style == 'argument:sentence':
   4098                     output_texts = []
   4099                     for argu in self.arguments:
   4100                         filler = (
   4101                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   4102                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   4103                         )
   4104                         output_texts.append("{} was acquitted of the charges by {}.".format(*filler))
   4105                         gold_sample = True
   4106                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   4107         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   4108         return (output_str, gold_sample)
   4109 
   4110     def decode(self, preds):
   4111         output = []
   4112         for cnt, pred in enumerate(preds.split('\n')):
   4113             used_o_cnt = 0
   4114             full_pred = pred.strip()
   4115             for o_style in OUTPUT_STYLE_SET:
   4116                 if o_style in self.output_style:
   4117                     if o_style == 'trigger:sentence':
   4118                         if used_o_cnt == cnt:
   4119                             try:
   4120                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   4121                                 triggers = triggers.split(' and ')
   4122                                 for t_cnt, t in enumerate(triggers):
   4123                                     if t != '<Trigger>':
   4124                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   4125                             except:
   4126                                 pass
   4127                         used_o_cnt += 1
   4128                     if o_style == 'argument:sentence':
   4129                         if used_o_cnt == cnt:
   4130                             try:
   4131                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   4132                                     defendant = prediction.split(' was acquitted of the charges by ', 1)[0]
   4133                                     defendant = defendant.split(' and ')
   4134                                     remain = prediction.split(' was acquitted of the charges by ', 1)[1]
   4135 
   4136                                     adjudicator = remain.rsplit('.',1)[0]
   4137                                     adjudicator = adjudicator.split(' and ')
   4138                                     for arg in defendant:
   4139                                         if arg != ROLE_PH_MAP['Defendant']:
   4140                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   4141                                     for arg in adjudicator:
   4142                                         if arg != ROLE_PH_MAP['Adjudicator']:
   4143                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   4144                             except:
   4145                                 pass
   4146                         used_o_cnt += 1
   4147         return output
   4148 
   4149 class Justice_Pardon(event_template):
   4150     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   4151         super().__init__(input_style, output_style, passage, event_type, gold_event)
   4152 
   4153     @classmethod
   4154     def get_keywords(self):
   4155         return ['pardon', 'pardoned', 'remission']
   4156 
   4157     def get_output_template(self):
   4158         output_template = ''
   4159         for o_style in OUTPUT_STYLE_SET:
   4160             if o_style in self.output_style:
   4161                 if o_style == 'trigger:sentence':
   4162                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   4163                 if o_style == 'argument:sentence':
   4164                     output_template += ' \n {}'.format('somebody received a pardon from some adjudicator.')
   4165         return ('\n'.join(output_template.split('\n')[1:])).strip()
   4166 
   4167     def generate_input_str(self, query_trigger):
   4168         input_str = self.passage
   4169         for i_style in INPUT_STYLE_SET:
   4170             if i_style in self.input_style:
   4171                 if i_style == 'event_type':
   4172                     input_str += ' \n {}'.format('justice event, pardon sub-type')
   4173                 if i_style == 'event_type_sent':
   4174                     input_str += ' \n {}'.format("The event is related to someone being pardoned.")
   4175                 if i_style == 'keywords':
   4176                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   4177                 if i_style == 'triggers':
   4178                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   4179                 if i_style == 'template':
   4180                     input_str += ' \n {}'.format(self.output_template)
   4181         return input_str
   4182 
   4183     def generate_output_str(self, query_trigger):
   4184         assert self.gold_event is not None
   4185         output_str = ''
   4186         gold_sample = False
   4187         for o_style in OUTPUT_STYLE_SET:
   4188             if o_style in self.output_style:
   4189                 if o_style == 'trigger:sentence':
   4190                     if self.trigger_text != '':
   4191                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   4192                         gold_sample = True
   4193                     else:
   4194                         output_str += ' \n Event trigger is <Trigger>'
   4195                 if o_style == 'argument:sentence':
   4196                     output_texts = []
   4197                     for argu in self.arguments:
   4198                         filler = (
   4199                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   4200                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   4201                         )
   4202                         output_texts.append("{} received a pardon from {}.".format(*filler))
   4203                         gold_sample = True
   4204                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   4205         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   4206         return (output_str, gold_sample)
   4207 
   4208     def decode(self, preds):
   4209         output = []
   4210         for cnt, pred in enumerate(preds.split('\n')):
   4211             used_o_cnt = 0
   4212             full_pred = pred.strip()
   4213             for o_style in OUTPUT_STYLE_SET:
   4214                 if o_style in self.output_style:
   4215                     if o_style == 'trigger:sentence':
   4216                         if used_o_cnt == cnt:
   4217                             try:
   4218                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   4219                                 triggers = triggers.split(' and ')
   4220                                 for t_cnt, t in enumerate(triggers):
   4221                                     if t != '<Trigger>':
   4222                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   4223                             except:
   4224                                 pass
   4225                         used_o_cnt += 1
   4226                     if o_style == 'argument:sentence':
   4227                         if used_o_cnt == cnt:
   4228                             try:
   4229                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   4230                                     defendant = prediction.split(' received a pardon from ', 1)[0]
   4231                                     defendant = defendant.split(' and ')
   4232                                     remain = prediction.split(' received a pardon from ', 1)[1]
   4233 
   4234                                     adjudicator = remain.rsplit('.',1)[0]
   4235                                     adjudicator = adjudicator.split(' and ')
   4236                                     for arg in defendant:
   4237                                         if arg != ROLE_PH_MAP['Defendant']:
   4238                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   4239                                     for arg in adjudicator:
   4240                                         if arg != ROLE_PH_MAP['Adjudicator']:
   4241                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   4242                             except:
   4243                                 pass
   4244                         used_o_cnt += 1
   4245         return output
   4246 
   4247 class Justice_Appeal(event_template):
   4248     def __init__(self, input_style, output_style, passage, event_type, gold_event=None):
   4249         super().__init__(input_style, output_style, passage, event_type, gold_event)
   4250     
   4251     @classmethod
   4252     def get_keywords(self):
   4253         return ['appeal', 'appealing', 'appeals']  
   4254 
   4255     def get_output_template(self):
   4256         output_template = ''
   4257         for o_style in OUTPUT_STYLE_SET:
   4258             if o_style in self.output_style:
   4259                 if o_style == 'trigger:sentence':
   4260                     output_template += ' \n {}'.format('Event trigger is <Trigger>')
   4261                 if o_style == 'argument:sentence':
   4262                     output_template += ' \n {}'.format('somebody in somewhere appealed the adjudication from some adjudicator.')
   4263         return ('\n'.join(output_template.split('\n')[1:])).strip()
   4264 
   4265     def generate_input_str(self, query_trigger):
   4266         input_str = self.passage
   4267         for i_style in INPUT_STYLE_SET:
   4268             if i_style in self.input_style:
   4269                 if i_style == 'event_type':
   4270                     input_str += ' \n {}'.format('justice event, appeal sub-type')
   4271                 if i_style == 'event_type_sent':
   4272                     input_str += ' \n {}'.format("The event is related to someone appealing the decision of a court.")
   4273                 if i_style == 'keywords':
   4274                     input_str += ' \n Similar triggers such as {}'.format(', '.join(self.get_keywords()))
   4275                 if i_style == 'triggers':
   4276                     input_str += ' \n The event trigger word is {}'.format(query_trigger)
   4277                 if i_style == 'template':
   4278                     input_str += ' \n {}'.format(self.output_template)
   4279         return input_str
   4280 
   4281     def generate_output_str(self, query_trigger):
   4282         assert self.gold_event is not None
   4283         output_str = ''
   4284         gold_sample = False
   4285         for o_style in OUTPUT_STYLE_SET:
   4286             if o_style in self.output_style:
   4287                 if o_style == 'trigger:sentence':
   4288                     if self.trigger_text != '':
   4289                         output_str += ' \n Event trigger is {}'.format(self.trigger_text)
   4290                         gold_sample = True
   4291                     else:
   4292                         output_str += ' \n Event trigger is <Trigger>'
   4293                 if o_style == 'argument:sentence':
   4294                     output_texts = []
   4295                     for argu in self.arguments:
   4296                         filler = (
   4297                             " and ".join([ a['argument text'] for a in argu['Defendant']]) if "Defendant" in argu.keys() else ROLE_PH_MAP['Defendant'],
   4298                             " and ".join([ a['argument text'] for a in argu['Place']]) if "Place" in argu.keys() else ROLE_PH_MAP['Place'],
   4299                             " and ".join([ a['argument text'] for a in argu['Adjudicator']]) if "Adjudicator" in argu.keys() else ROLE_PH_MAP['Adjudicator']
   4300                         )
   4301                         output_texts.append("{} in {} appealed the adjudication from {}.".format(*filler))
   4302                         gold_sample = True
   4303                     output_str += ' \n {}'.format(' <sep> '.join(output_texts))
   4304         output_str = ('\n'.join(output_str.split('\n')[1:])).strip()
   4305         return (output_str, gold_sample)
   4306 
   4307     def decode(self, preds):
   4308         output = []
   4309         for cnt, pred in enumerate(preds.split('\n')):
   4310             used_o_cnt = 0
   4311             full_pred = pred.strip()
   4312             for o_style in OUTPUT_STYLE_SET:
   4313                 if o_style in self.output_style:
   4314                     if o_style == 'trigger:sentence':
   4315                         if used_o_cnt == cnt:
   4316                             try:
   4317                                 triggers = full_pred.split('Event trigger is ', 1)[1]
   4318                                 triggers = triggers.split(' and ')
   4319                                 for t_cnt, t in enumerate(triggers):
   4320                                     if t != '<Trigger>':
   4321                                         output.append((t, self.event_type, {'tri counter': t_cnt})) # (text, type, kwargs)
   4322                             except:
   4323                                 pass
   4324                         used_o_cnt += 1
   4325                     if o_style == 'argument:sentence':
   4326                         if used_o_cnt == cnt:
   4327                             try:
   4328                                 for a_cnt, prediction in enumerate(full_pred.split(' <sep> ')):
   4329                                     plaintiff = prediction.split(' in ', 1)[0]
   4330                                     plaintiff = plaintiff.split(' and ')
   4331                                     remain = prediction.split(' in ', 1)[1]
   4332 
   4333                                     place = remain.split(' appealed the adjudication from ', 1)[0]
   4334                                     place = place.split(' and ')
   4335                                     remain = remain.split(' appealed the adjudication from ', 1)[1]
   4336 
   4337                                     adjudicator = remain.rsplit('.',1)[0]
   4338                                     adjudicator = adjudicator.split(' and ')
   4339 
   4340                                     for arg in plaintiff:
   4341                                         if arg != ROLE_PH_MAP['Defendant']:
   4342                                             output.append((arg, 'Defendant', {'cor tri cnt': a_cnt}))
   4343                                     for arg in place:
   4344                                         if arg != ROLE_PH_MAP['Place']:
   4345                                             output.append((arg, 'Place', {'cor tri cnt': a_cnt}))
   4346                                     for arg in adjudicator:
   4347                                         if arg != ROLE_PH_MAP['Adjudicator']:
   4348                                             output.append((arg, 'Adjudicator', {'cor tri cnt': a_cnt}))
   4349                             except:
   4350                                 pass
   4351                         used_o_cnt += 1
   4352         return output