@@ -0,0 +1,2366 @@
+#! /usr/bin/env python3%0A#%0A# Perform distant supervision on gene mentions%0A#%0A# Each input row contains a mention and the sentence it is from%0A#%0A%0Aimport fileinput%0Aimport json%0A%0Afrom dstruct.Sentence import Sentence%0Afrom dstruct.Mention import Mention%0Afrom helper.dictionaries import load_dict%0A%0A# Perform the supervision%0Adef supervise(mention, sentence):%0A    # If it's a gene symbol, and not an English word, and not a medical%0A    # acronym, and not a NIH or NSF grant code, then label it as correct%0A    # XXX (Matteo) Taken from pharm%0A    mention_word = mention.words%5B0%5D.word%0A    if mention_word in genes_dict and %5C%0A        mention_word.lower() not in english_dict and %5C%0A        mention_word not in med_acrons_dict and %5C%0A        mention_word not in nih_grants_dict and%5C%0A        mention_word not in nsf_grants_dict:%0A            mention.is_correct = True%0A    # Not correct if the previous word is one of the following keywords.%0A    # XXX (Matteo) Taken from pharm%0A    prev_word = sentence.get_prev_wordobject(mention)%0A    if prev_word != None and prev_word.word.lower() in %5B'figure', 'table', 'individual', %22figures%22, %22tables%22, %22individuals%22%5D:%0A        mention.is_correct = False%0A    if frozenset(%5Bsentence.doc_id, str(sentence.sent_id), mention_word%5D) in pos_mentions_dict:%0A        mention.is_correct = True%0A    if frozenset(%5Bsentence.doc_id, str(sentence.sent_id), mention_word%5D) in neg_mentions_dict:%0A        mention.is_correct = False%0A%0A%0A# Load the dictionaries that we need%0Agenes_dict = load_dict(%22genes%22)%0Aenglish_dict = load_dict(%22english%22)%0Anih_grants_dict = load_dict(%22nih_grants%22)%0Ansf_grants_dict = load_dict(%22nsf_grants%22)%0Amed_acrons_dict = load_dict(%22med_acrons%22)%0Apos_mentions_dict = load_dict(%22pos_gene_mentions%22)%0Aneg_mentions_dict = load_dict(%22neg_gene_mentions%22)%0A%0A# Process input%0Awith fileinput.input() as input_files:%0A    for line in input_files:%0A        row = json.loads(line)%0A        sentence = Sentence(row%5B%22doc_id%22%5D, row%5B%22sent_id%22%5D, row%5B%22wordidxs%22%5D,%0A            row%5B%22sentence_words%22%5D, row%5B%22poses%22%5D, row%5B%22ners%22%5D, row%5B%22lemmas%22%5D,%0A            row%5B%22dep_paths%22%5D, row%5B%22dep_parents%22%5D, row%5B%22bounding_boxes%22%5D)%0A        mention = Mention(row%5B%22type%22%5D, row%5B%22entity%22%5D,%0A                sentence.words%5Brow%5B%22start_word_idx%22%5D:row%5B%22end_word_idx%22%5D+1%5D)%0A        # Perform supervision%0A        supervise(mention, sentence)%0A        # Print mention%0A        print(mention.json_dump())%0A%0A

Add script to supervise gene mentions