/*
 * 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#.NET project. 
 * The latest version of the code is available on the site www.pullenti.ru
 */


const GetTextAttr = require("./../../ner/core/GetTextAttr");
const MetaToken = require("./../../ner/MetaToken");
const TextToken = require("./../../ner/TextToken");
const TerminParseAttr = require("./../../ner/core/TerminParseAttr");
const Termin = require("./../../ner/core/Termin");
const TerminCollection = require("./../../ner/core/TerminCollection");
const MiscHelper = require("./../../ner/core/MiscHelper");
const SemAttributeType = require("./../SemAttributeType");

class AdverbToken extends MetaToken {
    
    constructor(b, e) {
        super(b, e, null);
        this.typ = SemAttributeType.UNDEFINED;
        this.not = false;
        this.m_Spelling = null;
    }
    
    get spelling() {
        if (this.m_Spelling !== null) 
            return this.m_Spelling;
        return MiscHelper.getTextValueOfMetaToken(this, GetTextAttr.NO);
    }
    set spelling(value) {
        this.m_Spelling = value;
        return value;
    }
    
    toString() {
        if (this.typ === SemAttributeType.UNDEFINED) 
            return this.spelling;
        return (String(this.typ) + ": " + (this.not ? "НЕ " : "") + this.spelling);
    }
    
    static tryParse(t) {
        if (t === null) 
            return null;
        if ((t instanceof TextToken) && t.term === "НЕ") {
            let nn = AdverbToken.tryParse(t.next);
            if (nn !== null) {
                nn.not = true;
                nn.beginToken = t;
                return nn;
            }
        }
        let t0 = t;
        let t1 = null;
        if (t.next !== null && t.morph._class.isPreposition) 
            t = t.next;
        if (t.isValue("ДРУГ", null) || t.isValue("САМ", null)) {
            t1 = t.next;
            if (t1 !== null && t1.morph._class.isPreposition) 
                t1 = t1.next;
            if (t1 !== null) {
                if (t1.isValue("ДРУГ", null) && t.isValue("ДРУГ", null)) 
                    return AdverbToken._new3775(t0, t1, SemAttributeType.EACHOTHER);
                if (t1.isValue("СЕБЯ", null) && t.isValue("САМ", null)) 
                    return AdverbToken._new3775(t0, t1, SemAttributeType.HIMELF);
            }
        }
        let tok = AdverbToken.m_Termins.tryParse(t, TerminParseAttr.NO);
        if (tok !== null) {
            let res = AdverbToken._new3775(t0, tok.endToken, SemAttributeType.of(tok.termin.tag));
            t = res.endToken.next;
            if (t !== null && t.isComma) 
                t = t.next;
            if (res.typ === SemAttributeType.LESS || res.typ === SemAttributeType.GREAT) {
                if (t !== null && t.isValue("ЧЕМ", null)) 
                    res.endToken = t;
            }
            return res;
        }
        let mc = t.getMorphClassInDictionary();
        if (mc.isAdverb) 
            return new AdverbToken(t, t);
        if (t.isValue("ВСТРЕЧА", null) && t.previous !== null && t.previous.isValue("НА", null)) {
            let ne = AdverbToken.tryParse(t.next);
            if (ne !== null && ne.typ === SemAttributeType.EACHOTHER) 
                return new AdverbToken(t.previous, t);
        }
        return null;
    }
    
    static initialize() {
        if (AdverbToken.m_Termins !== null) 
            return;
        AdverbToken.m_Termins = new TerminCollection();
        let t = null;
        t = Termin._new96("ЕЩЕ", SemAttributeType.STILL);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("УЖЕ", SemAttributeType.ALREADY);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("ВСЕ", SemAttributeType.ALL);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("ЛЮБОЙ", SemAttributeType.ANY);
        t.addVariant("ЛЮБОЙ", false);
        t.addVariant("КАЖДЫЙ", false);
        t.addVariant("ЧТО УГОДНО", false);
        t.addVariant("ВСЯКИЙ", false);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("НЕКОТОРЫЙ", SemAttributeType.SOME);
        t.addVariant("НЕКИЙ", false);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("ДРУГОЙ", SemAttributeType.OTHER);
        t.addVariant("ИНОЙ", false);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("ВЕСЬ", SemAttributeType.WHOLE);
        t.addVariant("ЦЕЛИКОМ", false);
        t.addVariant("ПОЛНОСТЬЮ", false);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("ОЧЕНЬ", SemAttributeType.VERY);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("МЕНЬШЕ", SemAttributeType.LESS);
        t.addVariant("МЕНЕЕ", false);
        t.addVariant("МЕНЕЕ", false);
        t.addVariant("МЕНЬШЕ", false);
        AdverbToken.m_Termins.add(t);
        t = Termin._new96("БОЛЬШЕ", SemAttributeType.GREAT);
        t.addVariant("БОЛЕЕ", false);
        t.addVariant("СВЫШЕ", false);
        AdverbToken.m_Termins.add(t);
    }
    
    static _new3775(_arg1, _arg2, _arg3) {
        let res = new AdverbToken(_arg1, _arg2);
        res.typ = _arg3;
        return res;
    }
    
    static static_constructor() {
        AdverbToken.m_Termins = null;
    }
}


AdverbToken.static_constructor();

module.exports = AdverbToken