{ "cells": [ { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import os\n", "from rich import print\n", "os.chdir(\"/home/p289731/NWO_FrameNet/Code/football-chains-viz\")" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "from ast import literal_eval" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
(39, 5)\n",
       "
\n" ], "text/plain": [ "\u001b[1m(\u001b[0m\u001b[1;36m39\u001b[0m, \u001b[1;36m5\u001b[0m\u001b[1m)\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
framechanged_rolesunchanged_rolesroleschanged_role
0(0, 0, Draw, draw, NOUN)[Rangers][(COMPETITION_STAGE, [from, a, tight, Anglo-Sc...[(COMPETITION_STAGE, [from, a, tight, Anglo-Sc...Changed Something
1(0, 1, Match, contest, NOUN)[][(MATCH_LOCATION, [at, Old, Trafford]), (COMPE...[(MATCH_LOCATION, [at, Old, Trafford]), (COMPE...No Changed
2(1, 0, Competition, titleholders, NOUN)[][(TEAM, [Scottish])][(TEAM, [Scottish])]No Changed
3(1, 1, Concede_Goal, conceded, VERB)[Rangers][(CONCEDING_TEAM, [they]), (GOAL, [more, goals])][(CONCEDING_TEAM, [they]), (CONCEDING_TEAM, [W...Changed Something
4(1, 2, Competition_Stage, group, NOUN)[][(COMPETITION, [UEFA, Champions, League])][(COMPETITION, [UEFA, Champions, League])]No Changed
\n", "
" ], "text/plain": [ " frame changed_roles \\\n", "0 (0, 0, Draw, draw, NOUN) [Rangers] \n", "1 (0, 1, Match, contest, NOUN) [] \n", "2 (1, 0, Competition, titleholders, NOUN) [] \n", "3 (1, 1, Concede_Goal, conceded, VERB) [Rangers] \n", "4 (1, 2, Competition_Stage, group, NOUN) [] \n", "\n", " unchanged_roles \\\n", "0 [(COMPETITION_STAGE, [from, a, tight, Anglo-Sc... \n", "1 [(MATCH_LOCATION, [at, Old, Trafford]), (COMPE... \n", "2 [(TEAM, [Scottish])] \n", "3 [(CONCEDING_TEAM, [they]), (GOAL, [more, goals])] \n", "4 [(COMPETITION, [UEFA, Champions, League])] \n", "\n", " roles changed_role \n", "0 [(COMPETITION_STAGE, [from, a, tight, Anglo-Sc... Changed Something \n", "1 [(MATCH_LOCATION, [at, Old, Trafford]), (COMPE... No Changed \n", "2 [(TEAM, [Scottish])] No Changed \n", "3 [(CONCEDING_TEAM, [they]), (CONCEDING_TEAM, [W... Changed Something \n", "4 [(COMPETITION, [UEFA, Champions, League])] No Changed " ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = pd.read_csv(\n", " \"data/2002829_mapped_roles.csv\", index_col=0, \n", " converters={\"frame\": literal_eval, \"changed_roles\": literal_eval, \"unchanged_roles\": literal_eval, \"roles\": literal_eval}\n", " )\n", "print(data.shape)\n", "data.head()" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sentence_idxframe_idxframe_nameframe_targetchanged_rolesroles
000Drawdraw[Rangers][(COMPETITION_STAGE, [from, a, tight, Anglo-Sc...
101Matchcontest[][(MATCH_LOCATION, [at, Old, Trafford]), (COMPE...
210Competitiontitleholders[][(TEAM, [Scottish])]
311Concede_Goalconceded[Rangers][(CONCEDING_TEAM, [they]), (CONCEDING_TEAM, [W...
412Competition_Stagegroup[][(COMPETITION, [UEFA, Champions, League])]
\n", "
" ], "text/plain": [ " sentence_idx frame_idx frame_name frame_target changed_roles \\\n", "0 0 0 Draw draw [Rangers] \n", "1 0 1 Match contest [] \n", "2 1 0 Competition titleholders [] \n", "3 1 1 Concede_Goal conceded [Rangers] \n", "4 1 2 Competition_Stage group [] \n", "\n", " roles \n", "0 [(COMPETITION_STAGE, [from, a, tight, Anglo-Sc... \n", "1 [(MATCH_LOCATION, [at, Old, Trafford]), (COMPE... \n", "2 [(TEAM, [Scottish])] \n", "3 [(CONCEDING_TEAM, [they]), (CONCEDING_TEAM, [W... \n", "4 [(COMPETITION, [UEFA, Champions, League])] " ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# max_roles_per_frame = \n", "data_ = (\n", " data\n", " .assign(sentence_idx=data[\"frame\"].apply(lambda frame: frame[0]))\n", " .assign(frame_idx=data[\"frame\"].apply(lambda frame: frame[1]))\n", " .assign(frame_name=data[\"frame\"].apply(lambda frame: frame[2]))\n", " .assign(frame_target=data[\"frame\"].apply(lambda frame: frame[3]))\n", " .drop(columns=[\"frame\"])\n", ")[[\"sentence_idx\", \"frame_idx\", \"frame_name\", \"frame_target\", \"changed_roles\", \"roles\"]]\n", "data_.head()\n" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "max_sent = max(data_[\"sentence_idx\"])\n", "max_frame_per_sent = data_.groupby(\"sentence_idx\").agg({\"frame_idx\": max}).reset_index()\n", "sent_to_max_frame = dict(zip(max_frame_per_sent[\"sentence_idx\"], max_frame_per_sent[\"frame_idx\"]))" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
sentence_idxframe_idxframe_nameframe_targetchanged_rolesrolestime_pointfirst_role
000Drawdraw[Rangers][(COMPETITION_STAGE, [from, a, tight, Anglo-Sc...0.000000Rangers
311Concede_Goalconceded[Rangers][(CONCEDING_TEAM, [they]), (CONCEDING_TEAM, [W...0.187500Rangers
513Bring_Offreturn[Man. United][(SUBSTITUTED_PLAYER, [Antonio, Valencia]), (T...0.229167Man. United
616Bring_Offdeparting[Man. United][(SUBSTITUTED_PLAYER, [Antonio, Valencia])]0.291667Man. United
1123Victorytriumph[Man. United][(MATCH_LOCATION, [at, Leeds, United, AFC])]0.433333Man. United
1224Deployfielding[Rangers][(COACH, [his]), (PLAYER, [of, three, central,...0.466667Rangers
1325Playerfull-backs[Rangers][(PLAYER, [Steven, Whittaker, and, Kirk, Broad...0.500000Rangers
1431Drawdraw[Man. United][(TEAM1, [United, 's]), (MATCH_LOCATION, [at, ...0.523810Man. United
1532Shotnod[Man. United][(MOVING_BALL, [Fabio, 's, right-wing, cross])...0.547619Man. United
1633Passcross[Man. United][(TARGET, [right-wing]), (PASSER, [Fabio, 's])]0.571429Man. United
1835One_On_Onetwo-on-one[Man. United, Rangers, Man. United][(MOVING_BALL, [Fabio, 's, right-wing, cross])...0.619048Man. United
2037Interveneavert[Rangers][(SHOT, [the, threat]), (INTERVENING_PLAYER, [...0.666667Rangers
2547Being_Freeisolated[Rangers][(RECIPIENT, [Kenny, Miller])]0.796296Rangers
2649Teamdefence[Man. United][(TEAM, [United, 's])]0.833333Man. United
2750Controlgot[Rangers, Man. United, Rangers][(RECIPIENT, [Kirk, Broadfoot]), (RECIPIENT, [...0.833333Rangers
2851Passcross[Rangers][(PASSER, [Steven, Naismith])]0.846154Rangers
3053Challengechallenge[Man. United][(OPPONENT_PLAYER, [Smalling])]0.871795Man. United
3154Fieldedge[Man. United][(TEAM, [United])]0.884615Man. United
3356Controllatching[Rangers][(RECIPIENT, [Kirk, Broadfoot])]0.910256Rangers
3457Shotlofted[Man. United][(TARGET, [over, the, top]), (SHOOTER, [Ryan, ...0.923077Man. United
3558Passball[Man. United][(TARGET, [over, the, top]), (PASSER, [Ryan, G...0.935897Man. United
36510Shot_Supportsshot[Man. United][(SHOOTER, [Gibson])]0.961538Man. United
37511Shotwhisker[Man. United][(TARGET, [over]), (SHOOTER, [Gibson])]0.974359Man. United
\n", "
" ], "text/plain": [ " sentence_idx frame_idx frame_name frame_target \\\n", "0 0 0 Draw draw \n", "3 1 1 Concede_Goal conceded \n", "5 1 3 Bring_Off return \n", "6 1 6 Bring_Off departing \n", "11 2 3 Victory triumph \n", "12 2 4 Deploy fielding \n", "13 2 5 Player full-backs \n", "14 3 1 Draw draw \n", "15 3 2 Shot nod \n", "16 3 3 Pass cross \n", "18 3 5 One_On_One two-on-one \n", "20 3 7 Intervene avert \n", "25 4 7 Being_Free isolated \n", "26 4 9 Team defence \n", "27 5 0 Control got \n", "28 5 1 Pass cross \n", "30 5 3 Challenge challenge \n", "31 5 4 Field edge \n", "33 5 6 Control latching \n", "34 5 7 Shot lofted \n", "35 5 8 Pass ball \n", "36 5 10 Shot_Supports shot \n", "37 5 11 Shot whisker \n", "\n", " changed_roles \\\n", "0 [Rangers] \n", "3 [Rangers] \n", "5 [Man. United] \n", "6 [Man. United] \n", "11 [Man. United] \n", "12 [Rangers] \n", "13 [Rangers] \n", "14 [Man. United] \n", "15 [Man. United] \n", "16 [Man. United] \n", "18 [Man. United, Rangers, Man. United] \n", "20 [Rangers] \n", "25 [Rangers] \n", "26 [Man. United] \n", "27 [Rangers, Man. United, Rangers] \n", "28 [Rangers] \n", "30 [Man. United] \n", "31 [Man. United] \n", "33 [Rangers] \n", "34 [Man. United] \n", "35 [Man. United] \n", "36 [Man. United] \n", "37 [Man. United] \n", "\n", " roles time_point first_role \n", "0 [(COMPETITION_STAGE, [from, a, tight, Anglo-Sc... 0.000000 Rangers \n", "3 [(CONCEDING_TEAM, [they]), (CONCEDING_TEAM, [W... 0.187500 Rangers \n", "5 [(SUBSTITUTED_PLAYER, [Antonio, Valencia]), (T... 0.229167 Man. United \n", "6 [(SUBSTITUTED_PLAYER, [Antonio, Valencia])] 0.291667 Man. United \n", "11 [(MATCH_LOCATION, [at, Leeds, United, AFC])] 0.433333 Man. United \n", "12 [(COACH, [his]), (PLAYER, [of, three, central,... 0.466667 Rangers \n", "13 [(PLAYER, [Steven, Whittaker, and, Kirk, Broad... 0.500000 Rangers \n", "14 [(TEAM1, [United, 's]), (MATCH_LOCATION, [at, ... 0.523810 Man. United \n", "15 [(MOVING_BALL, [Fabio, 's, right-wing, cross])... 0.547619 Man. United \n", "16 [(TARGET, [right-wing]), (PASSER, [Fabio, 's])] 0.571429 Man. United \n", "18 [(MOVING_BALL, [Fabio, 's, right-wing, cross])... 0.619048 Man. United \n", "20 [(SHOT, [the, threat]), (INTERVENING_PLAYER, [... 0.666667 Rangers \n", "25 [(RECIPIENT, [Kenny, Miller])] 0.796296 Rangers \n", "26 [(TEAM, [United, 's])] 0.833333 Man. United \n", "27 [(RECIPIENT, [Kirk, Broadfoot]), (RECIPIENT, [... 0.833333 Rangers \n", "28 [(PASSER, [Steven, Naismith])] 0.846154 Rangers \n", "30 [(OPPONENT_PLAYER, [Smalling])] 0.871795 Man. United \n", "31 [(TEAM, [United])] 0.884615 Man. United \n", "33 [(RECIPIENT, [Kirk, Broadfoot])] 0.910256 Rangers \n", "34 [(TARGET, [over, the, top]), (SHOOTER, [Ryan, ... 0.923077 Man. United \n", "35 [(TARGET, [over, the, top]), (PASSER, [Ryan, G... 0.935897 Man. United \n", "36 [(SHOOTER, [Gibson])] 0.961538 Man. United \n", "37 [(TARGET, [over]), (SHOOTER, [Gibson])] 0.974359 Man. United " ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_with_time = data_.assign(\n", " time_point= (data_\n", " .apply(lambda row: (row[\"sentence_idx\"] + row[\"frame_idx\"] / (sent_to_max_frame[row[\"sentence_idx\"]])) / (max_sent + 1), axis=1)\n", " )\n", ")\n", "\n", "\n", "data_with_first_roles = data_with_time.assign(\n", " first_role = data_with_time[\"changed_roles\"].apply(lambda roles: roles[0] if len(roles) > 0 else None)\n", ")\n", "\n", "data_with_first_roles.dropna(axis=0, subset=[\"first_role\"])" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Man. United 14\n", "Rangers 9\n", "Name: first_role, dtype: int64" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data_with_first_roles.dropna(axis=0, subset=[\"first_role\"])[\"first_role\"].value_counts()" ] }, { "cell_type": "code", "execution_count": 76, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'Intervene': 'Shot',\n", " 'Challenge': 'One_On_One',\n", " 'Award_Goal': 'Goal',\n", " 'Deny': 'One_On_One',\n", " 'Intercept': 'Pass',\n", " 'Shot_Supports': 'Shot',\n", " 'Save': 'Shot',\n", " 'Pass': 'Pass',\n", " 'Ball_Bounce': 'Motion',\n", " 'Mark': 'Pass',\n", " 'Goal_Kickoff': 'Shot',\n", " 'Finish': 'Shot',\n", " 'Beat': 'One_On_One',\n", " 'Offside': 'Foul',\n", " 'Bad_Pass': 'Pass',\n", " 'Goal': 'Goal',\n", " 'Set_Piece': 'Foul',\n", " 'Shot': 'Shot',\n", " 'Player_Move_With_Ball': 'Motion',\n", " 'Sanction': 'Foul',\n", " 'Move': 'Move',\n", " 'Control': 'Pass',\n", " 'Shoot_At': 'Shot',\n", " 'Start_End_Match': 'Match',\n", " 'Match': 'Match',\n", " 'Deploy': 'Lineup',\n", " 'Start': 'Lineup',\n", " 'Player_Move': 'Motion',\n", " 'Elimination': 'Match',\n", " 'Result': 'Match',\n", " 'Bring_Off': 'Substitution',\n", " 'Away_Game': 'Match',\n", " 'Possession': 'State_Of_Match',\n", " 'Pass_Combination': 'Pass',\n", " 'Lose_Ball': 'One_On_One',\n", " 'Defense_Shot': 'Mix-Up',\n", " 'Receive_Card': 'Foul',\n", " 'Victory': 'Match',\n", " 'Supply_Pass': 'Pass',\n", " 'Bring_On': 'Substitution',\n", " 'Chance': 'Chance',\n", " 'Multiple_Goals': 'Goal',\n", " 'One_On_One': 'One_On_One',\n", " 'Substitute': 'Substitution',\n", " 'Own_Goal': 'Goal',\n", " 'Convert_Chance': 'Goal',\n", " 'Ball_Land': 'Motion',\n", " 'Progression': 'Match',\n", " 'Home_Game': 'Match',\n", " 'Referee_Decision': 'Foul',\n", " 'Concede_Goal': 'Goal',\n", " 'Mistake': 'Mix-Up',\n", " 'Tactics': 'State_Of_Match',\n", " 'Foul': 'Foul',\n", " 'Being_Free': 'Pass',\n", " 'Lead': 'State_Of_Match',\n", " 'Create_Chance': 'Chance',\n", " 'Win_Compensation': 'Foul',\n", " 'Trail': 'State_Of_Match',\n", " 'Ball_Move': 'Motion',\n", " 'Defeat': 'Match',\n", " 'Dissent': 'Foul',\n", " 'Follow_Up': 'Shot',\n", " 'Score': 'State_Of_Match',\n", " 'Draw': 'Match',\n", " 'Pass_Back': 'Pass',\n", " 'Simulation': 'Foul',\n", " 'Miss_Goal': 'Shot',\n", " 'Miss_Chance': 'Chance',\n", " 'Flick_On': 'Pass',\n", " 'Ball_Escape': 'Motion',\n", " 'Give_Card': 'Foul',\n", " 'Take_On': 'One_On_One',\n", " 'Connect': 'Pass',\n", " 'Goalkeeper_Advance': 'Motion',\n", " 'Hit': 'Shot',\n", " 'Advantage': 'Foul',\n", " 'Feign': 'Shot',\n", " 'Overcome_Goalkeeper': 'Goal',\n", " 'Prepare_Goal': 'Goal',\n", " 'Ball': 'Actors',\n", " 'Spectator_Activity': 'State_Of_Match',\n", " 'Goal_Target': 'Field',\n", " 'Player': 'Actors',\n", " 'Referee': 'Actors',\n", " 'Field': 'Field',\n", " 'Team': 'Actors',\n", " 'Bench': 'Field',\n", " 'Coach': 'Actors',\n", " 'Concede_Compensation': 'Foul',\n", " 'Match_Temporal_Subdivision': 'Match',\n", " 'Confusion': 'Mix-up',\n", " 'Score_Goal': 'Goal',\n", " 'Celebrate_Goal': 'Goal',\n", " 'Suspension': 'Lineup',\n", " 'Spectators': 'Actors',\n", " 'Competition_Stage': 'Competition',\n", " 'Body_Parts': 'Actors',\n", " 'Trick': 'One_On_One',\n", " 'Competition': 'Competition',\n", " 'Stadium': 'Field',\n", " 'Match_Quality': 'State_Of_Match',\n", " 'Ball_And_Goal': 'Shot',\n", " 'Equipment': 'Actors',\n", " 'Injuries': 'Foul',\n", " '': 'Pass',\n", " 'Shot_Quality': 'Shot'}" ] }, "execution_count": 76, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from lxml import etree as ET\n", "kicktionary = ET.parse(\"kicktionary_lu_info.xml\")\n", "frame_to_scenario = {\n", " lu.attrib[\"frame\"]: lu.attrib[\"scenario\"]\n", " for lu in kicktionary.xpath(\".//LEXICAL-UNIT\") if lu.attrib[\"frame\"]\n", "}\n", "frame_to_scenario" ] } ], "metadata": { "interpreter": { "hash": "1c3e697aa4e6ae3f4f7b554c053a671f50a0156c07fd90d57948174b29e29a61" }, "kernelspec": { "display_name": "Python 3.9.7 ('perspredict')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.7" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }