/*
 * 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 Utils = require("./../unisharp/Utils");

const GetTextAttr = require("./../ner/core/GetTextAttr");
const MiscHelper = require("./../ner/core/MiscHelper");
const ISemContainer = require("./ISemContainer");
const SemGraph = require("./SemGraph");
const SemFragmentType = require("./SemFragmentType");
const SemObjectType = require("./SemObjectType");

/**
 * Фрагмент блока (предложение)
 * 
 */
class SemFragment extends ISemContainer {
    
    constructor(blk) {
        super();
        this.m_Graph = new SemGraph();
        this.m_Higher = null;
        this.typ = SemFragmentType.UNDEFINED;
        this.isOr = false;
        this.beginToken = null;
        this.endToken = null;
        this.altFragments = new Array();
        this.rank = 0;
        this.tag = null;
        this.m_Higher = blk;
    }
    
    get graph() {
        return this.m_Graph;
    }
    
    get higher() {
        return this.m_Higher;
    }
    
    get block() {
        return this.m_Higher;
    }
    
    get rootObjects() {
        let res = new Array();
        for (const o of this.m_Graph.objects) {
            if (o.linksTo.length === 0) 
                res.push(o);
        }
        return res;
    }
    
    get canBeErrorStructure() {
        let cou = 0;
        let vcou = 0;
        for (const o of this.m_Graph.objects) {
            if (o.linksTo.length === 0) {
                if (o.typ === SemObjectType.VERB) 
                    vcou++;
                cou++;
            }
        }
        if (cou <= 1) 
            return false;
        return vcou < cou;
    }
    
    get spelling() {
        return MiscHelper.getTextValue(this.beginToken, this.endToken, GetTextAttr.KEEPREGISTER);
    }
    
    get beginChar() {
        return (this.beginToken === null ? 0 : this.beginToken.beginChar);
    }
    
    get endChar() {
        return (this.endToken === null ? 0 : this.endToken.endChar);
    }
    
    toString() {
        if (this.typ !== SemFragmentType.UNDEFINED) 
            return (String(this.typ) + ": " + (Utils.notNull(this.spelling, "?")));
        else 
            return Utils.notNull(this.spelling, "?");
    }
}


module.exports = SemFragment