Result connects a cause to its effect, i.e., the main eventuality of the first argument is understood to cause the eventuality given by the second.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | def LF_Result_L_L_case1(row): l=0 if (any(x in row.target_text.lower() for x in resultWords) or any(x in row.source_text.lower() for x in resultWords)): l=1 return l def LF_Result_L_L_case2(row): l = 0 if row.source_surface_act in ["Question", "Request", "Assertion"] \ and (row.target_dialogue_act in ["Offer", "Counteroffer"] \ or row.source_emitter == row.target_text.partition(' ')[0] or row.target_surface_act == "Request"): l=1 return l def LF_Result_L_L_case3(row): l = 0 if row.source_emitter == row.target_emitter and row.source_addressee == row.target_addressee \ and row.target_dialogue_act == "Counteroffer": l=1 return l def LF_Result_L_L_case4(row): l = 0 if row.source_dialogue_act == "Counteroffer" and row.target_dialogue_act == "Refusal": l=1 return l |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #1 -- get dialogues finals = [] dialogues = cands.dialogue_num.drop_duplicates() #dialogues = [103] for d in tqdm(dialogues): #keep track of dus involved in a seq as source or target -- one du cannot be source or target for > 1 rel memo_source = [] memo_target = [] # 2 -- get segment list seg_list = get_seg_list(cands[cands.dialogue_num == d]) # 3 -- create seg pairs list seg_pairs = [] for i, s in enumerate(seg_list): for n in [j for j in reversed(range((i+1)-20, i+1)) if j>=0]: try: seg_pairs.append((seg_list[n], seg_list[i+1])) except IndexError: pass # 4 -- for each pair, pull row and append rules for s in seg_pairs: row = cands[(cands.source_id == s[0]) & (cands.target_id == s[1])] if row.empty: continue else: r_index = row.index[0] row = row.iloc[0] #since we know no Result relations are backwards, eliminate immediately backwards = cands[(cands.source_id == s[1]) & (cands.target_id == s[0])] if backwards.shape[0] > 0: b_index = backwards.index[0] finals.append((b_index, -1)) #we only look at ling --> ling cases if row.source_type != 'Segment' or row.target_type != 'Segment': link = 0 else: if LF_Result_L_L_case1(row) or LF_Result_L_L_case2(row) or LF_Result_L_L_case3(row) or LF_Result_L_L_case4(row): #if LF_Result_L_L_case1(row) or LF_Result_L_L_case2(row): if row.target_id in memo_target or row.source_id in memo_source: link = 0 else: link = 1 memo_target.append(row.target_id) memo_source.append(row.source_id) else: link = 0 finals.append((r_index, link)) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | def LF_Result_L_NL(row): if ( # Linguistic => non_linguistic (("addtime" in row.source_text.lower() ) and (row.source_emitter != "Server") and ("this game will expire in" in row.target_text.lower()) and ( row.distance <= 3 ) ) or ( (any( x in row.source_text.lower() for x in (opinionWords + ["done"])) ) and endedtheirturn(row.target_text) and ( row.distance <= 9 ) ) or ( (any( x in row.source_text.lower() for x in ["start", "sit", "ready"]) ) and gamestarted(row.target_text) and ( row.distance <= 6 ) ) ): l=1 else: l=0 return l |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #1 -- get dialogues finals = [] dialogues = cands.dialogue_num.drop_duplicates() for d in tqdm(dialogues): # 2 -- get segment list seg_list = get_seg_list(cands[cands.dialogue_num == d]) # 3 -- create seg pairs list seg_pairs = [] for i, s in enumerate(seg_list): for n in [j for j in reversed(range((i+1)-20, i+1)) if j>=0]: try: seg_pairs.append((seg_list[n], seg_list[i+1])) except IndexError: pass # 4 -- for each pair, pull row and append rules for s in seg_pairs: row = cands[(cands.source_id == s[0]) & (cands.target_id == s[1])] if row.empty: continue else: r_index = row.index[0] row = row.iloc[0] # make sure that if any backwards links exist they are also 0 backwards = cands[(cands.source_id == s[1]) & (cands.target_id == s[0])] if backwards.shape[0] > 0: b_index = backwards.index[0] finals.append((b_index, -1)) #we only look at ling --> ling cases if row.source_type != 'Segment' or row.target_type != 'NonplayerSegment': link = 0 else: link_one = LF_Result_L_NL(row) if link_one: link = 1 else: link = 0 finals.append((r_index, link)) |
1 2 3 4 5 6 7 8 | def LF_Result_NL_L(row): #non-ling --> ling if ("type *addtime* to extend this game another" in row.source_text.lower()) \ and ("addtime" in row.target_text.lower()): l=1 else: l=0 return l |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #1 -- get dialogues finals = [] dialogues = cands.dialogue_num.drop_duplicates() for d in tqdm(dialogues): # 2 -- get segment list seg_list = get_seg_list(cands[cands.dialogue_num == d]) # 3 -- create seg pairs list seg_pairs = [] for i, s in enumerate(seg_list): for n in [j for j in reversed(range((i+1)-20, i+1)) if j>=0]: try: seg_pairs.append((seg_list[n], seg_list[i+1])) except IndexError: pass # 4 -- for each pair, pull row and append rules for s in seg_pairs: row = cands[(cands.source_id == s[0]) & (cands.target_id == s[1])] if row.empty: continue else: r_index = row.index[0] row = row.iloc[0] # make sure that if any backwards links exist they are also 0 backwards = cands[(cands.source_id == s[1]) & (cands.target_id == s[0])] if backwards.shape[0] > 0: b_index = backwards.index[0] finals.append((b_index, -1)) #we only look at ling --> ling cases if row.source_type != 'NonplayerSegment' or row.target_type != 'Segment': link = 0 else: link_one = LF_Result_NL_L(row) if link_one: link = 1 else: link = 0 finals.append((r_index, link)) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | def LF_Res_NL_NL_case1(row): l=0 if (endedtheirturn(row.source_text) and itsXsTurnToRollTheDice(row.target_text)) \ or (itsXsTurnToRollTheDice(row.source_text) and rolled(row.target_text)) \ or (willMoveTheRobber(row.source_text) and (stoleAResourceFrom(row.target_text) or movedRobber(row.target_text))) \ or (needsToDiscard(row.source_text) and discardedXresources(row.target_text)) \ or (rolled(row.source_text) and (get(row.target_text) or needsToDiscard(row.target_text) or noplayergetsanyt(row.target_text) or willMoveTheRobber(row.target_text))) \ or (XplayedAPCard(row.source_text) and (movedRobber(row.target_text) or willMoveTheRobber(row.target_text) or received(row.target_text))) \ or (itsXsTurnToBuildP(row.source_text) and XBuiltaP(row.target_text)) \ or (discardedXresources(row.source_text) and (movedRobber(row.target_text) or willMoveTheRobber(row.target_text))) \ or (movedRobber(row.source_text) and stoleAResourceFrom(row.target_text)) \ or (traded(row.source_text) and XBuiltaP(row.target_text)) \ or (XBuiltaP(row.source_text) and itsXsTurnToBuildP(row.source_text)): l=1 return l def LF_Res_NL_NL_case2(row): #dealing with CDUs l=0 if noplayergetsanyt(row.source_text) and has_resources(row.target_text) and is_head(cands, row.target_turn_id, row.target_span_end, "target"): l=1 elif get(row.source_text) and has_resources(row.target_text) and is_head(cands, row.source_turn_id, row.source_span_end) \ and is_head(cands, row.target_turn_id, row.target_span_end, "target"): l=1 return l |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | #1 -- get dialogues finals = [] dialogues = cands.dialogue_num.drop_duplicates() for d in tqdm(dialogues): memo_source = [] memo_target = [] # 2 -- get segment list seg_list = get_seg_list(cands[cands.dialogue_num == d]) # 3 -- create seg pairs list seg_pairs = [] for i, s in enumerate(seg_list): for n in [j for j in reversed(range((i+1)-20, i+1)) if j>=0]: try: seg_pairs.append((seg_list[n], seg_list[i+1])) except IndexError: pass # 4 -- for each pair, pull row and append rules for s in seg_pairs: row = cands[(cands.source_id == s[0]) & (cands.target_id == s[1])] if row.empty: continue else: r_index = row.index[0] row = row.iloc[0] # make sure that if any backwards links exist they are also 0 backwards = cands[(cands.source_id == s[1]) & (cands.target_id == s[0])] if backwards.shape[0] > 0: b_index = backwards.index[0] finals.append((b_index, -1)) #we only look at ling --> ling cases if row.source_type != 'NonplayerSegment' or row.target_type != 'NonplayerSegment': link = 0 else: if LF_Res_NL_NL_case2(row) or LF_Res_NL_NL_case1(row): #if LF_Res_NL_NL_case2(row) or LF_Res_NL_NL_case1(row): if row.target_id in memo_target or row.source_id in memo_source: link = 0 else: link = 1 memo_target.append(row.target_id) memo_source.append(row.source_id) else: link = 0 finals.append((r_index, link)) |