/*
 * 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.core;

public class SingleNumComparer {

    public ComplexNumCompareType typ = ComplexNumCompareType.UNCOMPARABLE;

    public double rank;

    public int delta;

    public SingleNumToken first;

    public SingleNumToken second;

    public SingleNumValue val1;

    public SingleNumValue val2;

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        if (rank > 0) 
            res.append(rank).append(": ");
        res.append(first);
        if (typ == ComplexNumCompareType.UNCOMPARABLE) 
            res.append(" ?? ");
        else if (typ == ComplexNumCompareType.EQUALS) 
            res.append(" == ");
        else if (typ == ComplexNumCompareType.LESS) 
            res.append(" < ");
        else if (typ == ComplexNumCompareType.GREAT) 
            res.append(" > ");
        res.append(second);
        if (delta > 0) 
            res.append(", Delt=").append(delta);
        return res.toString();
    }

    public void process(SingleNumToken fir, SingleNumToken sec) {
        first = fir;
        second = sec;
        typ = ComplexNumCompareType.UNCOMPARABLE;
        delta = 0;
        rank = 0.0;
        val1 = null;
        val2 = null;
        for (SingleNumValue v1 : fir.vals) {
            for (SingleNumValue v2 : sec.vals) {
                if (v1.typ != v2.typ) 
                    continue;
                double _rank = 1.0;
                ComplexNumCompareType ty = ComplexNumCompareType.UNCOMPARABLE;
                int delt = 0;
                if (v1.typ == SingleNumValueType.LETTER) {
                    char ch1 = Character.toUpperCase(v1.letter);
                    char ch2 = Character.toUpperCase(v2.letter);
                    if (com.pullenti.morph.LanguageHelper.isCyrillicChar(ch1) != com.pullenti.morph.LanguageHelper.isCyrillicChar(ch2)) {
                        if (com.pullenti.morph.LanguageHelper.isCyrillicChar(ch1)) {
                            char ch11 = com.pullenti.morph.LanguageHelper.getLatForCyr(ch1);
                            if (((int)ch11) != 0) 
                                ch1 = ch11;
                            else {
                                char ch22 = com.pullenti.morph.LanguageHelper.getCyrForLat(ch2);
                                if (((int)ch22) != 0) 
                                    ch2 = ch22;
                            }
                        }
                        else {
                            char ch11 = com.pullenti.morph.LanguageHelper.getCyrForLat(ch1);
                            if (((int)ch11) != 0) 
                                ch1 = ch11;
                            else {
                                char ch22 = com.pullenti.morph.LanguageHelper.getLatForCyr(ch2);
                                if (((int)ch22) != 0) 
                                    ch2 = ch22;
                            }
                        }
                    }
                    if (((int)ch1) < ((int)ch2)) {
                        ty = ComplexNumCompareType.LESS;
                        delt = ((int)ch2) - ((int)ch1);
                        if (ch1 == 'И' && ch2 == 'К') 
                            delt = 1;
                        else if (ch1 == 'Е' && ch2 == 'Ж') 
                            delt = 1;
                    }
                    else if (((int)ch1) > ((int)ch2)) {
                        ty = ComplexNumCompareType.GREAT;
                        delt = ((int)ch1) - ((int)ch2);
                        if (ch2 == 'И' && ch1 == 'К') 
                            delt = 1;
                        else if (ch2 == 'Е' && ch1 == 'Ж') 
                            delt = 1;
                    }
                    else 
                        ty = ComplexNumCompareType.EQUALS;
                }
                else if (v1.val < v2.val) {
                    ty = ComplexNumCompareType.LESS;
                    delt = v2.val - v1.val;
                }
                else if (v1.val > v2.val) {
                    ty = ComplexNumCompareType.GREAT;
                    delt = v1.val - v2.val;
                }
                else 
                    ty = ComplexNumCompareType.EQUALS;
                if (ty == ComplexNumCompareType.GREAT) 
                    _rank /= (2.0);
                if (_rank > rank) {
                    rank = _rank;
                    typ = ty;
                    delta = delt;
                    val1 = v1;
                    val2 = v2;
                    if (delta > 1) 
                        rank *= 0.98;
                }
            }
        }
        if (fir.suffix != null && sec.suffix != null) {
            if (com.pullenti.unisharp.Utils.stringsNe(fir.suffix, sec.suffix)) 
                rank *= 0.8;
        }
        else if (fir.suffix != null || sec.suffix != null) 
            rank *= 0.9;
    }
    public SingleNumComparer() {
    }
}
