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

// Примитив, из которых состоит часть декрета (статья, пункт и часть)
public class PartToken extends com.pullenti.ner.MetaToken implements Comparable<PartToken> {

    public PartToken(com.pullenti.ner.Token begin, com.pullenti.ner.Token end) {
        super(begin, end, null);
        if(_globalInstance == null) return;
        altTyp = ItemType.UNDEFINED;
    }

    public ItemType typ = ItemType.UNDEFINED;

    public ItemType altTyp = ItemType.UNDEFINED;

    public static class PartValue extends com.pullenti.ner.MetaToken {
    
        public PartValue(com.pullenti.ner.Token begin, com.pullenti.ner.Token end) {
            super(begin, end, null);
        }
    
        public String value;
    
        public String getSourceValue() {
            com.pullenti.ner.Token t0 = getBeginToken();
            com.pullenti.ner.Token t1 = getEndToken();
            if (t1.isChar('.')) 
                t1 = t1.getPrevious();
            else if (t1.isChar(')')) {
                boolean hasBr = false;
                for (com.pullenti.ner.Token tt = t0; tt != null && (tt.getEndChar() < getEndChar()); tt = tt.getNext()) {
                    if (tt.isChar('(')) 
                        hasBr = true;
                }
                if (!hasBr) 
                    t1 = t1.getPrevious();
            }
            if (t0.getBeginChar() > t1.getBeginChar()) 
                return "";
            return (new com.pullenti.ner.MetaToken(t0, t1, null)).getSourceText();
        }
    
    
        public int getIntValue() {
            if (com.pullenti.unisharp.Utils.isNullOrEmpty(value)) 
                return 0;
            int num;
            com.pullenti.unisharp.Outargwrapper<Integer> wrapnum1345 = new com.pullenti.unisharp.Outargwrapper<Integer>();
            boolean inoutres1346 = com.pullenti.unisharp.Utils.parseInteger(value, 0, null, wrapnum1345);
            num = (wrapnum1345.value != null ? wrapnum1345.value : 0);
            if (inoutres1346) 
                return num;
            return 0;
        }
    
    
        @Override
        public String toString() {
            return value;
        }
    
        public void correctValue() {
            if ((getEndToken().getNext() instanceof com.pullenti.ner.TextToken) && ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(this.getEndToken().getNext(), com.pullenti.ner.TextToken.class)).getLengthChar() == 1 && getEndToken().getNext().chars.isLetter()) {
                if (!getEndToken().isWhitespaceAfter()) {
                    value += ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(this.getEndToken().getNext(), com.pullenti.ner.TextToken.class)).term;
                    setEndToken(this.getEndToken().getNext());
                }
                else if ((getEndToken().getWhitespacesAfterCount() < 2) && getEndToken().getNext().getNext() != null && getEndToken().getNext().getNext().isChar(')')) {
                    value += ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(this.getEndToken().getNext(), com.pullenti.ner.TextToken.class)).term;
                    setEndToken(this.getEndToken().getNext().getNext());
                }
            }
            if (((getEndToken().getWhitespacesAfterCount() < 3) && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(this.getEndToken().getNext(), false, false) && (getEndToken().getNext().getNext() instanceof com.pullenti.ner.TextToken)) && getEndToken().getNext().getNext().getLengthChar() == 1 && com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(this.getEndToken().getNext().getNext().getNext(), false, this.getEndToken().getNext(), false)) {
                value = (value + "." + ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(this.getEndToken().getNext().getNext(), com.pullenti.ner.TextToken.class)).term);
                setEndToken(this.getEndToken().getNext().getNext().getNext());
            }
            if (((getEndToken().getWhitespacesAfterCount() < 3) && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(this.getEndToken().getNext(), false, false) && (getEndToken().getNext().getNext() instanceof com.pullenti.ner.NumberToken)) && com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(this.getEndToken().getNext().getNext().getNext(), false, this.getEndToken().getNext(), false)) {
                value = (value + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(this.getEndToken().getNext().getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                setEndToken(this.getEndToken().getNext().getNext().getNext());
            }
            if ((getEndToken().getNext() instanceof com.pullenti.ner.NumberToken) && (getEndToken().getWhitespacesAfterCount() < 2) && (getEndToken().getNext().getWhitespacesAfterCount() < 2)) {
                boolean ok = false;
                com.pullenti.ner.Token tt2 = getEndToken().getNext();
                if (tt2.isNewlineAfter()) 
                    ok = true;
                else if (tt2.getNext().getReferent() instanceof com.pullenti.ner.decree.DecreeReferent) 
                    ok = true;
                else if (tt2.getNext().isCharOf("<:.")) 
                    ok = true;
                else if (tt2.getNext().isValue("ПОСЛЕ", null) || com.pullenti.ner.decree.internal.DecreeChangeToken.M_TERMS.tryParse(tt2.getNext(), com.pullenti.ner.core.TerminParseAttr.NO) != null) 
                    ok = true;
                else {
                    com.pullenti.ner.decree.internal.PartToken ne = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt2.getNext(), null, false, false);
                    if (ne != null && ne.values.size() == 1) 
                        ok = true;
                }
                if (ok) {
                    setEndToken(this.getEndToken().getNext());
                    value = (value + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(this.getEndToken(), com.pullenti.ner.NumberToken.class)).getValue());
                }
            }
            for (com.pullenti.ner.Token t = getEndToken().getNext(); t != null; t = t.getNext()) {
                if (t.isWhitespaceBefore()) {
                    if (t.getWhitespacesBeforeCount() > 1) 
                        break;
                    if (t.isChar('<')) {
                    }
                    else {
                        if (((t instanceof com.pullenti.ner.TextToken) && t.getLengthChar() == 1 && t.getNext() != null) && t.getNext().isChar(')')) {
                            value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class)).term);
                            setEndToken((t = t.getNext()));
                        }
                        break;
                    }
                }
                if (t.isCharOf("_.") && !t.isWhitespaceAfter()) {
                    if (t.getNext() instanceof com.pullenti.ner.NumberToken) {
                        value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                        setEndToken((t = t.getNext()));
                        continue;
                    }
                    if (((t.getNext() != null && t.getNext().isChar('(') && (t.getNext().getNext() instanceof com.pullenti.ner.NumberToken)) && !t.getNext().isWhitespaceAfter() && t.getNext().getNext().getNext() != null) && t.getNext().getNext().getNext().isChar(')')) {
                        value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext().getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                        setEndToken(t.getNext().getNext().getNext());
                        continue;
                    }
                }
                if (t.isCharOf("ˡ¹²³")) {
                    value = (value + "." + (t.isCharOf("ˡ¹") ? "1" : (t.isChar('²') ? "2" : "3")));
                    setEndToken(t);
                    continue;
                }
                if ((t.isHiphen() && !t.isWhitespaceAfter() && (t.getNext() instanceof com.pullenti.ner.NumberToken)) && ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getIntValue() != null) {
                    PartValue pp = _new1347(t.getNext(), t.getNext(), ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                    pp.correctValue();
                    if (com.pullenti.unisharp.Utils.stringsEq(pp.value, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue())) {
                        int n1;
                        com.pullenti.unisharp.Outargwrapper<Integer> wrapn11348 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                        com.pullenti.unisharp.Utils.parseInteger(value, 0, null, wrapn11348);
                        n1 = (wrapn11348.value != null ? wrapn11348.value : 0);
                        if (n1 == 0 || n1 >= ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getIntValue()) {
                            value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                            setEndToken((t = t.getNext()));
                            continue;
                        }
                        if (((value != null && value.indexOf('.') > 0 && (t.getPrevious() instanceof com.pullenti.ner.NumberToken)) && t.getNext().getNext() != null && t.getNext().getNext().isChar('.')) && !(t.getNext().getNext().getNext() instanceof com.pullenti.ner.NumberToken)) {
                            value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                            setEndToken((t = t.getNext().getNext()));
                            break;
                        }
                    }
                }
                if (t.isCharOf("(<") && (t.getNext() instanceof com.pullenti.ner.NumberToken) && t.getNext().getNext() != null) {
                    if (t.getNext().getNext().isCharOf(")>")) {
                        value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                        setEndToken((t = t.getNext().getNext()));
                    }
                    else if ((t.getNext().getNext().isCharOf(".-") && (t.getNext().getNext().getNext() instanceof com.pullenti.ner.NumberToken) && t.getNext().getNext().getNext().getNext() != null) && t.getNext().getNext().getNext().getNext().isCharOf(")>")) {
                        value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue() + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext().getNext().getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                        setEndToken((t = t.getNext().getNext().getNext().getNext()));
                    }
                    if (t.getNext() != null && t.getNext().isChar('.') && !t.isWhitespaceAfter()) 
                        t = t.getNext();
                    continue;
                }
                if ((t.isChar('\\') && (t.getNext() instanceof com.pullenti.ner.NumberToken) && !t.isWhitespaceBefore()) && !t.isWhitespaceAfter()) {
                    value = (((value != null ? value : "")) + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                    setEndToken((t = t.getNext()));
                    continue;
                }
                break;
            }
            if (getEndToken().getNext() != null && getEndToken().getNext().isCharOf(".") && !getEndToken().isWhitespaceAfter()) {
                if (getEndToken().getNext().getNext() != null && (((this.getEndToken().getNext().getNext().getReferent() instanceof com.pullenti.ner.decree.DecreeReferent) || this.getEndToken().getNext().getNext().isHiphen())) && !getEndToken().getNext().isNewlineAfter()) 
                    setEndToken(this.getEndToken().getNext());
            }
            if (getBeginToken() == getEndToken() && getEndToken().getNext() != null && getEndToken().getNext().isChar(')')) {
                boolean ok = true;
                int lev = 0;
                for (com.pullenti.ner.Token ttt = getBeginToken().getPrevious(); ttt != null; ttt = ttt.getPrevious()) {
                    if (ttt.isNewlineAfter()) 
                        break;
                    if (ttt.isChar(')')) 
                        lev++;
                    else if (ttt.isChar('(')) {
                        lev--;
                        if (lev < 0) {
                            ok = false;
                            break;
                        }
                    }
                }
                if (ok) {
                    com.pullenti.ner.Token tt = getEndToken().getNext().getNext();
                    if (tt != null) {
                        if ((tt.getReferent() instanceof com.pullenti.ner.decree.DecreeReferent) || com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, false) != null) 
                            setEndToken(this.getEndToken().getNext());
                    }
                }
            }
        }
    
        public static PartValue _new1053(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, String _arg3) {
            PartValue res = new PartValue(_arg1, _arg2);
            res.value = _arg3;
            return res;
        }
    
        public static PartValue _new1347(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, String _arg3) {
            PartValue res = new PartValue(_arg1, _arg2);
            res.value = _arg3;
            return res;
        }
        public PartValue() {
            super();
        }
    }


    public java.util.ArrayList<PartValue> values = new java.util.ArrayList<PartValue>();

    public com.pullenti.ner.MetaToken name;

    public java.util.ArrayList<com.pullenti.ner.MetaToken> addNames = null;

    public int ind;

    public com.pullenti.ner.decree.DecreeReferent decree;

    public boolean isDoubt;

    public boolean isConfidential;

    public boolean delimAfter;

    public boolean hasTerminator;

    public com.pullenti.ner.TextToken anaforRef;

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder(typ.toString());
        if (altTyp != ItemType.UNDEFINED) 
            res.append("/").append(altTyp.toString());
        for (PartValue v : values) {
            res.append(" ").append(v);
        }
        if (name != null) 
            res.append(" \"").append(name.getSourceText()).append("\"");
        if (delimAfter) 
            res.append(", DelimAfter");
        if (isDoubt) 
            res.append(", Doubt");
        if (hasTerminator) 
            res.append(", Terminator");
        if (isConfidential) 
            res.append(", Confidential");
        if (anaforRef != null) 
            res.append(", Ref='").append(anaforRef.term).append("'");
        if (decree != null) 
            res.append(", Decree=").append(decree.toString());
        return res.toString();
    }

    public boolean addValue(int add) {
        if (values.size() != 1) 
            return false;
        int n;
        com.pullenti.unisharp.Outargwrapper<Integer> wrapn1349 = new com.pullenti.unisharp.Outargwrapper<Integer>();
        boolean inoutres1350 = com.pullenti.unisharp.Utils.parseInteger((values.get(0).value != null ? values.get(0).value : ""), 0, null, wrapn1349);
        n = (wrapn1349.value != null ? wrapn1349.value : 0);
        if (!inoutres1350) 
            return false;
        n += add;
        values.get(0).value = ((Integer)n).toString();
        return true;
    }

    public static PartToken tryAttach(com.pullenti.ner.Token t, PartToken prev, boolean inBracket, boolean ignoreNumber) {
        if (t == null) 
            return null;
        if (t.isValue("ПРОТОКОЛ", null)) {
        }
        PartToken res = null;
        if (t.getMorph()._getClass().isPersonalPronoun() && (t.getWhitespacesAfterCount() < 2)) {
            res = tryAttach(t.getNext(), prev, false, false);
            if (res != null) {
                res.anaforRef = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class);
                res.setBeginToken(t);
                return res;
            }
        }
        if (t.kit.miscData.containsKey("partAliases")) {
            com.pullenti.ner.core.TerminCollection partAliases = (com.pullenti.ner.core.TerminCollection)com.pullenti.unisharp.Utils.cast(t.kit.miscData.get("partAliases"), com.pullenti.ner.core.TerminCollection.class);
            com.pullenti.ner.core.TerminToken atok = partAliases.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO);
            if (atok != null) {
                com.pullenti.ner.decree.DecreePartReferent dapp = (com.pullenti.ner.decree.DecreePartReferent)com.pullenti.unisharp.Utils.cast(atok.termin.tag, com.pullenti.ner.decree.DecreePartReferent.class);
                PartToken app = _new1060(t, atok.getEndToken(), ItemType.APPENDIX, t.getMorph().clone());
                if (com.pullenti.unisharp.Utils.stringsNe(dapp.getAppendix(), "0") && dapp.getAppendix() != null) 
                    app.values.add(PartValue._new1347(t, t, dapp.getAppendix()));
                return app;
            }
        }
        com.pullenti.ner.TextToken tt = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class);
        if ((t instanceof com.pullenti.ner.NumberToken) && t.getNext() != null && (t.getWhitespacesAfterCount() < 3)) {
            java.util.ArrayList<com.pullenti.ner.NumberToken> nums = new java.util.ArrayList<com.pullenti.ner.NumberToken>();
            nums.add((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class));
            com.pullenti.ner.Token tt2 = t.getNext();
            for (; tt2 != null; tt2 = tt2.getNext()) {
                if (tt2.isCommaAnd() && (tt2.getNext() instanceof com.pullenti.ner.NumberToken)) {
                    tt2 = tt2.getNext();
                    nums.add((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt2, com.pullenti.ner.NumberToken.class));
                    if (tt2.getPrevious().isAnd()) {
                        tt2 = tt2.getNext();
                        break;
                    }
                }
                else 
                    break;
            }
            PartToken re = _createPartTyp0(tt2, prev);
            if (re != null) {
                com.pullenti.ner.Token t11 = re.getEndToken().getNext();
                boolean ok1 = false;
                if (t11 != null && (t11.getReferent() instanceof com.pullenti.ner.decree.DecreeReferent)) 
                    ok1 = true;
                else if (prev != null && t11 != null && !(t11 instanceof com.pullenti.ner.NumberToken)) 
                    ok1 = true;
                else if (t.getPrevious() != null && t.getPrevious().isValue("В", null)) 
                    ok1 = true;
                else if (t11 != null) {
                    DecreeChangeToken dcc = DecreeChangeToken.tryAttach(t11, null, false, null, false, false, null, false);
                    if (dcc != null) {
                        if (dcc.changeVal != null || dcc.actKind != com.pullenti.ner.decree.DecreeChangeKind.UNDEFINED) 
                            ok1 = true;
                    }
                }
                if (!ok1) {
                    PartToken res1 = tryAttach(t11, null, false, false);
                    if (res1 != null) 
                        ok1 = true;
                }
                if (ok1 || inBracket) {
                    re.setBeginToken(t);
                    String pref = "";
                    if (re.typ == ItemType.TABLEROW && re.getEndToken().getNext() != null) {
                        if (re.getEndToken().getNext().isValue("СВЕРХУ", null)) 
                            re.setEndToken(re.getEndToken().getNext());
                        else if (re.getEndToken().getNext().isValue("СНИЗУ", null)) {
                            pref = "-";
                            re.setEndToken(re.getEndToken().getNext());
                        }
                    }
                    for (com.pullenti.ner.NumberToken n : nums) {
                        re.values.add(PartValue._new1347(n, n, pref + n.getValue()));
                    }
                    return re;
                }
            }
        }
        if (t.isValue("ПОСЛЕДНИЙ", null)) {
            PartToken re = _createPartTyp0(t.getNext(), null);
            if (re != null) {
                re.setBeginToken(t);
                re.values.add(PartValue._new1347(t, t, t.getNormalCaseText(com.pullenti.morph.MorphClass.ADJECTIVE, com.pullenti.morph.MorphNumber.SINGULAR, com.pullenti.morph.MorphGender.UNDEFINED, false)));
                return re;
            }
        }
        if (((t instanceof com.pullenti.ner.NumberToken) && ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).typ == com.pullenti.ner.NumberSpellingType.DIGIT && prev == null) && t.getPrevious() != null) {
            com.pullenti.ner.Token t0 = t.getPrevious();
            boolean delim = false;
            if (t0.isChar(',') || t0.getMorph()._getClass().isConjunction()) {
                delim = true;
                t0 = t0.getPrevious();
            }
            if (t0 == null) 
                return null;
            com.pullenti.ner.decree.DecreePartReferent dr = (com.pullenti.ner.decree.DecreePartReferent)com.pullenti.unisharp.Utils.cast(t0.getReferent(), com.pullenti.ner.decree.DecreePartReferent.class);
            if (dr == null) {
                if (t0.isChar('(') && t.getNext() != null) {
                    if (t.getNext().isValue("ЧАСТЬ", null) || t.getNext().isValue("Ч", null)) {
                        com.pullenti.ner.Token te = t.getNext();
                        if (te.getNext() != null && te.getNext().isChar('.')) 
                            te = te.getNext();
                        res = _new1058(t, te, ItemType.PART);
                        res.values.add(PartValue._new1347(t, t, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue().toString()));
                        return res;
                    }
                }
                return null;
            }
            if (dr.getClause() == null) 
                return null;
            res = _new1357(t, t, ItemType.CLAUSE, !delim);
            PartValue pv = PartValue._new1347(t, t, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue().toString());
            res.values.add(pv);
            for (t = t.getNext(); t != null; t = t.getNext()) {
                if (t.isWhitespaceBefore()) 
                    break;
                else if (t.isCharOf("._") && (t.getNext() instanceof com.pullenti.ner.NumberToken)) {
                    t = t.getNext();
                    pv.setEndToken(res.setEndToken(t));
                    pv.value = (pv.value + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue());
                }
                else 
                    break;
            }
            return res;
        }
        if (((t instanceof com.pullenti.ner.NumberToken) && ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).typ == com.pullenti.ner.NumberSpellingType.DIGIT && prev != null) && prev.typ == ItemType.PREFIX && (t.getWhitespacesBeforeCount() < 3)) {
            PartValue pv = PartValue._new1347(t, t, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue().toString());
            pv.correctValue();
            com.pullenti.ner.Token ttt1 = pv.getEndToken().getNext();
            DecreeToken ne = DecreeToken.tryAttach(ttt1, null, false);
            boolean ok = false;
            if (ne != null && ne.typ == DecreeToken.ItemType.TYP) 
                ok = true;
            else if (com.pullenti.ner.decree.DecreeAnalyzer._checkOtherTyp(ttt1, true) != null) 
                ok = true;
            else if (com.pullenti.ner.decree.DecreeAnalyzer._getDecree(ttt1) != null) 
                ok = true;
            if (ok) {
                res = _new1058(t, pv.getEndToken(), ItemType.ITEM);
                res.values.add(pv);
                return res;
            }
        }
        if (tt == null) 
            return null;
        if (tt.getLengthChar() == 1 && !tt.chars.isAllLower()) {
            if (!com.pullenti.ner.core.MiscHelper.canBeStartOfSentence(tt)) {
                if (tt.getPrevious() != null && tt.getPrevious().isValue("ДОГОВОР", null)) {
                }
                else 
                    return null;
            }
        }
        com.pullenti.ner.Token t1 = tt;
        res = _createPartTyp0(t1, prev);
        if (res != null) 
            t1 = res.getEndToken();
        else if ((t1.isValue("СИЛУ", null) || t1.isValue("СОГЛАСНО", null) || t1.isValue("СООТВЕТСТВИЕ", null)) || ((t1.isValue("ПОЛОЖЕНИЕ", null) && t1.chars.isAllLower()))) {
            if (t1.isValue("СИЛУ", null) && t1.getPrevious() != null && t1.getPrevious().getMorph()._getClass().isVerb()) 
                return null;
            if (t1.isValue("ПОЛОЖЕНИЕ", null) && prev != null && !t1.chars.isAllLower()) 
                return null;
            res = _new1058(t1, t1, ItemType.PREFIX);
            if (t1.getNext() != null && t1.getNext().isValue("С", null)) 
                res.setEndToken(t1.getNext());
            return res;
        }
        else if (((t1.isValue("УГОЛОВНОЕ", null) || t1.isValue("КРИМІНАЛЬНА", null))) && t1.getNext() != null && ((t1.getNext().isValue("ДЕЛО", null) || t1.getNext().isValue("СПРАВА", null)))) {
            t1 = t1.getNext();
            if (t1.getNext() != null && t1.getNext().isValue("ПО", null)) 
                t1 = t1.getNext();
            return _new1058(t, t1, ItemType.PREFIX);
        }
        else if ((((t1.isValue("МОТИВИРОВОЧНЫЙ", null) || t1.isValue("МОТИВУВАЛЬНИЙ", null) || t1.isValue("РЕЗОЛЮТИВНЫЙ", null)) || t1.isValue("РЕЗОЛЮТИВНИЙ", null))) && t1.getNext() != null && ((t1.getNext().isValue("ЧАСТЬ", null) || t1.getNext().isValue("ЧАСТИНА", null)))) {
            PartToken rr = _new1058(t1, t1.getNext(), ItemType.PART);
            rr.values.add(PartValue._new1347(t1, t1, (t1.isValue("МОТИВИРОВОЧНЫЙ", null) || t1.isValue("МОТИВУВАЛЬНИЙ", null) ? "мотивировочная" : "резолютивная")));
            return rr;
        }
        if (res == null) {
            boolean oo = !t.kit.miscData.containsKey("APP_PART") && ((DecreeToken.isKeyword(tt, true) != null || tt.isValue("ПРОТОКОЛ", null) || tt.isValue("ВЕДОМОСТЬ", null)));
            if (oo) {
                t.kit.miscData.put("APP_PART", true);
                com.pullenti.ner.ReferentToken rt1 = com.pullenti.ner.decree.DecreeAnalyzer.tryAttachApproved(t1, null, null, null, true);
                t.kit.miscData.remove("APP_PART");
                if (rt1 != null && rt1.referent.findSlot("TYPE", "ПРИЛОЖЕНИЕ", true) != null) {
                    com.pullenti.ner.decree.DecreeReferent dr = (com.pullenti.ner.decree.DecreeReferent)com.pullenti.unisharp.Utils.cast(rt1.referent, com.pullenti.ner.decree.DecreeReferent.class);
                    PartToken p0 = _new1058(tt, rt1.getEndToken(), ItemType.APPENDIX);
                    if (dr.getNumber() != null) 
                        p0.values.add(PartValue._new1347(tt, tt, dr.getNumber()));
                    com.pullenti.ner.Slot sl = dr.findSlot(com.pullenti.ner.decree.DecreeReferent.ATTR_NAME, null, true);
                    if (sl != null && sl.occurrence.size() > 0) 
                        p0.name = (com.pullenti.ner.MetaToken)com.pullenti.unisharp.Utils.cast(sl.occurrence.get(0).tag, com.pullenti.ner.MetaToken.class);
                    p0.decree = dr.getOwner();
                    return p0;
                }
            }
            if ((t instanceof com.pullenti.ner.TextToken) && !t.chars.isAllLower()) {
                boolean ok = false;
                if (t.isNewlineBefore()) 
                    ok = true;
                else if (t.getPrevious().isCharOf(")") || t.getPrevious().isValue("В", null)) 
                    ok = true;
                else if (prev != null && prev.getEndToken().getNext() == t) 
                    ok = true;
                if (ok && DecreeToken.isKeyword(t, false) != null) {
                    int cou = 100;
                    for (com.pullenti.ner.Token ttt = t.getNext(); ttt != null && cou > 0; ttt = ttt.getNext(),cou--) {
                        if (ttt.isNewlineBefore()) 
                            break;
                        if (ttt.isValue("УТВЕРЖДЕННЫЙ", null)) 
                            break;
                        com.pullenti.ner.Referent r = ttt.getReferent();
                        if (r != null && com.pullenti.unisharp.Utils.stringsEq(r.getTypeName(), "ORGANIZATION")) 
                            break;
                        if (ttt.isChar('(')) {
                            PartToken res1 = tryAttach(ttt.getNext(), null, false, false);
                            if (res1 != null && res1.getEndToken().getNext() != null && res1.getEndToken().getNext().isChar(')')) {
                                res1.name = new com.pullenti.ner.MetaToken(t, ttt.getPrevious(), null);
                                res1.setBeginToken(t);
                                res1.setEndToken(res1.getEndToken().getNext());
                                res1.setMorph(t.getMorph());
                                return res1;
                            }
                        }
                        com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(ttt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                        if (br != null) {
                            ttt = br.getEndToken();
                            continue;
                        }
                        if (ttt.isComma() && ttt.getNext() != null && ttt.getNext().isValue("ЯВЛЯЮЩИЙСЯ", null)) {
                            PartToken res1 = tryAttach(ttt.getNext().getNext(), null, false, false);
                            if (res1 != null && res1.typ == ItemType.APPENDIX) {
                                res1.name = new com.pullenti.ner.MetaToken(t, ttt.getPrevious(), null);
                                res1.setBeginToken(t);
                                res1.setMorph(t.getMorph());
                                return res1;
                            }
                        }
                        if ((ttt instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.TextToken.class)).term, "ПРИЛОЖЕНИЯ")) {
                            PartToken res1 = tryAttach(ttt, null, false, false);
                            if (res1 != null && res1.typ == ItemType.APPENDIX) {
                                res1.name = new com.pullenti.ner.MetaToken(t, ttt.getPrevious(), null);
                                res1.setBeginToken(t);
                                res1.setMorph(t.getMorph());
                                return res1;
                            }
                        }
                        if (ttt instanceof com.pullenti.ner.TextToken) {
                            if (((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.TextToken.class)).isPureVerb()) 
                                break;
                        }
                    }
                }
            }
            return null;
        }
        if (ignoreNumber || res.typ == ItemType.NAME || res.typ == ItemType.PREAMBLE) 
            return res;
        if (res.isNewlineAfter()) {
            if (res.chars.isAllUpper()) 
                return null;
        }
        if (t1.getNext() != null && t1.getNext().isChar('.')) {
            if (!t1.getNext().isNewlineAfter() || (t1.getLengthChar() < 3)) {
                t1 = t1.getNext();
                if (t1.getNext() != null && com.pullenti.ner.core.MiscHelper.canBeStartOfSentence(t1.getNext())) {
                    if (t1.getNext() instanceof com.pullenti.ner.TextToken) 
                        return null;
                    if ((t1.getNext() instanceof com.pullenti.ner.NumberToken) && ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext(), com.pullenti.ner.NumberToken.class)).typ == com.pullenti.ner.NumberSpellingType.WORDS) 
                        return null;
                }
            }
        }
        t1 = t1.getNext();
        if (t1 == null) 
            return null;
        if (res.typ == ItemType.CLAUSE) {
            if (((t1 instanceof com.pullenti.ner.NumberToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.NumberToken.class)).getValue(), "3") && !t1.isWhitespaceAfter()) && t1.getNext() != null && t1.getNext().getLengthChar() == 2) 
                return null;
        }
        if (res.typ == ItemType.CLAUSE && t1.isValue("СТ", null)) {
            t1 = t1.getNext();
            if (t1 != null && t1.isChar('.')) 
                t1 = t1.getNext();
        }
        else if (res.typ == ItemType.PART && t1.isValue("Ч", null)) {
            t1 = t1.getNext();
            if (t1 != null && t1.isChar('.')) 
                t1 = t1.getNext();
        }
        else if (res.typ == ItemType.ITEM && t1.isValue("П", null)) {
            t1 = t1.getNext();
            if (t1 != null && t1.isChar('.')) 
                t1 = t1.getNext();
            res.altTyp = ItemType.SUBITEM;
        }
        else if ((res.typ == ItemType.ITEM && t1.isCharOf("\\/") && t1.getNext() != null) && t1.getNext().isValue("П", null)) {
            t1 = t1.getNext().getNext();
            if (t1 != null && t1.isChar('.')) 
                t1 = t1.getNext();
            res.altTyp = ItemType.SUBITEM;
        }
        if (t1 == null) 
            return null;
        if (res.typ == ItemType.CLAUSE && (t1.getReferent() instanceof com.pullenti.ner.decree.DecreeReferent) && t1.getNext() != null) {
            res.decree = (com.pullenti.ner.decree.DecreeReferent)com.pullenti.unisharp.Utils.cast(t1.getReferent(), com.pullenti.ner.decree.DecreeReferent.class);
            t1 = t1.getNext();
        }
        com.pullenti.ner.Token ttn = com.pullenti.ner.core.MiscHelper.checkNumberPrefix(t1);
        com.pullenti.ner.TextToken firstNumPrefix = null;
        if (ttn != null) {
            firstNumPrefix = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class);
            t1 = ttn;
        }
        if (t1 == null) 
            return null;
        boolean and = false;
        com.pullenti.ner.NumberSpellingType ntyp = com.pullenti.ner.NumberSpellingType.DIGIT;
        com.pullenti.ner.Token tt1 = t1;
        while (t1 != null) {
            if (t1.getWhitespacesBeforeCount() > 20) 
                break;
            if (t1 != tt1 && t1.isNewlineBefore()) {
                if (!t1.isCommaAnd()) 
                    break;
            }
            if (t1.isNewlineBefore()) {
                if (t1.getPrevious().isCharOf(";.")) {
                    if ((t1 instanceof com.pullenti.ner.NumberToken) && t1.getNext() != null && t1.getNext().isCharOf(",;")) {
                    }
                    else 
                        break;
                }
                else {
                    com.pullenti.ner.core.ComplexNumToken nnn = com.pullenti.ner.core.ComplexNumToken.tryParse(t1, null, false, false);
                    if (nnn != null && nnn.getSuffix() != null) {
                        if (com.pullenti.unisharp.Utils.stringsEq(nnn.getSuffix(), ")") && t.getPrevious() != null && t.getPrevious().isChar('(')) {
                        }
                        else 
                            break;
                    }
                }
            }
            if (ttn != null) {
                ttn = com.pullenti.ner.core.MiscHelper.checkNumberPrefix(t1);
                if (ttn != null) 
                    t1 = ttn;
            }
            if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t1, false, false)) {
                if (res.typ == ItemType.SENTENCE) 
                    break;
                com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(t1, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                if (br == null) 
                    break;
                boolean ook = false;
                if (((res.typ == ItemType.TABLEITEM || res.typ == ItemType.TABLESUBITEM || ((res.typ == ItemType.TABLEROW && !res.getBeginToken().isValue("СТРОКА", null))))) && !(t1.getNext() instanceof com.pullenti.ner.NumberToken)) 
                    ook = true;
                else if (res.typ == ItemType.TABLEROW && res.getBeginToken().isValue("СТРОКА", null)) {
                    if (br.getEndToken().getNext() != null && br.getEndToken().getNext().isValue("ТАБЛИЦА", null)) 
                        ook = true;
                }
                if (ook) {
                    PartValue pv0 = new PartValue(t1.getNext(), (br.getEndToken() instanceof com.pullenti.ner.TextToken ? br.getEndToken().getPrevious() : br.getEndToken()));
                    pv0.value = com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(pv0, com.pullenti.ner.core.GetTextAttr.KEEPREGISTER);
                    res.values.add(pv0);
                    res.setEndToken(br.getEndToken());
                    for (t = res.getEndToken().getNext(); t != null; t = t.getNext()) {
                        if (!t.isCommaAnd()) 
                            break;
                        br = com.pullenti.ner.core.BracketHelper.tryParse(t.getNext(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
                        if (br == null) 
                            break;
                        pv0 = new PartValue(br.getBeginToken().getNext(), br.getEndToken().getPrevious());
                        pv0.value = com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(pv0, com.pullenti.ner.core.GetTextAttr.KEEPREGISTER);
                        res.values.add(pv0);
                        res.setEndToken(br.getEndToken());
                        if (t.isAnd()) 
                            break;
                        t = br.getEndToken();
                    }
                    return res;
                }
                boolean ok = true;
                java.util.ArrayList<PartValue> newP = null;
                for (com.pullenti.ner.Token ttt = t1.getNext(); ttt != null; ttt = ttt.getNext()) {
                    if (ttt.getEndChar() > br.getEndToken().getPrevious().getEndChar()) 
                        break;
                    if (ttt.isChar(',')) 
                        continue;
                    if (ttt.isChar('<') && (ttt.getNext() instanceof com.pullenti.ner.NumberToken)) 
                        ttt = ttt.getNext();
                    if (ttt instanceof com.pullenti.ner.NumberToken) {
                        if (com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.NumberToken.class)).getValue(), "0")) {
                            ok = false;
                            break;
                        }
                        if (newP == null) 
                            newP = new java.util.ArrayList<PartValue>();
                        PartValue pv0 = PartValue._new1347(ttt, ttt, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.NumberToken.class)).getValue().toString());
                        pv0.correctValue();
                        ttt = pv0.getEndToken();
                        newP.add(pv0);
                        if (ttt.getNext() != null && ttt.getNext().isCharOf(".>")) 
                            ttt = ttt.getNext();
                        if (ttt.getNext() != null && !ttt.getNext().isCommaAnd() && (br.getEndChar() - ttt.getNext().getBeginChar()) > 20) {
                            res.name = new com.pullenti.ner.MetaToken(ttt.getNext(), br.getEndToken().getPrevious(), null);
                            break;
                        }
                        continue;
                    }
                    com.pullenti.ner.TextToken to = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.TextToken.class);
                    if (to == null) {
                        ok = false;
                        break;
                    }
                    if ((res.typ != ItemType.ITEM && res.typ != ItemType.SUBITEM && res.typ != ItemType.LIST) && res.typ != ItemType.INDENTION && res.typ != ItemType.SUBINDENTION) {
                        ok = false;
                        break;
                    }
                    if (!to.chars.isLetter() || to.getLengthChar() != 1) {
                        ok = false;
                        break;
                    }
                    if (newP == null) 
                        newP = new java.util.ArrayList<PartValue>();
                    PartValue pv = PartValue._new1347(ttt, ttt, to.term);
                    if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(ttt.getPrevious(), false, false)) 
                        pv.setBeginToken(ttt.getPrevious());
                    pv.correctValue();
                    ttt = pv.getEndToken();
                    if ((ttt.getNext() != null && ttt.getNext().isHiphen() && (ttt.getNext().getNext() instanceof com.pullenti.ner.TextToken)) && ttt.getNext().getNext().getLengthChar() == 1 && ttt.getNext().getNext().getNext() == br.getEndToken()) {
                        newP.add(pv);
                        ttt = ttt.getNext().getNext();
                        pv = PartValue._new1347(ttt, ttt, ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.TextToken.class)).term);
                    }
                    if (com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(ttt.getNext(), false, null, false)) 
                        pv.setEndToken((ttt = ttt.getNext()));
                    if (pv.getEndToken().getNext() == br.getEndToken()) 
                        pv.setEndToken((ttt = br.getEndToken()));
                    newP.add(pv);
                }
                if (newP == null || !ok) 
                    break;
                com.pullenti.unisharp.Utils.addToArrayList(res.values, newP);
                res.setEndToken(br.getEndToken());
                t1 = br.getEndToken().getNext();
                if (and) 
                    break;
                if (t1 != null && t1.isHiphen() && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t1.getNext(), false, false)) {
                    com.pullenti.ner.core.BracketSequenceToken br1 = com.pullenti.ner.core.BracketHelper.tryParse(t1.getNext(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
                    if (br1 != null && (t1.getNext().getNext() instanceof com.pullenti.ner.TextToken) && t1.getNext().getNext().getLengthChar() == 1) {
                        PartValue pv = PartValue._new1347(br1.getBeginToken(), t1.getNext().getNext(), ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1.getNext().getNext(), com.pullenti.ner.TextToken.class)).term);
                        pv.correctValue();
                        if (pv.getEndToken() == br1.getEndToken().getPrevious()) {
                            res.values.add(pv);
                            res.setEndToken(br1.getEndToken());
                            t1 = br1.getEndToken().getNext();
                        }
                    }
                }
                continue;
            }
            if (res.typ == ItemType.FORM) {
                if ((t1 instanceof com.pullenti.ner.TextToken) && !t1.chars.isAllUpper()) {
                }
                else if (_createPartTyp0(t1, null) != null) {
                }
                else {
                    com.pullenti.ner.Token t2 = t1;
                    for (com.pullenti.ner.Token tt2 = t1.getNext(); tt2 != null; tt2 = tt2.getNext()) {
                        if (tt2.isCharOf(",;") || com.pullenti.ner.core.BracketHelper.isBracket(tt2, false)) 
                            break;
                        if (tt2.getWhitespacesBeforeCount() < 3) {
                            if ((tt2 instanceof com.pullenti.ner.TextToken) && tt2.getLengthChar() >= 2 && tt2.getLengthChar() <= 3) {
                                if (tt2.chars.isAllUpper() || tt2.isValue("ГПК", null) || tt2.isValue("КАС", null)) {
                                    t2 = tt2;
                                    continue;
                                }
                            }
                        }
                        if (tt2.isWhitespaceBefore()) 
                            break;
                        if (tt2.isChar('.') && tt2.isWhitespaceAfter()) 
                            break;
                        t2 = tt2;
                    }
                    res.values.add(PartValue._new1347(t1, t2, com.pullenti.ner.core.MiscHelper.getTextValue(t1, t2, com.pullenti.ner.core.GetTextAttr.NO)));
                    res.setEndToken(t2);
                    t1 = t2.getNext();
                    continue;
                }
            }
            if (t1.isChar('|') && res.values.size() == 0 && (t1.getWhitespacesBeforeCount() < 2)) {
                res.values.add(PartValue._new1347(t1, t1, "1"));
                res.setEndToken(t1);
                return res;
            }
            if ((t1.isCharOf("ˡ¹²³")) && res.values.size() == 0 && (t1.getWhitespacesBeforeCount() < 2)) {
                res.values.add(PartValue._new1347(t1, t1, (t1.isCharOf("ˡ¹") ? "1" : (t1.isChar('²') ? "2" : "3"))));
                res.setEndToken(t1);
                return res;
            }
            if ((t1.isCharOf("<(") && (t1.getNext() instanceof com.pullenti.ner.NumberToken) && t1.getNext().getNext() != null) && t1.getNext().getNext().isCharOf(">)")) {
                PartValue pp = PartValue._new1347(t1, t1.getNext().getNext(), ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext(), com.pullenti.ner.NumberToken.class)).getValue());
                pp.correctValue();
                res.values.add(pp);
                t1 = res.setEndToken(pp.getEndToken());
                continue;
            }
            if ((t1.isChar('<') && res.typ == ItemType.FOOTNOTE && t1.getNext() != null) && t1.getNext().isChar('*')) {
                int cou = 0;
                com.pullenti.ner.Token t2 = t1.getNext();
                for (; t2 != null; t2 = t2.getNext()) {
                    if (t2.isChar('*')) 
                        cou++;
                    else {
                        if (!t2.isChar('>')) 
                            t2 = t2.getPrevious();
                        break;
                    }
                }
                PartValue pp = PartValue._new1347(t1, t2, ((Integer)cou).toString());
                res.values.add(pp);
                t1 = res.setEndToken(pp.getEndToken());
                continue;
            }
            if ((((t1.isValue("С", null) || t1.isValue("C", null))) && (t1.getNext() instanceof com.pullenti.ner.NumberToken) && t1.getNext().getNext() != null) && t1.getNext().getNext().isValue("ПО", null) && (t1.getNext().getNext().getNext() instanceof com.pullenti.ner.NumberToken)) {
                res.values.add(PartValue._new1347(t1.getNext(), t1.getNext(), ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext(), com.pullenti.ner.NumberToken.class)).getValue()));
                res.values.add(PartValue._new1347(t1.getNext().getNext().getNext(), t1.getNext().getNext().getNext(), ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext().getNext().getNext(), com.pullenti.ner.NumberToken.class)).getValue()));
                res.setEndToken(t1.getNext().getNext().getNext());
                break;
            }
            if (((t1 instanceof com.pullenti.ner.TextToken) && t1.getLengthChar() == 1 && t1.chars.isLetter()) && res.values.size() == 0) {
                if (t1.chars.isAllUpper() && ((res.typ == ItemType.SUBPROGRAM || res.typ == ItemType.LIST))) {
                    res.values.add(PartValue._new1347(t1, t1, ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term));
                    res.setEndToken(t1);
                    return res;
                }
                boolean ok = true;
                int lev = 0;
                for (com.pullenti.ner.Token ttt = t1.getPrevious(); ttt != null; ttt = ttt.getPrevious()) {
                    if (ttt.isNewlineAfter()) 
                        break;
                    if (ttt.isChar('(')) {
                        lev--;
                        if (lev < 0) {
                            ok = false;
                            break;
                        }
                    }
                    else if (ttt.isChar(')')) 
                        lev++;
                }
                if (ok && t1.getNext() != null && t1.getNext().isChar(')')) {
                    res.values.add(PartValue._new1347(t1, t1.getNext(), ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term));
                    res.setEndToken(t1.getNext());
                    t1 = t1.getNext().getNext();
                    continue;
                }
                if (ok && (t1.getNext() instanceof com.pullenti.ner.NumberToken) && !t1.isWhitespaceAfter()) {
                    res.values.add(PartValue._new1347(t1, t1.getNext(), (((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext(), com.pullenti.ner.NumberToken.class)).getValue())));
                    res.setEndToken(t1.getNext());
                    t1 = res.getEndToken().getNext();
                    if (t1 != null && t1.isChar(')')) {
                        res.setEndToken(t1);
                        t1 = t1.getNext();
                    }
                    continue;
                }
                if (((ok && t1.getNext() != null && t1.getNext().isCharOf("(.[")) && !t1.getNext().isWhitespaceAfter() && (t1.getNext().getNext() instanceof com.pullenti.ner.NumberToken)) && t1.getNext().getNext().getNext() != null && t1.getNext().getNext().getNext().isCharOf(")]")) {
                    res.values.add(PartValue._new1347(t1, t1.getNext().getNext().getNext(), (((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term + "." + ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext().getNext(), com.pullenti.ner.NumberToken.class)).getValue())));
                    res.setEndToken(t1.getNext().getNext().getNext());
                    t1 = res.getEndToken().getNext();
                    continue;
                }
                if (ok && tryAttach(t1.getNext(), null, false, false) != null) {
                    if (((t1.isAnd() || t1.isValue("К", null) || t1.isValue("В", null))) && t1.chars.isAllLower()) {
                    }
                    else {
                        res.values.add(PartValue._new1347(t1, t1, ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term));
                        res.setEndToken(t1);
                        t1 = t1.getNext();
                        continue;
                    }
                }
                if (t1.isValue("З", null) && t1.chars.isAllUpper()) {
                    PartValue val = PartValue._new1347(t1, t1, "3");
                    val.correctValue();
                    res.values.add(val);
                    res.setEndToken(val.getEndToken());
                    t1 = val.getEndToken().getNext();
                    continue;
                }
                if (res.values.size() == 0 && ((res.typ == ItemType.ITEM || res.typ == ItemType.SUBITEM))) {
                    ok = false;
                    if (t1.getNext() != null && t1.getNext().isCharOf(".,")) 
                        ok = true;
                    else if (DecreeChangeToken.M_TERMS.tryParse(t1.getNext(), com.pullenti.ner.core.TerminParseAttr.NO) != null) 
                        ok = true;
                    if (ok) {
                        res.values.add(PartValue._new1347(t1, t1, ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term));
                        res.setEndToken(t1);
                        return res;
                    }
                }
            }
            com.pullenti.ner.Token prefTo = null;
            if (res.values.size() > 0 && !(t1 instanceof com.pullenti.ner.NumberToken) && firstNumPrefix != null) {
                ttn = com.pullenti.ner.core.MiscHelper.checkNumberPrefix(t1);
                if (ttn != null) {
                    prefTo = t1;
                    t1 = ttn;
                }
            }
            if (t1 instanceof com.pullenti.ner.NumberToken) {
                com.pullenti.ner.Token tt0 = (prefTo != null ? prefTo : t1);
                if (res.values.size() > 0) {
                    if (res.values.get(0).getIntValue() == 0 && !Character.isDigit(res.values.get(0).value.charAt(0))) 
                        break;
                    if (((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.NumberToken.class)).typ != ntyp) 
                        break;
                    PartToken pp = tryAttach(t1, null, false, false);
                    if (pp != null) 
                        break;
                }
                ntyp = ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.NumberToken.class)).typ;
                PartValue val = PartValue._new1347(tt0, t1, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.NumberToken.class)).getValue().toString());
                val.correctValue();
                res.values.add(val);
                res.setEndToken(val.getEndToken());
                t1 = res.getEndToken().getNext();
                if ((res.typ == ItemType.FORM && (t1 instanceof com.pullenti.ner.TextToken) && t1.chars.isAllUpper()) && (t1.getLengthChar() < 5) && (t1.getWhitespacesBeforeCount() < 2)) {
                    val.setEndToken(res.setEndToken(t1));
                    t1 = t1.getNext();
                }
                if (and) 
                    break;
                if (res.typ == ItemType.ITEM && (t1 instanceof com.pullenti.ner.TextToken) && t1.isValue("ПРИМЕЧАНИЕ", null)) {
                    if (t1.getNext() == null || t1.getNext().isValue("К", null) || t1.getNext().isComma()) {
                        res.typ = ItemType.NOTICE;
                        res.setEndToken(t1);
                        return res;
                    }
                }
                continue;
            }
            com.pullenti.ner.NumberToken nt = com.pullenti.ner.core.NumberHelper.tryParseRoman(t1);
            if (nt != null) {
                PartValue pv = PartValue._new1347(t1, nt.getEndToken(), nt.getValue().toString());
                res.values.add(pv);
                pv.correctValue();
                res.setEndToken(pv.getEndToken());
                t1 = res.getEndToken().getNext();
                continue;
            }
            if ((t1 == tt1 && ((res.typ == ItemType.APPENDIX || res.typ == ItemType.ADDAGREE)) && t1.isValue("К", null)) && t1.getNext() != null) {
                if ((t1.getNext().getReferent() instanceof com.pullenti.ner.decree.DecreeReferent) || DecreeToken.isKeyword(t1.getNext(), false) != null || DecreeToken.isKeyword(t1.getNext().getNext(), false) != null) {
                    res.values.add(PartValue._new1347(t1, t1, ""));
                    break;
                }
            }
            if (res.typ == ItemType.ADDAGREE && firstNumPrefix != null && res.values.size() == 0) {
                DecreeToken ddd = DecreeToken.tryAttach(firstNumPrefix, null, false);
                if (ddd != null && ddd.typ == DecreeToken.ItemType.NUMBER && ddd.value != null) {
                    if (t1.getBeginChar() <= ddd.getEndToken().getBeginChar()) {
                        res.values.add(PartValue._new1347(t1, ddd.getEndToken(), ddd.value));
                        t1 = res.setEndToken(ddd.getEndToken());
                        break;
                    }
                }
            }
            if ((t1 instanceof com.pullenti.ner.TextToken) && t1.chars.isLatinLetter()) {
                com.pullenti.ner.TextToken te = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class);
                int j;
                String nn = "";
                for (j = 0; j < te.term.length(); j++) {
                    char ch = te.term.charAt(j);
                    if (ch == 'O') {
                        if (j == 0) 
                            break;
                        nn += "0";
                    }
                    else if (ch == 'I' || ch == 'L') 
                        nn += "1";
                    else 
                        break;
                }
                if (j >= te.term.length()) {
                    res.values.add(PartValue._new1347(t1, t1, nn));
                    res.setEndToken(t1);
                    break;
                }
            }
            if (res.values.size() == 0) 
                break;
            if (t1.isCharOf(",.")) {
                if (t1.isNewlineAfter() && t1.isChar('.')) 
                    break;
                t1 = t1.getNext();
                continue;
            }
            if (t1.isHiphen() && res.values.get(res.values.size() - 1).value.indexOf('.') > 0) {
                t1 = t1.getNext();
                continue;
            }
            if (t1.isAnd() || t1.isOr()) {
                t1 = t1.getNext();
                and = true;
                continue;
            }
            if (t1.isHiphen()) {
                com.pullenti.ner.NumberToken nmax = (com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t1.getNext(), com.pullenti.ner.NumberToken.class);
                if (nmax == null) 
                    nmax = com.pullenti.ner.core.NumberHelper.tryParseRoman(t1.getNext());
                if (nmax == null || nmax.getIntValue() == null) 
                    break;
                int min = res.values.get(res.values.size() - 1).getIntValue();
                if (min == 0) 
                    break;
                int max = nmax.getIntValue();
                if (max < min) 
                    break;
                if ((max - min) > 200) 
                    break;
                PartValue val = PartValue._new1347(t1.getNext(), (nmax == t1.getNext() ? t1.getNext() : nmax.getEndToken()), ((Integer)max).toString());
                val.correctValue();
                res.values.add(val);
                res.setEndToken(val.getEndToken());
                t1 = res.getEndToken().getNext();
                continue;
            }
            break;
        }
        if (res.decree == null && (res.getEndToken().getWhitespacesAfterCount() < 3) && (res.getEndToken().getNext().getReferent() instanceof com.pullenti.ner.decree.DecreeReferent)) {
            res.setEndToken(res.getEndToken().getNext());
            res.decree = (com.pullenti.ner.decree.DecreeReferent)com.pullenti.unisharp.Utils.cast(res.getEndToken().getReferent(), com.pullenti.ner.decree.DecreeReferent.class);
            if (res.typ == ItemType.PART && res.decree.getKind() == com.pullenti.ner.decree.DecreeKind.KODEX) {
                String nam = (String)com.pullenti.unisharp.Utils.notnull(res.decree.getStringValue("NAME"), "");
                if ((nam.indexOf("ГРАЖДАНСКИЙ") >= 0) || (nam.indexOf("НАЛОГОВЫЙ") >= 0)) 
                    res.typ = ItemType.DOCPART;
            }
        }
        com.pullenti.ner.Token tte2 = res.getEndToken().getNext();
        if (tte2 != null && tte2.isChar('.') && !tte2.isNewlineAfter()) 
            tte2 = tte2.getNext();
        if ((res.getWhitespacesAfterCount() < 3) && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tte2, true, false)) {
            int lev = _getRank(res.typ);
            if (((lev > 0 && lev <= _getRank(ItemType.CLAUSE))) || res.typ == ItemType.TABLE || res.typ == ItemType.FORM) {
                com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tte2, com.pullenti.ner.core.BracketParseAttr.CANCONTAINSVERBS, 100);
                if (br != null && br.getEndToken().getNext() != null && res.values.size() > 0) {
                    if (br.getEndToken().getNext().isValue("ЗАМЕНИТЬ", null) || br.getEndToken().getNext().isValue("ИСКЛЮЧИТЬ", null)) 
                        br = null;
                }
                if (br != null) {
                    res.name = br;
                    res.setEndToken(br.getEndToken());
                    for (com.pullenti.ner.Token tt2 = res.getEndToken().getNext(); tt2 != null; tt2 = tt2.getNext()) {
                        if (!tt2.isCommaAnd()) 
                            break;
                        br = com.pullenti.ner.core.BracketHelper.tryParse(tt2.getNext(), com.pullenti.ner.core.BracketParseAttr.CANCONTAINSVERBS, 100);
                        if (br == null || (br.getLengthChar() < 10)) 
                            break;
                        if (res.addNames == null) 
                            res.addNames = new java.util.ArrayList<com.pullenti.ner.MetaToken>();
                        res.addNames.add(br);
                        res.setEndToken(br.getEndToken());
                        if (tt2.isAnd()) 
                            break;
                        tt2 = br.getEndToken();
                    }
                }
            }
        }
        if (res.values.size() == 0 && res.name == null) {
            if ((((!ignoreNumber && res.typ != ItemType.PREAMBLE && res.typ != ItemType.NAME) && res.typ != ItemType.TABLE && res.typ != ItemType.SUBPROGRAM) && res.typ != ItemType.NOTICE && res.typ != ItemType.FOOTNOTE) && res.typ != ItemType.FORMULA && res.typ != ItemType.APPENDIX) 
                return null;
            if (res.getBeginToken() != res.getEndToken()) 
                res.setEndToken(res.getEndToken().getPrevious());
        }
        if (res.getEndToken().getNext() != null && res.getEndToken().getNext().isChar('(')) {
            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(res.getEndToken().getNext(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
            if (br != null && (br.getLengthChar() < 40)) {
                if ((br.getBeginToken().getNext().isValue("СЕКРЕТНО", null) || br.getBeginToken().getNext().isValue("СОВЕРШЕННО", null) || br.getBeginToken().getNext().isValue("ДСП", null)) || br.getBeginToken().getNext().isValue2("ДЛЯ", "СЛУЖЕБНОГО")) {
                    res.isConfidential = true;
                    res.setEndToken(br.getEndToken());
                }
            }
        }
        if (res.typ == ItemType.TABLE && res.getBeginToken() == res.getEndToken() && res.getBeginToken().isValue("НОРМА", null)) 
            return null;
        return res;
    }

    private static PartToken _createPartTyp0(com.pullenti.ner.Token t1, PartToken prev) {
        boolean isShort;
        com.pullenti.unisharp.Outargwrapper<Boolean> wrapisShort1391 = new com.pullenti.unisharp.Outargwrapper<Boolean>();
        PartToken pt = __createPartTyp(t1, prev, wrapisShort1391);
        isShort = (wrapisShort1391.value != null ? wrapisShort1391.value : false);
        if (pt == null) 
            return null;
        if (t1.getLengthChar() > 4) {
            pt.setMorph(t1.getMorph());
            if ((t1 instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t1, com.pullenti.ner.TextToken.class)).term, "СТАТЬЮ")) {
                pt.setMorph(t1.getMorph().clone());
                pt.getMorph().removeItems(com.pullenti.morph.MorphCase.ACCUSATIVE);
            }
        }
        if ((isShort && !pt.getEndToken().isWhitespaceAfter() && pt.getEndToken().getNext() != null) && pt.getEndToken().getNext().isChar('.')) {
            if (!pt.getEndToken().getNext().isNewlineAfter()) 
                pt.setEndToken(pt.getEndToken().getNext());
        }
        return pt;
    }

    private static PartToken __createPartTyp(com.pullenti.ner.Token t1, PartToken prev, com.pullenti.unisharp.Outargwrapper<Boolean> isShort) {
        isShort.value = false;
        if (t1 == null) 
            return null;
        if (t1.isValue("ТЕРМИНОЛОГИЧЕСКИЙ", null)) {
            PartToken res = __createPartTyp(t1.getNext(), prev, isShort);
            if (res != null) 
                res.setBeginToken(t1);
            return res;
        }
        if (t1.isValue("ЧАСТЬ", "ЧАСТИНА") || t1.isValue("PART", null)) 
            return _new1058(t1, t1, ItemType.PART);
        if (t1.isValue("Ч", null)) {
            isShort.value = true;
            return _new1058(t1, t1, ItemType.PART);
        }
        if (t1.isValue("ГЛАВА", null) || t1.isValue("ГЛ", null) || t1.isValue("CHAPTER", null)) {
            isShort.value = t1.getLengthChar() == 2;
            return _new1058(t1, t1, ItemType.CHAPTER);
        }
        if (t1.isValue("ПРИЛОЖЕНИЕ", "ДОДАТОК") || t1.isValue("ПРИЛ", null) || t1.isValue("APPENDIX", null)) {
            if ((t1.isNewlineBefore() && t1.getLengthChar() > 6 && t1.getNext() != null) && t1.getNext().isChar(':')) 
                return null;
            if (t1.getPrevious() != null && t1.getPrevious().isValue("МОБИЛЬНЫЙ", null)) 
                return null;
            isShort.value = t1.getLengthChar() < 5;
            return _new1058(t1, t1, ItemType.APPENDIX);
        }
        if (t1.isValue("ПРИМЕЧАНИЕ", "ПРИМІТКА") || t1.isValue("ПРИМ", null)) {
            isShort.value = t1.getLengthChar() < 5;
            return _new1058(t1, t1, ItemType.NOTICE);
        }
        if (t1.isValue("ФОРМУЛА", null)) 
            return _new1058(t1, t1, ItemType.FORMULA);
        if (t1.isValue("ФОРМА", null)) 
            return _new1058(t1, t1, ItemType.FORM);
        if (t1.isValue("ТАБЛИЦА", null) || t1.isValue("НОРМА", null)) {
            PartToken res = _new1058(t1, t1, ItemType.TABLE);
            if (t1.getNext() != null && t1.getNext().isValue("НОРМА", null)) 
                res.setEndToken(t1.getNext());
            return res;
        }
        if (t1.isValue("ЛИСТ", null)) 
            return _new1058(t1, t1, ItemType.LIST);
        if (t1.isValue("СТРОКА", null) || t1.isValue("ПОЗИЦИЯ", null)) {
            if (t1.getNext() != null && t1.getNext().isValue("ТАБЛИЦА", null)) 
                return _new1058(t1, t1.getNext(), ItemType.TABLEROW);
            return _new1058(t1, t1, ItemType.TABLEROW);
        }
        if (t1.isValue("ГРАФА", null) || t1.isValue("СУБПОЗИЦИЯ", null)) {
            if (t1.getNext() != null && t1.getNext().isValue("ТАБЛИЦА", null)) 
                return _new1058(t1, t1.getNext(), ItemType.TABLEITEM);
            return _new1058(t1, t1, ItemType.TABLEITEM);
        }
        if (t1.isValue("ПРОГРАФКА", null)) {
            if (t1.getNext() != null && t1.getNext().isValue("ТАБЛИЦА", null)) 
                return _new1058(t1, t1.getNext(), ItemType.TABLESUBITEM);
            return _new1058(t1, t1, ItemType.TABLESUBITEM);
        }
        if (t1.isValue("СТОЛБЕЦ", null)) {
            if (t1.getNext() != null && t1.getNext().isValue("ТАБЛИЦА", null)) 
                return _new1058(t1, t1.getNext(), ItemType.TABLECOLUMN);
            return _new1058(t1, t1, ItemType.TABLECOLUMN);
        }
        if (t1.isValue("ПРЕДЛОЖЕНИЕ", null)) 
            return _new1058(t1, t1, ItemType.SENTENCE);
        if (t1.isValue("СНОСКА", null)) {
            if (t1.getPrevious() != null && t1.getPrevious().isValue("ЗНАК", null)) {
            }
            else 
                return _new1058(t1, t1, ItemType.FOOTNOTE);
        }
        if (t1.isValue("СТАТЬЯ", "СТАТТЯ") || t1.isValue("СТ", null) || t1.isValue("ARTICLE", null)) {
            isShort.value = t1.getLengthChar() < 3;
            return _new1058(t1, t1, ItemType.CLAUSE);
        }
        if (t1.isValue("ПУНКТ", null) || t1.isValue("П", null) || t1.isValue("ПП", null)) {
            isShort.value = t1.getLengthChar() < 3;
            return _new1412(t1, t1, ItemType.ITEM, (t1.isValue("ПП", null) ? ItemType.SUBITEM : ItemType.UNDEFINED));
        }
        if (t1.isValue("ПОДПУНКТ", "ПІДПУНКТ") || t1.isValue("ПОЛПУНКТА", null)) 
            return _new1058(t1, t1, ItemType.SUBITEM);
        if (t1.isValue("ПРЕАМБУЛА", null)) 
            return _new1058(t1, t1, ItemType.PREAMBLE);
        if (t1.isValue("НАИМЕНОВАНИЕ", null) || t1.isValue("НАЗВАНИЕ", null)) 
            return _new1058(t1, t1, ItemType.NAME);
        if (t1.isValue("ПОДП", null) || t1.isValue("ПІДП", null)) {
            isShort.value = true;
            return _new1058(t1, t1, ItemType.SUBITEM);
        }
        if (t1.isValue("РАЗДЕЛ", "РОЗДІЛ") || t1.isValue("РАЗД", null) || t1.isValue("SECTION", null)) {
            isShort.value = t1.getLengthChar() < 5;
            return _new1058(t1, t1, ItemType.SECTION);
        }
        if (((t1.isValue("Р", null) || t1.isValue("P", null))) && t1.getNext() != null && t1.getNext().isChar('.')) {
            if (prev != null) {
                if (prev.typ == ItemType.ITEM || prev.typ == ItemType.SUBITEM) {
                    isShort.value = true;
                    return _new1058(t1, t1.getNext(), ItemType.SECTION);
                }
            }
        }
        if (t1.isValue("ПОДРАЗДЕЛ", "ПІДРОЗДІЛ") || t1.isValue("SUBSECTION", null)) 
            return _new1058(t1, t1, ItemType.SUBSECTION);
        if (t1.isValue("ПАРАГРАФ", null) || t1.isValue("§", null) || t1.isValue("PARAGRAPH", null)) 
            return _new1058(t1, t1, ItemType.PARAGRAPH);
        if (t1.isValue("АБЗАЦ", null) || t1.isValue("АБЗ", null)) {
            isShort.value = t1.getLengthChar() < 7;
            return _new1058(t1, t1, ItemType.INDENTION);
        }
        if (t1.isValue("СТРАНИЦА", "СТОРІНКА") || t1.isValue("СТР", "СТОР") || t1.isValue("PAGE", null)) {
            isShort.value = t1.getLengthChar() < 7;
            return _new1058(t1, t1, ItemType.PAGE);
        }
        if (t1.isValue("ПОДАБЗАЦ", "ПІДАБЗАЦ") || t1.isValue("ПОДАБЗ", "ПІДАБЗ")) 
            return _new1058(t1, t1, ItemType.SUBINDENTION);
        if (t1.isValue("ПОДПАРАГРАФ", "ПІДПАРАГРАФ") || t1.isValue("SUBPARAGRAPH", null)) 
            return _new1058(t1, t1, ItemType.SUBPARAGRAPH);
        if (t1.isValue("ПОДПРОГРАММА", "ПІДПРОГРАМА")) 
            return _new1058(t1, t1, ItemType.SUBPROGRAM);
        if (t1.isValue("ДОПСОГЛАШЕНИЕ", null)) 
            return _new1058(t1, t1, ItemType.ADDAGREE);
        if (((t1.isValue("ДОП", null) || t1.isValue("ДОПОЛНИТЕЛЬНЫЙ", "ДОДАТКОВА"))) && t1.getNext() != null) {
            com.pullenti.ner.Token tt = t1.getNext();
            if (tt.isChar('.') && tt.getNext() != null) 
                tt = tt.getNext();
            if (tt.isValue("СОГЛАШЕНИЕ", "УГОДА")) 
                return _new1058(t1, tt, ItemType.ADDAGREE);
        }
        return null;
    }

    public static java.util.ArrayList<PartToken> tryAttachList(com.pullenti.ner.Token t, boolean inBracket, int maxCount) {
        PartToken p = tryAttach(t, null, inBracket, false);
        if (p == null) 
            return null;
        if (p.typ == ItemType.PREFIX) {
            if ((p.getWhitespacesAfterCount() < 3) && (p.getEndToken().getNext() instanceof com.pullenti.ner.NumberToken)) {
            }
            else 
                return null;
        }
        java.util.ArrayList<PartToken> res = new java.util.ArrayList<PartToken>();
        res.add(p);
        if (p.isNewlineAfter() && p.isNewlineBefore()) {
            if (!p.getBeginToken().chars.isAllLower()) 
                return res;
        }
        com.pullenti.ner.Token tt = p.getEndToken().getNext();
        while (tt != null) {
            if (tt.getWhitespacesBeforeCount() > 15) {
                if (tt.getPrevious() != null && tt.getPrevious().isCommaAnd()) {
                }
                else 
                    break;
            }
            if (maxCount > 0 && res.size() >= maxCount) 
                break;
            boolean delim = false;
            if (((tt.isCharOf(",;.:") || tt.isAnd() || tt.isOr())) && tt.getNext() != null) {
                if (tt.isCharOf(";.:")) {
                    if (tt.isNewlineAfter()) 
                        break;
                    res.get(res.size() - 1).hasTerminator = true;
                }
                else {
                    res.get(res.size() - 1).delimAfter = true;
                    if ((tt.getNext() != null && tt.getNext().isValue("А", null) && tt.getNext().getNext() != null) && tt.getNext().getNext().isValue("ТАКЖЕ", "ТАКОЖ")) 
                        tt = tt.getNext().getNext();
                }
                tt = tt.getNext();
                delim = true;
            }
            if (tt == null) 
                break;
            if (tt.isNewlineBefore()) {
                if (tt.chars.isLetter() && !tt.chars.isAllLower()) 
                    break;
            }
            if (tt.isChar('(')) {
                com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                if (br != null) {
                    java.util.ArrayList<PartToken> li = tryAttachList(tt.getNext(), true, 40);
                    if (li != null && li.size() > 0) {
                        if (li.get(0).typ == ItemType.PARAGRAPH || li.get(0).typ == ItemType.PART || li.get(0).typ == ItemType.ITEM) {
                            if (li.get(li.size() - 1).getEndToken().getNext() == br.getEndToken()) {
                                if (p.values.size() > 1) {
                                    for (int ii = 1; ii < p.values.size(); ii++) {
                                        PartToken pp = _new1058(p.values.get(ii).getBeginToken(), (ii == (p.values.size() - 1) ? p.getEndToken() : p.values.get(ii).getEndToken()), p.typ);
                                        pp.values.add(p.values.get(ii));
                                        res.add(pp);
                                    }
                                    if (p.values.get(1).getBeginToken().getPrevious() != null && p.values.get(1).getBeginToken().getPrevious().getEndChar() >= p.getBeginToken().getBeginChar()) 
                                        p.setEndToken(p.values.get(1).getBeginToken().getPrevious());
                                    for(int jjj = 1 + p.values.size() - 1 - 1, mmm = 1; jjj >= mmm; jjj--) p.values.remove(jjj);
                                }
                                com.pullenti.unisharp.Utils.addToArrayList(res, li);
                                li.get(li.size() - 1).setEndToken(br.getEndToken());
                                tt = br.getEndToken().getNext();
                                continue;
                            }
                        }
                    }
                }
            }
            PartToken p0 = tryAttach(tt, p, inBracket, false);
            if (p0 == null && ((tt.isValue("В", null) || tt.isValue("ДО", null)))) 
                p0 = tryAttach(tt.getNext(), p, inBracket, false);
            if (p0 == null && ((tt.isValue("К", null) || tt.isValue("УКАЗАННЫЙ", null)))) {
                if (tt.getNext() != null && tt.getNext().getMorphClassInDictionary().isAdjective()) 
                    tt = tt.getNext();
                p0 = tryAttach(tt.getNext(), p, inBracket, false);
            }
            if (p0 == null) {
                if (com.pullenti.ner.core.BracketHelper.isBracket(tt, false)) {
                    com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                    if (br != null) {
                        p0 = tryAttach(br.getEndToken().getNext(), null, false, false);
                        if (p0 != null && p0.typ != ItemType.PREFIX && p0.values.size() > 0) {
                            if (tt.isChar('(')) {
                                PartToken p1 = tryAttach(tt.getNext(), p, true, false);
                                if (p1 != null && p1.typ != ItemType.PREFIX) {
                                    res.add(p1);
                                    p1.setEndToken(br.getEndToken());
                                    tt = br.getEndToken().getNext();
                                    continue;
                                }
                            }
                            res.get(res.size() - 1).setEndToken(br.getEndToken());
                            res.get(res.size() - 1).name = br;
                            if (p0.isNewlineBefore()) 
                                break;
                            p = p0;
                            res.add(p);
                            tt = p.getEndToken().getNext();
                            continue;
                        }
                        if ((com.pullenti.ner.core.BracketHelper.isBracket(tt, true) && (tt.getWhitespacesBeforeCount() < 3) && res.get(res.size() - 1).typ == ItemType.APPENDIX) && res.get(res.size() - 1).name == null) {
                            res.get(res.size() - 1).setEndToken(br.getEndToken());
                            res.get(res.size() - 1).name = br;
                            tt = br.getEndToken().getNext();
                            continue;
                        }
                    }
                }
                if (tt.isNewlineBefore()) {
                    if (res.size() == 1 && res.get(0).isNewlineBefore()) 
                        break;
                    if (tt.getPrevious() != null && tt.getPrevious().isCommaAnd()) {
                    }
                    else 
                        break;
                }
                if ((tt instanceof com.pullenti.ner.NumberToken) && delim) {
                    p0 = null;
                    if (p.typ == ItemType.CLAUSE || inBracket) 
                        p0 = _new1058(tt, tt, ItemType.CLAUSE);
                    else if (res.size() > 1 && res.get(res.size() - 2).typ == ItemType.CLAUSE && res.get(res.size() - 1).typ == ItemType.PART) 
                        p0 = _new1058(tt, tt, ItemType.CLAUSE);
                    else if ((res.size() > 2 && res.get(res.size() - 3).typ == ItemType.CLAUSE && res.get(res.size() - 2).typ == ItemType.PART) && res.get(res.size() - 1).typ == ItemType.ITEM) 
                        p0 = _new1058(tt, tt, ItemType.CLAUSE);
                    else if (res.size() > 0 && res.get(res.size() - 1).values.size() > 0 && (res.get(res.size() - 1).values.get(0).value.indexOf(".") >= 0)) 
                        p0 = _new1058(tt, tt, res.get(res.size() - 1).typ);
                    if (p0 == null) 
                        break;
                    PartValue vv = PartValue._new1347(tt, tt, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.NumberToken.class)).getValue().toString());
                    p0.values.add(vv);
                    vv.correctValue();
                    p0.setEndToken(vv.getEndToken());
                    tt = p0.getEndToken().getNext();
                    if (tt != null && tt.isHiphen() && (tt.getNext() instanceof com.pullenti.ner.NumberToken)) {
                        tt = tt.getNext();
                        vv = PartValue._new1347(tt, tt, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.NumberToken.class)).getValue().toString());
                        vv.correctValue();
                        p0.values.add(vv);
                        p0.setEndToken(vv.getEndToken());
                        tt = p0.getEndToken().getNext();
                    }
                }
            }
            if (tt != null && tt.isChar(',') && !tt.isNewlineAfter()) {
                PartToken p1 = tryAttach(tt.getNext(), p, false, false);
                if (p1 != null && _getRank(p1.typ) > 0 && _getRank(p.typ) > 0) {
                    if (_getRank(p1.typ) < _getRank(p.typ)) 
                        p0 = p1;
                }
            }
            if (p0 == null) 
                break;
            if (p0.isNewlineBefore() && res.size() == 1 && res.get(0).isNewlineBefore()) 
                break;
            if (p0.getMorph() != null && p0.getMorph().getCase().isInstrumental()) {
                if ((p.typ != ItemType.PREFIX && !p.delimAfter && p.getMorph() != null) && !p.getMorph().getCase().isInstrumental()) 
                    break;
                else if ((p.getBeginToken() instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(p.getBeginToken(), com.pullenti.ner.TextToken.class)).term, "СТАТЬЮ")) 
                    break;
            }
            if (p0.typ == ItemType.ITEM && p.typ == ItemType.ITEM) {
                if (p0.altTyp == ItemType.UNDEFINED && p.altTyp == ItemType.SUBITEM) {
                    p.typ = ItemType.SUBITEM;
                    p.altTyp = ItemType.UNDEFINED;
                }
                else if (p.altTyp == ItemType.UNDEFINED && p0.altTyp == ItemType.SUBITEM) {
                    p0.typ = ItemType.SUBITEM;
                    p0.altTyp = ItemType.UNDEFINED;
                }
                else if (p0.altTyp == ItemType.SUBITEM && p.altTyp == ItemType.SUBITEM) {
                    PartToken _next = tryAttach(p0.getEndToken().getNext(), null, false, false);
                    if (_next != null && _next.typ == ItemType.ITEM && _next.altTyp == ItemType.UNDEFINED) {
                        p.typ = ItemType.SUBITEM;
                        p.altTyp = ItemType.UNDEFINED;
                        p0.typ = ItemType.SUBITEM;
                        p0.altTyp = ItemType.UNDEFINED;
                    }
                }
            }
            p = p0;
            res.add(p);
            if (p.typ == ItemType.APPENDIX && res.size() > 1 && res.get(res.size() - 2).typ == ItemType.APPENDIX) {
                if (p.getBeginToken().getPrevious().isValue("К", null) || ((p.getBeginToken().getPrevious().getPrevious() != null && p.getBeginToken().getPrevious().getPrevious().isValue("К", null)))) 
                    res.get(res.size() - 2).typ = ItemType.APPENDIX2;
            }
            tt = p.getEndToken().getNext();
        }
        for (int i = 0; i < (res.size() - 1); i++) {
            if (res.get(i).typ == ItemType.PART && res.get(i + 1).typ == ItemType.PART && res.get(i).values.size() > 1) {
                int v1 = res.get(i).values.get(res.get(i).values.size() - 2).getIntValue();
                int v2 = res.get(i).values.get(res.get(i).values.size() - 1).getIntValue();
                if (v1 == 0 || v2 == 0) 
                    continue;
                if ((v2 - v1) < 10) 
                    continue;
                PartToken pt = _new1058(res.get(i).getEndToken(), res.get(i).getEndToken(), ItemType.CLAUSE);
                pt.values.add(PartValue._new1347(res.get(i).getEndToken(), res.get(i).getEndToken(), ((Integer)v2).toString()));
                res.get(i).values.remove(res.get(i).values.size() - 1);
                if (res.get(i).getEndToken() != res.get(i).getBeginToken()) 
                    res.get(i).setEndToken(res.get(i).getEndToken().getPrevious());
                res.add(i + 1, pt);
            }
        }
        if ((res.size() == 1 && res.get(0).typ == ItemType.SUBPROGRAM && res.get(0).getEndToken().getNext() != null) && res.get(0).getEndToken().getNext().isChar('.')) 
            res.get(0).setEndToken(res.get(0).getEndToken().getNext());
        for (int i = res.size() - 1; i >= 0; i--) {
            p = res.get(i);
            if ((p.decree == null && p.isNewlineAfter() && p.isNewlineBefore()) && p.typ != ItemType.SUBPROGRAM) {
                for(int jjj = i + res.size() - i - 1, mmm = i; jjj >= mmm; jjj--) res.remove(jjj);
                continue;
            }
            if (((i == 0 && res.size() > 1 && ((p.isNewlineBefore() || ((p.getBeginToken().getPrevious() != null && p.getBeginToken().getPrevious().isTableControlChar()))))) && p.hasTerminator && p.getEndToken().getNext() != null) && p.getEndToken().getNext().isChar('.') && com.pullenti.ner.core.MiscHelper.canBeStartOfSentence(p.getEndToken().getNext().getNext())) {
                res.remove(i);
                continue;
            }
        }
        if (res.size() > 1 && res.get(res.size() - 1).typ == ItemType.NAME) 
            res.remove(res.size() - 1);
        if (res.size() == 1 && res.get(0).typ == ItemType.PREFIX) 
            return null;
        if (res.size() == 1 && res.get(0).typ == ItemType.SENTENCE) {
            DecreeToken dt = DecreeToken.tryAttach(res.get(0).getEndToken().getNext(), null, false);
            if (dt != null && dt.typ == DecreeToken.ItemType.DATE) 
                return null;
        }
        return (res.size() == 0 ? null : res);
    }

    public boolean canBeNextNarrow(PartToken p, java.util.ArrayList<PartToken> parts) {
        if (typ == ItemType.FORMULA) 
            return false;
        if (p.typ == ItemType.FORMULA) 
            return true;
        if (p.typ == ItemType.FREETEXT) 
            return true;
        if (typ == ItemType.FREETEXT) 
            return false;
        if (typ == ItemType.SENTENCE) 
            return false;
        if (p.typ == ItemType.SENTENCE) {
            if (((typ == ItemType.PREAMBLE || typ == ItemType.INDENTION || typ == ItemType.PART) || typ == ItemType.ITEM || typ == ItemType.SUBITEM) || typ == ItemType.TABLESUBITEM) 
                return true;
            return false;
        }
        if (typ == ItemType.TABLE) {
            if (((p.typ == ItemType.TABLECOLUMN || p.typ == ItemType.TABLEROW || p.typ == ItemType.TABLEITEM) || p.typ == ItemType.TABLESUBITEM || p.typ == ItemType.NAME) || p.typ == ItemType.ITEM) 
                return true;
        }
        if (typ == p.typ) {
            if (typ != ItemType.SUBITEM) 
                return false;
            if (p.values != null && p.values.size() > 0 && p.values.get(0).getIntValue() == 0) {
                if (values != null && values.size() > 0 && values.get(0).getIntValue() > 0) 
                    return true;
            }
            return false;
        }
        if (typ == ItemType.PART || p.typ == ItemType.PART) 
            return true;
        if (typ == ItemType.NOTICE || typ == ItemType.FOOTNOTE) {
            if (p.typ == ItemType.INDENTION) 
                return true;
        }
        int i1 = _getRank(typ);
        int i2 = _getRank(p.typ);
        if (typ == ItemType.TABLEROW && parts != null) {
            for (PartToken pp : parts) {
                if (pp.typ == ItemType.ITEM) {
                    i1 += 2;
                    break;
                }
            }
        }
        if (p.typ == ItemType.TABLEROW && parts != null) {
            for (PartToken pp : parts) {
                if (pp.typ == ItemType.ITEM) {
                    i2 += 2;
                    break;
                }
            }
        }
        if (i1 >= 0 && i2 >= 0) 
            return i1 < i2;
        return false;
    }

    public static boolean isPartBefore(com.pullenti.ner.Token t0) {
        if (t0 == null) 
            return false;
        int i = 0;
        for (com.pullenti.ner.Token tt = t0.getPrevious(); tt != null; tt = tt.getPrevious()) {
            if (tt.isNewlineAfter() || (tt instanceof com.pullenti.ner.ReferentToken)) 
                break;
            else {
                PartToken st = PartToken.tryAttach(tt, null, false, false);
                if (st != null) {
                    if (st.getEndToken().getNext() == t0) 
                        return true;
                    break;
                }
                if ((tt instanceof com.pullenti.ner.TextToken) && tt.chars.isLetter()) {
                    if ((++i) > 2) 
                        break;
                }
            }
        }
        return false;
    }

    public static int _getRank(ItemType t) {
        if (t == ItemType.DOCPART) 
            return 1;
        if (t == ItemType.APPENDIX) 
            return 1;
        if (t == ItemType.APPENDIX2) 
            return 2;
        if (t == ItemType.SECTION) 
            return 2;
        if (t == ItemType.SUBPROGRAM) 
            return 2;
        if (t == ItemType.SUBSECTION) 
            return 3;
        if (t == ItemType.CHAPTER) 
            return 4;
        if (t == ItemType.PREAMBLE) 
            return 5;
        if (t == ItemType.PARAGRAPH) 
            return 5;
        if (t == ItemType.SUBPARAGRAPH) 
            return 6;
        if (t == ItemType.PAGE) 
            return 6;
        if (t == ItemType.CLAUSE) 
            return 7;
        if (t == ItemType.FORM) 
            return 8;
        if (t == ItemType.TABLE) 
            return 8;
        if (t == ItemType.LIST) 
            return 9;
        if (t == ItemType.PART) 
            return 9;
        if (t == ItemType.NOTICE) 
            return 9;
        if (t == ItemType.TABLEROW) 
            return 10;
        if (t == ItemType.TABLEITEM) 
            return 11;
        if (t == ItemType.TABLESUBITEM) 
            return 12;
        if (t == ItemType.ITEM) 
            return 10;
        if (t == ItemType.SUBITEM) 
            return 11;
        if (t == ItemType.NAME) 
            return 12;
        if (t == ItemType.INDENTION) 
            return 13;
        if (t == ItemType.SUBINDENTION) 
            return 14;
        if (t == ItemType.SENTENCE) 
            return 15;
        if (t == ItemType.TABLECOLUMN) 
            return 16;
        if (t == ItemType.FOOTNOTE) 
            return 16;
        if (t == ItemType.FORMULA) 
            return 17;
        if (t == ItemType.FREETEXT) 
            return 20;
        return 0;
    }

    public static String _getAttrNameByTyp(ItemType _typ) {
        if (_typ == ItemType.CHAPTER) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_CHAPTER;
        if (_typ == ItemType.APPENDIX) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_APPENDIX;
        if (_typ == ItemType.APPENDIX2) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_APPENDIX2;
        if (_typ == ItemType.CLAUSE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_CLAUSE;
        if (_typ == ItemType.INDENTION) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_INDENTION;
        if (_typ == ItemType.ITEM) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_ITEM;
        if (_typ == ItemType.PARAGRAPH) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_PARAGRAPH;
        if (_typ == ItemType.SUBPARAGRAPH) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBPARAGRAPH;
        if (_typ == ItemType.PART) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_PART;
        if (_typ == ItemType.SECTION) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SECTION;
        if (_typ == ItemType.SUBSECTION) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBSECTION;
        if (_typ == ItemType.SUBINDENTION) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBINDENTION;
        if (_typ == ItemType.SUBITEM) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBITEM;
        if (_typ == ItemType.PREAMBLE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_PREAMBLE;
        if (_typ == ItemType.NOTICE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_NOTICE;
        if (_typ == ItemType.FOOTNOTE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_FOOTNOTE;
        if (_typ == ItemType.FORMULA) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_FORMULA;
        if (_typ == ItemType.FORM) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_FORM;
        if (_typ == ItemType.LIST) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_LIST;
        if (_typ == ItemType.TABLE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLE;
        if (_typ == ItemType.TABLECOLUMN) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLECOLUMN;
        if (_typ == ItemType.TABLEROW) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLEROW;
        if (_typ == ItemType.TABLEITEM) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLEITEM;
        if (_typ == ItemType.TABLESUBITEM) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLESUBITEM;
        if (_typ == ItemType.SENTENCE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SENTENCE;
        if (_typ == ItemType.NAME) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_NAMEASITEM;
        if (_typ == ItemType.SUBPROGRAM) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBPROGRAM;
        if (_typ == ItemType.ADDAGREE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_ADDAGREE;
        if (_typ == ItemType.DOCPART) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_DOCPART;
        if (_typ == ItemType.PAGE) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_PAGE;
        if (_typ == ItemType.FREETEXT) 
            return com.pullenti.ner.decree.DecreePartReferent.ATTR_FREETEXT;
        return null;
    }

    public static com.pullenti.ner.instrument.InstrumentKind _getInstrKindByTyp(ItemType _typ) {
        if (_typ == ItemType.CHAPTER) 
            return com.pullenti.ner.instrument.InstrumentKind.CHAPTER;
        if (_typ == ItemType.APPENDIX) 
            return com.pullenti.ner.instrument.InstrumentKind.APPENDIX;
        if (_typ == ItemType.CLAUSE) 
            return com.pullenti.ner.instrument.InstrumentKind.CLAUSE;
        if (_typ == ItemType.INDENTION) 
            return com.pullenti.ner.instrument.InstrumentKind.INDENTION;
        if (_typ == ItemType.ITEM) 
            return com.pullenti.ner.instrument.InstrumentKind.ITEM;
        if (_typ == ItemType.PARAGRAPH) 
            return com.pullenti.ner.instrument.InstrumentKind.PARAGRAPH;
        if (_typ == ItemType.SUBPARAGRAPH) 
            return com.pullenti.ner.instrument.InstrumentKind.SUBPARAGRAPH;
        if (_typ == ItemType.PART) 
            return com.pullenti.ner.instrument.InstrumentKind.CLAUSEPART;
        if (_typ == ItemType.SECTION) 
            return com.pullenti.ner.instrument.InstrumentKind.SECTION;
        if (_typ == ItemType.SUBSECTION) 
            return com.pullenti.ner.instrument.InstrumentKind.SUBSECTION;
        if (_typ == ItemType.SUBITEM) 
            return com.pullenti.ner.instrument.InstrumentKind.SUBITEM;
        if (_typ == ItemType.PREAMBLE) 
            return com.pullenti.ner.instrument.InstrumentKind.PREAMBLE;
        if (_typ == ItemType.NOTICE) 
            return com.pullenti.ner.instrument.InstrumentKind.NOTICE;
        if (_typ == ItemType.DOCPART) 
            return com.pullenti.ner.instrument.InstrumentKind.DOCPART;
        if (_typ == ItemType.TABLE) 
            return com.pullenti.ner.instrument.InstrumentKind.TABLE;
        return com.pullenti.ner.instrument.InstrumentKind.UNDEFINED;
    }

    public static ItemType _getTypeByAttrName(String _name) {
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_CHAPTER)) 
            return ItemType.CHAPTER;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_APPENDIX)) 
            return ItemType.APPENDIX;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_APPENDIX2)) 
            return ItemType.APPENDIX2;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_CLAUSE)) 
            return ItemType.CLAUSE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_INDENTION)) 
            return ItemType.INDENTION;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_ITEM)) 
            return ItemType.ITEM;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_PARAGRAPH)) 
            return ItemType.PARAGRAPH;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBPARAGRAPH)) 
            return ItemType.SUBPARAGRAPH;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_PART)) 
            return ItemType.PART;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SECTION)) 
            return ItemType.SECTION;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBSECTION)) 
            return ItemType.SUBSECTION;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBINDENTION)) 
            return ItemType.SUBINDENTION;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBITEM)) 
            return ItemType.SUBITEM;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_NOTICE)) 
            return ItemType.NOTICE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_FOOTNOTE)) 
            return ItemType.FOOTNOTE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_FORMULA)) 
            return ItemType.FORMULA;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_FORM)) 
            return ItemType.FORM;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_LIST)) 
            return ItemType.LIST;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLE)) 
            return ItemType.TABLE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLECOLUMN)) 
            return ItemType.TABLECOLUMN;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLEROW)) 
            return ItemType.TABLEROW;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLEITEM)) 
            return ItemType.TABLEITEM;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_TABLESUBITEM)) 
            return ItemType.TABLESUBITEM;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SENTENCE)) 
            return ItemType.SENTENCE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_NAMEASITEM)) 
            return ItemType.NAME;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_PREAMBLE)) 
            return ItemType.PREAMBLE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_SUBPROGRAM)) 
            return ItemType.SUBPROGRAM;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_ADDAGREE)) 
            return ItemType.ADDAGREE;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_DOCPART)) 
            return ItemType.DOCPART;
        if (com.pullenti.unisharp.Utils.stringsEq(_name, com.pullenti.ner.decree.DecreePartReferent.ATTR_FREETEXT)) 
            return ItemType.FREETEXT;
        return ItemType.PREFIX;
    }

    public static java.util.ArrayList<com.pullenti.ner.decree.DecreePartReferent> tryCreateBetween(com.pullenti.ner.decree.DecreePartReferent p1, com.pullenti.ner.decree.DecreePartReferent p2) {
        String notEqAttr = null;
        String val1 = null;
        String val2 = null;
        for (com.pullenti.ner.Slot s1 : p1.getSlots()) {
            if (p2.findSlot(s1.getTypeName(), s1.getValue(), true) != null) 
                continue;
            else {
                if (notEqAttr != null) 
                    return null;
                val2 = p2.getStringValue(s1.getTypeName());
                if (val2 == null) 
                    return null;
                notEqAttr = s1.getTypeName();
                val1 = (String)com.pullenti.unisharp.Utils.cast(s1.getValue(), String.class);
            }
        }
        if (val1 == null || val2 == null) 
            return null;
        java.util.ArrayList<String> diap = com.pullenti.ner.instrument.internal.NumberingHelper.createDiap(val1, val2);
        if (diap == null || (diap.size() < 3)) 
            return null;
        java.util.ArrayList<com.pullenti.ner.decree.DecreePartReferent> res = new java.util.ArrayList<com.pullenti.ner.decree.DecreePartReferent>();
        for (int i = 1; i < (diap.size() - 1); i++) {
            com.pullenti.ner.decree.DecreePartReferent dpr = new com.pullenti.ner.decree.DecreePartReferent();
            for (com.pullenti.ner.Slot s : p1.getSlots()) {
                Object val = s.getValue();
                if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), notEqAttr)) 
                    val = diap.get(i);
                dpr.addSlot(s.getTypeName(), val, false, 0);
            }
            res.add(dpr);
        }
        return res;
    }

    public static int getNumber(String str) {
        if (com.pullenti.unisharp.Utils.isNullOrEmpty(str)) 
            return 0;
        int i;
        com.pullenti.unisharp.Outargwrapper<Integer> wrapi1441 = new com.pullenti.unisharp.Outargwrapper<Integer>();
        boolean inoutres1442 = com.pullenti.unisharp.Utils.parseInteger(str, 0, null, wrapi1441);
        i = (wrapi1441.value != null ? wrapi1441.value : 0);
        if (inoutres1442) 
            return i;
        if (!Character.isLetter(str.charAt(0))) 
            return 0;
        char ch = Character.toUpperCase(str.charAt(0));
        if (((int)ch) < 0x80) {
            i = (((int)ch) - ((int)'A')) + 1;
            if ((ch == 'Z' && str.length() > 2 && str.charAt(1) == '.') && Character.isDigit(str.charAt(2))) {
                int n;
                com.pullenti.unisharp.Outargwrapper<Integer> wrapn1437 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                boolean inoutres1438 = com.pullenti.unisharp.Utils.parseInteger(str.substring(2), 0, null, wrapn1437);
                n = (wrapn1437.value != null ? wrapn1437.value : 0);
                if (inoutres1438) 
                    i += n;
            }
        }
        else if (com.pullenti.morph.LanguageHelper.isCyrillicChar(ch)) {
            i = ruNums.indexOf(ch);
            if (i < 0) 
                return 0;
            i++;
            if ((ch == 'Я' && str.length() > 2 && str.charAt(1) == '.') && Character.isDigit(str.charAt(2))) {
                int n;
                com.pullenti.unisharp.Outargwrapper<Integer> wrapn1439 = new com.pullenti.unisharp.Outargwrapper<Integer>();
                boolean inoutres1440 = com.pullenti.unisharp.Utils.parseInteger(str.substring(2), 0, null, wrapn1439);
                n = (wrapn1439.value != null ? wrapn1439.value : 0);
                if (inoutres1440) 
                    i += n;
            }
        }
        if (i < 0) 
            return 0;
        return i;
    }

    private static String ruNums = "АБВГДЕЖЗИКЛМНОПРСТУФХЦЧШЩЭЮЯ";

    @Override
    public int compareTo(PartToken other) {
        if ((typ.value()) > (other.typ.value())) 
            return -1;
        if ((typ.value()) < (other.typ.value())) 
            return 1;
        return 0;
    }

    public static void sort(java.util.ArrayList<PartToken> list) {
        for (int ii = 0; ii < list.size(); ii++) {
            for (int jj = 0; jj < (list.size() - 1); jj++) {
                if (list.get(jj).compareTo(list.get(jj + 1)) > 0) {
                    PartToken pp = list.get(jj);
                    com.pullenti.unisharp.Utils.putArrayValue(list, jj, list.get(jj + 1));
                    com.pullenti.unisharp.Utils.putArrayValue(list, jj + 1, pp);
                }
            }
        }
    }

    public static PartToken _new1052(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, ItemType _arg3, Object _arg4) {
        PartToken res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.tag = _arg4;
        return res;
    }

    public static PartToken _new1056(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, ItemType _arg3, com.pullenti.ner.MorphCollection _arg4, Object _arg5) {
        PartToken res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.setMorph(_arg4);
        res.tag = _arg5;
        return res;
    }

    public static PartToken _new1058(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, ItemType _arg3) {
        PartToken res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        return res;
    }

    public static PartToken _new1060(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, ItemType _arg3, com.pullenti.ner.MorphCollection _arg4) {
        PartToken res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.setMorph(_arg4);
        return res;
    }

    public static PartToken _new1357(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, ItemType _arg3, boolean _arg4) {
        PartToken res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.isDoubt = _arg4;
        return res;
    }

    public static PartToken _new1412(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, ItemType _arg3, ItemType _arg4) {
        PartToken res = new PartToken(_arg1, _arg2);
        res.typ = _arg3;
        res.altTyp = _arg4;
        return res;
    }

    public static class ItemType implements Comparable<ItemType> {
    
        public static final ItemType UNDEFINED; // 0
    
        public static final ItemType PREFIX; // 1
    
        public static final ItemType DOCPART; // 2
    
        public static final ItemType SUBPROGRAM; // 3
    
        public static final ItemType APPENDIX; // 4
    
        public static final ItemType APPENDIX2; // 5
    
        public static final ItemType SECTION; // 6
    
        public static final ItemType SUBSECTION; // 7
    
        public static final ItemType CHAPTER; // 8
    
        public static final ItemType CLAUSE; // 9
    
        public static final ItemType PART; // 10
    
        public static final ItemType PARAGRAPH; // 11
    
        public static final ItemType SUBPARAGRAPH; // 12
    
        public static final ItemType ITEM; // 13
    
        public static final ItemType SUBITEM; // 14
    
        public static final ItemType INDENTION; // 15
    
        public static final ItemType SUBINDENTION; // 16
    
        public static final ItemType PREAMBLE; // 17
    
        public static final ItemType NOTICE; // 18
    
        public static final ItemType FOOTNOTE; // 19
    
        public static final ItemType FORMULA; // 20
    
        public static final ItemType FORM; // 21
    
        public static final ItemType TABLE; // 22
    
        public static final ItemType TABLECOLUMN; // 23
    
        public static final ItemType TABLEROW; // 24
    
        public static final ItemType TABLEITEM; // 25
    
        public static final ItemType TABLESUBITEM; // 26
    
        public static final ItemType LIST; // 27
    
        public static final ItemType SENTENCE; // 28
    
        public static final ItemType PAGE; // 29
    
        public static final ItemType ADDAGREE; // 30
    
        public static final ItemType NAME; // 31
    
        public static final ItemType FREETEXT; // 32
    
    
        public int value() { return m_val; }
        private int m_val;
        private String m_str;
        private ItemType(int val, String str) { m_val = val; m_str = str; }
        @Override
        public String toString() {
            if(m_str != null) return m_str;
            return ((Integer)m_val).toString();
        }
        @Override
        public int hashCode() {
            return (int)m_val;
        }
        @Override
        public int compareTo(ItemType v) {
            if(m_val < v.m_val) return -1;
            if(m_val > v.m_val) return 1;
            return 0;
        }
        private static java.util.HashMap<Integer, ItemType> mapIntToEnum; 
        private static java.util.HashMap<String, ItemType> mapStringToEnum; 
        private static ItemType[] m_Values; 
        private static java.util.Collection<Integer> m_Keys; 
        public static ItemType of(int val) {
            if (mapIntToEnum.containsKey(val)) return mapIntToEnum.get(val);
            ItemType item = new ItemType(val, ((Integer)val).toString());
            mapIntToEnum.put(val, item);
            mapStringToEnum.put(item.m_str.toUpperCase(), item);
            return item; 
        }
        public static ItemType of(String str) {
            str = str.toUpperCase(); 
            if (mapStringToEnum.containsKey(str)) return mapStringToEnum.get(str);
            return null; 
        }
        public static boolean isDefined(Object val) {
            if(val instanceof Integer) return m_Keys.contains((Integer)val); 
            return false; 
        }
        public static ItemType[] getValues() {
            return m_Values; 
        }
        static {
            mapIntToEnum = new java.util.HashMap<Integer, ItemType>();
            mapStringToEnum = new java.util.HashMap<String, ItemType>();
            UNDEFINED = new ItemType(0, "UNDEFINED");
            mapIntToEnum.put(UNDEFINED.value(), UNDEFINED);
            mapStringToEnum.put(UNDEFINED.m_str.toUpperCase(), UNDEFINED);
            PREFIX = new ItemType(1, "PREFIX");
            mapIntToEnum.put(PREFIX.value(), PREFIX);
            mapStringToEnum.put(PREFIX.m_str.toUpperCase(), PREFIX);
            DOCPART = new ItemType(2, "DOCPART");
            mapIntToEnum.put(DOCPART.value(), DOCPART);
            mapStringToEnum.put(DOCPART.m_str.toUpperCase(), DOCPART);
            SUBPROGRAM = new ItemType(3, "SUBPROGRAM");
            mapIntToEnum.put(SUBPROGRAM.value(), SUBPROGRAM);
            mapStringToEnum.put(SUBPROGRAM.m_str.toUpperCase(), SUBPROGRAM);
            APPENDIX = new ItemType(4, "APPENDIX");
            mapIntToEnum.put(APPENDIX.value(), APPENDIX);
            mapStringToEnum.put(APPENDIX.m_str.toUpperCase(), APPENDIX);
            APPENDIX2 = new ItemType(5, "APPENDIX2");
            mapIntToEnum.put(APPENDIX2.value(), APPENDIX2);
            mapStringToEnum.put(APPENDIX2.m_str.toUpperCase(), APPENDIX2);
            SECTION = new ItemType(6, "SECTION");
            mapIntToEnum.put(SECTION.value(), SECTION);
            mapStringToEnum.put(SECTION.m_str.toUpperCase(), SECTION);
            SUBSECTION = new ItemType(7, "SUBSECTION");
            mapIntToEnum.put(SUBSECTION.value(), SUBSECTION);
            mapStringToEnum.put(SUBSECTION.m_str.toUpperCase(), SUBSECTION);
            CHAPTER = new ItemType(8, "CHAPTER");
            mapIntToEnum.put(CHAPTER.value(), CHAPTER);
            mapStringToEnum.put(CHAPTER.m_str.toUpperCase(), CHAPTER);
            CLAUSE = new ItemType(9, "CLAUSE");
            mapIntToEnum.put(CLAUSE.value(), CLAUSE);
            mapStringToEnum.put(CLAUSE.m_str.toUpperCase(), CLAUSE);
            PART = new ItemType(10, "PART");
            mapIntToEnum.put(PART.value(), PART);
            mapStringToEnum.put(PART.m_str.toUpperCase(), PART);
            PARAGRAPH = new ItemType(11, "PARAGRAPH");
            mapIntToEnum.put(PARAGRAPH.value(), PARAGRAPH);
            mapStringToEnum.put(PARAGRAPH.m_str.toUpperCase(), PARAGRAPH);
            SUBPARAGRAPH = new ItemType(12, "SUBPARAGRAPH");
            mapIntToEnum.put(SUBPARAGRAPH.value(), SUBPARAGRAPH);
            mapStringToEnum.put(SUBPARAGRAPH.m_str.toUpperCase(), SUBPARAGRAPH);
            ITEM = new ItemType(13, "ITEM");
            mapIntToEnum.put(ITEM.value(), ITEM);
            mapStringToEnum.put(ITEM.m_str.toUpperCase(), ITEM);
            SUBITEM = new ItemType(14, "SUBITEM");
            mapIntToEnum.put(SUBITEM.value(), SUBITEM);
            mapStringToEnum.put(SUBITEM.m_str.toUpperCase(), SUBITEM);
            INDENTION = new ItemType(15, "INDENTION");
            mapIntToEnum.put(INDENTION.value(), INDENTION);
            mapStringToEnum.put(INDENTION.m_str.toUpperCase(), INDENTION);
            SUBINDENTION = new ItemType(16, "SUBINDENTION");
            mapIntToEnum.put(SUBINDENTION.value(), SUBINDENTION);
            mapStringToEnum.put(SUBINDENTION.m_str.toUpperCase(), SUBINDENTION);
            PREAMBLE = new ItemType(17, "PREAMBLE");
            mapIntToEnum.put(PREAMBLE.value(), PREAMBLE);
            mapStringToEnum.put(PREAMBLE.m_str.toUpperCase(), PREAMBLE);
            NOTICE = new ItemType(18, "NOTICE");
            mapIntToEnum.put(NOTICE.value(), NOTICE);
            mapStringToEnum.put(NOTICE.m_str.toUpperCase(), NOTICE);
            FOOTNOTE = new ItemType(19, "FOOTNOTE");
            mapIntToEnum.put(FOOTNOTE.value(), FOOTNOTE);
            mapStringToEnum.put(FOOTNOTE.m_str.toUpperCase(), FOOTNOTE);
            FORMULA = new ItemType(20, "FORMULA");
            mapIntToEnum.put(FORMULA.value(), FORMULA);
            mapStringToEnum.put(FORMULA.m_str.toUpperCase(), FORMULA);
            FORM = new ItemType(21, "FORM");
            mapIntToEnum.put(FORM.value(), FORM);
            mapStringToEnum.put(FORM.m_str.toUpperCase(), FORM);
            TABLE = new ItemType(22, "TABLE");
            mapIntToEnum.put(TABLE.value(), TABLE);
            mapStringToEnum.put(TABLE.m_str.toUpperCase(), TABLE);
            TABLECOLUMN = new ItemType(23, "TABLECOLUMN");
            mapIntToEnum.put(TABLECOLUMN.value(), TABLECOLUMN);
            mapStringToEnum.put(TABLECOLUMN.m_str.toUpperCase(), TABLECOLUMN);
            TABLEROW = new ItemType(24, "TABLEROW");
            mapIntToEnum.put(TABLEROW.value(), TABLEROW);
            mapStringToEnum.put(TABLEROW.m_str.toUpperCase(), TABLEROW);
            TABLEITEM = new ItemType(25, "TABLEITEM");
            mapIntToEnum.put(TABLEITEM.value(), TABLEITEM);
            mapStringToEnum.put(TABLEITEM.m_str.toUpperCase(), TABLEITEM);
            TABLESUBITEM = new ItemType(26, "TABLESUBITEM");
            mapIntToEnum.put(TABLESUBITEM.value(), TABLESUBITEM);
            mapStringToEnum.put(TABLESUBITEM.m_str.toUpperCase(), TABLESUBITEM);
            LIST = new ItemType(27, "LIST");
            mapIntToEnum.put(LIST.value(), LIST);
            mapStringToEnum.put(LIST.m_str.toUpperCase(), LIST);
            SENTENCE = new ItemType(28, "SENTENCE");
            mapIntToEnum.put(SENTENCE.value(), SENTENCE);
            mapStringToEnum.put(SENTENCE.m_str.toUpperCase(), SENTENCE);
            PAGE = new ItemType(29, "PAGE");
            mapIntToEnum.put(PAGE.value(), PAGE);
            mapStringToEnum.put(PAGE.m_str.toUpperCase(), PAGE);
            ADDAGREE = new ItemType(30, "ADDAGREE");
            mapIntToEnum.put(ADDAGREE.value(), ADDAGREE);
            mapStringToEnum.put(ADDAGREE.m_str.toUpperCase(), ADDAGREE);
            NAME = new ItemType(31, "NAME");
            mapIntToEnum.put(NAME.value(), NAME);
            mapStringToEnum.put(NAME.m_str.toUpperCase(), NAME);
            FREETEXT = new ItemType(32, "FREETEXT");
            mapIntToEnum.put(FREETEXT.value(), FREETEXT);
            mapStringToEnum.put(FREETEXT.m_str.toUpperCase(), FREETEXT);
            java.util.Collection<ItemType> col = mapIntToEnum.values();
            m_Values = new ItemType[col.size()];
            col.toArray(m_Values);
            m_Keys = new java.util.ArrayList<Integer>(mapIntToEnum.keySet());
        }
    }

    public PartToken() {
        super();
        if(_globalInstance == null) return;
        altTyp = ItemType.UNDEFINED;
    }
    public static PartToken _globalInstance;
    
    static {
        try { _globalInstance = new PartToken(); } 
        catch(Exception e) { }
    }
}
