/*
 * SDK Pullenti Lingvo, version 4.33, fabruary 2026. Copyright (c) 2013-2026, Pullenti. All rights reserved. 
 * Non-Commercial Freeware and Commercial Software.
 * This class is generated using the converter Unisharping (www.unisharping.ru) from Pullenti C# project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */

package com.pullenti.ner.chemical;

/**
 * Анализатор химических формул (специфический анализатор)
 */
public class ChemicalAnalyzer extends com.pullenti.ner.Analyzer {

    /**
     * Имя анализатора ("CHEMICAL")
     */
    public static final String ANALYZER_NAME = "CHEMICAL";

    @Override
    public String getName() {
        return ANALYZER_NAME;
    }


    @Override
    public String getCaption() {
        return "Химические формулы";
    }


    @Override
    public String getDescription() {
        return "Химические формулы и их текстовые аналоги";
    }


    @Override
    public com.pullenti.ner.Analyzer clone() {
        return new ChemicalAnalyzer();
    }

    @Override
    public boolean isSpecific() {
        return true;
    }


    @Override
    public java.util.Collection<com.pullenti.ner.metadata.ReferentClass> getTypeSystem() {
        return java.util.Arrays.asList(new com.pullenti.ner.metadata.ReferentClass[] {MetaChemical.GLOBALMETA});
    }


    @Override
    public java.util.HashMap<String, byte[]> getImages() {
        java.util.HashMap<String, byte[]> res = new java.util.HashMap<String, byte[]>();
        res.put(MetaChemical.IMAGEID.toString(), com.pullenti.ner.core.internal.ResourceHelper3.getBytes("chemical.png"));
        return res;
    }


    @Override
    public com.pullenti.ner.Referent createReferent(String type) {
        if (com.pullenti.unisharp.Utils.stringsEq(type, ChemicalFormulaReferent.OBJ_TYPENAME)) 
            return new ChemicalFormulaReferent();
        return null;
    }

    @Override
    public int getProgressWeight() {
        return 1;
    }


    @Override
    public void process(com.pullenti.ner.core.AnalysisKit kit) {
        com.pullenti.ner.core.AnalyzerData ad = kit.getAnalyzerData(this);
        java.util.ArrayList<java.util.ArrayList<com.pullenti.ner.chemical.internal.ChemicalToken>> probs = new java.util.ArrayList<java.util.ArrayList<com.pullenti.ner.chemical.internal.ChemicalToken>>();
        for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
            java.util.ArrayList<com.pullenti.ner.chemical.internal.ChemicalToken> li = com.pullenti.ner.chemical.internal.ChemicalToken.tryParseList(t, 0);
            if (li == null || li.size() == 0) 
                continue;
            t = li.get(li.size() - 1).getEndToken();
            ChemicalFormulaReferent cf = com.pullenti.ner.chemical.internal.ChemicalToken.createReferent(li);
            if (cf == null) {
                probs.add(li);
                continue;
            }
            cf = (ChemicalFormulaReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(cf), ChemicalFormulaReferent.class);
            com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(cf, li.get(0).getBeginToken(), t, null);
            kit.embedToken(rt);
            t = rt;
        }
        for (java.util.ArrayList<com.pullenti.ner.chemical.internal.ChemicalToken> pr : probs) {
            ChemicalFormulaReferent cf = com.pullenti.ner.chemical.internal.ChemicalToken.createReferent(pr);
            if (cf == null) 
                continue;
            cf = (ChemicalFormulaReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(cf), ChemicalFormulaReferent.class);
            com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(cf, pr.get(0).getBeginToken(), pr.get(pr.size() - 1).getEndToken(), null);
            kit.embedToken(rt);
        }
    }

    public static void initialize() {
        MetaChemical.initialize();
        com.pullenti.ner.chemical.internal.ChemicalToken.initialize();
        com.pullenti.ner.ProcessorService.registerAnalyzer(new ChemicalAnalyzer());
    }
    public ChemicalAnalyzer() {
        super();
    }
}
