<commit_before>#! /usr/bin/env python3
#
# Extract, add features to, and supervise mentions extracted from geneRifs.
# Print a big warning if we don't find a mention contained the labelled gene.
#

import fileinput
import json
import sys

from dstruct.Sentence import Sentence
from extract_gene_mentions import extract, add_features

def main():
    # Process the input
    with fileinput.input() as input_files:
        for line in input_files:
            line_dict = json.loads(line)
            sentence = Sentence(line_dict["doc_id"], line_dict["sent_id"],
                    line_dict["wordidxs"], line_dict["words"],
                    line_dict["poses"], line_dict["ners"], line_dict["lemmas"],
                    line_dict["dep_paths"], line_dict["dep_parents"],
                    line_dict["bounding_boxes"])
            # This is the 'labelled' gene that we know is in the sentence
            gene = line_dict["gene"]
            found_gene = False
            # Extract mentions from sentence
            for mention in extract(sentence):
                add_features(mention)
                # Check whether this mention contains the 'labelled' gene
                # XXX (Matteo) is this the right check?
                if mention.entity.find(gene) > -1: 
                    found_gene = True
                    mention.is_correct = True
                print(mention.json_dump())
            # Print big warning if we did not find the 'labelled' gene
            # and exit with failure code!
            if not found_gene:
                sys.stderr.err("WARNING: Not found mention of '{}' in geneRifs {} ('{}')\n".format(gene, line_dict["doc_id"], " ".join(line_dict["words"])))
                return 1
    return 0

if __name__ == "__main__":
    sys.exit(main())
<commit_msg>Comment out exiting with error<commit_after>#! /usr/bin/env python3
#
# Extract, add features to, and supervise mentions extracted from geneRifs.
# Print a big warning if we don't find a mention contained the labelled gene.
#

import fileinput
import json
import sys

from dstruct.Sentence import Sentence
from extract_gene_mentions import extract, add_features

def main():
    # Process the input
    with fileinput.input() as input_files:
        for line in input_files:
            line_dict = json.loads(line)
            sentence = Sentence(line_dict["doc_id"], line_dict["sent_id"],
                    line_dict["wordidxs"], line_dict["words"],
                    line_dict["poses"], line_dict["ners"], line_dict["lemmas"],
                    line_dict["dep_paths"], line_dict["dep_parents"],
                    line_dict["bounding_boxes"])
            # This is the 'labelled' gene that we know is in the sentence
            gene = line_dict["gene"]
            found_gene = False
            # Extract mentions from sentence
            for mention in extract(sentence):
                add_features(mention)
                # Check whether this mention contains the 'labelled' gene
                # XXX (Matteo) is this the right check?
                if mention.entity.find(gene) > -1: 
                    found_gene = True
                    mention.is_correct = True
                print(mention.json_dump())
            # Print big warning if we did not find the 'labelled' gene
            #if not found_gene:
            #    sys.stderr.err("WARNING: Not found mention of '{}' in geneRifs {} ('{}')\n".format(gene, line_dict["doc_id"], " ".join(line_dict["words"])))
    return 0

if __name__ == "__main__":
    sys.exit(main())

{'fraction_non_alphanumeric': 0.09831460674157304, 'fraction_numerical': 0.001966292134831461, 'mean_word_length': 2.1823056300268098, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5303812', 'n_tokens_mistral': 1003, 'n_tokens_neox': 936, 'n_words': 303}