<commit_before>package org.grobid.core.engines;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.grobid.core.analyzers.QuantityAnalyzer;
import org.grobid.core.data.Measurement;
import org.grobid.core.data.Quantity;
import org.grobid.core.data.Unit;
import org.grobid.core.data.Value;
import org.grobid.core.data.normalization.NormalisationException;
import org.grobid.core.data.normalization.QuantityNormaliser;
import org.grobid.core.engines.label.QuantitiesTaggingLabels;
import org.grobid.core.engines.label.TaggingLabel;
import org.grobid.core.exceptions.GrobidException;
import org.grobid.core.features.FeaturesVectorQuantities;
import org.grobid.core.layout.BoundingBox;
import org.grobid.core.layout.LayoutToken;
import org.grobid.core.lexicon.QuantityLexicon;
import org.grobid.core.tokenization.TaggingTokenCluster;
import org.grobid.core.tokenization.TaggingTokenClusteror;
import org.grobid.core.utilities.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.grobid.core.engines.label.QuantitiesTaggingLabels.*;

/**
 * Quantity/measurement extraction.
 *
 * @author <NAME>
 */
public class QuantityParser extends AbstractParser {
    private static final Logger LOGGER = LoggerFactory.getLogger(QuantityParser.class);

    private static volatile QuantityParser instance;
    private ValueParser valueParser = ValueParser.getInstance();
    private QuantifiedObjectParser quantifiedObjectParser;
    private QuantityNormaliser quantityNormaliser = new QuantityNormaliser();
//    private EnglishTokenizer tokeniser;
    private boolean disableSubstanceParser = false;

    public static QuantityParser getInstance(boolean disableSubstance) {
        if (instance == null) {
            instance = getNewInstance(disableSubstance);
        }
        return instance;
    }

    public static QuantityParser getInstance() {
        if (instance == null) {
            instance = getNewInstance(false);
        }
        return instance;
    }

    private static synchronized QuantityParser getNewInstance(boolean disableSubstanceParser) {
        QuantityParser instance = new QuantityParser();

        if (!disableSubstanceParser) {
            QuantifiedObjectParser substanceParser = QuantifiedObjectParser.getInstance();
            instance.setQuantifiedObjectParser(substanceParser);
        }
        instance.setDisableSubstanceParser(disableSubstanceParser);

        return instance;
    }

    private QuantityLexicon quantityLexicon = null;
    private MeasurementOperations measurementOperations = null;

    @Inject
    public QuantityParser() {
        super(QuantitiesModels.QUANTITIES);
        quantityLexicon = QuantityLexicon.getInstance();
        measurementOperations = new MeasurementOperations();
        instance = this;
//        this.tokeniser = new EnglishTokenizer();
    }

    public List<Measurement> process(List<LayoutToken> layoutTokens) {

        List<Measurement> measurements = new ArrayList<>();
<commit_msg>initialise the normaliser in constructor instead than in the static context<commit_after>package org.grobid.core.engines;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.grobid.core.analyzers.QuantityAnalyzer;
import org.grobid.core.data.Measurement;
import org.grobid.core.data.Quantity;
import org.grobid.core.data.Unit;
import org.grobid.core.data.Value;
import org.grobid.core.data.normalization.NormalisationException;
import org.grobid.core.data.normalization.QuantityNormaliser;
import org.grobid.core.engines.label.QuantitiesTaggingLabels;
import org.grobid.core.engines.label.TaggingLabel;
import org.grobid.core.exceptions.GrobidException;
import org.grobid.core.features.FeaturesVectorQuantities;
import org.grobid.core.layout.BoundingBox;
import org.grobid.core.layout.LayoutToken;
import org.grobid.core.lexicon.QuantityLexicon;
import org.grobid.core.tokenization.TaggingTokenCluster;
import org.grobid.core.tokenization.TaggingTokenClusteror;
import org.grobid.core.utilities.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static org.apache.commons.collections4.CollectionUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.grobid.core.engines.label.QuantitiesTaggingLabels.*;

/**
 * Quantity/measurement extraction.
 *
 * @author <NAME>
 */
public class QuantityParser extends AbstractParser {
    private static final Logger LOGGER = LoggerFactory.getLogger(QuantityParser.class);

    private static volatile QuantityParser instance;
    private ValueParser valueParser = ValueParser.getInstance();
    private QuantifiedObjectParser quantifiedObjectParser;
    private QuantityNormaliser quantityNormaliser;
    //    private EnglishTokenizer tokeniser;
    private boolean disableSubstanceParser = false;

    public static QuantityParser getInstance(boolean disableSubstance) {
        if (instance == null) {
            instance = getNewInstance(disableSubstance);
        }
        return instance;
    }

    public static QuantityParser getInstance() {
        if (instance == null) {
            instance = getNewInstance(false);
        }
        return instance;
    }

    private static synchronized QuantityParser getNewInstance(boolean disableSubstanceParser) {
        QuantityParser instance = new QuantityParser();

        if (!disableSubstanceParser) {
            QuantifiedObjectParser substanceParser = QuantifiedObjectParser.getInstance();
            instance.setQuantifiedObjectParser(substanceParser);
        }
        instance.setDisableSubstanceParser(disableSubstanceParser);

        return instance;
    }

    private QuantityLexicon quantityLexicon = null;
    private MeasurementOperations measurementOperations = null;

    @Inject
    public QuantityParser() {
        super(QuantitiesModels.QUANTITIES);
        this.quantityLexicon = QuantityLexicon.getInstance();
        this.measurementOperations = new MeasurementOperations();
//        this.tokeniser = new EnglishTokenizer();
        this.quantityNormaliser = new QuantityNormaliser();
        this.instance = this;
    }

    public List<Measurement> process(List<LayoutToken> layoutTokens) {

        List<Measurement> measurements = new ArrayList<>();

{'fraction_non_alphanumeric': 0.08642158316039135, 'fraction_numerical': 0.0017788319003854136, 'mean_word_length': 4.304245283018868, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '825087', 'n_tokens_mistral': 1843, 'n_tokens_neox': 1801, 'n_words': 359}