Skip to content

Tweet Event Type Identification

oana-inel edited this page Nov 2, 2015 · 5 revisions

In this template the goal is to find the related/relevant topic (from a known list) for the given tweet.

Input for the crowdsourcing task:

The input consists of English tweets and a list of 9 event types that have a high probability to be referred to in the tweets. The list of event types is the following:

  • [Davos_world_economic_forum_2014]
  • [2014_anti-China_protests_in_Vietnam]
  • [Islands_disputed_between_China_and_Japan]
  • [FIFA_worldcup_2014]
  • [Korean_MV_Sewol_ferry_sinking]
  • [Japan_whaling_and_dolphin_hunting]
  • [Disappearance_of_Malaysia_Airlines_Flight_370]
  • [Ukraine_crisis_2014]
  • [NONE OF THE ABOVE]

Annotation setting

The crowd receives a tweet and the list of 8 event types aforementioned + the option “NONE”. First, the crowd is asked to select all the events that are referred to in the tweet. Second, the crowd is asked to highlight all the word phrases in the tweet that refer to the selected event(s) and link the highlighted word phrases with the selected event types (in case multiple events are selected). If none of the events are referred to in the tweets, the workers can choose an 9th option, “NONE”. In this case they are not requested to highlight any word phrase in the tweet but type in “N/A”.

Result vector

The result of each worker on a tweet is represented as follows:

  • tweet event type vector: for the given event types, we construct a vector having a dimension of 9 (the event types + option “none”)
  • tweet - event type word vector: in order to capture the tweet words that refer to the selected event we construct a vector having the dimension equal to the number of words in the tweet, for each event type that was selected

Possible adaptations of this template

This template could be executed in other versions as well: (1) with a different list of events/topics, (2) without linking the highlighted words with the event/topic, (3) with the option "OTHER TOPIC" and a text field where the workers can provide the topic of the tweet.

Screenshot

Code

<div class='eventextraction'>
<p>Which of the following EVENTS can you identify in this TEXT:</p>
  <fieldset>
    <div class="passage" id="passage">{{tweet}}</div>
  </fieldset>
<p></p>
<br />
  
<cml:checkboxes label="STEP 1: Select all the EVENT(s) that relate to the TEXT above:" class="" name="event" instructions="To understand what the different events are CLICK on each EVENT to open its Wikipedia article. To proceed to Step 2 you need to make at least one selection in Step 1." validates="required">
  <cml:checkbox  label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/World_Economic_Forum"&gt;Davos world economic forum 2014&lt;/a&gt;] ' value="[Davos_world_economic_forum_2014]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/Senkaku_Islands"&gt;Islands disputed between China and Japan&lt;/a&gt; ] ' value="[Islands_disputed_between_China_and_Japan]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/2014_FIFA_World_Cup"&gt;FIFA worldcup 2014&lt;/a&gt; ] ' value="[FIFA_worldcup_2014]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/Sinking_of_the_MV_Sewol"&gt;Korean MV Sewol ferry sinking&lt;/a&gt; ] ' value="[Korean_MV_Sewol_ferry_sinking]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/Whaling_in_Japan"&gt;Japan whaling and dolphin hunting&lt;/a&gt; ] ' value="[Japan_whaling_and_dolphin_hunting]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/Malaysia_Airlines_Flight_370"&gt;Disappearence of Malaysia Airlines Flight 370&lt;/a&gt; ] ' value="[Disappearance_of_Malaysia_Airlines_Flight_370]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/2014_Vietnam_anti-China_protests"&gt;2014 anti-China protests in Vietnam&lt;/a&gt; ] ' value="[2014_anti-China_protests_in_Vietnam]" />
  <cml:checkbox label='[&lt;a target="_blank" href="http://en.wikipedia.org/wiki/Ukrainian_crisis"&gt;Ukraine crisis 2014&lt;/a&gt; ] ' value="[Ukraine_crisis_2014]" />
  <cml:checkbox label='[NONE OF THE ABOVE EVENTS ARE REFERRED TO IN THE TEXT]' value="[NONE]" />
</cml:checkboxes>

  <cml:group class="needsHighlight" only-if="event:[[NONE]]++(event:[[Davos_world_economic_forum_2014]]||event:[[2014_anti-China_protests_in_Vietnam]]||event:[[Ukraine_crisis_2014]]||event:[[Islands_disputed_between_China_and_Japan]]||event:[[FIFA_worldcup_2014]]||event:[[Korean_MV_Sewol_ferry_sinking]]||event:[[Japan_whaling_and_dolphin_hunting]]||event:[[Disappearance_of_Malaysia_Airlines_Flight_370]])||(!event:[[NONE]]++(event:[[Davos_world_economic_forum_2014]]||event:[[Islands_disputed_between_China_and_Japan]]||event:[[FIFA_worldcup_2014]]||event:[[Korean_MV_Sewol_ferry_sinking]]||event:[[Japan_whaling_and_dolphin_hunting]]||event:[[Disappearance_of_Malaysia_Airlines_Flight_370]]||event:[[2014_anti-China_protests_in_Vietnam]]||event:[[Ukraine_crisis_2014]]))">
  <cml:hidden name='ev0a' class='ev0a' />
  <cml:hidden name='ev1a' class='ev1a' />
  <cml:hidden name='ev2a' class='ev2a' />
  <cml:hidden name='ev3a' class='ev3a' />
  <cml:hidden name='ev4a' class='ev4a' />
  <cml:hidden name='ev5a' class='ev5a' />
  <cml:hidden name='ev6a' class='ev6a' />
  <cml:hidden name='ev7a' class='ev7a' />
  <cml:hidden name='ev8a' class='ev8a' />
  <cml:hidden name='ev9a' class='ev9a' />
  <cml:hidden name='ev10a' class='ev10a' />
  <cml:hidden name='ev11a' class='ev11a' />
  <cml:hidden name='ev12a' class='ev12a' />
  <cml:hidden name='ev13a' class='ev13a' />
  <cml:hidden name='ev14a' class='ev14a' />

    <cml:group class='highlightWords' label="STEP 2: Highlight words in the TEXT that relate to the EVENT(s) you selected in STEP1" instructions="You can remove a highlighted WORD PHRASE by clicking the Remove button next to it. You can select up to 15 words and phrases that refer to the selected EVENTS(s). DO NOT copy the whole TEXT.">
  <div id='opinion0' class='opinion'><span class='term event0term'></span><cml:select id='event0' name='event0' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove0' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion1' class='opinion'><span class='term event1term'></span><cml:select id='event1' name='event1' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove1' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion2' class='opinion'><span class='term event2term'></span><cml:select id='event2' name='event2' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove2' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion3' class='opinion'><span class='term event3term'></span><cml:select id='event3' name='event3' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove3' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion4' class='opinion'><span class='term event4term'></span><cml:select id='event4' name='event4' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove4' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion5' class='opinion'><span class='term event5term'></span><cml:select id='event5' name='event5' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove5' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion6' class='opinion'><span class='term event6term'></span><cml:select id='event6' name='event6' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove6' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion7' class='opinion'><span class='term event7term'></span><cml:select id='event7' name='event7' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove7' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion8' class='opinion'><span class='term event8term'></span><cml:select id='event8' name='event8' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove8' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove</span><div style='clear:both;'></div></div>
  <div id='opinion9' class='opinion'><span class='term event9term'></span><cml:select id='event9' name='event9' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove9' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove </span><div style='clear:both;'></div></div>
  <div id='opinion10' class='opinion'><span class='term event10term'></span><cml:select id='event10' name='event10' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove10' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove </span><div style='clear:both;'></div></div>
  <div id='opinion11' class='opinion'><span class='term event11term'></span><cml:select id='event11' name='event11' class='event' validates='required' default='CHOOSE EVENT TYPE'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove11' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove </span><div style='clear:both;'></div></div>  
  <div id='opinion12' class='opinion'><span class='term event12term'></span><cml:select id='event12' name='event12' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove12' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove </span><div style='clear:both;'></div></div>
  <div id='opinion13' class='opinion'><span class='term event13term'></span><cml:select id='event13' name='event13' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove13' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove </span><div style='clear:both;'></div></div>
  <div id='opinion14' class='opinion'><span class='term event14term'></span><cml:select id='event14' name='event14' class='event' validates='required' default='CHOOSE the related EVENT'><cml:option value='[Davos_world_economic_forum_2014]' label='Davos world economic forum 2014' /><cml:option value='[Islands_disputed_between_China_and_Japan]' label='Islands disputed between China and Japan' /><cml:option value='[FIFA_worldcup_2014]' label='FIFA worldcup 2014' /><cml:option value='[Korean_MV_Sewol_ferry_sinking]' label='Korean MV Sewol ferry sinking' /><cml:option value='[Japan_whaling_and_dolphin_hunting]' label='Japan whaling and dolphin hunting' /><cml:option value='[Disappearance_of_Malaysia_Airlines_Flight_370]' label='Disappearence of Malaysia Airlines Flight 370' /><cml:option value='[2014_anti-China_protests_in_Vietnam]' label='2014 anti-China protests in Vietnam' /><cml:option value='[Ukraine_crisis_2014]' label='Ukraine crisis 2014' /></cml:select><span id='remove14' class='btn btn-danger btn-small remove'><i class='icon-trash icon-white'></i> Remove </span><div style='clear:both;'></div></div>
  </cml:group>
</cml:group>

  <cml:text label="STEP 2: Type 'N/A' if none of the EVENTS above are referred to in the TEXT." class="noHighlightWords" name="noHighlightWords" only-if="event:[[NONE]]++!event:[[Davos_world_economic_forum_2014]]++!event:[[Islands_disputed_between_China_and_Japan]]++!event:[[FIFA_worldcup_2014]]++!event:[[Korean_MV_Sewol_ferry_sinking]]++!event:[[Japan_whaling_and_dolphin_hunting]]++!event:[[Disappearance_of_Malaysia_Airlines_Flight_370]]++!event:[[2014_anti-China_protests_in_Vietnam]]++!event:[[Ukraine_crisis_2014]]" instructions="Answer N/A if you selected [NONE] in STEP 1." validates="required"/>

  <cml:text label="Validated when all the labels are analyzed" name="checkfield" class="checkfield" validates="required"/>
</div>
.highlightterm { background-color: #b3de69; border: 1px solid #73be29; }

.passage {
  color: blue;
  font-size: large;
  font-weight: bold;
}

.cml .cml_field .instructions {
  color: #e32636;
}

.eventextraction hr { margin-top: 22px; }
.eventextraction fieldset, #example fieldset { border: 1px solid #737373; padding: 10px; margin: 0px; -webkit-border-radius: 5px;
     -moz-border-radius: 5px;
     border-radius: 5px; }
.eventextraction legend, #example legend { border: 0px; margin: 0px; padding: 0 5px 0 5px; width: auto; font-weight: inherit; font-size: inherit; line-height: inherit; letter-spacing: inherit; }
.passage { text-align:center; }

.eventextraction { -moz-user-select: none; -khtml-user-select: none; -webkit-user-select: none; user-select: none;}
.eventextraction .passage .word:hover { cursor: pointer; cursor: hand; background-color: rgba(0,0,0,.2); }

.passage .word { position:relative; display: inline-block; line-height: 32px; z-index: 5; margin: 0px; padding: 4px 6px 5px 6px; -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; }
.passage .term { position: relative; z-index: 5; margin: 0px; padding: 6px 0px 7px 0px; }

/* nested annotations are smaller than their parents */
.passage .term .term { padding: 3px 0px 4px 0px; }
.passage .term .term .term { padding: 0px 0px 1px 0px; }

.term .term:first-of-type { margin-left:1px; }
.term .term:last-of-type { margin-right:1px; }

.term .word:first-of-type { margin-left:-1px; }
.term .word:last-of-type { margin-right:-1px; }
.term span:first-of-type .word:first-of-type {margin-left:-3px;}
.term span:last-of-type .word:last-of-type {margin-right:-3px;}
.term span:first-of-type span:first-of-type .word:first-of-type {margin-left:-5px;}
.term span:last-of-type span:last-of-type .word:last-of-type {margin-right:-5px;}

.passage .term .term .term .term { padding: 0px 0px 1px 0px; margin:-1px;}

.term { -webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px; -webkit-box-shadow: inset 0px 1px 1px #fff, 0 1px 0px 0px #000;
     -moz-box-shadow: inset 0px 1px 1px #fff, 0 1px 0px 0px #000;
     box-shadow: inset 0px 1px 1px #fff, 0 1px 0px 0px #000; }

#example { position: relative; }
#example .exampleRel { text-align:center; font-size:16px; font-weight:bold; letter-spacing: 1px; line-height:14px; }
#example .term { padding-left:4px; padding-right:4px; }

.event { margin-bottom: 0px; width: inherit; }
.event .legend { display: none; }
.event .term { margin: 0 2px 0 2px; line-height:30px; padding: 4px; }

.intensity { margin-bottom: 0px; width: inherit; }
.intensity .legend { display: none; }
.opinion .term { padding: 4px; }
.opinion { margin: 2px 0 2px 0; display:none; }

.posneg { margin-bottom: 0px; width: inherit; }
.posneg .legend { display: none; }

.opinion .term, .cml_field.event, .cml_field.intensity, .cml_field.posneg, .cml_field.remove {
  float: left;
  margin: 0 2px 0 2px;
}

.hidden { display: none; }

// .opinion {display: none; }

.instructions { color: #e32636; }
.remove { margin-left: 10px; }

.highlightWords .instructions { padding-left: 16px; background-image: url("/assets/glyphicons_halflings_085_circle_info_grey.png"); background-repeat: no-repeat; background-position: 0 2px; font-size: 10pt; height: 14px; margin: 10px 0 0 0; }

.event0term { background-color: #8dd3c7; border: 1px solid #4D9387; }
.event1term { background-color: #ffffb3; border: 1px solid #BFBF73; }
.event2term { background-color: #bebada; border: 1px solid #7E7A9A; }
.event3term { background-color: #fb8072; border: 1px solid #BB4032; }
.event4term { background-color: #80b1d3; border: 1px solid #407193; }
.event5term { background-color: #fdb462; border: 1px solid #BD7422; }
.event6term { background-color: #b3de69; border: 1px solid #739E29; }
.event7term { background-color: #fccde5; border: 1px solid #BC8DA5; }
.event8term { background-color: #d9d9d9; border: 1px solid #999999; }
.event9term { background-color: #bc80bd; border: 1px solid #7C407D; }

.event10term { background-color: #ccebc5; border: 1px solid #8CAB85; }
.event11term { background-color: #ffed6f; border: 1px solid #BFAD2F; }
.event12term { background-color: #a6cee3; border: 1px solid #668EA3; }
.event13term { background-color: #7fc8b4; border: 1px solid #3F8874; }
.event14term { background-color: #b2df8a; border: 1px solid #729F4A; }
.event15term { background-color: #b3a06c; border: 1px solid #73602C; }
.event16term { background-color: #fb9a99; border: 1px solid #BB5A59; }
.event17term { background-color: #e39adc; border: 1px solid #A35A9C; }
.event18term { background-color: #fdbf6f; border: 1px solid #BD7F2F; }
.event19term { background-color: #df7f80; border: 1px solid #9F3F40; }

.event20term { background-color: #cab2d6; border: 1px solid #8A7296; }
.event21term { background-color: #aa8d9a; border: 1px solid #6A4D5A; }
.event22term { background-color: #ffff99; border: 1px solid #BFBF59; }
.event23term { background-color: #b1a9b8; border: 1px solid #716978; }
.event24term { background-color: #fbb4ae; border: 1px solid #BB746E; }
.event25term { background-color: #b3cde3; border: 1px solid #738DA3; }
.event26term { background-color: #ccebc5; border: 1px solid #8CAB85; }
.event27term { background-color: #decbe4; border: 1px solid #9E8BA4; }
.event28term { background-color: #fed9a6; border: 1px solid #BE9966; }
.event29term { background-color: #ffffcc; border: 1px solid #BFBF8C; }
require(['jquery-noconflict'], function(jQuery) {
  
  //Ensure MooTools is where it must be
  Window.implement('$', function(el, nc){
    return document.id(el, nc, this.document);
  });
  var $ = window.jQuery;
  var totalHighlights = 0;
  var selected = [];
  
  $('.checkfield').parents('.cml_field').css({'position':'absolute','z-index':'-999'});

  // Preprocess
  
  // Array with available relation slots
  // Because all fields are hardcoded, they must be re-used.
  $('.eventextraction').each(function() {
    $(this)[0].highlightWords = [];
    $(this)[0].typeId = 0; // // next unused slot
    for(i=0;i<30;i++) {
      $(this)[0].highlightWords.push(0);
    }
  });
  var color = ['#8dd3c7','#ffffb3','#bebada','#fb8072','#80b1d3','#fdb462','#b3de69','#fccde5','#d9d9d9','#bc80bd'
               ,'#ccebc5','#ffed6f','#a6cee3','#1f78b4','#b2df8a'];

  
  // remove relation function
  $('.remove').click(function() {
    var id = $(this).attr('id');
    id = id.replace('remove','');
    
    $('#opinion' + id).hide(''); // hide relation
    $('#opinion' + id).children('.term').text(''); // remove text from term
    $('#opinion' + id + ' select').prop('selectedIndex',0); // reset selections
    
    $('.ev' + id + 'a').val(""); // reset hidden term range
    $('.passage').find('.event' + id + 'term').replaceWith(function() { // remove terms from passages
      return $(this).contents();
    });
    
    // remove any partial selections to maintain color usage
    $('.passage').find('#selection').replaceWith(function() {
      return $(this).contents();
    });
    
    $('.eventextraction')[0].highlightWords[id] = 0;
    $('.eventextraction')[0].typeId = jQuery.inArray(0,$('.eventextraction')[0].highlightWords); // get next unused relation slot

    totalHighlights --;
    
 //   alert(selected.join());
 //   alert($('.checkfield').val());
    if (selected.length == 1 && selected.indexOf('[NONE]') > -1) {
        $('.checkfield').val("done");
    }
    else if (selected.length == 0){
        $('.checkfield').val("");
    }
    else {
      if (totalHighlights == 0)
        $('.checkfield').val("");
      else
        $('.checkfield').val("done"); 
    }
  });
  
  // split passages
  $(".eventextraction .passage").each(function() {
    var words = $(this).text().split(" ");
    var passage = "";
    $.each(words, function(i, v) {
     passage += "<span class='word'>" + v + "</span>";
    });
    $(this).html(passage);
  });
  
  // Highlighting functions
  // highlight term
  function highlightTerm(passage, start) {
    var id = $(passage).parents('.eventextraction')[0].typeId;
    if(!$(start).parents('#selection').length && id != -1) { // if no selection is made and maximum matches is not reached
      
      $(passage).children('#selection').contents().unwrap();
      start.wrapAll("<span class='term event" + id + "term' id='selection' />");

      $(passage).find('span:not(#selection)').bind('mouseover', function(e) {
        highlightMultiple(start, $(e.target), passage, id);
      });

    } else { // remove when click on selection
      $(passage).children('#selection').replaceWith(function() {
        return $(this).contents();
      });
    }
  }
  
  // highlight range of terms
  function highlightMultiple(start, end, passage, id) {
    // ignore margins between elements
    $(passage).find('#selection').contents().unwrap();
    if(start.is(end)) { // single element
      $(start).wrapAll("<span class='term event" + id + "term' id='selection'/>");
    } else { // if range of elements
      if($(passage).find('span').index(start) > $(passage).find('span').index(end)) { // swap if end is before start
        var temp = end;
        end = start;
        start = temp;
      }
      
      
      if(!start.parent().not($('#selection')).is(end.parent().not($('#selection')))) {
        // common parent element
        var common = end.parents().not($('#selection')).has(start).first();
        
        if(start.parent('.term').not(common).length) { // if word has a parent term
          start = $(common).children().has(start);
          // $(start).parent('.term');
        }
        
        if(end.parent('.term').not(common).length) {
          end = $(common).children().has(end);
          //end = $(end).parent('.term');
        }
      }
      // highlight range
      $(start).nextUntil(end.next()).andSelf().wrapAll("<span class='term event" + id + "term' id='selection' />");
    }
  }

  
  // get word range index
  function selectionIndex(passage) {
    var selection = $(passage).find('#selection .word');
    var startId = $(passage).find('.word').index(selection.first());
    if(selection.length == 1) { // single word
      return startId;
    } else { // range of words
      return startId + "-" + (startId + selection.length - 1);
    }
  }
  
  // finish selection and link terms
  function endSelection() {
    var typeId = $('.eventextraction')[0].typeId;

    // add terms in relation selection
    $('.ev' + typeId + 'a').val(selectionIndex($('.eventextraction').find('#passage')));
    $('#opinion' + typeId + ' .term').text($('#passage #selection .word').not(":last").append(" ").end().text());
    $('#opinion' + typeId).slideDown();
       
    $('.event option').each(function() {
      if ( selected.indexOf($(this).val()) == -1 ) {
        $(this).hide();
      }
      else {
        $(this).show();
        if (selected.length == 1 || (selected.length == 2 && selected.indexOf('[NONE]') > -1)) {
          $(this).attr("selected", "selected");
        }
        else {
          $(this).removeAttr("selected");
        }
      }
    });
    
    // remove selection ids
    $('#selection').removeAttr('id');

    // set relation slot as occupied; find next slot;
    $('.eventextraction')[0].highlightWords[typeId] = 1;
    $('.eventextraction')[0].typeId = jQuery.inArray(0,$('.eventextraction')[0].highlightWords);  // next unused slot
  
    totalHighlights ++;
    
    if (selected.length == 1 && selected.indexOf('[NONE]') > -1) {
        $('.checkfield').val("done");
    }
    else if (selected.length == 0){
        $('.checkfield').val("");
    }
    else {
      if (totalHighlights == 0)
        $('.checkfield').val("");
      else
        $('.checkfield').val("done"); 
    }
    
  }
    
  $('body').on('click', 'input.event', function() {
    selected = [];
    $("input.event:checked").each(function() {
      selected.push($(this).val());
    });
    $('.event option').each(function() {
         //  alert($(this).val());
      if ( selected.indexOf($(this).val()) == -1 ) {
        $(this).hide();
      }
      else {
        $(this).show();
        if (selected.length == 1 || (selected.length == 2 && selected.indexOf('[NONE]') > -1)) {
          $(this).attr("selected", "selected");
        }
        else {
          $(this).removeAttr("selected");
        }
      }
         });
    if ((selected.length == 0) || (selected.length == 1 && selected.indexOf('[NONE]') > -1)) {
      $( "span.remove" ).each(function( index ) {
        var id = $(this).attr('id');
        id = id.replace('remove','');
        $('#opinion' + id).hide(''); // hide relation
        $('#opinion' + id).children('.term').text(''); // remove text from term
        $('#opinion' + id + ' select').prop('selectedIndex',0); // reset selections
        
        $('.ev' + id + 'a').val(""); // reset hidden term range
        $('.passage').find('.event' + id + 'term').replaceWith(function() { // remove terms from passages
          return $(this).contents();
        });
        
        $('.eventextraction')[0].highlightWords[id] = 0;
        $('.eventextraction')[0].typeId = jQuery.inArray(0,$('.eventextraction')[0].highlightWords); // get next unused relation slot
        totalHighlights --;
        
        if (selected.length == 1 && selected.indexOf('[NONE]') > -1) {
        $('.checkfield').val("done");
    }
    else if (selected.length == 0){
        $('.checkfield').val("");
    }
    else {
      if (totalHighlights == 0)
        $('.checkfield').val("");
      else
        $('.checkfield').val("done"); 
    }
    
      });
    }
  });
           
  $(".passage span:not(#selection)").mousedown(function(e) {
    //if only NONE selected, then do not activate 
    if (totalHighlights < 15)
    if (selected.length != 0) 
      if ((selected.length == 1 && selected.indexOf('[NONE]') == -1) || selected.length > 1)
        highlightTerm($(this).parents('.passage'), $(e.target));
    
  }).mouseup(function() {
    $('span').unbind('mouseover');
    if($(this).parents('.eventextraction').find('#passage #selection').length) {
      endSelection();
    }
  });
});
Clone this wiki locally