<commit_before>package org.intermine.bio.dataconversion;

/*
 * Copyright (C) 2002-2009 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.io.File;
import java.io.FileReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.intermine.bio.ontology.OboParser;
import org.intermine.bio.ontology.OboRelation;
import org.intermine.bio.ontology.OboTerm;
import org.intermine.bio.ontology.OboTermSynonym;
import org.intermine.dataconversion.DataConverter;
import org.intermine.dataconversion.ItemWriter;
import org.intermine.metadata.Model;
import org.intermine.objectstore.ObjectStoreException;
import org.intermine.xml.full.Attribute;
import org.intermine.xml.full.Item;
import org.intermine.xml.full.Reference;

/**
 * Convert tree of OboTerms into Items.
 *
 * @author <NAME>
 * @see DagConverter
 */
public class OboConverter extends DataConverter
{
    private static final Logger LOG = Logger.getLogger(DataConverter.class);

    protected String dagFilename;
    protected String termClass;
    protected int uniqueId = 0;
    protected int uniqueSynId = 0;
    protected Collection<OboTerm> oboTerms;
    protected List<OboRelation> oboRelations;
    protected Map<String, Item> nameToTerm = new HashMap<String, Item>();
    protected Map<OboTermSynonym, Item> synToItem = new HashMap<OboTermSynonym, Item>();
    protected Item ontology;
    private boolean createRelations = true;
    
    /**
     * Constructor for this class.
     *
     * @param writer an ItemWriter used to handle the resultant Items
     * @param model the Model
     * @param dagFilename the name of the DAG file
     * @param dagName the title of the dag, as present in any static data
     * @param url the URL of the source of this ontology
     * @param termClass the class of the Term
     */
    public OboConverter(ItemWriter writer, Model model, String dagFilename, String dagName,
                        String url, String termClass) {
        super(writer, model);
        this.dagFilename = dagFilename;
        this.termClass = termClass;

        ontology = createItem("Ontology");
        ontology.addAttribute(new Attribute("title", dagName));
        ontology.addAttribute(new Attribute("url", url));
    }

    /**
     * Set to false to prevent storing OntologyRelation objects that include the relationship types
     * between terms.
     * @param createrelations property to parse
     */
    public void setCreaterelations(String createrelations) {
        if (createrelations.equalsIgnoreCase("true")) {
            this.createRelations = true;
        } else {
            this.createRelations = false;
        }
    }
    
    /**
     * Process every DAG term and output it as a Item.
     *
     * @throws Exception if an error occurs in processing
     */
    public void process() throws Exception {
        if (true) {
            return;
        }
        nameToTerm = new HashMap<String, Item>();
        synToItem = new HashMap<OboTermSynonym, Item>();
        OboParser parser = new OboParser();
        parser.processOntology(new FileReader(new File(dagFilename)));
        parser.processRelations(dagFilename);<commit_msg>Removed debug code.<commit_after>package org.intermine.bio.dataconversion;

/*
 * Copyright (C) 2002-2009 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.io.File;
import java.io.FileReader;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.intermine.bio.ontology.OboParser;
import org.intermine.bio.ontology.OboRelation;
import org.intermine.bio.ontology.OboTerm;
import org.intermine.bio.ontology.OboTermSynonym;
import org.intermine.dataconversion.DataConverter;
import org.intermine.dataconversion.ItemWriter;
import org.intermine.metadata.Model;
import org.intermine.objectstore.ObjectStoreException;
import org.intermine.xml.full.Attribute;
import org.intermine.xml.full.Item;
import org.intermine.xml.full.Reference;

/**
 * Convert tree of OboTerms into Items.
 *
 * @author <NAME>
 * @see DagConverter
 */
public class OboConverter extends DataConverter
{
    private static final Logger LOG = Logger.getLogger(DataConverter.class);

    protected String dagFilename;
    protected String termClass;
    protected int uniqueId = 0;
    protected int uniqueSynId = 0;
    protected Collection<OboTerm> oboTerms;
    protected List<OboRelation> oboRelations;
    protected Map<String, Item> nameToTerm = new HashMap<String, Item>();
    protected Map<OboTermSynonym, Item> synToItem = new HashMap<OboTermSynonym, Item>();
    protected Item ontology;
    private boolean createRelations = true;
    
    /**
     * Constructor for this class.
     *
     * @param writer an ItemWriter used to handle the resultant Items
     * @param model the Model
     * @param dagFilename the name of the DAG file
     * @param dagName the title of the dag, as present in any static data
     * @param url the URL of the source of this ontology
     * @param termClass the class of the Term
     */
    public OboConverter(ItemWriter writer, Model model, String dagFilename, String dagName,
                        String url, String termClass) {
        super(writer, model);
        this.dagFilename = dagFilename;
        this.termClass = termClass;

        ontology = createItem("Ontology");
        ontology.addAttribute(new Attribute("title", dagName));
        ontology.addAttribute(new Attribute("url", url));
    }

    /**
     * Set to false to prevent storing OntologyRelation objects that include the relationship types
     * between terms.
     * @param createrelations property to parse
     */
    public void setCreaterelations(String createrelations) {
        if (createrelations.equalsIgnoreCase("true")) {
            this.createRelations = true;
        } else {
            this.createRelations = false;
        }
    }
    
    /**
     * Process every DAG term and output it as a Item.
     *
     * @throws Exception if an error occurs in processing
     */
    public void process() throws Exception {
        nameToTerm = new HashMap<String, Item>();
        synToItem = new HashMap<OboTermSynonym, Item>();
        OboParser parser = new OboParser();
        parser.processOntology(new FileReader(new File(dagFilename)));
        parser.processRelations(dagFilename);
{'fraction_non_alphanumeric': 0.0878162256469904, 'fraction_numerical': 0.00319860424542018, 'mean_word_length': 3.2228360957642725, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, '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': '533511', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1885, 'n_words': 586}