Skip to content

Medical Relation Extraction

Bouncer edited this page Oct 7, 2014 · 2 revisions

In this template the goal is to provide the set of relations that are expressed in a sentence between prior selected Factors.

Annotation setting

The workers are given a medical sentence with two highlighted terms (factors) in it. They are asked to select all relations (out of 11 possible) that are expressed in the sentence between the two factors. If there is no relation expressed in this sentence between the two factors they need to choose NONE. If there is a relation, but it is not on the list of 11 possible relations, they need to choose OTHER. In both cases, provide an explanation text as a verification step. The workers highlight in the sentence the exact words that express the selected relations. For this task multiple answers are allowed.

Result vector

The crowd answers are stored in a vector, which captures each selection of the crowd as following: [R1, R2, R3, R4, R5, R6, R7, R8, R9, R10, R11, NONE, OTHER, Answer-Validation-NONE, Answer-Validation-OTHER]

Possible adaptations of this template

This template could be executed in three versions, (1) with verification question, (2) without verification questions and (3) with gold sentences.

Screenshot

Code

<p>In this sentence:</p><p class="word_split"><strong><em></em></strong>{{sentence_text}}<strong><em></em></strong></p>
<p>Is<strong>&#160;

{{terms_first_text}}</strong>&#160;<em>----related-to----&#160;</em><strong>&#160;
{{terms_second_text}}?</strong></p>

<cml:checkboxes label="STEP 1: Select the valid RELATION(s)" class="" instructions="It is important that you understand what the different relation types mean. HOVER MOUSE over each relation name to see the DEFINITION and an EXAMPLE." validates="required" aggregation="avg">
	<cml:checkbox label="[TREATS]" value="[TREATS]" title="TREATS: Therapeutic use of an ingredient or a drug, e.g. penicillin cures infection, etc."/> 
	<cml:checkbox label="[PREVENTS]" value="[PREVENTS]" title="PREVENTS: Preventative use of an ingredient or a drug, e.g. vitamin C reduces the risk of influenza, etc."/> 
	<cml:checkbox label="[DIAGNOSED_BY_TEST_OR_DRUG]" value="[DIAGNOSE_BY_TEST_OR_DRUG]" title="DIAGNOSE_BY_TEST_OR_DRUG: Diagnostic use of an ingredient, test or a drug, e.g.  RINNE test is used for determining hearing loss, etc."/>
	<cml:checkbox label="[CAUSES]" value="[CAUSES]" title="CAUSES: The underlying reason for a symptom or a disease, e.g. fever induces dizziness etc."/>
	<cml:checkbox label="[LOCATION]" value="[LOCATION]" title="LOCATION: Body part or anatomical structure in which disease or disorder is observed, e.g. leukimia is found in the circulatory system, etc."/>
	<cml:checkbox label="[SYMPTOM]" value="[SYMPTOM]" title="SYMPTOM: Deviation from normal function indicating the presence of disease or abnormality, e.g. pain is a symptom of a broken arm, etc."/>
	<cml:checkbox label="[MANIFESTATION]" value="[MANIFESTATION]" title="MANIFESTATION: Links disorders to the observations (manifestations) that are closely associated with them, e.g. abdominal distension is a manifestation of liver failure."/>
	<cml:checkbox label="[CONTRAINDICATES]" value="[CONTRAINDICATES]" title="CONTRAINDICATES: A condition that indicates that drug or treatment SHOULD NOT BE USED, e.g. patients with obesity should avoid using danazol."/>
	<cml:checkbox label="[ASSOCIATED_WITH]" value="[ASSOCIATED_WITH]" title="ASSOCIATED_WITH: Signs, symptoms or findings that often appear together, e.g. patients who smoke often have yellow teeth."/> 
	<cml:checkbox label="[SIDE_EFFECT]" value="[SIDE_EFFECT]" title="SIDE_EFFECT: A secondary condition or symptom that results from a drug or treatment, e.g. use of antidepressants causes dryness in the eyes."/>
	<cml:checkbox label="[IS_A]" value="[IS_A]" title="IS_A: A relation that indicates that one of the terms is more specific variation of the other, e.g. migraine is a kind of headache."/>
	<cml:checkbox label="[PART_OF]" value="[PART_OF]" title="PART_OF: An anatomical or structural sub-component, e.g. the left ventrical is part of the heart."/>
	<cml:checkbox label="[OTHER]" value="[OTHER]" title="OTHER: The words are related, but not by any of the above relations."/>
	<cml:checkbox label="[NONE]" value="[NONE]" title="NONE: There is no relation between those words in this sentence"/> 
</cml:checkboxes>

<cml:text label="Selected relations" class="relations" name="relations" validates="required"/>
<cml:text label="STEP 2a: Highlight in the sentence ONLY the words that express the RELATION you selected in STEP1" class="highlightWords" name="step_2a_copy__paste_only_the_words_from_the_sentence_that_express_the_relation_you_selected_in_step1" instructions="Highlight ONLY the words that express the RELATION you have selected in STEP1. Answer N/A if you selected [NONE] in STEP 1. DO NOT copy the whole sentence." validates="required"/>
<cml:textarea label="STEP 2b: If you selected [NONE] in STEP 1, explain why" class="others" instructions="If you think there is a relation between those two words, but it is different than any of the relations in STEP 1, then type the relation here. If you think there is no relation between those terms, explain why do you think it is. Answer N/A if you have selected a relation in STEP 1 other than [NONE]." validates="required" default="Answer N/A if you have selected a relation in STEP 1 other than [NONE]."/>
.word_split span:hover {
    background-color:gray;
}

.cml .cml_field .instructions {
  color: #e32636;
}
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;

selectedIds = new Array();
checkboxes = new Array();
inputText = document.getElementsByClassName('relations validates-required relations validates');
inputWordsText = document.getElementsByClassName('step_2a_copy__paste_only_the_words_from_the_sentence_that_express_the_relation_you_selected_in_step1 validates-required highlightWords validates');
inputOtherText = document.getElementsByClassName('step_2b_if_you_selected_none_in_step_1_explain_why validates-required others validates');
inputElements = document.getElementsByTagName('input');
sentence = document.getElementsByClassName("word_split");
defaultMsg = inputOtherText[0].value;
  
    (function($){function injector(t,splitter,klass,after){var a=t.text().split(splitter),inject='';if(a.length){$(a).each(function(i,item){inject+='<span class="'+klass+(i+1)+'">'+item+'</span>'+after});t.empty().append(inject)}}var methods={init:function(){return this.each(function(){injector($(this),'','char','')})},words:function(){return this.each(function(){injector($(this),' ','word',' ')})},lines:function(){return this.each(function(){var r="eefec303079ad17405c889e092e105b0";injector($(this).children("br").replaceWith(r).end(),r,'line','')})}};$.fn.lettering=function(method){if(method&&methods[method]){return methods[method].apply(this,[].slice.call(arguments,1))}else if(method==='letters'||!method){return methods.init.apply(this,[].slice.call(arguments,0))}$.error('Method '+method+' does not exist on jQuery.lettering');return this}})(jQuery);
   
Array.prototype.remove = function(x) { 
    for(i in this){
        if(this[i].toString() == x.toString()){
            this.splice(i,1)
        }
    }
};
  
Array.prototype.clear = function() {
    this.splice(0, this.length);
};
  
String.prototype.trim = function () {
  return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

  $(document).ready(function(){
    $(".word_split").lettering('words');
    inputText[0].readOnly = true;
    inputWordsText[0].readOnly = true;
    var spans = $(".word_split").find("span").each(function() {
      var idNumber = $(this).attr("class").slice(4);
      $(this).attr("id", idNumber);
    });
    for (j = 0; j < inputElements.length; j++) {
      if (inputElements[j].type == 'checkbox') {
        checkboxes.push(parseInt(j));
      }
    }
    
    for(i=0; i<checkboxes.length; ++i) {
      index = checkboxes[i];
      inputElements[index].onclick=function() { 
        if(this.checked) {
          inputText[0].value += this.value + " ";
          if (this.value == "[NONE]") {
            inputWordsText[0].readOnly = false;
            inputWordsText[0].value = "";
            $('span').each(function(){ 
              if($(this ).css( "background-color","yellow" )){ 
                $(this ).css( "background-color","" ); 
                selectedIds.clear();
              } 
            }); 
          }
          else {
            if (inputText[0].value.indexOf("[NONE]") != -1) {
              inputWordsText[0].readOnly = false;
            }
            else {
              inputWordsText[0].readOnly = true;  
            }
          }
        }
        else {
          newValue = inputText[0].value.replace(this.value + " ", "");
          inputText[0].value = newValue;
          newValue = "";
          if (this.value == "[NONE]") {
            inputWordsText[0].readOnly = true;
            inputWordsText[0].value = "";
          }
          if (inputText[0].value == "") {
            inputWordsText[0].value = "";
            $('span').each(function(){ 
              if($(this ).css( "background-color","yellow" )){ 
                $(this ).css( "background-color","" ); 
                selectedIds.clear();
              } 
            }); 
          }
        }
      };
    }
  });

  inputWordsText[0].onchange = function() {
    if (inputWordsText[0].value.trim().length == 0) {
      inputWordsText[0].value = "";
    }
  };
  
  inputOtherText[0].onchange = function() {
    if (inputOtherText[0].value.trim().length == 0) {
      inputOtherText[0].value = "";
    }
    if (inputOtherText[0].value == defaultMsg) {
      inputOtherText[0].value = "";
    }
  };
  
  sentence[0].onclick = function( event ) {
    index = event.target.parentNode.id;
    if (inputText[0].value.indexOf("[NONE]") == -1 && inputText[0].value.trim().length != 0) {
      if(event.target.nodeName == "SPAN") {
        if(inputWordsText[0].readOnly == true) {
          if (event.target.style.backgroundColor == "yellow") {
            selectedIds.remove(event.target.id);
            selection = updateHighlightedWords(selectedIds);
            inputWordsText[0].value = selection;
            event.target.style.backgroundColor = "white";
          }
          else {
            selectedIds.push(parseInt(event.target.id));
            event.target.style.backgroundColor = "yellow";
            selection = updateHighlightedWords(selectedIds);
            inputWordsText[0].value = selection;
          }
        }
      }
    }
  };
    
    function updateHighlightedWords(arrayId) {
      arrayId.sort(function(a, b) {
        if (isNaN(a) || isNaN(b)) {
          if (a > b) return 1;
          else return -1;
        }
        return a - b;
      });
      
      var selection2 = "";
      for (var i = 0; i < arrayId.length; i ++) {
        var num = parseInt(arrayId[i]);
        var n = num.toString();
        selection2 += document.getElementById(n).innerHTML + " ";
      }
      
      return selection2;
    }
  
});
Clone this wiki locally