<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mskcc.cbio.oncokb.bo.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.mskcc.cbio.oncokb.bo.DrugBo;
import org.mskcc.cbio.oncokb.dao.DrugDao;
import org.mskcc.cbio.oncokb.model.Drug;

/**
 *
 * @author jgao
 */
public class DrugBoImpl extends GenericBoImpl<Drug, DrugDao> implements DrugBo {
    @Override
    public Drug findDrugByName(String drugName) {
        return getDao().findDrugByName(drugName);
    }
    
    @Override
    public List<Drug> findDrugsByNames(Collection<String> drugNames) {
        List<Drug> drugs = new ArrayList<Drug>();
        for (String drugName : drugNames) {
            Drug drug = getDao().findDrugByName(drugName);
            if (drug != null) {
                drugs.add(drug);
            }
        }
        return drugs;
    }

    @Override
    public List<Drug> findDrugsBySynonym(String synonym) {
        return getDao().findDrugBySynonym(synonym);
    }

    @Override
    public List<Drug> guessDrugs(String drugNameOrSynonym) {
        Drug drug = findDrugByName(drugNameOrSynonym);
        if (drug!=null) {
            return Collections.singletonList(drug);
        }
        
        return findDrugsBySynonym(drugNameOrSynonym);
    }

    @Override
    public Drug guessUnambiguousDrug(String drugNameOrSynonym) {
        List<Drug> drugs = guessDrugs(drugNameOrSynonym);
        if (drugs.size()==1) {
            return drugs.get(0);
        }
        
        return null;
    }

    @Override
    public List<Drug> findDrugsByAtcCode(String atcCode) {
        return getDao().findDrugByAtcCode(atcCode);
    }
}<commit_msg>Always uppercase the first letter of the drug name<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mskcc.cbio.oncokb.bo.impl;

import org.mskcc.cbio.oncokb.bo.DrugBo;
import org.mskcc.cbio.oncokb.dao.DrugDao;
import org.mskcc.cbio.oncokb.model.Drug;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * @author jgao
 */
public class DrugBoImpl extends GenericBoImpl<Drug, DrugDao> implements DrugBo {
    private String correctDrugName(String drugName) {
        // Always uppercase first letter
        if (drugName == null || drugName.length() < 2) {
            return drugName;
        }
        return drugName.substring(0, 1).toUpperCase() + drugName.substring(1);
    }

    @Override
    public Drug findDrugByName(String drugName) {
        return getDao().findDrugByName(drugName);
    }

    @Override
    public List<Drug> findDrugsByNames(Collection<String> drugNames) {
        List<Drug> drugs = new ArrayList<Drug>();
        for (String drugName : drugNames) {
            Drug drug = getDao().findDrugByName(drugName);
            if (drug != null) {
                drugs.add(drug);
            }
        }
        return drugs;
    }

    @Override
    public List<Drug> findDrugsBySynonym(String synonym) {
        return getDao().findDrugBySynonym(synonym);
    }

    @Override
    public List<Drug> guessDrugs(String drugNameOrSynonym) {
        Drug drug = findDrugByName(drugNameOrSynonym);
        if (drug != null) {
            return Collections.singletonList(drug);
        }

        return findDrugsBySynonym(drugNameOrSynonym);
    }

    @Override
    public Drug guessUnambiguousDrug(String drugNameOrSynonym) {
        List<Drug> drugs = guessDrugs(drugNameOrSynonym);
        if (drugs.size() == 1) {
            return drugs.get(0);
        }

        return null;
    }

    @Override
    public List<Drug> findDrugsByAtcCode(String atcCode) {
        return getDao().findDrugByAtcCode(atcCode);
    }

    @Override
    public void update(Drug drug) {
        if (drug != null) {
            drug.setDrugName(correctDrugName(drug.getDrugName()));
        }
        super.update(drug);
    }

    @Override
    public void save(Drug drug) {
        if (drug != null) {
            drug.setDrugName(correctDrugName(drug.getDrugName()));
        }
        super.save(drug);
    }

    @Override
    public void saveOrUpdate(Drug drug) {
        if (drug != null) {
            drug.setDrugName(correctDrugName(drug.getDrugName()));
        }
        super.saveOrUpdate(drug);
    }
}
{'fraction_non_alphanumeric': 0.10687022900763359, 'fraction_numerical': 0.001796138302649304, 'mean_word_length': 2.530110935023772, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 21, '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': '4153330', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1438, 'n_words': 283}