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

/**
 * Анализатор ссылок на НПА
 */
public class DecreeAnalyzer extends com.pullenti.ner.Analyzer {

    public static java.util.ArrayList<com.pullenti.ner.ReferentToken> tryAttach(java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts, com.pullenti.ner.decree.internal.DecreeToken baseTyp, com.pullenti.ner.core.AnalyzerData ad) {
        if (ad == null) 
            ad = getData(dts.get(0));
        if (ad.level > 2) 
            return null;
        ad.level++;
        java.util.ArrayList<com.pullenti.ner.ReferentToken> res = _TryAttach(dts, baseTyp, false, ad);
        if (res == null && ((dts.size() == 1 || ((dts.size() == 2 && dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG)))) && dts.get(0).typRefBack) {
            for (com.pullenti.ner.Token t = dts.get(0).getBeginToken().getPrevious(); t != null; t = t.getPrevious()) {
                DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), DecreeReferent.class);
                if (dr == null) 
                    continue;
                if (t.tag instanceof String) {
                    if (com.pullenti.unisharp.Utils.stringsEq((String)com.pullenti.unisharp.Utils.cast(t.tag, String.class), "ignored")) 
                        continue;
                }
                if (dr.checkTypename(dts.get(0).value)) {
                }
                else if (dr.getOwner() != null && dr.getOwner().checkTypename(dts.get(0).value)) 
                    dr = dr.getOwner();
                else 
                    continue;
                if (dts.size() == 2 && dts.get(1).ref != null) {
                    com.pullenti.ner.Referent _org = (com.pullenti.ner.Referent)com.pullenti.unisharp.Utils.cast(dr.getSlotValue(DecreeReferent.ATTR_SOURCE), com.pullenti.ner.Referent.class);
                    if (_org != null) {
                        if (!_org.canBeEquals(dts.get(1).ref.referent, com.pullenti.ner.core.ReferentsEqualType.WITHINONETEXT)) 
                            continue;
                    }
                }
                res = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                res.add(new com.pullenti.ner.ReferentToken(dr, dts.get(0).getBeginToken(), dts.get(dts.size() - 1).getEndToken(), null));
                break;
            }
        }
        ad.level--;
        return res;
    }

    private static java.util.ArrayList<com.pullenti.ner.ReferentToken> _TryAttach(java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts, com.pullenti.ner.decree.internal.DecreeToken baseTyp, boolean afterDecree, com.pullenti.ner.core.AnalyzerData ad) {
        if (dts == null || (dts.size() < 1)) 
            return null;
        if (dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.EDITION && dts.size() > 1) 
            dts.remove(0);
        if (dts.size() == 2 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG && dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
            return null;
        if (dts.size() == 2 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
            if ((dts.get(0).getLengthChar() < 3) && !dts.get(0).isWhitespaceAfter() && dts.get(0).isDoubtful) 
                return null;
            if (dts.get(0).isNewlineAfter()) 
                return null;
        }
        if (dts.size() == 1) {
            if (dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DECREEREF && dts.get(0).ref != null) {
                if (baseTyp != null) {
                    com.pullenti.ner.Referent re = dts.get(0).ref.getReferent();
                    DecreeReferent dre = (DecreeReferent)com.pullenti.unisharp.Utils.cast(re, DecreeReferent.class);
                    if (dre == null && (re instanceof DecreePartReferent)) 
                        dre = ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(re, DecreePartReferent.class)).getOwner();
                    if (dre != null) {
                        if (!dre.checkTypename(baseTyp.value)) 
                            return null;
                    }
                }
                java.util.ArrayList<com.pullenti.ner.ReferentToken> reli = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                reli.add(new com.pullenti.ner.ReferentToken(dts.get(0).ref.referent, dts.get(0).getBeginToken(), dts.get(0).getEndToken(), null));
                return reli;
            }
        }
        DecreeReferent dec0 = null;
        boolean kodeks = false;
        boolean canbesingle = false;
        int maxEmpty = 30;
        for (com.pullenti.ner.Token t = dts.get(0).getBeginToken().getPrevious(); t != null; t = t.getPrevious()) {
            if (t.isCommaAnd()) 
                continue;
            if (t.isChar(')')) {
                int cou = 0;
                for (t = t.getPrevious(); t != null; t = t.getPrevious()) {
                    if (t.isChar('(')) 
                        break;
                    else if ((++cou) > 200) 
                        break;
                }
                if (t != null && t.isChar('(')) 
                    continue;
                break;
            }
            if ((--maxEmpty) < 0) 
                break;
            if (!t.chars.isLetter()) 
                continue;
            dec0 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), DecreeReferent.class);
            if (dec0 != null) {
                if (com.pullenti.ner.decree.internal.DecreeToken.getKind(dec0.getTyp(), null) == DecreeKind.KODEX) 
                    kodeks = true;
                else if (dec0.getKind() == DecreeKind.PUBLISHER) 
                    dec0 = null;
            }
            break;
        }
        DecreeReferent dec = new DecreeReferent();
        int i = 0;
        com.pullenti.ner.MorphCollection _morph = null;
        boolean isNounDoubt = false;
        com.pullenti.ner.decree.internal.DecreeToken numTok = null;
        com.pullenti.ner.decree.internal.DecreeToken typTok = null;
        int nl = 0;
        for (i = 0; i < dts.size(); i++) {
            if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                if (dts.get(i).value == null) 
                    break;
                if (dts.get(i).value.startsWith("ПРОЕКТ")) {
                    if (i > 0) 
                        return null;
                }
                if (dts.get(i).isNewlineBefore()) {
                    if (dec.getDate() != null || dec.getNumber() != null) 
                        break;
                }
                if (dec.getTyp() != null) {
                    if (((com.pullenti.unisharp.Utils.stringsEq(dec.getTyp(), "РЕШЕНИЕ") || com.pullenti.unisharp.Utils.stringsEq(dec.getTyp(), "РІШЕННЯ"))) && com.pullenti.unisharp.Utils.stringsEq(dts.get(i).value, "ПРОТОКОЛ")) {
                    }
                    else if (((com.pullenti.unisharp.Utils.stringsEq(dec.getTyp(), dts.get(i).value) || com.pullenti.unisharp.Utils.stringsEq(dts.get(i).value, "ТЕХНИЧЕСКИЙ РЕГЛАМЕНТ"))) && com.pullenti.unisharp.Utils.stringsEq(dec.getTyp(), "ГОСТ")) {
                        if (((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                            if (dec.getNumber() != null) 
                                break;
                            if (i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                                break;
                        }
                        continue;
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(dts.get(i).value, dec.getTyp())) {
                        if ((i + 1) >= dts.size() || dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME) 
                            continue;
                        else if ((((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME) && dec.getNumber() == null) {
                        }
                        else 
                            break;
                    }
                    else 
                        break;
                }
                DecreeKind ki = com.pullenti.ner.decree.internal.DecreeToken.getKind(dts.get(i).value, null);
                if (ki == DecreeKind.STANDARD) {
                    if (i > 0) {
                        if (dts.size() == 2 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && com.pullenti.unisharp.Utils.stringsEq(dts.get(i).value, "ТЕХНИЧЕСКИЕ УСЛОВИЯ")) {
                        }
                        else 
                            return null;
                    }
                }
                if (ki == DecreeKind.KODEX) {
                    if (i > 0) 
                        break;
                    if (com.pullenti.unisharp.Utils.stringsNe(dts.get(i).value, "ОСНОВЫ ЗАКОНОДАТЕЛЬСТВА") && com.pullenti.unisharp.Utils.stringsNe(dts.get(i).value, "ОСНОВИ ЗАКОНОДАВСТВА")) 
                        kodeks = true;
                    else 
                        kodeks = false;
                }
                else 
                    kodeks = false;
                _morph = dts.get(i).getMorph();
                dec.addTyp(dts.get(i));
                if (typTok == null) 
                    typTok = dts.get(i);
                if (dts.get(i).canBeSingleDecree) 
                    canbesingle = true;
                if (dts.get(i).fullValue != null) 
                    dec.addNameStr(dts.get(i).fullValue, dts.get(i));
                isNounDoubt = dts.get(i).isDoubtful;
                if (isNounDoubt && i == 0) {
                    if (com.pullenti.ner.decree.internal.PartToken.isPartBefore(dts.get(i).getBeginToken())) 
                        isNounDoubt = false;
                }
                if (dts.get(i).ref != null) {
                    if (dec.findSlot(DecreeReferent.ATTR_GEO, null, true) == null) {
                        com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_GEO, dts.get(i).ref.referent, false, 0);
                        ss.addAnnotation(dts.get(i).ref);
                        dec.addExtReferent(dts.get(i).ref);
                    }
                }
                if (dts.get(i).srcRef != null) {
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts.get(i).srcRef, false, 0);
                    ss.addAnnotation(dts.get(i));
                }
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                if (dec.getDate() != null) 
                    break;
                if (kodeks) {
                    if (i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                    }
                    else if (((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                    }
                    else 
                        break;
                }
                if (i == (dts.size() - 1)) {
                    if (!dts.get(i).getBeginToken().isValue("ОТ", "ВІД")) {
                        DecreeKind ty = com.pullenti.ner.decree.internal.DecreeToken.getKind(dec.getTyp(), null);
                        if ((ty == DecreeKind.KONVENTION || ty == DecreeKind.CONTRACT || ty == DecreeKind.LICENSE) || com.pullenti.unisharp.Utils.stringsEq(dec.getTyp0(), "ПИСЬМО") || com.pullenti.unisharp.Utils.stringsEq(dec.getTyp0(), "ЛИСТ")) {
                        }
                        else 
                            break;
                    }
                }
                dec.addDate(dts.get(i));
                dec.addExtReferent(dts.get(i).ref);
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATERANGE) {
                if (dec.getKind() != DecreeKind.PROGRAM) 
                    break;
                dec.addDate(dts.get(i));
                dec.addExtReferent(dts.get(i).ref);
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.EDITION) {
                if (dts.get(i).isNewlineBefore() && !dts.get(i).getBeginToken().chars.isAllLower() && !dts.get(i).getBeginToken().isChar('(')) 
                    break;
                if (((i + 2) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                    break;
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                if (kodeks) {
                    if (((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                    }
                    else if (i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                    }
                    else 
                        break;
                }
                numTok = dts.get(i);
                if (dts.get(i).isDelo()) {
                    if (dec.getCaseNumber() != null) 
                        break;
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_CASENUMBER, dts.get(i).value, true, 0);
                    ss.addAnnotation(dts.get(i));
                    continue;
                }
                if (dec.getNumber() != null) {
                    if (i > 2 && ((dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER || dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG)) && dts.get(i - 2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                    }
                    else 
                        break;
                }
                if (dts.get(i).isNewlineBefore()) {
                    if (dec.getTyp() == null && dec0 == null) 
                        break;
                }
                if (com.pullenti.morph.LanguageHelper.endsWith(dts.get(i).value, "ФЗ")) 
                    dec.setTyp("ФЕДЕРАЛЬНЫЙ ЗАКОН");
                if (com.pullenti.morph.LanguageHelper.endsWith(dts.get(i).value, "ФКЗ")) 
                    dec.setTyp("ФЕДЕРАЛЬНЫЙ КОНСТИТУЦИОННЫЙ ЗАКОН");
                if (dts.get(i).value != null && com.pullenti.unisharp.Utils.startsWithString(dts.get(i).value, "ПР", true) && dec.getTyp() == null) 
                    dec.setTyp("ПОРУЧЕНИЕ");
                if (dec.getTyp() == null) {
                    if (dec0 == null && !afterDecree && baseTyp == null) 
                        break;
                }
                dec.addNumber(dts.get(i));
                if (dts.get(i).children != null) {
                    int cou = 0;
                    for (com.pullenti.ner.Slot s : dec.getSlots()) {
                        if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreeReferent.ATTR_SOURCE)) 
                            cou++;
                    }
                    if (cou == (dts.get(i).children.size() + 1)) {
                        for (com.pullenti.ner.decree.internal.DecreeToken dd : dts.get(i).children) {
                            dec.addNumber(dd);
                        }
                        dts.get(i).children = null;
                    }
                }
                continue;
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME) {
                if (dec.getTyp() == null && dec.getNumber() == null && dec0 == null) {
                    if (dts.get(i).typKind == DecreeKind.CLASSIFIER || dts.get(i).typKind == DecreeKind.STANDARD) {
                    }
                    else if ((i == 0 && ((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) && (dts.get(i + 1).getWhitespacesBeforeCount() < 3)) {
                    }
                    else 
                        break;
                }
                if (dec.getStringValue(DecreeReferent.ATTR_NAME) != null) {
                    if (kodeks) 
                        break;
                    if (i > 0 && dts.get(i - 1).getEndToken().getNext() == dts.get(i).getBeginToken()) {
                    }
                    else if (dts.get(i).typKind == DecreeKind.CLASSIFIER) {
                    }
                    else 
                        break;
                }
                com.pullenti.ner.Token tt0 = dts.get(i).getBeginToken();
                com.pullenti.ner.Token tt1 = dts.get(i).getEndToken();
                if ((i > 0 && dts.get(i - 1).isNewlineAfter() && ((i + 1) < dts.size())) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && (dts.get(i + 1).getWhitespacesBeforeCount() < 3)) 
                    break;
                if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt0, true, false) && com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(tt1, true, tt0, false)) {
                    tt0 = tt0.getNext();
                    tt1 = tt1.getPrevious();
                    for (com.pullenti.ner.Token tt = tt0; tt != null && (tt.getEndChar() < tt1.getEndChar()); tt = tt.getNext()) {
                        if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, true, false)) {
                            com.pullenti.ner.core.BracketSequenceToken br1 = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                            if (br1 != null && br1.getEndToken() == dts.get(i).getEndToken()) {
                                tt1 = tt1.getNext();
                                break;
                            }
                        }
                    }
                }
                String nam = com.pullenti.ner.core.MiscHelper.getTextValue(tt0, tt1, com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER);
                if (kodeks && !(nam.toUpperCase().indexOf("КОДЕКС") >= 0)) 
                    nam = "Кодекс " + nam;
                if (dts.get(i).fullValue != null) 
                    dec.addNameStr(dts.get(i).fullValue, dts.get(i));
                dec.addNameStr(nam, (tt0.getBeginChar() <= tt1.getBeginChar() ? new com.pullenti.ner.MetaToken(tt0, tt1, null) : null));
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.BETWEEN) {
                if (dec.getKind() != DecreeKind.CONTRACT) 
                    break;
                for (com.pullenti.ner.decree.internal.DecreeToken chh : dts.get(i).children) {
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, chh.ref.referent, false, 0);
                    ss.setTag(chh.getSourceText());
                    ss.addAnnotation(chh);
                    if (chh.ref.referent instanceof com.pullenti.ner.person.PersonPropertyReferent) 
                        dec.addExtReferent(chh.ref);
                }
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER) {
                if (kodeks) 
                    break;
                if (dec.getName() != null) 
                    break;
                if (((i == 0 || i == (dts.size() - 1))) && dts.get(i).getBeginToken().chars.isAllLower()) 
                    break;
                if (i == 0 && dts.size() > 1 && dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                    break;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) != null) {
                }
                if (dts.get(i).ref != null) {
                    DecreeKind ty = com.pullenti.ner.decree.internal.DecreeToken.getKind(dec.getTyp(), null);
                    if (ty == DecreeKind.USTAV) {
                        if (!(dts.get(i).ref.referent instanceof com.pullenti.ner._org.OrganizationReferent)) 
                            break;
                    }
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts.get(i).ref.referent, false, 0);
                    ss.setTag(dts.get(i).getSourceText());
                    ss.addAnnotation(dts.get(i));
                    if (dts.get(i).ref.referent instanceof com.pullenti.ner.person.PersonPropertyReferent) 
                        dec.addExtReferent(dts.get(i).ref);
                }
                else {
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, com.pullenti.ner.core.MiscHelper.convertFirstCharUpperAndOtherLower(dts.get(i).value), false, 0);
                    ss.setTag(dts.get(i).getSourceText());
                    ss.addAnnotation(dts.get(i));
                }
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG) {
                if (kodeks) {
                    if (i != 1 || dts.get(i).getWhitespacesBeforeCount() > 3) 
                        break;
                    if (dts.size() == 2 || ((dts.size() == 3 && dts.get(2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.MISC))) {
                    }
                    else 
                        break;
                    isNounDoubt = false;
                }
                else if (dec.getName() != null) 
                    break;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) != null) {
                    if (i > 2 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && ((dts.get(i - 2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG || dts.get(i - 2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER))) {
                    }
                    else if (dts.get(i).getBeginToken().getPrevious() != null && dts.get(i).getBeginToken().getPrevious().isAnd()) {
                    }
                    else if (i > 0 && ((dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER || dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG))) {
                    }
                    else if (i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dts.get(i - 1).srcRef == dec.getSlotValue(DecreeReferent.ATTR_SOURCE)) {
                    }
                    else 
                        break;
                }
                com.pullenti.ner.ReferentToken ttt = (com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(dts.get(i).getBeginToken(), com.pullenti.ner.ReferentToken.class);
                if (ttt != null && ttt == dts.get(i).getEndToken() && ttt.getBeginToken() != ttt.getEndToken()) {
                    if ((ttt.getBeginToken().getReferent() instanceof com.pullenti.ner._org.OrganizationReferent) && ttt.getBeginToken().getNext().isComma()) {
                        com.pullenti.ner.Slot sl1 = dec.addSlot(DecreeReferent.ATTR_SOURCE, ttt.getBeginToken().getReferent(), false, 0);
                        sl1.setTag(ttt.getBeginToken().getSourceText());
                        sl1.addAnnotation((com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(ttt.getBeginToken(), com.pullenti.ner.ReferentToken.class));
                    }
                }
                com.pullenti.ner.Slot sl = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts.get(i).ref.referent, false, 0);
                sl.setTag(dts.get(i).getSourceText());
                sl.addAnnotation(dts.get(i));
                if (((i + 2) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.UNKNOWN && (dts.get(i + 1).getWhitespacesBeforeCount() < 2)) {
                    if (dts.get(i + 2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER || dts.get(i + 2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                        sl.setTag((new com.pullenti.ner.MetaToken(dts.get(i).getBeginToken(), dts.get(i + 1).getEndToken(), null)).getSourceText());
                        i++;
                    }
                }
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TERR) {
                if (dec.findSlot(DecreeReferent.ATTR_GEO, null, true) != null) 
                    break;
                if (i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME) 
                    break;
                if (dts.get(i).isNewlineBefore() && ((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) 
                    break;
                com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_GEO, dts.get(i).ref.referent, false, 0);
                ss.addAnnotation(dts.get(i));
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.UNKNOWN) {
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) != null) 
                    break;
                if (kodeks) 
                    break;
                if ((dec.getKind() == DecreeKind.CONTRACT && i == 1 && ((i + 1) < dts.size())) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                    dec.addNameStr(com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(dts.get(i), com.pullenti.ner.core.GetTextAttr.KEEPREGISTER), dts.get(i));
                    continue;
                }
                if (i == 0) {
                    if (dec0 == null && !afterDecree) 
                        break;
                    boolean ok1 = false;
                    if (((i + 1) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                        ok1 = true;
                    else if (((i + 2) < dts.size()) && dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TERR && dts.get(i + 2).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                        ok1 = true;
                    if (!ok1) 
                        break;
                }
                else if (dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER || dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG) 
                    continue;
                if ((i + 1) >= dts.size()) 
                    break;
                if (dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dts.get(0).isDoubtful) 
                    break;
                if (dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER || dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE || dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME) {
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts.get(i).value, false, 0);
                    ss.setTag(dts.get(i).getSourceText());
                    ss.addAnnotation(dts.get(i));
                    continue;
                }
                if (dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TERR) {
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, dts.get(i).value, false, 0);
                    ss.setTag(dts.get(i).getSourceText());
                    ss.addAnnotation(dts.get(i));
                    continue;
                }
                if (dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER) {
                    String s = com.pullenti.ner.core.MiscHelper.getTextValue(dts.get(i).getBeginToken(), dts.get(i + 1).getEndToken(), com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                    dts.get(i).setEndToken(dts.get(i + 1).getEndToken());
                    com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, s, false, 0);
                    ss.setTag(dts.get(i).getSourceText());
                    ss.addAnnotation(dts.get(i));
                    i++;
                    continue;
                }
                break;
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.MISC) {
                if (i == 0 || kodeks) 
                    break;
                if ((i + 1) >= dts.size()) {
                    if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(dts.get(i).getEndToken().getNext(), true, false)) 
                        continue;
                    if (i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                        if (com.pullenti.ner.decree.internal.DecreeToken.tryAttachName(dts.get(i).getEndToken().getNext(), null, true, false, false) != null) 
                            continue;
                    }
                }
                else if (dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME || dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER || dts.get(i + 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) 
                    continue;
                break;
            }
            else 
                break;
        }
        if (i == 0) 
            return null;
        if (dec.getTyp() == null || ((dec0 != null && dts.get(0).typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP))) {
            if (dec0 != null) {
                if (dec.getNumber() == null && dec.getDate() == null && dec.findSlot(DecreeReferent.ATTR_NAME, null, true) == null) 
                    return null;
                if (dec.getTyp() == null) 
                    dec.setTyp(dec0.getTyp());
                if (dec.findSlot(DecreeReferent.ATTR_GEO, null, true) == null) 
                    dec.addSlot(DecreeReferent.ATTR_GEO, dec0.getStringValue(DecreeReferent.ATTR_GEO), false, 0);
                if (dec.findSlot(DecreeReferent.ATTR_DATE, null, true) == null && dec0.getDate() != null) 
                    dec.addSlot(DecreeReferent.ATTR_DATE, dec0.getSlotValue(DecreeReferent.ATTR_DATE), false, 0);
                com.pullenti.ner.Slot sl;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) == null) {
                    if ((((sl = dec0.findSlot(DecreeReferent.ATTR_SOURCE, null, true)))) != null) {
                        com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, sl.getValue(), false, 0);
                        ss.setTag(sl.getTag());
                        ss.mergeOccurence(sl);
                    }
                }
            }
            else if (baseTyp != null && afterDecree) 
                dec.addTyp(baseTyp);
            else 
                return null;
        }
        com.pullenti.ner.Token et = dts.get(i - 1).getEndToken();
        if ((((!afterDecree && dts.size() == i && i == 3) && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) && dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) != null && et.getNext() != null) && et.getNext().isComma() && dec.getNumber() != null) {
            for (com.pullenti.ner.Token tt = et.getNext(); tt != null; tt = tt.getNext()) {
                if (!tt.isChar(',')) 
                    break;
                java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> ddd = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(tt.getNext(), dts.get(0), 10, false);
                if (ddd == null || (ddd.size() < 2) || ddd.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                    break;
                boolean hasNum = false;
                for (com.pullenti.ner.decree.internal.DecreeToken d : ddd) {
                    if (d.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                        hasNum = true;
                    else if (d.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                        hasNum = false;
                        break;
                    }
                }
                if (!hasNum) 
                    break;
                java.util.ArrayList<com.pullenti.ner.ReferentToken> rtt = _TryAttach(ddd, dts.get(0), true, ad);
                if (rtt == null) 
                    break;
                dec.mergeSlots(rtt.get(0).referent, true);
                et = (tt = rtt.get(0).getEndToken());
            }
        }
        if (((et.getNext() != null && et.getNext().isChar('<') && (et.getNext().getNext() instanceof com.pullenti.ner.ReferentToken)) && et.getNext().getNext().getNext() != null && et.getNext().getNext().getNext().isChar('>')) && com.pullenti.unisharp.Utils.stringsEq(et.getNext().getNext().getReferent().getTypeName(), "URI")) 
            et = et.getNext().getNext().getNext();
        String num = dec.getNumber();
        if ((dec.findSlot(DecreeReferent.ATTR_NAME, null, true) == null && (i < dts.size()) && dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) && dec.getKind() == DecreeKind.PROJECT) {
            java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts1 = new java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken>(dts);
            for(int jjj = 0 + i - 1, mmm = 0; jjj >= mmm; jjj--) dts1.remove(jjj);
            java.util.ArrayList<com.pullenti.ner.ReferentToken> rt1 = _TryAttach(dts1, null, true, ad);
            if (rt1 != null) {
                dec.addNameStr(com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(rt1.get(0), com.pullenti.ner.core.GetTextAttr.KEEPREGISTER), rt1.get(0));
                et = rt1.get(0).getEndToken();
            }
        }
        if (com.pullenti.unisharp.Utils.stringsEq(dec.getTyp(), "РУКОВОДЯЩИЙ ДОКУМЕНТ") && !et.isNewlineAfter()) {
            com.pullenti.ner.decree.internal.DecreeToken typ1 = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(et.getNext(), null, false);
            if (typ1 != null && typ1.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && com.pullenti.unisharp.Utils.stringsEq(typ1.value, dec.getTyp())) {
                com.pullenti.ner.Token tt = typ1.getEndToken().getNext();
                for (; tt != null; tt = tt.getNext()) {
                    if (tt.isChar('.') || tt.isHiphen() || tt.isValue("ОТРАСЛЬ", null)) {
                    }
                    else 
                        break;
                }
                com.pullenti.ner.decree.internal.DecreeToken dn = com.pullenti.ner.decree.internal.DecreeToken.tryAttachName(tt, dec.getTyp(), false, false, false);
                if (dn != null) {
                    if (dn.fullValue != null) 
                        dec.addNameStr(dn.fullValue, dn);
                    if (dn.value != null) 
                        dec.addNameStr(dn.value, dn);
                    et = dn.getEndToken();
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_NAME, null, true) == null && !kodeks && et.getNext() != null) {
            com.pullenti.ner.decree.internal.DecreeToken dn = com.pullenti.ner.decree.internal.DecreeToken.tryAttachName((et.getNext().isChar(':') ? et.getNext().getNext() : et.getNext()), dec.getTyp(), false, false, false);
            if (dn != null && et.getNext().chars.isAllLower() && num != null) {
                if (ad != null) {
                    for (com.pullenti.ner.Referent r : ad.getReferents()) {
                        if (r.findSlot(DecreeReferent.ATTR_NUMBER, num, true) != null) {
                            if (r.canBeEquals(dec, com.pullenti.ner.core.ReferentsEqualType.WITHINONETEXT)) {
                                if (r.findSlot(DecreeReferent.ATTR_NAME, dn.value, true) == null) 
                                    dn = null;
                                break;
                            }
                        }
                    }
                }
            }
            if (dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dn != null && et.isNewlineAfter()) 
                dn = null;
            if (dn != null) {
                if (dec.getKind() == DecreeKind.PROGRAM) {
                    dn.setBeginToken(dts.get(0).getBeginToken());
                    dn.fullValue = com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(dn, com.pullenti.ner.core.GetTextAttr.of((com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVESINGLE.value()) | (com.pullenti.ner.core.GetTextAttr.KEEPREGISTER.value())));
                    if (com.pullenti.unisharp.Utils.startsWithString(dn.fullValue, "ГОСПРОГРАММА", true)) 
                        dn.fullValue = "Государственная программа" + dn.fullValue.substring(12);
                }
                if (dec.getKind() == DecreeKind.PROGRAM) {
                    for (com.pullenti.ner.Token tt1 = dn.getEndToken().getPrevious(); tt1 != null && tt1.getBeginChar() > dn.getBeginChar(); tt1 = (tt1 == null ? null : tt1.getPrevious())) {
                        if (tt1.isChar(')') && tt1.getPrevious() != null) 
                            tt1 = tt1.getPrevious();
                        if (tt1.getReferent() instanceof com.pullenti.ner.date.DateRangeReferent) 
                            dec.addSlot(DecreeReferent.ATTR_DATE, tt1.getReferent(), false, 0);
                        else if ((tt1.getReferent() instanceof com.pullenti.ner.date.DateReferent) && tt1.getPrevious() != null && tt1.getPrevious().isValue("ДО", null)) {
                            com.pullenti.ner.ReferentToken rt11 = tt1.kit.processReferent("DATE", tt1.getPrevious(), null);
                            if (rt11 != null && (rt11.referent instanceof com.pullenti.ner.date.DateRangeReferent)) {
                                dec.addSlot(DecreeReferent.ATTR_DATE, rt11.referent, false, 0);
                                dec.addExtReferent(rt11);
                                tt1 = tt1.getPrevious();
                            }
                            else 
                                break;
                        }
                        else if ((tt1.getReferent() instanceof com.pullenti.ner.date.DateReferent) && tt1.getPrevious() != null && ((tt1.getPrevious().isValue("НА", null) || tt1.getPrevious().isValue("В", null)))) {
                            dec.addSlot(DecreeReferent.ATTR_DATE, tt1.getReferent(), false, 0);
                            tt1 = tt1.getPrevious();
                        }
                        else 
                            break;
                        for (tt1 = tt1.getPrevious(); tt1 != null && tt1.getBeginChar() > dn.getBeginChar(); tt1 = (tt1 == null ? null : tt1.getPrevious())) {
                            if (tt1.getMorph()._getClass().isConjunction() || tt1.getMorph()._getClass().isPreposition()) 
                                continue;
                            if (tt1.isValue("ПЕРИОД", "ПЕРІОД") || tt1.isValue("ПЕРСПЕКТИВА", null)) 
                                continue;
                            if (tt1.isChar('(')) 
                                continue;
                            break;
                        }
                        if (tt1 != null && tt1.getEndChar() > dn.getBeginChar()) {
                            if (dn.fullValue == null) 
                                dn.fullValue = dn.value;
                            dn.value = com.pullenti.ner.core.MiscHelper.getTextValue(dn.getBeginToken(), tt1, com.pullenti.ner.core.GetTextAttr.of((com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVESINGLE.value()) | (com.pullenti.ner.core.GetTextAttr.KEEPREGISTER.value())));
                        }
                        tt1 = tt1.getNext();
                    }
                }
                if (dn.fullValue != null) 
                    dec.addNameStr(dn.fullValue, dn);
                if ((dts.size() == 1 && dec.getKind() != DecreeKind.PROGRAM && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) && dn.getBeginToken().getMorph().getCase().isGenitive() && !dn.getBeginToken().getMorph()._getClass().isPreposition()) {
                    String str = com.pullenti.ner.core.MiscHelper.getTextValue(dts.get(0).getBeginToken(), dn.getEndToken(), com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                    dec.addNameStr(str, new com.pullenti.ner.MetaToken(dts.get(0).getBeginToken(), dn.getEndToken(), null));
                }
                else 
                    dec.addNameStr(dn.value, new com.pullenti.ner.MetaToken(dts.get(0).getBeginToken(), dn.getEndToken(), null));
                et = dn.getEndToken();
                boolean br = false;
                for (com.pullenti.ner.Token tt = et.getNext(); tt != null; tt = tt.getNext()) {
                    if (tt.isChar('(')) {
                        br = true;
                        continue;
                    }
                    if (tt.isChar(')') && br) {
                        et = tt;
                        continue;
                    }
                    if ((tt.getReferent() instanceof com.pullenti.ner.date.DateRangeReferent) && dec.getKind() == DecreeKind.PROGRAM) {
                        dec.addSlot(DecreeReferent.ATTR_DATE, tt.getReferent(), false, 0);
                        et = tt;
                        continue;
                    }
                    dn = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(tt, null, false);
                    if (dn == null) 
                        break;
                    if (dn.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE && dec.getDate() == null) {
                        if (dec.addDate(dn)) {
                            et = (tt = dn.getEndToken());
                            continue;
                        }
                    }
                    if (dn.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && dec.getNumber() == null) {
                        dec.addNumber(dn);
                        et = (tt = dn.getEndToken());
                        continue;
                    }
                    if (dn.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATERANGE && dec.getKind() == DecreeKind.PROGRAM) {
                        if (dec.addDate(dn)) {
                            et = (tt = dn.getEndToken());
                            continue;
                        }
                    }
                    if (dn.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TERR && dec.findSlot(DecreeReferent.ATTR_GEO, null, true) == null && dn.ref != null) {
                        dec.addSlot(DecreeReferent.ATTR_GEO, dn.ref.referent, false, 0);
                        et = (tt = dn.getEndToken());
                        continue;
                    }
                    break;
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) == null) {
            com.pullenti.ner.Token tt0 = dts.get(0).getBeginToken().getPrevious();
            if ((tt0 != null && tt0.isValue("В", "У") && tt0.getPrevious() != null) && (tt0.getPrevious().getReferent() instanceof com.pullenti.ner._org.OrganizationReferent)) {
                com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, tt0.getPrevious().getReferent(), false, 0);
                ss.addAnnotation((com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(tt0.getPrevious(), com.pullenti.ner.ReferentToken.class));
            }
        }
        if (!canbesingle && !dec.checkCorrection(isNounDoubt)) {
            String ty = dec.getTyp();
            com.pullenti.ner.Slot sl = null;
            if (dec0 != null && dec.getDate() != null && dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) == null) 
                sl = dec0.findSlot(DecreeReferent.ATTR_SOURCE, null, true);
            if (sl != null && (((((com.pullenti.unisharp.Utils.stringsEq(ty, "ПОСТАНОВЛЕНИЕ") || com.pullenti.unisharp.Utils.stringsEq(ty, "ПОСТАНОВА") || com.pullenti.unisharp.Utils.stringsEq(ty, "ОПРЕДЕЛЕНИЕ")) || com.pullenti.unisharp.Utils.stringsEq(ty, "ВИЗНАЧЕННЯ") || com.pullenti.unisharp.Utils.stringsEq(ty, "РЕШЕНИЕ")) || com.pullenti.unisharp.Utils.stringsEq(ty, "РІШЕННЯ") || com.pullenti.unisharp.Utils.stringsEq(ty, "ПРИГОВОР")) || com.pullenti.unisharp.Utils.stringsEq(ty, "ВИРОК")))) 
                dec.addSlot(sl.getTypeName(), sl.getValue(), false, 0).setTag(sl.getTag());
            else {
                int eqDecs = 0;
                DecreeReferent dr0 = null;
                if (num != null) {
                    if (ad != null) {
                        for (com.pullenti.ner.Referent r : ad.getReferents()) {
                            if (r.findSlot(DecreeReferent.ATTR_NUMBER, num, true) != null) {
                                if (r.canBeEquals(dec, com.pullenti.ner.core.ReferentsEqualType.WITHINONETEXT)) {
                                    eqDecs++;
                                    dr0 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(r, DecreeReferent.class);
                                }
                            }
                        }
                    }
                }
                if (eqDecs == 1) 
                    dec.mergeSlots(dr0, true);
                else {
                    boolean ok1 = false;
                    if (num != null) {
                        for (com.pullenti.ner.Token tt = dts.get(0).getBeginToken().getPrevious(); tt != null; tt = tt.getPrevious()) {
                            if (tt.isCharOf(":,") || tt.isHiphen() || com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, false, false)) {
                            }
                            else {
                                if (tt.isValue("ДАЛЕЕ", "ДАЛІ") || tt.isValue("УТВЕРЖДЕННЫЙ", null)) 
                                    ok1 = true;
                                break;
                            }
                        }
                    }
                    if (!ok1) 
                        return null;
                }
            }
        }
        com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(dec, dts.get(0).getBeginToken(), et, null);
        if (dec.getSlots().size() == 2 && com.pullenti.unisharp.Utils.stringsEq(dec.getSlots().get(0).getTypeName(), DecreeReferent.ATTR_TYPE) && com.pullenti.unisharp.Utils.stringsEq(dec.getSlots().get(1).getTypeName(), DecreeReferent.ATTR_NAME)) {
            boolean err = true;
            for (com.pullenti.ner.Token tt = rt.getBeginToken(); tt != null && tt.getEndChar() <= rt.getEndChar(); tt = tt.getNext()) {
                if (tt.getReferent() instanceof com.pullenti.ner.geo.GeoReferent) {
                }
                else if ((tt instanceof com.pullenti.ner.TextToken) && tt.chars.isLetter() && !tt.chars.isAllLower()) {
                    err = false;
                    break;
                }
            }
            if (err) 
                return null;
        }
        if (_morph != null) 
            rt.setMorph(_morph);
        if (rt.chars.isAllLower()) {
            if (com.pullenti.unisharp.Utils.stringsEq(dec.getTyp0(), "ДЕКЛАРАЦИЯ") || com.pullenti.unisharp.Utils.stringsEq(dec.getTyp0(), "ДЕКЛАРАЦІЯ")) 
                return null;
            if (((com.pullenti.unisharp.Utils.stringsEq(dec.getTyp0(), "КОНСТИТУЦИЯ") || com.pullenti.unisharp.Utils.stringsEq(dec.getTyp0(), "КОНСТИТУЦІЯ"))) && rt.getBeginToken() == rt.getEndToken()) {
                boolean ok1 = false;
                int cou = 10;
                for (com.pullenti.ner.Token tt = rt.getBeginToken().getPrevious(); tt != null && cou > 0; tt = tt.getPrevious(),cou--) {
                    if (tt.isNewlineAfter()) 
                        break;
                    com.pullenti.ner.decree.internal.PartToken pt = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, false);
                    if (pt != null && pt.typ != com.pullenti.ner.decree.internal.PartToken.ItemType.PREFIX && pt.getEndToken().getNext() == rt.getBeginToken()) {
                        ok1 = true;
                        break;
                    }
                }
                if (!ok1) 
                    return null;
            }
        }
        if (num != null && ((num.indexOf('/') > 0 || num.indexOf(',') > 0))) {
            int cou = 0;
            for (com.pullenti.ner.Slot s : dec.getSlots()) {
                if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreeReferent.ATTR_NUMBER)) 
                    cou++;
            }
            if (cou == 1) {
                int owns = 0;
                for (com.pullenti.ner.Slot s : dec.getSlots()) {
                    if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreeReferent.ATTR_SOURCE)) 
                        owns++;
                }
                if (owns > 1) {
                    String[] nums = com.pullenti.unisharp.Utils.split(num, String.valueOf('/'), false);
                    String[] nums2 = com.pullenti.unisharp.Utils.split(num, String.valueOf(','), false);
                    String strNum = null;
                    for (int ii = 0; ii < dts.size(); ii++) {
                        if (dts.get(ii).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                            strNum = dts.get(ii).getSourceText();
                            break;
                        }
                    }
                    if (nums2.length == owns && owns > 1) {
                        dec.addSlot(DecreeReferent.ATTR_NUMBER, null, true, 0);
                        for (String n : nums2) {
                            dec.addSlot(DecreeReferent.ATTR_NUMBER, n.trim(), false, 0).setTag(strNum);
                        }
                    }
                    else if (nums.length == owns && owns > 1) {
                        dec.addSlot(DecreeReferent.ATTR_NUMBER, null, true, 0);
                        for (String n : nums) {
                            dec.addSlot(DecreeReferent.ATTR_NUMBER, n.trim(), false, 0).setTag(strNum);
                        }
                    }
                }
            }
        }
        if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(rt.getBeginToken().getPrevious(), true, false) && com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(rt.getEndToken().getNext(), true, rt.getBeginToken().getPrevious(), false)) {
            rt.setBeginToken(rt.getBeginToken().getPrevious());
            rt.setEndToken(rt.getEndToken().getNext());
            java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts1 = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(rt.getEndToken().getNext(), null, 10, false);
            if (dts1 != null && dts1.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE && dec.findSlot(DecreeReferent.ATTR_DATE, null, true) == null) {
                dec.addDate(dts1.get(0));
                rt.setEndToken(dts1.get(0).getEndToken());
                if (dts1.size() > 1 && dts1.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && dec.getNumber() == null) {
                    dec.addNumber(dts1.get(1));
                    rt.setEndToken(dts1.get(1).getEndToken());
                }
            }
        }
        if (dec.getKind() == DecreeKind.STANDARD && dec.getName() == null && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(rt.getEndToken().getNext(), true, false)) {
            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(rt.getEndToken().getNext(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
            if (br != null) {
                dec.addNameStr(com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(br, com.pullenti.ner.core.GetTextAttr.KEEPREGISTER), br);
                rt.setEndToken(br.getEndToken());
            }
        }
        if (dec.getKind() == DecreeKind.PROGRAM && dec.findSlot(DecreeReferent.ATTR_DATE, null, true) == null) {
            if (rt.getBeginToken().getPrevious() != null && rt.getBeginToken().getPrevious().isValue("ПАСПОРТ", null)) {
                int cou = 0;
                for (com.pullenti.ner.Token tt = rt.getEndToken().getNext(); tt != null && (cou < 1000); tt = (tt == null ? null : tt.getNext())) {
                    if (tt.isValue("СРОК", "ТЕРМІН") && tt.getNext() != null && tt.getNext().isValue("РЕАЛИЗАЦИЯ", "РЕАЛІЗАЦІЯ")) {
                    }
                    else 
                        continue;
                    tt = tt.getNext().getNext();
                    if (tt == null) 
                        break;
                    com.pullenti.ner.decree.internal.DecreeToken dtok = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(tt, null, false);
                    if (dtok != null && dtok.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && ((com.pullenti.unisharp.Utils.stringsEq(dtok.value, "ПРОГРАММА") || com.pullenti.unisharp.Utils.stringsEq(dtok.value, "ПРОГРАМА")))) 
                        tt = dtok.getEndToken().getNext();
                    for (; tt != null; tt = tt.getNext()) {
                        if (tt.isHiphen() || tt.isTableControlChar() || tt.isValue("ПРОГРАММА", "ПРОГРАМА")) {
                        }
                        else if (tt.getReferent() instanceof com.pullenti.ner.date.DateRangeReferent) {
                            dec.addSlot(DecreeReferent.ATTR_DATE, tt.getReferent(), false, 0);
                            break;
                        }
                        else 
                            break;
                    }
                    break;
                }
            }
        }
        if (rt.getEndToken().getNext() != null && rt.getEndToken().getNext().isChar('(')) {
            com.pullenti.ner.date.DateReferent dt = null;
            boolean ok = false;
            for (com.pullenti.ner.Token tt = rt.getEndToken().getNext().getNext(); tt != null; tt = tt.getNext()) {
                com.pullenti.ner.Referent r = tt.getReferent();
                if (r instanceof com.pullenti.ner.geo.GeoReferent) 
                    continue;
                if (r instanceof com.pullenti.ner.date.DateReferent) {
                    dt = (com.pullenti.ner.date.DateReferent)com.pullenti.unisharp.Utils.cast(r, com.pullenti.ner.date.DateReferent.class);
                    continue;
                }
                if (tt.getMorph()._getClass().isPreposition()) 
                    continue;
                if (tt.getMorph()._getClass().isVerb()) 
                    continue;
                if (tt.isChar(')') && dt != null) {
                    dec.addSlot(DecreeReferent.ATTR_DATE, dt, false, 0);
                    rt.setEndToken(tt);
                    ok = true;
                }
                break;
            }
            if (!ok) {
                java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts1 = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(rt.getEndToken().getNext().getNext(), null, 10, false);
                if (dts1 != null) {
                    java.util.ArrayList<com.pullenti.ner.ReferentToken> rtt = _TryAttach(dts1, typTok, true, ad);
                    if ((rtt != null && rtt.size() == 1 && rtt.get(0).getEndToken().getNext() != null) && rtt.get(0).getEndToken().getNext().isChar(')')) {
                        DecreeReferent dec1 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(rtt.get(0).referent, DecreeReferent.class);
                        ok = com.pullenti.unisharp.Utils.stringsEq(dec.getTyp(), dec1.getTyp());
                        if ((ok && dec1.getNumber() != null && dec.getNumber() != null) && com.pullenti.unisharp.Utils.stringsNe(dec.getNumber(), dec1.getNumber())) 
                            ok = false;
                        if ((ok && dec1.getDate() != null && dec.getDate() != null) && dec.getDate().compareTo(dec1.getDate()) != 0) 
                            ok = false;
                        if (ok) {
                            dec.mergeSlots(rtt.get(0).referent, true);
                            rt.setEndToken(rtt.get(0).getEndToken().getNext());
                        }
                    }
                }
                else if (dec.getKind() == DecreeKind.CLASSIFIER) {
                    com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(rt.getEndToken().getNext(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
                    if (br != null) 
                        rt.setEndToken(br.getEndToken());
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_NAME, null, true) == null && !rt.isNewlineBefore()) {
            com.pullenti.ner.Token tt0 = null;
            int cou = 40;
            for (com.pullenti.ner.Token tt = rt.getBeginToken().getPrevious(); tt != null && cou > 0; tt = tt.getPrevious(),cou--) {
                if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, true, false)) 
                    tt0 = tt;
                else if ((tt instanceof com.pullenti.ner.TextToken) && tt.chars.isLetter()) 
                    tt0 = tt;
                if (tt.isNewlineBefore()) 
                    break;
            }
            com.pullenti.ner.decree.internal.DecreeToken nam = com.pullenti.ner.decree.internal.DecreeToken.tryAttachName(tt0, dec.getTyp(), false, false, false);
            if (nam != null && (nam.getEndChar() < rt.getBeginChar())) {
                if (nam.getEndToken().getNext() == rt.getBeginToken() || ((nam.getEndToken().getNext().isComma() && nam.getEndToken().getNext().getNext() == rt.getBeginToken()))) {
                    rt.setBeginToken(tt0);
                    dec.addNameStr(nam.value, nam);
                }
            }
        }
        if (dec.findSlot(DecreeReferent.ATTR_NAME, null, true) == null && !rt.isNewlineAfter()) {
            if (rt.isNewlineBefore() || ((rt.getBeginToken().getPrevious() != null && rt.getBeginToken().getPrevious().getLengthChar() == 1 && ((rt.getBeginToken().getPrevious().isNewlineBefore() || rt.getBeginToken().getPrevious().isTableControlChar()))))) {
                if (dec.getKind() == DecreeKind.STANDARD && dec.getNumber() != null) {
                    com.pullenti.ner.decree.internal.DecreeToken nam = com.pullenti.ner.decree.internal.DecreeToken.tryAttachNameToEndOfLine(rt.getEndToken().getNext(), false);
                    if (nam != null) {
                        rt.setEndToken(nam.getEndToken());
                        dec.addNameStr(nam.value, nam);
                    }
                }
            }
        }
        java.util.ArrayList<com.pullenti.ner.ReferentToken> rtLi = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
        if (((i + 1) < dts.size()) && dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.EDITION && !dts.get(i).isNewlineBefore()) {
            for(int jjj = 0 + i + 1 - 1, mmm = 0; jjj >= mmm; jjj--) dts.remove(jjj);
            java.util.ArrayList<com.pullenti.ner.ReferentToken> ed = _TryAttach(dts, baseTyp, true, ad);
            if (ed != null && ed.size() > 0) {
                com.pullenti.unisharp.Utils.addToArrayList(rtLi, ed);
                for (com.pullenti.ner.ReferentToken e : ed) {
                    dec.addSlot(DecreeReferent.ATTR_EDITION, e.referent, false, 0);
                }
                rt.setEndToken(ed.get(ed.size() - 1).getEndToken());
            }
        }
        else if (((i < (dts.size() - 1)) && i > 0 && dts.get(i - 1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.EDITION) && !dts.get(i - 1).isNewlineBefore()) {
            for(int jjj = 0 + i - 1, mmm = 0; jjj >= mmm; jjj--) dts.remove(jjj);
            java.util.ArrayList<com.pullenti.ner.ReferentToken> ed = _TryAttach(dts, baseTyp, true, ad);
            if (ed != null && ed.size() > 0) {
                com.pullenti.unisharp.Utils.addToArrayList(rtLi, ed);
                for (com.pullenti.ner.ReferentToken e : ed) {
                    dec.addSlot(DecreeReferent.ATTR_EDITION, e.referent, false, 0);
                }
                rt.setEndToken(ed.get(ed.size() - 1).getEndToken());
            }
        }
        if (dec.getKind() == DecreeKind.LAW || dec.getKind() == DecreeKind.ORDER) {
        }
        else {
            com.pullenti.ner.ReferentToken rt22 = DecreeAnalyzer._tryAttachApproved(rt.getEndToken().getNext(), ad, true, false, null);
            if (rt22 != null) {
                rt.setEndToken(rt22.getEndToken());
                DecreeReferent dr00 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(rt22.referent, DecreeReferent.class);
                if (dr00.getTyp() == null) {
                    for (com.pullenti.ner.Slot s : dr00.getSlots()) {
                        if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreeReferent.ATTR_DATE) || com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreeReferent.ATTR_SOURCE)) {
                            if (dec.findSlot(s.getTypeName(), null, true) == null) 
                                dec.addSlot(s.getTypeName(), s.getValue(), false, 0);
                        }
                    }
                    dr00 = null;
                }
                if (dr00 != null) {
                    rtLi.add(rt22);
                    dec.addSlot(DecreeReferent.ATTR_OWNER, rt22.referent, false, 0);
                }
            }
        }
        if (dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dts.get(0).typKind == DecreeKind.CLASSIFIER) {
            if (((rt.getBeginToken().getPrevious() != null && rt.getBeginToken().getPrevious().isChar(')') && (rt.getBeginToken().getPrevious().getPrevious() instanceof com.pullenti.ner.TextToken)) && rt.getBeginToken().getPrevious().getPrevious().chars.isAllUpper() && rt.getBeginToken().getPrevious().getPrevious().getPrevious() != null) && rt.getBeginToken().getPrevious().getPrevious().getPrevious().isChar('(')) {
                rt.setBeginToken(rt.getBeginToken().getPrevious().getPrevious().getPrevious());
                dec.addNameStr(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(rt.getBeginToken().getNext(), com.pullenti.ner.TextToken.class)).term, new com.pullenti.ner.MetaToken(rt.getBeginToken().getNext(), rt.getBeginToken().getNext(), null));
            }
        }
        rtLi.add(rt);
        if (numTok != null && numTok.children != null) {
            com.pullenti.ner.Token end = rt.getEndToken();
            rt.setEndToken(numTok.children.get(0).getBeginToken().getPrevious());
            if (rt.getEndToken().isCommaAnd()) 
                rt.setEndToken(rt.getEndToken().getPrevious());
            for (int ii = 0; ii < numTok.children.size(); ii++) {
                DecreeReferent dr1 = new DecreeReferent();
                for (com.pullenti.ner.Slot s : rt.referent.getSlots()) {
                    if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreeReferent.ATTR_NUMBER)) 
                        dr1.addSlot(s.getTypeName(), numTok.children.get(ii).value, false, 0).setTag(numTok.children.get(ii).getSourceText());
                    else {
                        com.pullenti.ner.Slot ss = dr1.addSlot(s.getTypeName(), s.getValue(), false, 0);
                        if (ss != null) 
                            ss.setTag(s.getTag());
                    }
                }
                com.pullenti.ner.ReferentToken rt1 = new com.pullenti.ner.ReferentToken(dr1, numTok.children.get(ii).getBeginToken(), numTok.children.get(ii).getEndToken(), null);
                if (ii == (numTok.children.size() - 1)) 
                    rt1.setEndToken(end);
                rtLi.add(rt1);
            }
        }
        if ((dts.size() == 2 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && dts.get(0).typKind == DecreeKind.STANDARD) && dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
            for (com.pullenti.ner.Token ttt = dts.get(1).getEndToken().getNext(); ttt != null; ttt = ttt.getNext()) {
                if (!ttt.isCommaAnd()) 
                    break;
                com.pullenti.ner.decree.internal.DecreeToken nu = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(ttt.getNext(), dts.get(0), false);
                if (nu == null || nu.typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                    break;
                DecreeReferent dr1 = new DecreeReferent();
                dr1.setTyp(dec.getTyp());
                dr1.addNumber(nu);
                rtLi.add(new com.pullenti.ner.ReferentToken(dr1, ttt.getNext(), nu.getEndToken(), null));
                if (!ttt.isComma()) 
                    break;
                ttt = nu.getEndToken();
            }
        }
        return rtLi;
    }

    private void _processPartsAndChanges(com.pullenti.ner.core.AnalysisKit kit, com.pullenti.ner.decree.internal.DecreeToken baseTyp) throws Exception {
        com.pullenti.ner.core.AnalyzerData ad = kit.getAnalyzerData(this);
        java.util.ArrayList<DecreePartReferent> undefinedDecrees = new java.util.ArrayList<DecreePartReferent>();
        com.pullenti.ner.ReferentToken rootChange = null;
        com.pullenti.ner.decree.internal.DecreeChangeToken rootChangeQues = null;
        DecreeChangeReferent lastChange = null;
        DecreeReferent changeDecree = null;
        DecreePartReferent changePart = new DecreePartReferent();
        java.util.ArrayList<DecreePartReferent> changeStack = new java.util.ArrayList<DecreePartReferent>();
        int expireRegime = 0;
        int hasStartChange = 0;
        com.pullenti.ner.decree.internal.DecreeChangeToken lastAppend2 = null;
        boolean hasChangeKeyword = false;
        for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
            if (t.isIgnored()) 
                continue;
            java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> dts = null;
            if (t.isNewlineBefore() && t.isChar('(')) {
            }
            com.pullenti.ner.decree.internal.DecreeChangeToken dcht = null;
            boolean ok1 = t.isNewlineBefore();
            boolean ignNl = false;
            if (!ok1) {
                if (rootChange != null && t.getPrevious() != null && t.getPrevious().isChar(':')) 
                    ok1 = true;
            }
            if (!ok1) {
                if ((t.getPrevious() instanceof com.pullenti.ner.ReferentToken) && (t.getPrevious().getReferent() instanceof DecreeChangeReferent)) {
                    ok1 = true;
                    ignNl = expireRegime > 0;
                    for (; t.getNext() != null; t = t.getNext()) {
                        if (t.isCharOf(";,:.")) {
                        }
                        else if (t.isAnd() && !t.isNewlineBefore() && !t.getNext().isCharOf(").>")) {
                        }
                        else if (t.isValue2("А", "ТАКЖЕ") && t.getNext().getNext() != null) 
                            t = t.getNext();
                        else 
                            break;
                    }
                }
            }
            if (!ok1 && t.getPrevious() != null && t.getPrevious().isTableControlChar()) {
                if (t.getPrevious().isNewlineBefore() || rootChange != null) 
                    ok1 = true;
            }
            if (ok1) {
                if (t.isValue("Е", null) && t.getNext() != null && t.getNext().isChar(')')) {
                }
                if (t.isValue2("ДОПОЛНИТЕЛЬНОЕ", "СОГЛАШЕНИЕ")) 
                    hasChangeKeyword = true;
                if ((t instanceof com.pullenti.ner.NumberToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue(), "15")) {
                }
                dcht = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(t, (rootChange == null ? null : (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(rootChange.referent, DecreeChangeReferent.class)), false, changeStack, false, false, null, ignNl);
                if (dcht != null && t.isValue("ПРИЛОЖЕНИЕ", null)) {
                    com.pullenti.ner.instrument.internal.InstrToken1 line = com.pullenti.ner.instrument.internal.InstrToken1.parse(t, true, null, 0, null, false, 0, false, false);
                    if (line != null && (line.getLengthChar() < 30)) 
                        dcht = null;
                }
                if (((dcht != null && dcht.parts != null && dcht.parts.size() == 1) && dcht.getBeginToken() == dcht.parts.get(0).getBeginToken() && dcht.getEndToken() == dcht.parts.get(0).getEndToken()) && dcht.isNewlineAfter() && dcht.parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE) {
                    dcht = null;
                    rootChange = null;
                    changePart.getSlots().clear();
                    expireRegime = 0;
                    changeStack.clear();
                }
                if (dcht != null) {
                    if (dcht.hasChangeKeyword) 
                        hasChangeKeyword = true;
                    if (dcht.actKind2 == DecreeChangeKind.APPEND && dcht.parts != null) 
                        lastAppend2 = dcht;
                    else if (lastAppend2 != null && dcht.parts != null && dcht.actKind == DecreeChangeKind.UNDEFINED) {
                        dcht.newParts = dcht.parts;
                        dcht.parts = lastAppend2.parts;
                        dcht.realPart = lastAppend2.realPart;
                        if (dcht.realPart != null) 
                            dcht.parts = null;
                        dcht.actKind = DecreeChangeKind.APPEND;
                    }
                }
            }
            if (dcht != null && ((dcht.isStart() || dcht.changeVal != null)) && !dcht.ignorable) {
                if (dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTMULTU) {
                    if (rootChange != null && dcht.decree == null && dcht.parts != null) 
                        dcht.typ = com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.SINGLE;
                    else {
                        expireRegime = 0;
                        hasStartChange = 3;
                        lastAppend2 = null;
                        rootChange = null;
                        changePart.getSlots().clear();
                        changeDecree = null;
                    }
                }
                else if (dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.SINGLE) {
                    com.pullenti.ner.decree.internal.DecreeChangeToken dcht1 = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(dcht.getEndToken().getNext(), (rootChange == null ? null : (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(rootChange.referent, DecreeChangeReferent.class)), false, changeStack, false, false, null, false);
                    if (dcht1 != null && dcht1.isStart() && !dcht1.ignorable) {
                        hasStartChange = 2;
                        if (dcht.decreeTok != null && dcht.decree != null) {
                            com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(dcht.decree, dcht.decreeTok.getBeginToken(), dcht.decreeTok.getEndToken(), null);
                            kit.embedToken(rt);
                            t = rt;
                            if (dcht.getEndChar() == t.getEndChar()) 
                                dcht.setEndToken(t);
                        }
                    }
                }
                else if (dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTSINGLE && dcht.decree != null && expireRegime == 0) {
                    boolean ok = (dcht.hasChangeKeyword || lastChange != null || hasChangeKeyword) || dcht.changeVal != null || dcht.actKind != DecreeChangeKind.UNDEFINED;
                    if (!ok && t.getReferent() != dcht.decree) {
                        for (com.pullenti.ner.Token tt2 = dcht.getEndToken().getNext(); tt2 != null; tt2 = tt2.getNext()) {
                            com.pullenti.ner.decree.internal.DecreeChangeToken next = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(tt2, null, true, null, false, false, null, false);
                            if (next != null) {
                                if (next.changeVal != null || next.actKind != DecreeChangeKind.UNDEFINED) 
                                    ok = true;
                                break;
                            }
                            if (tt2.isComma()) 
                                continue;
                            if (tt2.isValue("ВНЕСТИ", null)) 
                                ok = true;
                            break;
                        }
                    }
                    if (ok) {
                        hasStartChange = 2;
                        hasChangeKeyword = true;
                        if (dcht.decreeTok != null) {
                            com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(dcht.decree, dcht.decreeTok.getBeginToken(), dcht.decreeTok.getEndToken(), null);
                            kit.embedToken(rt);
                            t = rt;
                            if (dcht.getEndChar() == t.getEndChar()) 
                                dcht.setEndToken(t);
                        }
                    }
                    else 
                        dts = (dcht.parts != null ? dcht.parts : dcht.newParts);
                }
                if (dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTSINGLE && rootChange != null && dcht.decree == null) 
                    hasStartChange = 2;
                else if ((dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.SINGLE && dcht.decree != null && dcht.getEndToken().isChar(':')) && dcht.isNewlineAfter()) 
                    hasStartChange = 2;
                if (hasStartChange <= 0 && expireRegime == 0) {
                    dts = com.pullenti.ner.decree.internal.PartToken.tryAttachList(t, false, 40);
                    changeStack.clear();
                    if (dcht.actKind == DecreeChangeKind.EXPIRE) 
                        expireRegime = 1;
                    else if (dcht.actKind == DecreeChangeKind.SUSPEND) 
                        expireRegime = 2;
                    if (!dcht.ignorable) 
                        dts = (dcht.parts != null ? dcht.parts : dcht.newParts);
                }
                else {
                    if (dcht.decree != null) {
                        if (changeDecree != dcht.decree) 
                            rootChange = null;
                        changeDecree = dcht.decree;
                        changePart.getSlots().clear();
                        changeStack.clear();
                    }
                    if (dcht.actKind == DecreeChangeKind.EXPIRE) 
                        expireRegime = 1;
                    else if (dcht.actKind == DecreeChangeKind.SUSPEND) 
                        expireRegime = 2;
                    else if (dcht.actKind == DecreeChangeKind.EXPIRECHANGES) 
                        expireRegime = 3;
                    if (!dcht.ignorable) {
                        dts = dcht.parts;
                        if ((dts == null && dcht.newParts != null && dcht.actKind == DecreeChangeKind.UNDEFINED) && dcht.changeVal == null) 
                            dts = dcht.newParts;
                    }
                }
            }
            else {
                dts = com.pullenti.ner.decree.internal.PartToken.tryAttachList(t, false, 40);
                if ((dcht == null && t.isNewlineBefore() && !t.isCharOf("[")) && !t.isTableControlChar()) {
                    boolean keepExpire = false;
                    if (expireRegime > 0) {
                        com.pullenti.ner.Token tt3 = t;
                        for (int kk = 0; kk < 3; kk++) {
                            com.pullenti.ner.instrument.internal.InstrToken1 line = com.pullenti.ner.instrument.internal.InstrToken1.parse(tt3, true, null, 0, null, false, 0, false, false);
                            if (line == null) 
                                break;
                            if (line.numbers.size() > 0) {
                                com.pullenti.ner.decree.internal.DecreeChangeToken ddd = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(tt3, null, false, null, false, false, null, false);
                                if (ddd != null) {
                                    if (ddd.isNewlineAfter()) 
                                        keepExpire = true;
                                    else if (ddd.getEndToken().getNext().isCharOf(";.")) 
                                        keepExpire = true;
                                }
                            }
                            tt3 = line.getEndToken().getNext();
                        }
                    }
                    if (!keepExpire) {
                        expireRegime = 0;
                        hasStartChange--;
                    }
                }
            }
            if (dts != null && dts.size() > 0 && rootChange != null) {
                if (dts.get(0).getBeginChar() < rootChange.getBeginChar()) 
                    dts = null;
            }
            if (dts != null && dts.size() == 1) {
                if ((dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FORM || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FORMULA || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.NAME) || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.LIST) {
                    if (rootChange == null && ((rootChangeQues == null || dts.get(0).values.size() == 0))) 
                        dts = null;
                }
            }
            if (dts != null && dts.size() == 2 && dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PREFIX) {
                if ((dts.get(1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FORM || dts.get(1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FORMULA || dts.get(1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.NAME) || dts.get(1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE || dts.get(1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.LIST) {
                    if (rootChange == null && ((rootChangeQues == null || dts.get(0).values.size() == 0))) 
                        dts = null;
                }
            }
            if (dts != null && dts.size() >= 1) {
                if (dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FORM || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.LIST) {
                    if (rootChange == null && ((rootChangeQues == null || dts.get(0).values.size() == 0))) 
                        dts = null;
                }
            }
            if (dcht != null && dts != null && !dcht.ignorable) {
                for (com.pullenti.ner.decree.internal.PartToken pp : dts) {
                    if (pp.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX && pp.values.size() == 0) {
                        if (!com.pullenti.unisharp.Utils.isNullOrEmpty(changePart.getAppendix())) 
                            pp.values.add(com.pullenti.ner.decree.internal.PartToken.PartValue._new1053(pp.getBeginToken(), pp.getEndToken(), changePart.getAppendix()));
                    }
                    else 
                        changePart.removeSlots(pp.typ);
                }
            }
            if (dcht != null && dcht.newParts != null) {
                for (com.pullenti.ner.decree.internal.PartToken pp : dcht.newParts) {
                    changePart.removeSlots(pp.typ);
                }
            }
            if (changePart.getPreamble() != null && changePart.getSlots().size() > 2) 
                changePart.setPreamble(null);
            if (changePart.getNameAsItem() != null) 
                changePart.setNameAsItem(null);
            if (changePart.getFreetext() != null) 
                changePart.setFreetext(null);
            java.util.ArrayList<com.pullenti.ner.MetaToken> rts = tryAttachParts(dts, baseTyp, (hasStartChange > 0 ? changeDecree : null), rootChange != null);
            if (rts != null) {
            }
            if (dcht != null && dcht.addParts != null) {
                for (java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> dts2 : dcht.addParts) {
                    java.util.ArrayList<com.pullenti.ner.MetaToken> rts2 = tryAttachParts(dts2, baseTyp, (hasStartChange > 0 ? changeDecree : null), rootChange != null);
                    if (rts2 == null || rts2.size() == 0) 
                        continue;
                    if (rts == null) 
                        rts = rts2;
                    else 
                        com.pullenti.unisharp.Utils.addToArrayList(rts, rts2);
                }
            }
            java.util.ArrayList<DecreePartReferent> dprs = null;
            java.util.HashMap<DecreePartReferent, DecreePartReferent> diaps = null;
            java.util.HashMap<Integer, com.pullenti.ner.Token> begs = null;
            java.util.HashMap<Integer, com.pullenti.ner.Token> ends = null;
            if (rts != null) {
                for (com.pullenti.ner.MetaToken kp : rts) {
                    java.util.ArrayList<DecreePartReferent> dprList = (java.util.ArrayList<DecreePartReferent>)com.pullenti.unisharp.Utils.cast(kp.tag, java.util.ArrayList.class);
                    if (dprList == null) 
                        continue;
                    for (int i = 0; i < dprList.size(); i++) {
                        DecreePartReferent dr = dprList.get(i);
                        if (dr.getOwner() == null && dr.getClause() != null && dr.getLocalTyp() == null) {
                            if (!undefinedDecrees.contains(dr)) 
                                undefinedDecrees.add(dr);
                        }
                        if ((dr.getClause() == null && dr.getDocPart() != null && dr.getPart() == null) && changePart.getClause() != null) {
                            dr.setPart(dr.getDocPart());
                            dr.setDocPart(null);
                        }
                        if (dr.getOwner() != null && dr.getClause() != null) 
                            undefinedDecrees.clear();
                        boolean ignLast = false;
                        if (dts.size() == 1) {
                            if ((dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SENTENCE || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.INDENTION || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FORMULA) || dts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PREAMBLE) 
                                ignLast = true;
                        }
                        if (dcht != null && !dcht.ignorable) 
                            dr.addHighLevelInfo(changePart);
                        if (lastChange != null && lastChange.getOwners().size() > 0) {
                            DecreePartReferent dr0 = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(lastChange.getOwners().get(0), DecreePartReferent.class);
                            if (dr0 != null && dr.getOwner() == dr0.getOwner()) {
                                if (dr0.getAppendix() != null && dr.getAppendix() != null && com.pullenti.unisharp.Utils.stringsNe(dr0.getAppendix(), dr.getAppendix())) {
                                    lastChange = null;
                                    if (changeStack.size() == 1) 
                                        changeStack.add(0, dr);
                                }
                                else {
                                    int mle = dr.getMinLevel();
                                    if (mle == 1 && dr.getDocPart() != null && dr0.getDocPart() == null) {
                                        dr.setPart(dr.getDocPart());
                                        dr.setDocPart(null);
                                        mle = dr.getMinLevel();
                                    }
                                    if (mle == 0 || mle <= com.pullenti.ner.decree.internal.PartToken._getRank(com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE)) {
                                    }
                                    else if (dr.getIndention() != null && dr.getSlots().size() == 2) 
                                        dr.addHighLevelInfo(dr0);
                                }
                            }
                        }
                        if (dr.getTableColumn() != null) {
                            if (rootChange != null) 
                                dr.setTable("0");
                            else 
                                continue;
                        }
                        if (dr.getTableRow() != null || dr.getTableItem() != null || dr.getTableSubItem() != null) {
                            if (dr.getTable() == null) {
                                if (rootChange != null) 
                                    dr.setTable("0");
                                else 
                                    continue;
                            }
                        }
                        dr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(dr), DecreePartReferent.class);
                        if (rts.size() == 1 && dprList.size() == 1) {
                            if (lastAppend2 != null && lastAppend2.parts == dts) 
                                lastAppend2.realPart = dr;
                            if (dcht != null && dcht.parts == dts) 
                                dcht.realPart = dr;
                            if (dcht != null && dcht.alias != null && dr.getAppendix() != null) {
                                com.pullenti.ner.core.TerminCollection partAliases = null;
                                Object oo;
                                com.pullenti.unisharp.Outargwrapper<Object> wrapoo1444 = new com.pullenti.unisharp.Outargwrapper<Object>();
                                boolean inoutres1445 = com.pullenti.unisharp.Utils.tryGetValue(kit.miscData, "partAliases", wrapoo1444);
                                oo = wrapoo1444.value;
                                if (!inoutres1445) 
                                    kit.miscData.put("partAliases", (partAliases = new com.pullenti.ner.core.TerminCollection()));
                                else 
                                    partAliases = (com.pullenti.ner.core.TerminCollection)oo;
                                com.pullenti.ner.core.Termin term = new com.pullenti.ner.core.Termin(null, null, false);
                                term.initBy(dcht.alias.getBeginToken(), dcht.alias.getEndToken().getPrevious(), dr, false);
                                partAliases.add(term);
                            }
                            if (changeDecree != null) {
                                if (dr.getOwner() != null && dr.getOwner() != changeDecree) {
                                }
                                else if (changeStack.size() == 0 || ((dcht != null && ((dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.SINGLE || dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTSINGLE))))) {
                                    changePart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(dr.clone(), DecreePartReferent.class);
                                    changePart.setNameAsItem(null);
                                    changePart.setPreamble(null);
                                    changeStack.add(0, changePart);
                                }
                            }
                        }
                        if (dprs == null) 
                            dprs = new java.util.ArrayList<DecreePartReferent>();
                        dprs.add(dr);
                        com.pullenti.ner.ReferentToken rt;
                        if (i == 0) 
                            rt = com.pullenti.ner.ReferentToken._new958(dr, kp.getBeginToken(), kp.getEndToken(), kp.getMorph());
                        else 
                            rt = new com.pullenti.ner.ReferentToken(dr, t, t, null);
                        kit.embedToken(rt);
                        t = rt;
                        if (dprs.size() > 1 && t.getPrevious() != null && ((t.getPrevious().isHiphen() || t.getPrevious().isValue("ПО", null)))) {
                            if (diaps == null) 
                                diaps = new java.util.HashMap<DecreePartReferent, DecreePartReferent>();
                            if (!diaps.containsKey(dprs.get(dprs.size() - 2))) 
                                diaps.put(dprs.get(dprs.size() - 2), dprs.get(dprs.size() - 1));
                        }
                        if (begs == null) 
                            begs = new java.util.HashMap<Integer, com.pullenti.ner.Token>();
                        if (!begs.containsKey(t.getBeginChar())) 
                            begs.put(t.getBeginChar(), t);
                        else 
                            begs.put(t.getBeginChar(), t);
                        if (ends == null) 
                            ends = new java.util.HashMap<Integer, com.pullenti.ner.Token>();
                        if (!ends.containsKey(t.getEndChar())) 
                            ends.put(t.getEndChar(), t);
                        else 
                            ends.put(t.getEndChar(), t);
                        if (dcht != null && !dcht.ignorable) {
                            if (dcht.getBeginChar() == t.getBeginChar()) 
                                dcht.setBeginToken(t);
                            if (dcht.getEndChar() == t.getEndChar()) 
                                dcht.setEndToken(t);
                            if (t.getEndChar() > dcht.getEndChar()) 
                                dcht.setEndToken(t);
                            dcht.realPart = dr;
                        }
                    }
                }
            }
            if (dts != null && dts.size() > 0 && dts.get(dts.size() - 1).getEndChar() > t.getEndChar()) 
                t = dts.get(dts.size() - 1).getEndToken();
            if (dcht != null && ((hasStartChange > 0 || expireRegime > 0)) && !dcht.ignorable) {
                if (dcht.getEndChar() > t.getEndChar()) 
                    t = dcht.getEndToken();
                java.util.ArrayList<com.pullenti.ner.ReferentToken> chrt = null;
                if ((dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.SINGLE && dcht.decree != null && dcht.getEndToken().isChar(':')) && dcht.actKind == DecreeChangeKind.UNDEFINED) {
                    if (rootChange == null || changeDecree == null) 
                        dcht.typ = com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTMULTU;
                    else if (changeDecree != dcht.decree) 
                        dcht.typ = com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTMULTU;
                }
                if (dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTMULTU && ((rootChangeQues == null || rootChangeQues.decree != dcht.decree))) {
                    rootChange = null;
                    changeStack.clear();
                    if (dcht.decree != null) {
                        while (dcht.addDecrees != null && dcht.addDecrees.size() > 0) {
                            DecreeReferent d0 = dcht.addDecrees.get(0);
                            if (d0.getOwner() != null) {
                                if (dcht.decree.getOwner() == d0.getOwner()) {
                                    dcht.decree = d0.getOwner();
                                    dcht.addDecrees.remove(0);
                                    continue;
                                }
                                if (d0.getOwner() == dcht.decree || d0 == dcht.decree) {
                                    dcht.addDecrees.remove(0);
                                    continue;
                                }
                            }
                            else if (dcht.decree.getOwner() == d0) {
                                dcht.decree = d0.getOwner();
                                dcht.addDecrees.remove(0);
                                continue;
                            }
                            break;
                        }
                        changeDecree = dcht.decree;
                    }
                    if (dprs != null && dprs.size() > 0) {
                        if (changeDecree == null && dprs.get(0).getOwner() != null) 
                            changeDecree = dprs.get(0).getOwner();
                        changeStack.add(0, dprs.get(0));
                        changePart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(dprs.get(0).clone(), DecreePartReferent.class);
                    }
                    if (((changeStack.size() > 0 || dcht.decree != null)) && expireRegime == 0) {
                        DecreeChangeReferent rch = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(DecreeChangeReferent._new1447(DecreeChangeKind.CONTAINER)), DecreeChangeReferent.class);
                        if (changeStack.size() > 0) 
                            rch.addSlot(DecreeChangeReferent.ATTR_OWNER, changeStack.get(0), false, 0);
                        else {
                            rch.addSlot(DecreeChangeReferent.ATTR_OWNER, dcht.decree, false, 0);
                            if (dcht.addDecrees != null) {
                                for (DecreeReferent d : dcht.addDecrees) {
                                    rch.addSlot(DecreeChangeReferent.ATTR_OWNER, d, false, 0);
                                }
                            }
                        }
                        if (dcht.appExtChanges != null && rch.getValue() == null) {
                            DecreeChangeValueReferent appCh = DecreeChangeValueReferent._new1049(DecreeChangeValueKind.EXTAPPENDIX);
                            appCh.setValue((dcht.appExtChanges.values.size() == 0 ? "" : dcht.appExtChanges.values.get(0).toString()));
                            rch.setValue((DecreeChangeValueReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(appCh), DecreeChangeValueReferent.class));
                        }
                        rootChange = new com.pullenti.ner.ReferentToken(rch, dcht.getBeginToken(), dcht.getEndToken(), null);
                        if (rootChange.getEndToken().isChar(':')) 
                            rootChange.setEndToken(rootChange.getEndToken().getPrevious());
                        for (com.pullenti.ner.Token tt0 = dcht.getBeginToken().getPrevious(); tt0 != null; tt0 = tt0.getPrevious()) {
                            if (tt0.isNewlineBefore() && (dcht.getBeginChar() - tt0.getBeginChar()) > 30) {
                                com.pullenti.ner.decree.internal.DecreeChangeToken dcht0 = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(tt0, null, false, null, false, false, null, false);
                                if ((dcht0 != null && dcht0.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTSINGLE && dcht0.decree != null) && dcht.decree != null) {
                                    if (dcht0.decree.canBeEquals(dcht.decree, com.pullenti.ner.core.ReferentsEqualType.WITHINONETEXT) || dcht0.decree.canBeEquals(dcht.decree.getOwner(), com.pullenti.ner.core.ReferentsEqualType.WITHINONETEXT)) 
                                        rootChange.setBeginToken(dcht0.getBeginToken());
                                }
                                break;
                            }
                        }
                        kit.embedToken(rootChange);
                        t = rootChange;
                        if (t.getNext() != null && t.getNext().isChar(':')) 
                            t = t.getNext();
                    }
                    if (expireRegime == 0) {
                        if (t.isNewlineAfter()) 
                            continue;
                        com.pullenti.ner.decree.internal.DecreeChangeToken tt2 = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(t.getNext(), null, false, null, false, false, null, false);
                        if (tt2 != null && tt2.actKind != DecreeChangeKind.UNDEFINED) {
                        }
                        else 
                            continue;
                    }
                }
                if (dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.SINGLE && dprs != null && dprs.size() == 1) {
                    while (changeStack.size() > 0) {
                        if (dprs.get(0).isAllItemsLessLevel(changeStack.get(0), true)) 
                            break;
                        else 
                            changeStack.remove(0);
                    }
                    changeStack.add(0, dprs.get(0));
                    if (dprs.get(0).getOwner() != null && changeDecree != dprs.get(0).getOwner()) {
                        changeDecree = dprs.get(0).getOwner();
                        changeStack.clear();
                        changeStack.add(0, dprs.get(0));
                    }
                    changePart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(dprs.get(0).clone(), DecreePartReferent.class);
                    continue;
                }
                if (dprs == null && dcht.realPart != null) {
                    dprs = new java.util.ArrayList<DecreePartReferent>();
                    dprs.add(dcht.realPart);
                }
                if ((dprs == null && dcht.actKind == DecreeChangeKind.REMOVE && changeStack.size() > 0) && (changeStack.get(0) instanceof DecreePartReferent)) {
                    dprs = new java.util.ArrayList<DecreePartReferent>();
                    dprs.add((DecreePartReferent)com.pullenti.unisharp.Utils.cast(changeStack.get(0), DecreePartReferent.class));
                }
                DecreePartReferent prevPart = null;
                DecreeChangeReferent prev = null;
                for (com.pullenti.ner.Token tt2 = dcht.getBeginToken().getPrevious(); tt2 != null; tt2 = tt2.getPrevious()) {
                    if (tt2.getReferent() instanceof DecreePartReferent) {
                        if (changeStack.size() > 0 && changeStack.get(0).getParentReferent() == ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt2.getReferent(), DecreePartReferent.class)).getParentReferent()) {
                            prevPart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt2.getReferent(), DecreePartReferent.class);
                            break;
                        }
                        if (changeStack.size() == 0 && ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt2.getReferent(), DecreePartReferent.class)).getParentReferent() == changeDecree) {
                            prevPart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt2.getReferent(), DecreePartReferent.class);
                            break;
                        }
                    }
                    if (tt2.getLengthChar() == 1 || (tt2 instanceof com.pullenti.ner.NumberToken)) 
                        continue;
                    prev = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(tt2.getReferent(), DecreeChangeReferent.class);
                    if (prev != null) {
                        if (prev.getKind() == DecreeChangeKind.NEW) 
                            continue;
                        prevPart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(prev.getSlotValue(DecreeChangeReferent.ATTR_OWNER), DecreePartReferent.class);
                        if (prevPart != null && ((prevPart.getNameAsItem() != null || prevPart.getPreamble() != null || prevPart.getFreetext() != null))) {
                            prevPart = null;
                            continue;
                        }
                        if (rootChange != null && prev != rootChange.referent && prevPart == null) 
                            changeStack.clear();
                    }
                    break;
                }
                if (dcht.hasAnafor && dcht.parts == null && prevPart != null) 
                    dcht.realPart = prevPart;
                if (dcht.parts == null && dcht.newParts != null && dcht.actKind == DecreeChangeKind.UNDEFINED) {
                    if (lastChange != null && lastChange.getKind() == DecreeChangeKind.APPEND) {
                        dcht.actKind = DecreeChangeKind.APPEND;
                        dcht.realPart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(lastChange.getParentReferent(), DecreePartReferent.class);
                    }
                    else if (lastAppend2 != null && lastAppend2.realPart != null) {
                        dcht.actKind = DecreeChangeKind.APPEND;
                        dcht.realPart = lastAppend2.realPart;
                    }
                }
                if (dprs != null && dprs.size() > 0) {
                    if (dcht.inPart != null && dcht.realPart != null && dprs.get(0) == dcht.realPart) {
                        com.pullenti.ner.decree.internal.PartToken ppp = com.pullenti.ner.decree.internal.PartToken.tryAttach(dcht.inPart, null, false, true);
                        if (ppp != null) {
                            DecreePartReferent rp = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(dcht.realPart.clone(), DecreePartReferent.class);
                            rp.addSlot(com.pullenti.ner.decree.internal.PartToken._getAttrNameByTyp(ppp.typ), "?", false, 0);
                            dcht.realPart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(rp), DecreePartReferent.class);
                            com.pullenti.unisharp.Utils.putArrayValue(dprs, 0, dcht.realPart);
                        }
                    }
                    chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents(dprs.get(0), dcht);
                    if (chrt == null && expireRegime > 0) {
                        chrt = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                        DecreeChangeReferent dcr = DecreeChangeReferent._new1447((expireRegime == 1 ? DecreeChangeKind.EXPIRE : DecreeChangeKind.SUSPEND));
                        chrt.add(new com.pullenti.ner.ReferentToken(dcr, dcht.getBeginToken(), dcht.getEndToken(), null));
                    }
                    if ((((chrt == null && dcht.actKind == DecreeChangeKind.UNDEFINED && dcht.actKind2 == DecreeChangeKind.UNDEFINED) && prev != null && prev.getKind() == DecreeChangeKind.APPEND) && dcht.changeVal != null && prevPart != null) && dcht.realPart == null) {
                        dcht.actKind = DecreeChangeKind.APPEND;
                        if (dcht.newParts == null) 
                            dcht.newParts = dcht.parts;
                        dcht.realPart = prevPart;
                        dcht.parts = null;
                        chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents(prevPart, dcht);
                    }
                }
                else if (dcht.actKind != DecreeChangeKind.EXPIRE) {
                    boolean ee = false;
                    if (dcht.partTyp == com.pullenti.ner.decree.internal.PartToken.ItemType.UNDEFINED) {
                        if (changeStack.size() == 0) {
                            ee = true;
                            chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents(changeDecree, dcht);
                        }
                        else if (prevPart != null) {
                            ee = true;
                            chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents(prevPart, dcht);
                        }
                    }
                    if (!ee && changeDecree != null) {
                        com.pullenti.ner.Referent dr = changeDecree;
                        if (prevPart != null && prevPart.getOwner() == dr && prevPart.isAllItemsOverThisLevel(dcht.partTyp)) 
                            dr = prevPart;
                        else if (rootChange != null) {
                            for (com.pullenti.ner.Token tt2 = t.getPrevious(); tt2 != null && tt2.getBeginChar() > rootChange.getEndChar(); tt2 = tt2.getPrevious()) {
                                com.pullenti.ner.Referent rr = tt2.getReferent();
                                if (rr == null) 
                                    continue;
                                DecreePartReferent pp = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(rr, DecreePartReferent.class);
                                if (pp == null && (rr instanceof DecreeChangeReferent)) 
                                    pp = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(rr.getSlotValue(DecreePartReferent.ATTR_OWNER), DecreePartReferent.class);
                                if (pp == null) 
                                    continue;
                                if (pp.getOwner() != null && pp.getOwner().getKind() == DecreeKind.PUBLISHER) 
                                    continue;
                                pp = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(pp.clone(), DecreePartReferent.class);
                                com.pullenti.ner.Slot sl = pp.findSlot(com.pullenti.ner.decree.internal.PartToken._getAttrNameByTyp(dcht.partTyp), null, true);
                                if (sl != null) 
                                    pp.getSlots().remove(sl);
                                if (pp.getSlots().size() > 1 && pp.isAllItemsOverThisLevel(dcht.partTyp)) {
                                    dr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(pp), DecreePartReferent.class);
                                    break;
                                }
                            }
                        }
                        if (dr == changeDecree && changePart.getSlots().size() > 1 && dcht.actKind == DecreeChangeKind.APPEND) {
                            if (changePart.isAllItemsOverThisLevel(dcht.partTyp)) 
                                dr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(changePart), DecreePartReferent.class);
                        }
                        if ((dr instanceof DecreeReferent) && changePart.getAppendix() != null) 
                            dr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(changePart), DecreePartReferent.class);
                        ee = true;
                        chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents(dr, dcht);
                    }
                    if (lastChange != null && !ee && lastChange.getOwners().size() > 0) 
                        chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents(lastChange.getOwners().get(0), dcht);
                }
                if ((dprs == null && chrt == null && ((dcht.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.VALUE || dcht.changeVal != null))) && changeStack.size() > 0) 
                    chrt = com.pullenti.ner.decree.internal.DecreeChangeToken.attachReferents((dcht.realPart != null ? dcht.realPart : (prevPart == null || (changeStack.get(0) instanceof DecreePartReferent) ? changeStack.get(0) : prevPart)), dcht);
                if (chrt == null && ((expireRegime > 0 || dcht.actKind == DecreeChangeKind.EXPIRE || dcht.actKind == DecreeChangeKind.SUSPEND)) && dprs == null) {
                    chrt = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                    if (dcht.decree != null) {
                        DecreeChangeReferent dcr = DecreeChangeReferent._new1447(DecreeChangeKind.EXPIRE);
                        dcr.addSlot(DecreeChangeReferent.ATTR_OWNER, dcht.decree, false, 0);
                        chrt.add(new com.pullenti.ner.ReferentToken(dcr, dcht.getBeginToken(), dcht.getEndToken(), null));
                    }
                    for (com.pullenti.ner.Token tt = dcht.getEndToken().getNext(); tt != null; tt = tt.getNext()) {
                        if (tt.getNext() == null) 
                            break;
                        if (tt.isCharOf("(<")) {
                            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                            if (br != null) {
                                tt = br.getEndToken();
                                chrt.get(chrt.size() - 1).setEndToken(tt);
                                continue;
                            }
                        }
                        if (!tt.isCommaAnd() && !tt.isChar(';')) {
                            if (chrt.size() > 0) 
                                break;
                        }
                        else 
                            tt = tt.getNext();
                        if (tt.getReferent() instanceof DecreeReferent) {
                            DecreeChangeReferent dcr = DecreeChangeReferent._new1447((expireRegime == 1 || dcht.actKind == DecreeChangeKind.EXPIRE ? DecreeChangeKind.EXPIRE : DecreeChangeKind.SUSPEND));
                            dcr.addSlot(DecreeChangeReferent.ATTR_OWNER, tt.getReferent(), false, 0);
                            com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(dcr, tt, tt, null);
                            if (tt.getNext() != null && tt.getNext().isChar('(')) {
                                com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt.getNext(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
                                if (br != null) 
                                    rt.setEndToken((tt = br.getEndToken()));
                            }
                            chrt.add(rt);
                            continue;
                        }
                        break;
                    }
                }
                if (chrt == null && dcht.decree != null && rootChange == null) {
                    if (rootChangeQues != null && rootChangeQues.decree == dcht.decree && rootChangeQues.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTMULTU) {
                    }
                    else 
                        rootChangeQues = dcht;
                }
                if (chrt != null) {
                    if (((dprs != null && dprs.size() == 2 && chrt.size() == 2) && (chrt.get(0).referent instanceof DecreeChangeValueReferent) && (chrt.get(1).referent instanceof DecreeChangeReferent)) && ((DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(chrt.get(1).referent, DecreeChangeReferent.class)).getKind() == DecreeChangeKind.NEW) {
                        java.util.ArrayList<com.pullenti.ner.ReferentToken> vals = com.pullenti.ner.decree.internal.DecreeChangeToken.splitValue(chrt.get(0), dprs.get(0));
                        java.util.ArrayList<DecreePartReferent> diap = null;
                        if (diaps == null) {
                            diap = new java.util.ArrayList<DecreePartReferent>();
                            diap.add(dprs.get(0));
                            diap.add(dprs.get(1));
                        }
                        else if (diaps.size() == 1) {
                            for (java.util.Map.Entry<DecreePartReferent, DecreePartReferent> kp : diaps.entrySet()) {
                                diap = com.pullenti.ner.decree.internal.PartToken.tryCreateBetween(kp.getKey(), kp.getValue());
                                if (diap != null) {
                                    diap.add(0, dprs.get(0));
                                    diap.add(dprs.get(1));
                                }
                                break;
                            }
                        }
                        if (diap != null && vals != null && vals.size() == diap.size()) {
                            for (int i = 0; i < diap.size(); i++) {
                                DecreeChangeReferent drc = new DecreeChangeReferent();
                                drc.setKind(DecreeChangeKind.NEW);
                                if (i > 0 && ((i + 1) < diap.size())) 
                                    com.pullenti.unisharp.Utils.putArrayValue(diap, i, (DecreePartReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(diap.get(i)), DecreePartReferent.class));
                                drc.addSlot(DecreeChangeReferent.ATTR_OWNER, diap.get(i), false, 0);
                                drc.addSlot(DecreeChangeReferent.ATTR_VALUE, vals.get(i).referent, false, 0);
                                com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(drc, vals.get(i).getBeginToken(), vals.get(i).getEndToken(), null);
                                if (i == 0) 
                                    rt.setBeginToken(chrt.get(1).getBeginToken());
                                else 
                                    drc.addSlot("SPLIT", "true", false, 0);
                                vals.add(rt);
                            }
                            chrt = vals;
                            diaps = null;
                            dprs = null;
                        }
                    }
                    for (com.pullenti.ner.ReferentToken rt : chrt) {
                        rt.referent = ad.registerReferent(rt.referent);
                        if (rt.referent instanceof DecreeChangeReferent) {
                            lastChange = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreeChangeReferent.class);
                            if (dprs != null && dprs.size() > 0) {
                                if (((DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreeChangeReferent.class)).getKind() != DecreeChangeKind.NEW) 
                                    changePart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(dprs.get(0).clone(), DecreePartReferent.class);
                                int ii;
                                for (ii = 0; ii < (dprs.size() - 1); ii++) {
                                    lastChange.addSlot(DecreeChangeReferent.ATTR_OWNER, dprs.get(ii), false, 0);
                                }
                                if (diaps != null) {
                                    for (java.util.Map.Entry<DecreePartReferent, DecreePartReferent> kp : diaps.entrySet()) {
                                        java.util.ArrayList<DecreePartReferent> diap = com.pullenti.ner.decree.internal.PartToken.tryCreateBetween(kp.getKey(), kp.getValue());
                                        if (diap != null && diap.size() > 0) {
                                            kp.getKey().addSlot("RANGE", "START", false, 0);
                                            kp.getValue().addSlot("RANGE", "END", false, 0);
                                            for (DecreePartReferent d : diap) {
                                                d.addSlot("RANGE", "MIDDLE", false, 0);
                                                com.pullenti.ner.Referent dd = ad.registerReferent(d);
                                                lastChange.addSlot(DecreeChangeReferent.ATTR_OWNER, dd, false, 0);
                                            }
                                        }
                                    }
                                }
                                for (; ii < dprs.size(); ii++) {
                                    lastChange.addSlot(DecreeChangeReferent.ATTR_OWNER, dprs.get(ii), false, 0);
                                }
                            }
                        }
                        if (rt.getBeginToken() == null || rt.getEndToken() == null) 
                            continue;
                        if (begs != null && begs.containsKey(rt.getBeginChar())) 
                            rt.setBeginToken(begs.get(rt.getBeginChar()));
                        if (ends != null && ends.containsKey(rt.getEndChar())) 
                            rt.setEndToken(ends.get(rt.getEndChar()));
                        if (rootChange == null && rootChangeQues != null) {
                            DecreeChangeReferent rch = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(DecreeChangeReferent._new1447(DecreeChangeKind.CONTAINER)), DecreeChangeReferent.class);
                            rch.addSlot(DecreeChangeReferent.ATTR_OWNER, rootChangeQues.decree, false, 0);
                            rootChange = new com.pullenti.ner.ReferentToken(rch, rootChangeQues.getBeginToken(), rootChangeQues.getEndToken(), null);
                            if (rootChange.getEndToken().isChar(':')) 
                                rootChange.setEndToken(rootChange.getEndToken().getPrevious());
                            kit.embedToken(rootChange);
                            rootChangeQues = null;
                        }
                        if (rootChange != null && (rt.referent instanceof DecreeChangeReferent)) 
                            rootChange.referent.addSlot(DecreeChangeReferent.ATTR_CHILD, rt.referent, false, 0);
                        if (changePart.getTableSubItem() != null) 
                            changePart.setTableSubItem(null);
                        else 
                            changePart.setTableItem(null);
                        kit.embedToken(rt);
                        t = rt;
                        if (begs == null) 
                            begs = new java.util.HashMap<Integer, com.pullenti.ner.Token>();
                        if (!begs.containsKey(t.getBeginChar())) 
                            begs.put(t.getBeginChar(), t);
                        else 
                            begs.put(t.getBeginChar(), t);
                        if (ends == null) 
                            ends = new java.util.HashMap<Integer, com.pullenti.ner.Token>();
                        if (!ends.containsKey(t.getEndChar())) 
                            ends.put(t.getEndChar(), t);
                        else 
                            ends.put(t.getEndChar(), t);
                    }
                }
            }
        }
        DecreeChangeReferent own = null;
        for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
            DecreeChangeReferent ch = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), DecreeChangeReferent.class);
            if (ch == null) 
                continue;
            com.pullenti.ner.ReferentToken t0 = (com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.ReferentToken.class);
            t = t0;
            if (ch.getKind() == DecreeChangeKind.CONTAINER) {
                if (ch.getChildren().size() == 0) 
                    continue;
                own = ch;
                DecreeReferent dec = (DecreeReferent)com.pullenti.unisharp.Utils.cast(ch.getSlotValue(DecreeChangeReferent.ATTR_OWNER), DecreeReferent.class);
                if (dec != null && dec.getKind() == DecreeKind.CONTRACT) 
                    continue;
            }
            com.pullenti.ner.Token tt = t.getNext();
            boolean notAttachVal = false;
            boolean isPsevdoApp = false;
            while (tt != null) {
                for (; tt != null; tt = tt.getNext()) {
                    if (tt.isNewlineBefore()) 
                        break;
                }
                if (tt == null) 
                    break;
                com.pullenti.ner.decree.internal.PartToken pp = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, false);
                if (pp != null) {
                    com.pullenti.ner.Token tte = pp.getEndToken().getNext();
                    if (tte != null && tte.isCharOf(".)")) 
                        tte = tte.getNext();
                    if (tte == null || tte.isNewlineAfter()) {
                        tt = null;
                        break;
                    }
                    if (tte.isValue2("О", "ВНЕСЕНИИ")) {
                        tt = null;
                        break;
                    }
                }
                if (tt.isValue("ПРИЛОЖЕНИЕ", null)) {
                    com.pullenti.ner.decree.internal.PartToken pp2 = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, false);
                    if (pp2 != null) {
                        if (pp2.isNewlineAfter() || ((pp2.getEndToken().getNext() != null && pp2.getEndToken().getNext().isValue("К", null)))) {
                            boolean stop = true;
                            com.pullenti.ner.Referent ooo = (com.pullenti.ner.Referent)com.pullenti.unisharp.Utils.cast(ch.getSlotValue(DecreeChangeReferent.ATTR_OWNER), com.pullenti.ner.Referent.class);
                            if ((ooo instanceof DecreeReferent) && tt.getPrevious() == t0) {
                                stop = false;
                                com.pullenti.ner.MetaToken mtt = (com.pullenti.ner.MetaToken)com.pullenti.unisharp.Utils.cast(t0.getEndToken(), com.pullenti.ner.MetaToken.class);
                                if (mtt != null) {
                                    if (com.pullenti.ner.core.BracketHelper.isBracket(mtt.getEndToken(), false) || com.pullenti.ner.core.BracketHelper.isBracket(mtt.getEndToken().getPrevious(), false)) 
                                        stop = true;
                                    else 
                                        isPsevdoApp = true;
                                }
                            }
                            if (stop) {
                                tt = null;
                                break;
                            }
                        }
                    }
                }
                com.pullenti.ner.Token ttt = tt;
                com.pullenti.ner.core.ComplexNumToken num = com.pullenti.ner.core.ComplexNumToken.tryParse(tt, null, false, false);
                if (num != null) 
                    ttt = num.getEndToken().getNext();
                if (ttt == null) 
                    break;
                if (ttt.getReferent() instanceof DecreeChangeReferent) {
                    tt = null;
                    break;
                }
                com.pullenti.ner.decree.internal.DecreeChangeToken dcr = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(tt, ch, false, null, false, false, null, false);
                if (dcr != null) {
                    if (dcr.isNewlineAfter()) {
                        if (tt == dcr.getEndToken()) 
                            tt = dcr.getEndToken().getNext();
                        else 
                            tt = dcr.getEndToken();
                        continue;
                    }
                    if (dcr.getEndToken().getNext() != null && dcr.getEndToken().getNext().isChar(':') && dcr.getEndToken().isWhitespaceAfter()) {
                        tt = dcr.getEndToken().getNext();
                        continue;
                    }
                    if (dcr.actKind != DecreeChangeKind.UNDEFINED) 
                        notAttachVal = true;
                }
                tt = ttt;
                break;
            }
            if (tt == null) 
                continue;
            t = tt;
            com.pullenti.ner.Token t1 = null;
            DecreeChangeReferent chh = null;
            boolean toChangeRegime = false;
            DecreePartReferent realPart = null;
            for (; tt != null; tt = tt.getNext()) {
                chh = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreeChangeReferent.class);
                if (chh != null) {
                    if (tt.isNewlineBefore()) 
                        t1 = tt.getPrevious();
                    break;
                }
                if (realPart == null && (tt.getReferent() instanceof DecreePartReferent) && !tt.getMorph().getCase().isInstrumental()) 
                    realPart = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreePartReferent.class);
                if (tt.isValue3("ВСТУПАТЬ", "В", "СИЛУ")) 
                    break;
                if (!tt.isNewlineBefore()) 
                    continue;
                t1 = tt.getPrevious();
                if (tt.isValue("НАИМЕНОВАНИЕ", null)) 
                    continue;
                com.pullenti.ner.instrument.internal.InstrToken1 iii = com.pullenti.ner.instrument.internal.InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                if (iii != null) {
                    if (iii.typ == com.pullenti.ner.instrument.internal.InstrToken1.Types.EDITIONS) 
                        break;
                    if (iii.isExpired) 
                        break;
                    if (tt.isTableControlChar()) {
                        t1 = (tt = iii.getEndToken());
                        continue;
                    }
                }
                if (tt.isValue("ИЗМЕНЕНИЯ", null)) {
                    if (tt.isNewlineAfter()) 
                        break;
                    if (t.getNext() != null && tt.getNext().isComma()) 
                        break;
                }
                if (tt.isValue("ПРИЛОЖЕНИЕ", null) || tt.isValue("УТВЕРЖДЕНО", null)) {
                    if (tt == t0.getNext() && isPsevdoApp) {
                    }
                    else 
                        break;
                }
                if (tt.isValue("ПЕРЕЧЕНЬ", null) && tt.isNewlineAfter()) 
                    break;
                com.pullenti.ner.Token ttt = tt;
                com.pullenti.ner.core.ComplexNumToken num = com.pullenti.ner.core.ComplexNumToken.tryParse(tt, null, false, false);
                if (num != null) 
                    ttt = num.getEndToken().getNext();
                if (ttt == null) 
                    break;
                chh = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(ttt.getReferent(), DecreeChangeReferent.class);
                if (chh != null) 
                    break;
                if (toChangeRegime) 
                    continue;
                com.pullenti.ner.decree.internal.DecreeChangeToken dcr = com.pullenti.ner.decree.internal.DecreeChangeToken.tryAttach(tt, null, false, null, false, false, null, false);
                if (dcr != null) {
                    if (dcr.isNewlineAfter()) 
                        break;
                    if (dcr.getEndToken().getNext() != null && dcr.getEndToken().getNext().isChar(':') && dcr.getEndToken().isWhitespaceAfter()) 
                        break;
                    if (dcr.typ == com.pullenti.ner.decree.internal.DecreeChangeTokenTyp.STARTSINGLE) {
                        if (dcr.actKind != DecreeChangeKind.UNDEFINED) {
                            toChangeRegime = true;
                            continue;
                        }
                        if (dcr.changeVal != null) {
                            if ((dcr.getBeginChar() + 5) < dcr.changeVal.getBeginChar()) 
                                toChangeRegime = true;
                            tt = dcr.getEndToken();
                            continue;
                        }
                        if (dcr.realPart == null) 
                            break;
                        realPart = dcr.realPart;
                        if (dcr.getEndToken().getNext() != null) {
                            if (dcr.getEndToken().getNext().isValue2("УТРАТИТЬ", "СИЛУ")) 
                                break;
                        }
                    }
                }
            }
            if (t1 == null || chh == null) 
                continue;
            if (chh.getKind() == DecreeChangeKind.CONTAINER) {
                if (chh.getChildren().size() == 0) 
                    continue;
            }
            if (t1.isCharOf(".;")) 
                t1 = t1.getPrevious();
            if ((t1.getEndChar() - t.getBeginChar()) < 20) 
                continue;
            boolean not = false;
            for (com.pullenti.ner.Token tt2 = t1; tt2 != null && tt2.getBeginChar() >= t.getBeginChar(); tt2 = tt2.getPrevious()) {
                if (tt2.getReferent() instanceof DecreePartReferent) {
                    not = true;
                    break;
                }
                else if ((tt2 instanceof com.pullenti.ner.NumberToken) || tt2.getLengthChar() == 1) {
                }
                else 
                    break;
            }
            if (not) 
                continue;
            com.pullenti.ner.Token t00 = t;
            for (; t00 != null; t00 = t00.getPrevious()) {
                if (t00.isNewlineBefore()) 
                    break;
            }
            boolean ok = false;
            for (com.pullenti.ner.Token ttt = t00; ttt != null && ttt.getEndChar() <= t1.getEndChar(); ttt = ttt.getNext()) {
                com.pullenti.ner.Token ttt2 = com.pullenti.ner.core.MiscHelper.checkImage(ttt);
                if (ttt2 != null) {
                    ttt = ttt2;
                    continue;
                }
                if (ttt.isValue("ДОКУМЕНТ", null)) 
                    break;
                if ((ttt.getLengthChar() < 4) || (ttt instanceof com.pullenti.ner.NumberToken)) 
                    continue;
                ok = true;
                break;
            }
            if (!ok) 
                continue;
            if (((!toChangeRegime && !notAttachVal && com.pullenti.ner.core.BracketHelper.isBracket(t1, false)) && ((ch.getKind() == DecreeChangeKind.APPEND || ch.getKind() == DecreeChangeKind.NEW)) && (((t0.getEndChar() + 7) >= t00.getBeginChar() || t0.getEndToken().getNext() == t || t0.getEndToken().getNext().getNext() == t))) && (t0.getEndToken().getReferent() instanceof DecreeChangeValueReferent)) {
                DecreeChangeValueReferent val = (DecreeChangeValueReferent)com.pullenti.unisharp.Utils.cast(t0.getEndToken().getReferent(), DecreeChangeValueReferent.class);
                val.setEndChar(t1.getBeginChar() - 1);
                if (!com.pullenti.ner.core.BracketHelper.isBracket(t1, true)) 
                    val.setEndChar(t1.getBeginChar());
                val.getOccurrence().get(0).endChar = t1.getEndChar();
                val.setValue(kit.getSofa().getText().substring(val.getBeginChar(), val.getBeginChar() + (val.getEndChar() + 1) - val.getBeginChar()));
                ch.getOccurrence().get(0).endChar = t1.getEndChar();
                com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(ch, t0, t1, null);
                t.kit.embedToken(rt);
                t = rt;
            }
            else if (own != null) {
                DecreeChangeReferent ch1 = new DecreeChangeReferent();
                ch1.setKind(DecreeChangeKind.ERROR);
                if (realPart != null) 
                    ch1.addSlot(DecreeChangeReferent.ATTR_OWNER, realPart, false, 0);
                own.addSlot(DecreeChangeReferent.ATTR_CHILD, ch1, false, 0);
                com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(ad.registerReferent(ch1), t, t1, null);
                t.kit.embedToken(rt);
                t = rt;
            }
        }
        com.pullenti.ner.Token lastChangeToken = null;
        java.util.ArrayList<DecreeChangeValueReferent> extVals = new java.util.ArrayList<DecreeChangeValueReferent>();
        for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
            DecreeChangeReferent ch = (DecreeChangeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), DecreeChangeReferent.class);
            if (ch == null) 
                continue;
            lastChangeToken = t;
            for (com.pullenti.ner.Slot s : ch.getSlots()) {
                if (s.getValue() instanceof DecreeChangeValueReferent) {
                    DecreeChangeValueReferent v = (DecreeChangeValueReferent)com.pullenti.unisharp.Utils.cast(s.getValue(), DecreeChangeValueReferent.class);
                    if (v.getKind() == DecreeChangeValueKind.EXTAPPENDIX) 
                        extVals.add(v);
                }
            }
        }
        if (extVals.size() > 0) {
            com.pullenti.ner.Token t = lastChangeToken.getNext();
            for (; t != null; t = t.getNext()) {
                if (!t.isNewlineBefore()) 
                    continue;
                if (extVals.size() == 0) 
                    break;
                if ((t instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class)).term, "ПРИЛОЖЕНИЕ") && !t.chars.isAllLower()) {
                }
                else 
                    continue;
                String val = (String)com.pullenti.unisharp.Utils.notnull(extVals.get(0).getValue(), "");
                com.pullenti.ner.Token tt = (com.pullenti.ner.Token)com.pullenti.unisharp.Utils.notnull(com.pullenti.ner.core.MiscHelper.checkNumberPrefix(t.getNext()), (t != null ? t.getNext() : null));
                if (tt == null) 
                    break;
                if (tt instanceof com.pullenti.ner.NumberToken) {
                    if (com.pullenti.unisharp.Utils.stringsNe(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.NumberToken.class)).getValue(), val)) 
                        continue;
                    tt = tt.getNext();
                }
                else if (!com.pullenti.unisharp.Utils.isNullOrEmpty(val)) 
                    continue;
                for (; tt != null; tt = tt.getNext()) {
                    if (com.pullenti.ner.core.BracketHelper.isBracket(tt, true)) 
                        break;
                    if (tt.isValue("ПРИЛОЖЕНИЕ", null)) 
                        break;
                    com.pullenti.ner.instrument.internal.InstrToken1 line = com.pullenti.ner.instrument.internal.InstrToken1.parse(tt, true, null, 0, null, false, 0, false, false);
                    if (line == null) 
                        break;
                    if (tt.chars.isAllLower() || tt.isValue("К", null) || tt.isValue("ОТ", null)) {
                        tt = line.getEndToken();
                        continue;
                    }
                    break;
                }
                if (tt == null || !tt.isNewlineBefore()) 
                    continue;
                com.pullenti.ner.Token tt0 = tt;
                com.pullenti.ner.Token tt1 = tt;
                for (tt = tt.getNext(); tt != null; tt = tt.getNext()) {
                    if (!tt.isNewlineBefore()) {
                        tt1 = tt;
                        continue;
                    }
                    if ((tt instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).term, "ПРИЛОЖЕНИЕ") && !tt.chars.isAllLower()) {
                    }
                    else {
                        tt1 = tt;
                        continue;
                    }
                    tt = (com.pullenti.ner.Token)com.pullenti.unisharp.Utils.notnull(com.pullenti.ner.core.MiscHelper.checkNumberPrefix(tt.getNext()), (tt != null ? tt.getNext() : null));
                    if (tt == null) 
                        break;
                    boolean stop = true;
                    for (String ni : extVals.get(0).getNewItems()) {
                        if (ni.startsWith("APPENDIX ")) {
                            String val2 = ni.substring(9);
                            if ((tt instanceof com.pullenti.ner.NumberToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.NumberToken.class)).getValue(), val2)) 
                                stop = false;
                        }
                    }
                    if (stop) 
                        break;
                }
                if (com.pullenti.ner.core.BracketHelper.isBracket(tt0, true)) {
                    tt0 = tt0.getNext();
                    if (com.pullenti.ner.core.BracketHelper.isBracket(tt1, true)) 
                        tt1 = tt1.getPrevious();
                    else if (tt1.isCharOf(";.") && com.pullenti.ner.core.BracketHelper.isBracket(tt1.getPrevious(), true)) 
                        tt1 = tt1.getPrevious().getPrevious();
                }
                if (tt0.getEndChar() >= tt1.getBeginChar()) 
                    continue;
                extVals.get(0).setKind(DecreeChangeValueKind.TEXT);
                extVals.get(0).setBeginChar(tt0.getBeginChar());
                extVals.get(0).setEndChar(tt1.getEndChar());
                com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(extVals.get(0), tt0, tt1, null);
                extVals.get(0).setValue(rt.getSourceText());
                extVals.get(0).getOccurrence().clear();
                kit.embedToken(rt);
                t = rt;
                extVals.remove(0);
            }
        }
    }

    public static com.pullenti.ner.Token canBeStartOfAttachApproved(com.pullenti.ner.Token t) {
        if (!(t instanceof com.pullenti.ner.TextToken)) 
            return null;
        if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t, true, false)) {
            if (t.getNext() == null) 
                return null;
            if (t.getNext().chars.isAllLower() || !t.getNext().chars.isLetter()) 
                return null;
            return t;
        }
        if (t instanceof com.pullenti.ner.NumberToken) 
            return null;
        com.pullenti.ner.Token tt = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t, false);
        boolean doubt = false;
        if (tt == null && ((t.isValue("СОСТАВ", null) || t.isValue("СРОК", null)))) {
            if (t.getPrevious() != null && t.getPrevious().isValue("В", null)) {
                tt = t;
                doubt = true;
            }
        }
        com.pullenti.ner.Token keyTok = tt;
        if (tt != null) {
            if (t.isValue("НАСТОЯЩИЙ", null)) 
                return null;
            if (t.chars.isAllLower() && ((t.isValue("УСЛОВИЕ", null) || t.isValue("ПОЛОЖЕНИЕ", null)))) 
                return null;
            if (t.getPrevious() != null && t.getPrevious().isValue("НАСТОЯЩИЙ", null)) 
                return null;
            com.pullenti.ner.Token tt0 = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t.getPrevious(), false);
            if (tt0 == tt) 
                return null;
            if (t.getPrevious() != null && com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t.getPrevious().getPrevious(), false) == tt) 
                return null;
            if (t.isValue("ПЕРЕЧЕНЬ", null) && t.isNewlineBefore() && t.getMorph().getCase().isNominative()) 
                return null;
            com.pullenti.morph.MorphClass mc0 = t.getMorphClassInDictionary();
            if (mc0.isPronoun()) 
                return null;
            tt = t;
        }
        boolean changes = false;
        if (tt == null || tt.getNext() == null) {
            if ((t.isValue("ИЗМЕНЕНИЕ", null) && (((t.getPrevious() instanceof com.pullenti.ner.NumberToken) || t.isNewlineBefore())) && t.getNext() != null) && t.getNext().isComma()) {
                com.pullenti.ner.Token tt1 = t.getNext().getNext();
                if (tt1.isValue3("КОТОРЫЙ", "ВНОСИТЬСЯ", "В")) {
                    if (!t.isNewlineBefore() || t.chars.isAllLower()) 
                        return t;
                    tt = tt1.getNext().getNext().getNext();
                    changes = true;
                }
                else if (tt1.isValue2("ВНОСИМЫЙ", "В")) {
                    tt1 = tt1.getNext().getNext();
                    changes = true;
                }
                else 
                    return null;
            }
            else 
                return null;
        }
        else {
            int cou2 = 7;
            if (doubt) 
                cou2 = 2;
            for (com.pullenti.ner.Token tt2 = t.getPrevious(); tt2 != null && cou2 > 0; tt2 = tt2.getPrevious(),cou2--) {
                if ((tt2.isValue("ВНЕСТИ", null) || tt2.isValue("ВНОСИТЬ", null) || tt2.isValue("ИЗМЕНЕНИЕ", null)) || tt2.isValue("ДОПОЛНИТЬ", null) || tt2.isValue("ИЗЛОЖИТЬ", null)) {
                    changes = true;
                    break;
                }
                if ((((tt2 instanceof com.pullenti.ner.NumberToken) || tt2.getLengthChar() == 1)) && tt2 != t.getPrevious()) 
                    cou2++;
                com.pullenti.ner.decree.internal.PartToken pp = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt2, null, false, false);
                if (pp != null && pp.getEndToken().getNext() == t) {
                    changes = true;
                    break;
                }
            }
            for (com.pullenti.ner.Token tt2 = t.getNext(); tt2 != null; tt2 = tt2.getNext()) {
                if (com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t, false) != null) 
                    break;
                if ((tt2.isComma() && tt2.getNext() != null && tt2.getNext().isValue("УТВЕРЖДЕННЫЙ", null)) && keyTok != null) 
                    return tt;
                if (tt2.isNewlineBefore()) 
                    break;
            }
        }
        if (tt == null) 
            return null;
        if (!changes) {
            if (!(t instanceof com.pullenti.ner.TextToken) || !t.chars.isCyrillicLetter() || keyTok == null) 
                return null;
            if (t.chars.isAllLower()) {
                if (t.getPrevious() != null) {
                    if (t.getPrevious().isValue("В", null) || t.getPrevious().isValue("К", null)) {
                        if (keyTok.getNext() != null && keyTok.getNext().isComma()) 
                            return null;
                        return tt;
                    }
                }
                return null;
            }
        }
        return tt;
    }

    private static com.pullenti.ner.Token _checkChangesTo(com.pullenti.ner.Token t) {
        if (t != null && ((t.isValue("ПЕРЕЧЕНЬ", null) || t.isValue("СПИСОК", null)))) 
            t = t.getNext();
        if (t == null || !t.isValue("ИЗМЕНЕНИЕ", null)) 
            return null;
        for (t = t.getNext(); t != null; t = t.getNext()) {
            if ((t.isComma() || t.isValue("КОТОРЫЙ", null) || t.isValue("ВНОСИТЬСЯ", null)) || t.isValue("ВНОСИМЫЙ", null) || t.isValue("В", null)) 
                continue;
            if (t.getReferent() instanceof DecreeReferent) 
                return t;
            if (t instanceof com.pullenti.ner.ReferentToken) 
                continue;
            com.pullenti.ner.core.NounPhraseToken npt = com.pullenti.ner.core.NounPhraseHelper.tryParse(t, com.pullenti.ner.core.NounPhraseParseAttr.PARSEPREPOSITION, 0, null);
            if (npt != null) {
                if (npt.getEndToken().isValue("РЕАЛИЗАЦИЯ", null) || npt.getEndToken().isValue("АКТ", null) || npt.getEndToken().isValue("ВОПРОС", null)) {
                    t = npt.getEndToken();
                    continue;
                }
            }
            if (t.getPrevious().isValue("В", null)) 
                return t;
            break;
        }
        return null;
    }

    public static com.pullenti.ner.ReferentToken tryAttachApproved(com.pullenti.ner.Token t, com.pullenti.ner.core.AnalyzerData ad, com.pullenti.ner.core.TerminCollection aliases, com.pullenti.ner.core.TerminCollection attachednames, boolean partRegime) {
        if (t == null) 
            return null;
        com.pullenti.ner.core.BracketSequenceToken br = null;
        if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t, true, false)) 
            br = com.pullenti.ner.core.BracketHelper.tryParse(t, com.pullenti.ner.core.BracketParseAttr.NO, 100);
        else if ((t.getPrevious() instanceof com.pullenti.ner.TextToken) && t.getPrevious().getLengthChar() == 1 && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t.getPrevious(), true, false)) 
            br = com.pullenti.ner.core.BracketHelper.tryParse(t.getPrevious(), com.pullenti.ner.core.BracketParseAttr.NO, 100);
        if (br != null) {
            if (br.getLengthChar() < 20) 
                return null;
            com.pullenti.ner.ReferentToken rt0 = _tryAttachApproved(br.getEndToken().getNext(), ad, false, true, aliases);
            if (rt0 != null) {
                DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(rt0.referent, DecreeReferent.class);
                rt0.setBeginToken(br.getBeginToken());
                String nam = com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(br, com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER);
                if (dr.getTyp() == null) {
                    com.pullenti.ner.decree.internal.DecreeToken dt = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(br.getBeginToken().getNext(), null, false);
                    if (dt != null && dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                        dr.addTyp(dt);
                        if (dt.getEndToken().getNext() != null && dt.getEndToken().getNext().isValue("О", null)) {
                            nam = com.pullenti.ner.core.MiscHelper.getTextValue(dt.getEndToken().getNext(), br.getEndToken(), com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER);
                            br.setBeginToken(dt.getEndToken().getNext());
                        }
                    }
                }
                if (nam != null) 
                    dr.addNameStr(nam, br);
                return rt0;
            }
            if (br.getBeginToken() == t.getPrevious()) 
                return null;
        }
        if ((t instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class)).term, "ПЕРЕЧЕНЬ")) {
        }
        com.pullenti.ner.core.TerminToken atok = (attachednames == null ? null : attachednames.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO));
        if (atok != null) {
            if (t.isNewlineBefore() && atok.isNewlineAfter() && !t.chars.isAllLower()) 
                return null;
            if (t.isNewlineBefore() && t.isValue("ИЗМЕНЕНИЕ", null)) 
                return null;
        }
        com.pullenti.ner.Token t0 = t;
        com.pullenti.ner.Token tt = canBeStartOfAttachApproved(t);
        if (tt == null) {
            if (atok == null) 
                return null;
            tt = t;
        }
        else 
            t = tt;
        com.pullenti.ner.Token keyTok = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t, false);
        boolean doubt = false;
        if (keyTok == null && ((t.isValue("СОСТАВ", null) || t.isValue("СРОК", null) || t.isValue("ФОРМА", null)))) {
            keyTok = t;
            doubt = true;
        }
        if (t.isValue("ГОСУДАРСТВЕННЫЙ", null)) {
        }
        if ((t.getNext() instanceof com.pullenti.ner.TextToken) && ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t.getNext(), com.pullenti.ner.TextToken.class)).isPureVerb()) 
            return null;
        com.pullenti.ner.Token chTok = _checkChangesTo(t);
        if (chTok != null && t.isValue("ИЗМЕНЕНИЕ", null)) {
            if (t.getPrevious() != null && t.getPrevious().isValue("ПЕРЕЧЕНЬ", null)) 
                return null;
        }
        if (chTok != null && (chTok.getReferent() instanceof DecreeReferent)) {
            DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(chTok.getReferent(), DecreeReferent.class);
            if (dr.getOwner() != null) 
                chTok.kit.debedToken(chTok);
        }
        int cou = 0;
        com.pullenti.ner.MetaToken alias = null;
        com.pullenti.ner.Token aliasT0 = null;
        boolean hasNl = false;
        boolean hasOrg = false;
        boolean hasVerb = false;
        com.pullenti.ner.Token lastTok = null;
        boolean keywordAfter = chTok != null;
        boolean hasWich = false;
        boolean hasRegisterAfter = false;
        boolean accord = false;
        com.pullenti.ner.Token changeStartTok = null;
        if ((t.getPrevious() != null && t.getPrevious().isValue("В", null) && t.getPrevious().getPrevious() != null) && t.getPrevious().getPrevious().isValue("ВНОСИТЬСЯ", null)) 
            keywordAfter = true;
        else if ((t.getPrevious() != null && t.getPrevious().isValue("ТЕКСТ", null) && t.getPrevious().getPrevious() != null) && t.getPrevious().getPrevious().isValue("В", null)) 
            keywordAfter = true;
        for (tt = tt.getNext(); tt != null; tt = tt.getNext()) {
            if (atok != null) {
                if (tt.getEndChar() <= atok.getEndChar()) 
                    continue;
            }
            if (tt.isValue("УСТАНОВЛЕННЫЙ", null)) {
            }
            if ((++cou) > 100) 
                break;
            lastTok = tt;
            if (tt.isCharOf(";.") || com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(tt, false, null, false) || tt.isHiphen()) {
                if (keyTok != null && keyTok == tt.getPrevious() && !keyTok.isValue("СОСТАВ", null)) {
                    if (tt.getNext() == null) 
                        return null;
                    com.pullenti.morph.MorphClass mc0 = tt.getNext().getMorphClassInDictionary();
                    if (mc0.isAdjective()) {
                    }
                    else 
                        return null;
                }
            }
            if (tt.isTableControlChar()) 
                break;
            if (tt.isHiphen() && tt.getPrevious() == keyTok) 
                break;
            if (tt.isComma() && tt.getPrevious() == keyTok && tt.getNext() != null) {
                if (tt.getNext().isValue("КАСАЮЩИЙСЯ", null)) 
                    break;
                if (tt.getNext().isValue("КОТОРЫЙ", null) || tt.getNext().getMorphClassInDictionary().isVerb()) {
                }
                else {
                    boolean ok = false;
                    for (com.pullenti.ner.Token ttt = tt.getNext(); ttt != null; ttt = ttt.getNext()) {
                        com.pullenti.ner.core.NounPhraseToken npt = com.pullenti.ner.core.NounPhraseHelper.tryParse(ttt, com.pullenti.ner.core.NounPhraseParseAttr.NO, 0, null);
                        if (npt == null) 
                            break;
                        if (ttt.getPrevious().isAnd()) {
                            ok = true;
                            tt = npt.getEndToken();
                            break;
                        }
                        ttt = npt.getEndToken().getNext();
                        if (ttt == null || !ttt.isCommaAnd()) 
                            break;
                    }
                    if (ok) 
                        continue;
                }
            }
            if (tt.isValue3("В", "СООТВЕТСТВИИ", "С")) 
                accord = true;
            if ((tt instanceof com.pullenti.ner.TextToken) && !tt.chars.isLetter() && tt.getLengthChar() == 1) {
                if (!com.pullenti.ner.core.BracketHelper.isBracket(tt, false) && !tt.isCharOf(",.:;№\\/") && !tt.isHiphen()) 
                    break;
            }
            if ((!partRegime && tt.isComma() && tt.getNext() != null) && tt.getNext().isAnd() && com.pullenti.ner.decree.internal.DecreeToken.isKeyword(tt.getNext().getNext(), false) != null) {
                com.pullenti.ner.ReferentToken next = tryAttachApproved(tt.getNext().getNext(), ad, aliases, attachednames, false);
                if (next != null && next.referent.getSlotValue(DecreeReferent.ATTR_OWNER) != null) {
                    String nam = com.pullenti.ner.core.MiscHelper.getTextValue(t, tt.getPrevious(), com.pullenti.ner.core.GetTextAttr.of((com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE.value()) | (com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER.value())));
                    if (nam == null || (nam.length() < 20) || nam.length() > 1000) 
                        return null;
                    com.pullenti.ner.decree.internal.DecreeToken dt = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(t, null, false);
                    DecreeReferent dec0 = new DecreeReferent();
                    if (dt != null && dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                        dec0.addTyp(dt);
                    dec0.addNameStr(nam, new com.pullenti.ner.MetaToken(t, tt.getPrevious(), null));
                    dec0.setOwner(((DecreeReferent)com.pullenti.unisharp.Utils.cast(next.referent, DecreeReferent.class)).getOwner());
                    return com.pullenti.ner.ReferentToken._new960(dec0, t, tt, alias);
                }
            }
            com.pullenti.ner.decree.internal.PartToken appNum = null;
            com.pullenti.ner.Token appBefore = null;
            DecreeReferent appOwn = null;
            boolean isBr = false;
            if ((tt.isValue2("ЯВЛЯЮЩИЙСЯ", "ПРИЛОЖЕНИЕМ") || tt.isValue2("ПРЕДУСМОТРЕННЫЙ", "ПРИЛОЖЕНИЕМ") || tt.isValue3("ПРИВЕДЕННЫЙ", "В", "ПРИЛОЖЕНИИ")) || ((tt.isChar('(') && tt.getNext() != null && tt.getNext().isValue("ПРИЛОЖЕНИЕ", null)))) {
                appBefore = tt.getPrevious();
                keywordAfter = true;
                if (tt.isValue("ПРИВЕДЕННЫЙ", null)) 
                    tt = tt.getNext();
                com.pullenti.ner.decree.internal.PartToken pp = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt.getNext(), null, false, false);
                if (pp == null) 
                    pp = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt.getNext(), null, false, true);
                if (pp == null) 
                    break;
                com.pullenti.ner.Token tt2 = pp.getEndToken().getNext();
                if (tt2 != null && tt2.isValue("К", null)) 
                    tt2 = tt2.getNext();
                isBr = tt.isChar('(');
                if (tt2 != null && (tt2.getReferent() instanceof DecreeReferent)) {
                    java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> pps = com.pullenti.ner.decree.internal.PartToken.tryAttachList(t, false, 40);
                    if (pps != null && pps.size() > 0) 
                        break;
                    appNum = pp;
                    tt = tt2;
                }
                else if (tt2 != null && tt2.isValue("УКАЗАННЫЙ", null)) {
                    com.pullenti.ner.Token tt3 = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(tt2.getNext(), true);
                    if (tt3 == null) 
                        break;
                    String norm = tt3.getNormalCaseText(null, com.pullenti.morph.MorphNumber.UNDEFINED, com.pullenti.morph.MorphGender.UNDEFINED, false);
                    int cou4 = 500;
                    for (com.pullenti.ner.Token tt4 = t.getPrevious(); tt4 != null && cou4 > 0; tt4 = tt4.getPrevious(),cou4--) {
                        DecreeReferent dd = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt4.getReferent(), DecreeReferent.class);
                        if (dd == null) 
                            continue;
                        if (dd.checkTypename(norm)) {
                            appOwn = dd;
                            tt = tt3;
                            appNum = pp;
                            break;
                        }
                    }
                    if (appOwn == null) 
                        break;
                }
                else if (partRegime) {
                    appNum = pp;
                    tt = tt2;
                }
                else 
                    break;
            }
            if (tt.isValue("ПРЕДУСМОТРЕННЫЙ", null)) {
                java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> pps = com.pullenti.ner.decree.internal.PartToken.tryAttachList(tt.getNext(), false, 40);
                if (pps != null && pps.size() > 0) {
                    if (pps.get(pps.size() - 1).decree != null) {
                        tt = pps.get(pps.size() - 1).getEndToken();
                        continue;
                    }
                    com.pullenti.ner.Token tt2 = pps.get(pps.size() - 1).getEndToken().getNext();
                    if (tt2 != null && (tt2.getReferent() instanceof DecreeReferent)) {
                        tt = tt2;
                        continue;
                    }
                    if (tt2 != null) {
                        com.pullenti.ner.decree.internal.DecreeToken dd = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(tt2, null, false);
                        if (dd != null && dd.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                            tt = dd.getEndToken();
                            continue;
                        }
                    }
                }
            }
            if (tt.isComma() && tt.getNext() != null && tt.getNext().isValue("УСТАНОВЛЕННЫЙ", null)) 
                tt = tt.getNext();
            if (tt.isValue("УСТАНОВЛЕННЫЙ", null) && tt.getNext() != null) {
                if (com.pullenti.ner.decree.internal.DecreeToken.isKeyword(tt.getNext(), false) != null || (tt.getNext().getReferent() instanceof DecreeReferent)) {
                    com.pullenti.ner.Token ttt2;
                    for (ttt2 = tt.getNext(); ttt2 != null; ttt2 = ttt2.getNext()) {
                        if (ttt2.isCommaAnd()) 
                            continue;
                        if (ttt2.getReferent() instanceof DecreeReferent) 
                            continue;
                        com.pullenti.ner.decree.internal.DecreeToken ddd = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(ttt2, null, false);
                        if (ddd == null) 
                            break;
                        if (ddd.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && ttt2 != tt.getNext()) 
                            break;
                        ttt2 = ddd.getEndToken();
                    }
                    if (ttt2 != null && ttt2.isValue("УТВЕРЖДЕННЫЙ", null)) 
                        tt = ttt2;
                }
            }
            if (tt.isValue("СЛЕДУЮЩИЙ", null)) {
                com.pullenti.ner.core.NounPhraseToken npt = com.pullenti.ner.core.NounPhraseHelper.tryParse(tt, com.pullenti.ner.core.NounPhraseParseAttr.NO, 0, null);
                if (npt != null && npt.getEndToken().getNext() != null && npt.getEndToken().getNext().isCharOf(":;")) {
                    keywordAfter = true;
                    if (keyTok != null && keyTok.isValue("УСТАВ", null)) 
                        break;
                    if (npt.getEndToken().isValue("ИЗМЕНЕНИЕ", null)) 
                        break;
                    if (changeStartTok != null) 
                        break;
                    return null;
                }
            }
            if (tt.isValue("КОТОРЫЙ", null)) 
                hasWich = true;
            if (tt.isNewlineBefore()) {
                if (atok != null) {
                    if ((tt instanceof com.pullenti.ner.TextToken) && tt.chars.isAllLower()) {
                    }
                    else 
                        break;
                }
                if (tt.getNewlinesBeforeCount() > 2) 
                    break;
                if (com.pullenti.ner.core.MiscHelper.checkImage(tt) != null) 
                    break;
                if (com.pullenti.ner.decree.internal.DecreeChangeToken._canBeChangeToken(tt, 0, false, false)) 
                    break;
                if (tt instanceof com.pullenti.ner.NumberToken) 
                    break;
                if (tt.getNext() != null && tt.getNext().isCharOf(".)")) 
                    break;
                if (tt.getPrevious() != null && tt.getPrevious().isCharOf(";.")) 
                    break;
                if ((tt instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).term, "ИСТОЧНИК")) 
                    break;
                if (tt.isValue("ГАРАНТ", null) || tt.isValue("КОНСУЛЬТАНТПЛЮС", null)) 
                    break;
                if (tt.isChar('(')) {
                }
                else if (!tt.chars.isAllUpper() && tt.getPrevious().chars.isAllUpper()) 
                    break;
                hasNl = true;
                com.pullenti.ner.decree.internal.PartToken pp = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, false);
                if (pp != null && !tt.chars.isAllLower()) 
                    return null;
                if (tt.getReferent() instanceof DecreeReferent) 
                    break;
                if (tt.getNewlinesBeforeCount() > 1) {
                    if (!tt.chars.isAllLower()) 
                        break;
                }
            }
            if ((((tt instanceof com.pullenti.ner.NumberToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.NumberToken.class)).getValue(), "1"))) || tt.isValue("ДРУГОЙ", null) || tt.isValue("ИНОЙ", null)) {
                if (tt.getNext() != null && tt.getNext().isValue("СТОРОНА", null)) 
                    return null;
            }
            if (tt.isCharOf(":;")) {
                if (hasNl) 
                    break;
                if (keyTok != null && tt == keyTok.getNext()) {
                    if (changeStartTok != null) 
                        break;
                    return null;
                }
                if (tt.isNewlineAfter()) {
                    if (t.getPrevious() != null && t.getPrevious().isValue("В", null)) 
                        break;
                }
            }
            if (tt.isValue2("В", "РЕДАКЦИИ")) {
                tt = tt.getNext();
                continue;
            }
            if (tt.isChar('(') && tt.getNext() != null) {
                if (tt.getPrevious() == keyTok) 
                    break;
                DecreeReferent dr1 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getNext().getReferent(), DecreeReferent.class);
                if (dr1 != null) {
                    if (dr1.getKind() == DecreeKind.PUBLISHER) {
                        hasRegisterAfter = true;
                        break;
                    }
                }
                DecreePartReferent pr1 = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt.getNext().getReferent(), DecreePartReferent.class);
                if (pr1 != null && pr1.getOwner() != null && pr1.getOwner().getKind() == DecreeKind.PUBLISHER) {
                    hasRegisterAfter = true;
                    break;
                }
                com.pullenti.ner.Token tt0 = tt;
                com.pullenti.ner.MetaToken mt = (partRegime ? null : _checkAliasAfter(tt));
                if (mt != null) {
                    aliasT0 = tt;
                    alias = mt;
                    tt = mt.getEndToken();
                    if (tt.getNext() != null && tt.getNext().isCommaAnd() && (t.getEndChar() < tt0.getPrevious().getBeginChar())) {
                        com.pullenti.ner.ReferentToken next = tryAttachApproved(tt.getNext().getNext(), ad, aliases, null, false);
                        if (next != null) {
                            String nam = com.pullenti.ner.core.MiscHelper.getTextValue(t, tt0.getPrevious(), com.pullenti.ner.core.GetTextAttr.of((com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE.value()) | (com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER.value())));
                            if (nam == null || (nam.length() < 20) || nam.length() > 1000) 
                                return null;
                            com.pullenti.ner.decree.internal.DecreeToken dt = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(t, null, false);
                            DecreeReferent dec0 = new DecreeReferent();
                            if (dt != null && dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                                dec0.addTyp(dt);
                            dec0.addNameStr(nam, new com.pullenti.ner.MetaToken(t, tt0.getPrevious(), null));
                            dec0.setOwner(((DecreeReferent)com.pullenti.unisharp.Utils.cast(next.referent, DecreeReferent.class)).getOwner());
                            return com.pullenti.ner.ReferentToken._new960(dec0, t, tt, alias);
                        }
                    }
                    if (atok != null) 
                        break;
                    continue;
                }
            }
            com.pullenti.ner.Token tok2 = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(tt, false);
            if (tok2 != null) {
                if (t.getPrevious() != null && t.getPrevious().isValue("В", null) && !hasVerb) {
                }
                else if (!hasVerb) {
                }
                else if (!hasWich) 
                    break;
            }
            com.pullenti.ner.Referent r = tt.getPrevious().getReferent();
            if (r != null && com.pullenti.unisharp.Utils.stringsEq(r.getTypeName(), "ORGANIZATION") && tt == t.getNext()) 
                hasOrg = true;
            if ((!partRegime && (tt.getReferent() instanceof DecreeReferent) && ((DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreeReferent.class)).getOwner() != null) && keyTok != null) {
                DecreeReferent dec0 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreeReferent.class);
                java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dtt = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(((com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.ReferentToken.class)).getBeginToken(), null, 10, false);
                if (dtt != null && dtt.size() > 1) {
                    com.pullenti.ner.ReferentToken rt00 = _tryAttachApproved(dtt.get(dtt.size() - 1).getEndToken().getNext(), ad, true, false, aliases);
                    if (rt00 != null && dec0.getOwner().canBeEquals(((DecreeReferent)com.pullenti.unisharp.Utils.cast(rt00.referent, DecreeReferent.class)).getOwner(), com.pullenti.ner.core.ReferentsEqualType.WITHINONETEXT) && rt00.getEndChar() == tt.getEndChar()) {
                        com.pullenti.ner.Token tt1 = tt.kit.debedToken(tt);
                        dec0.setOwner(null);
                        tt = dtt.get(dtt.size() - 1).getEndToken().getNext();
                    }
                }
            }
            com.pullenti.ner.ReferentToken rt0 = (partRegime ? null : _tryAttachApproved(tt, ad, true, false, aliases));
            if (rt0 == null && appNum != null) {
                rt0 = new com.pullenti.ner.ReferentToken(null, tt, tt, null);
                DecreeReferent own = (appOwn != null ? appOwn : ((DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreeReferent.class)));
                if (own != null && own.getOwner() != null && !partRegime) 
                    own = own.getOwner();
                DecreeReferent ddd = DecreeReferent._new1455(own);
                rt0.referent = ddd;
                ddd.addSlot(DecreeReferent.ATTR_TYPE, "ПРИЛОЖЕНИЕ", false, 0);
                if (appNum != null && appNum.values.size() == 1) 
                    ddd.addSlot(DecreeReferent.ATTR_NUMBER, appNum.values.get(0).toString(), false, 0);
            }
            if (rt0 != null) {
                if (tt.isChar('(') && tt.getNext().isValue("ВВЕСТИ", null)) 
                    return null;
                com.pullenti.ner.Token t1 = (appBefore == null ? tt.getPrevious() : appBefore);
                if (t1.isComma()) 
                    t1 = t1.getPrevious();
                if (aliasT0 != null) 
                    t1 = aliasT0.getPrevious();
                if (t1.isValue("РЕДАКЦИЯ", null)) 
                    t1 = t1.getPrevious();
                if (t1.isValue("В", null)) 
                    t1 = t1.getPrevious();
                if (t1.isComma()) 
                    t1 = t1.getPrevious();
                com.pullenti.ner.Token t00 = t;
                if (t == t1) 
                    return null;
                String nam = com.pullenti.ner.core.MiscHelper.getTextValue(t, t1, com.pullenti.ner.core.GetTextAttr.of((com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE.value()) | (com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER.value())));
                if (nam == null) 
                    return null;
                if (nam.length() > 1000) 
                    return null;
                if (t.getNext() == t1 && (nam.length() < 20)) 
                    return null;
                com.pullenti.ner.decree.internal.DecreeToken dt = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(t, null, false);
                DecreeReferent dec = (DecreeReferent)com.pullenti.unisharp.Utils.cast(rt0.referent, DecreeReferent.class);
                if (dt != null && dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && ((DecreeReferent)com.pullenti.unisharp.Utils.cast(rt0.referent, DecreeReferent.class)).getTyp() == null) {
                    dec.addTyp(dt);
                    if (dt.getEndToken().getNext() != null && dt.getEndToken().getNext().isValue("О", "ПРО")) {
                        dec.addNameStr(nam, new com.pullenti.ner.MetaToken(t00, t1, null));
                        t00 = dt.getEndToken().getNext();
                        nam = com.pullenti.ner.core.MiscHelper.getTextValue(t00, t1, com.pullenti.ner.core.GetTextAttr.RESTOREREGISTER);
                    }
                    else if (t.isValue("КОНСТИТУЦИЯ", null)) 
                        nam = null;
                }
                if (nam != null) 
                    dec.addNameStr(nam, (t00.getBeginChar() <= t1.getBeginChar() ? new com.pullenti.ner.MetaToken(t00, t1, null) : null));
                if (dec.getSlots().size() < 2) 
                    return null;
                rt0.setBeginToken(t);
                rt0.tag = alias;
                if (dec.findSlot(DecreeReferent.ATTR_SOURCE, null, true) == null) {
                    if (t.getPrevious() != null && t.getPrevious().isValue("В", null) && (t.getPrevious().getPrevious() instanceof com.pullenti.ner.ReferentToken)) {
                        if (t.getPrevious().getPrevious().getReferent() instanceof com.pullenti.ner._org.OrganizationReferent) {
                            com.pullenti.ner.Slot ss = dec.addSlot(DecreeReferent.ATTR_SOURCE, t.getPrevious().getPrevious().getReferent(), false, 0);
                            ss.addAnnotation((com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(t.getPrevious().getPrevious(), com.pullenti.ner.ReferentToken.class));
                        }
                    }
                }
                if (isBr && rt0.getEndToken().getNext() != null && rt0.getEndToken().getNext().isChar(')')) 
                    rt0.setEndToken(rt0.getEndToken().getNext());
                return rt0;
            }
            com.pullenti.ner.core.BracketSequenceToken br1 = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
            if (br1 != null) {
                tt = br1.getEndToken();
                continue;
            }
            if (tt.isCharOf(".;")) 
                break;
            if (tt.isNewlineBefore() && tt.getPrevious() != null && tt.getPrevious().isChar('.')) 
                break;
            if (changeStartTok == null && !accord && com.pullenti.ner.decree.internal.DecreeChangeToken._canBeChangeToken(tt, 0, true, false)) {
                if (atok != null) 
                    break;
                changeStartTok = tt;
                if (tt.getPrevious() != null && tt.getPrevious().isValue("В", null)) 
                    changeStartTok = tt.getPrevious();
            }
            boolean noVerb = false;
            if ((tt instanceof com.pullenti.ner.TextToken) && ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).isPureVerb() && !hasWich) {
                hasVerb = true;
                if (tt.isValue2("ИЗЛОЖИТЬ", "В")) 
                    break;
                if (tt.getPrevious().isValue("КОТОРЫЙ", null)) 
                    noVerb = true;
                else if (tt.getMorph().containsAttr("инф.", null)) 
                    noVerb = true;
                else if (tt.isValue("ПРИМЕНЯТЬСЯ", null)) 
                    noVerb = true;
                else 
                    break;
            }
            com.pullenti.morph.MorphClass mc = tt.getMorphClassInDictionary();
            if (((mc.isVerb() && !mc.isAdjective() && !mc.isPreposition()) && !mc.isNoun() && !noVerb) && tt.getMorph().getCase().isUndefined()) {
                if ((tt instanceof com.pullenti.ner.TextToken) && ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).term.endsWith("СЯ")) {
                }
                else 
                    hasVerb = true;
            }
            if (hasOrg) 
                break;
            if (tt.isComma() && tt.getNext() != null && tt.getNext().isValue("УТВЕРЖДЕННЫЙ", null)) 
                break;
            if (tt.getPrevious().isComma() && com.pullenti.ner.decree.internal.DecreeChangeToken._canBeChangeToken(tt, 0, true, false)) 
                break;
        }
        if (partRegime) 
            return null;
        if (atok != null) {
            DecreeReferent dd = new DecreeReferent();
            dd.addNameStr(atok.termin.getCanonicText(), atok);
            com.pullenti.ner.ReferentToken rt = com.pullenti.ner.ReferentToken._new960(dd, t0, (alias == null ? atok.getEndToken() : alias.getEndToken()), alias);
            return rt;
        }
        if (changeStartTok != null) 
            tt = changeStartTok;
        if (((tt != null || ((lastTok != null && (cou < 30))))) && ((keyTok != null || keywordAfter)) && ((!t.chars.isAllLower() || ((t.getPrevious() != null && t.getPrevious().isValue("В", null)))))) {
            if (t.getPrevious() != null && t.getPrevious().isValue("ТЕКСТ", null)) {
                if (t.getPrevious().getPrevious() != null && t.getPrevious().getPrevious().isValue("В", null)) {
                }
                else 
                    return null;
            }
            if (t.chars.isAllLower() && !keywordAfter && !hasRegisterAfter) 
                return null;
            com.pullenti.ner.decree.internal.PartToken pt = com.pullenti.ner.decree.internal.PartToken.tryAttach(t, null, false, false);
            if (pt != null && pt.values.size() > 0) 
                return null;
            if (aliases != null) {
                com.pullenti.ner.core.TerminToken tok = aliases.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO);
                if (tok != null) 
                    return new com.pullenti.ner.ReferentToken((com.pullenti.ner.Referent)com.pullenti.unisharp.Utils.cast(tok.termin.tag, com.pullenti.ner.Referent.class), t, tok.getEndToken(), null);
            }
            cou = 500;
            if (atok != null) 
                cou = 50000;
            if (tt == null) 
                tt = lastTok.getPrevious();
            if (t.getPrevious() == null || t.getBeginChar() >= tt.getPrevious().getBeginChar()) 
                return null;
            if (((t.isNewlineBefore() || ((t.getPrevious() != null && t.getPrevious().isChar('.'))))) && tt.isNewlineBefore()) 
                return null;
            com.pullenti.ner.decree.internal.DecreeToken ty = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(t, null, false);
            if (ty != null && ty.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                if (t.getMorph().getNumber() == com.pullenti.morph.MorphNumber.PLURAL) 
                    return null;
            }
            String typ = (keyTok == null ? null : keyTok.getNormalCaseText(com.pullenti.morph.MorphClass.NOUN, com.pullenti.morph.MorphNumber.UNDEFINED, com.pullenti.morph.MorphGender.UNDEFINED, false));
            if (tt.getPrevious().isCharOf(".;:,")) 
                tt = tt.getPrevious();
            if (t.isNewlineBefore()) {
                if (t.isValue("ОСНОВЫ", null)) {
                }
                if (tt.isNewlineBefore()) 
                    return null;
            }
            String nam = null;
            String nam2 = null;
            nam = com.pullenti.ner.core.MiscHelper.getTextValue(t, tt.getPrevious(), com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
            boolean ignore = false;
            for (com.pullenti.ner.Token ttt = t.getPrevious(); ttt != null && cou > 0; ttt = ttt.getPrevious(),cou--) {
                if (typ == null) 
                    break;
                if (ttt instanceof com.pullenti.ner.TextToken) {
                    if (com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(ttt, com.pullenti.ner.TextToken.class)).term, "ПРИКАЗЫВАЮ")) 
                        ignore = true;
                }
                if (ttt.isValue2("В", "СООТВЕТСТВИИ")) 
                    ignore = false;
                if (ignore) 
                    continue;
                DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(ttt.getReferent(), DecreeReferent.class);
                if (dr == null) 
                    continue;
                if (dr.getKind() == DecreeKind.PUBLISHER) 
                    continue;
                if (dr.getKind() == DecreeKind.KODEX || com.pullenti.unisharp.Utils.stringsEq(dr.getTyp(), "КОНСТИТУЦИЯ")) 
                    continue;
                if (!dr.checkTypename(typ)) {
                    boolean ok = hasRegisterAfter;
                    if ((lastTok != null && lastTok.isChar(':') && lastTok.isNewlineAfter()) && !doubt) 
                        ok = true;
                    if (ttt.getNext().isValue("УТВЕРДИТЬ", null) && ((t.getBeginChar() - ttt.getNext().getEndChar()) < 30)) 
                        ok = true;
                    if (ok) {
                        DecreeReferent dd = new DecreeReferent();
                        dd.addNameStr((nam2 != null ? nam2 : nam), new com.pullenti.ner.MetaToken(t, tt.getPrevious(), null));
                        if (dr.getOwner() != null) 
                            dd.setOwner(dr.getOwner());
                        else if (dr.getTyp() != null) 
                            dd.setOwner(dr);
                        return new com.pullenti.ner.ReferentToken(dd, t, tt.getPrevious(), null);
                    }
                    continue;
                }
                if (dr.findSlot(DecreeReferent.ATTR_NAME, nam, true) != null) 
                    return new com.pullenti.ner.ReferentToken(dr, t, tt.getPrevious(), null);
                if (nam2 != null && dr.findSlot(DecreeReferent.ATTR_NAME, nam2, true) != null) 
                    return new com.pullenti.ner.ReferentToken(dr, t, tt.getPrevious(), null);
                String nnn = nam;
                for (int k = 1; k < 5; k++) {
                    int ii = nnn.lastIndexOf(',');
                    if (ii < 0) 
                        break;
                    nnn = nnn.substring(0, 0 + ii).trim();
                    if (dr.findSlot(DecreeReferent.ATTR_NAME, nnn, true) == null) 
                        continue;
                    for (com.pullenti.ner.Token tte = tt.getPrevious(); tte != null; tte = tte.getPrevious()) {
                        if (tte.isComma()) {
                            if ((--k) == 0) {
                                if (t.getBeginChar() <= tte.getPrevious().getBeginChar()) 
                                    return new com.pullenti.ner.ReferentToken(dr, t, tte.getPrevious(), null);
                            }
                        }
                    }
                    break;
                }
                if (dr.getName() != null) {
                    com.pullenti.ner.core.Termin term = new com.pullenti.ner.core.Termin(dr.getName(), null, false);
                    com.pullenti.ner.core.TerminToken tok = term.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO);
                    if (tok != null) 
                        return new com.pullenti.ner.ReferentToken(dr, t, tok.getEndToken(), null);
                    String nam0 = dr.getName();
                    for (int i = 0; (i < nam0.length()) && (i < nam.length()); i++) {
                        if (nam0.charAt(i) != nam.charAt(i)) {
                            if (i >= 50) 
                                return new com.pullenti.ner.ReferentToken(dr, t, tt.getPrevious(), null);
                            break;
                        }
                    }
                }
                if (ty == null) {
                    DecreeReferent dd = new DecreeReferent();
                    dd.addNameStr((nam2 != null ? nam2 : nam), new com.pullenti.ner.MetaToken(t, tt.getPrevious(), null));
                    if (dr.getOwner() != null) 
                        dd.setOwner(dr.getOwner());
                    else if (dr.getTyp() != null) 
                        dd.setOwner(dr);
                    return new com.pullenti.ner.ReferentToken(dd, t, tt.getPrevious(), null);
                }
            }
            if (keyTok != null && keyTok.isValue("УСТАВ", null) && keyTok.getNext() == tt.getPrevious()) {
                if ((tt.getPrevious().getReferent() instanceof com.pullenti.ner.geo.GeoReferent) || (tt.getPrevious().getReferent() instanceof com.pullenti.ner._org.OrganizationReferent)) {
                    DecreeReferent dr = new DecreeReferent();
                    dr.addSlot(DecreeReferent.ATTR_TYPE, "УСТАВ", false, 0);
                    dr.addSlot(DecreeReferent.ATTR_NAME, nam, false, 0);
                    return new com.pullenti.ner.ReferentToken(dr, t, tt.getPrevious(), null);
                }
            }
            boolean ok1 = false;
            if ((((t0 instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t0, com.pullenti.ner.TextToken.class)).term, "ИЗМЕНЕНИЯ") && !t0.chars.isAllLower()) && t0.isNewlineBefore() && keywordAfter) && tt.isNewlineBefore()) 
                ok1 = true;
            else if (keyTok != null) {
                com.pullenti.ner.Token ttt2 = t0.getPrevious();
                for (; ttt2 != null; ttt2 = ttt2.getPrevious()) {
                    if ((ttt2.isValue("ТЕКСТ", null) || ttt2.isValue("В", null) || ttt2.isCharOf(".)")) || (ttt2 instanceof com.pullenti.ner.NumberToken)) {
                    }
                    else {
                        if (ttt2.isNewlineAfter()) 
                            ok1 = true;
                        break;
                    }
                }
            }
            if (ok1 && com.pullenti.ner.decree.internal.DecreeChangeToken._canBeChangeToken(tt, 0, false, false)) {
                if (keyTok != null) {
                    if (keyTok.isValue("АКТ", null) && keyTok.getMorph().getNumber() == com.pullenti.morph.MorphNumber.PLURAL) 
                        return null;
                }
                if (com.pullenti.ner.decree.internal.DecreeChangeToken._tryParseSpecialPart0(t, false) != null) 
                    return null;
                DecreeReferent dr = new DecreeReferent();
                dr.addSlot(DecreeReferent.ATTR_NAME, nam, false, 0);
                return new com.pullenti.ner.ReferentToken(dr, t, tt.getPrevious(), null);
            }
        }
        return null;
    }

    public static com.pullenti.ner.ReferentToken _tryAttachApproved(com.pullenti.ner.Token t, com.pullenti.ner.core.AnalyzerData ad, boolean mustBeComma, boolean nameInBrackets, com.pullenti.ner.core.TerminCollection aliases) {
        if (t == null) 
            return null;
        if (t.getReferent() instanceof DecreeReferent) {
            com.pullenti.ner.ReferentToken rt0 = _tryAttachApproved(((com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.ReferentToken.class)).getBeginToken(), ad, true, false, null);
            if (rt0 != null && rt0.getEndChar() == t.getEndChar()) {
                if (rt0.referent.getSlots().size() <= 1) 
                    return new com.pullenti.ner.ReferentToken(rt0.referent, t, t, null);
                DecreeReferent dr0 = new DecreeReferent();
                dr0.setOwner((DecreeReferent)com.pullenti.unisharp.Utils.cast((ad == null ? rt0.referent : ad.registerReferent(rt0.referent)), DecreeReferent.class));
                return new com.pullenti.ner.ReferentToken(dr0, t, t, null);
            }
        }
        if (t.getNext() == null) 
            return null;
        com.pullenti.ner.Token t0 = t;
        if (!t.isCharOf("(,") && !t.isHiphen()) {
            if (t.getPrevious() != null && t.getPrevious().isComma()) {
            }
            else if (mustBeComma) 
                return null;
        }
        else 
            t = t.getNext();
        boolean ok = false;
        for (; t != null; t = t.getNext()) {
            if (t.isCommaAnd() || t.getMorph()._getClass().isPreposition()) 
                continue;
            if ((t.getReferent() instanceof com.pullenti.ner.geo.GeoReferent) && ((com.pullenti.ner.geo.GeoReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), com.pullenti.ner.geo.GeoReferent.class)).isCity()) 
                continue;
            if ((((((((t.isValue("УТВ", null) || t.isValue("УТВЕРЖДАТЬ", "СТВЕРДЖУВАТИ") || t.isValue("УТВЕРДИТЬ", "ЗАТВЕРДИТИ")) || t.isValue("УТВЕРЖДЕННЫЙ", "ЗАТВЕРДЖЕНИЙ") || t.isValue("РАТИФИЦИРОВАННЫЙ", null)) || t.isValue("ЗАТВЕРДЖУВАТИ", null) || t.isValue("СТВЕРДИТИ", null)) || t.isValue("ЗАТВЕРДИТИ", null) || t.isValue("ПРИНЯТЬ", "ПРИЙНЯТИ")) || t.isValue("ПРИНЯТЫЙ", "ПРИЙНЯТИЙ") || t.isValue("ВВОДИТЬ", "ВВОДИТИ")) || t.isValue("ВВЕСТИ", null) || t.isValue("ВВЕДЕННЫЙ", "ВВЕДЕНИЙ")) || t.isValue("ПОДПИСАТЬ", "ПІДПИСАТИ") || t.isValue("ПОДПИСЫВАТЬ", "ПІДПИСУВАТИ")) || t.isValue("ЗАКЛЮЧИТЬ", "УКЛАСТИ") || t.isValue("ЗАКЛЮЧАТЬ", "УКЛАДАТИ")) {
                ok = true;
                if (t.getNext() != null && t.getNext().isChar('.')) 
                    t = t.getNext();
            }
            else if (t.isValue("УСТАНОВЛЕННЫЙ", null)) {
                com.pullenti.ner.Token tt = t.getPrevious();
                if (tt != null && tt.isComma()) 
                    tt = tt.getPrevious();
                if (tt != null) {
                    if (tt.isValue("ПОРЯДОК", null)) 
                        break;
                }
                ok = true;
            }
            else if (t.isValue("ДЕЙСТВИЕ", null) || t.isValue("ДІЯ", null)) {
            }
            else if (t.isValue("ОПРЕДЕЛЕННЫЙ", null) && t.getNext() != null && (t.getNext().getReferent() instanceof DecreeReferent)) {
                ok = true;
                t = t.getNext();
                break;
            }
            else if (nameInBrackets && t0.isHiphen()) {
                ok = true;
                break;
            }
            else if (t.isValue2("ПРИЛАГАЕМЫЙ", "К")) {
                ok = true;
                t = t.getNext();
            }
            else 
                break;
        }
        if (!ok) 
            return null;
        if (t == null) 
            return null;
        if (t.getReferent() instanceof DecreeReferent) {
            DecreeReferent dr = new DecreeReferent();
            dr.setOwner((DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), DecreeReferent.class));
            if (dr.getOwner() == null) 
                return null;
            com.pullenti.ner.ReferentToken res0 = new com.pullenti.ner.ReferentToken(dr, t, t, null);
            if (t0.isChar('(') && t.getNext() != null && t.getNext().isChar(')')) 
                res0.setEndToken(t.getNext());
            return res0;
        }
        com.pullenti.ner.core.AnalysisKit kit = t.kit;
        Object olev = null;
        int lev = 0;
        com.pullenti.unisharp.Outargwrapper<Object> wrapolev1457 = new com.pullenti.unisharp.Outargwrapper<Object>();
        boolean inoutres1458 = com.pullenti.unisharp.Utils.tryGetValue(kit.miscData, "dovr", wrapolev1457);
        olev = wrapolev1457.value;
        if (!inoutres1458) 
            kit.miscData.put("dovr", (lev = 1));
        else {
            lev = (int)olev;
            if (lev > 2) 
                return null;
            lev++;
            kit.miscData.put("dovr", lev);
        }
        try {
            java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(t, null, 10, false);
            if (dts == null) 
                return null;
            java.util.ArrayList<com.pullenti.ner.ReferentToken> rt = tryAttach(dts, null, ad);
            if (rt == null) {
                int hasDate = 0;
                int hasNum = 0;
                int hasOwn = 0;
                int hasTyp = 0;
                int ii;
                for (ii = 0; ii < dts.size(); ii++) {
                    if (dts.get(ii).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                        hasNum++;
                    else if ((dts.get(ii).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE && dts.get(ii).ref != null && (dts.get(ii).ref.referent instanceof com.pullenti.ner.date.DateReferent)) && ((com.pullenti.ner.date.DateReferent)com.pullenti.unisharp.Utils.cast(dts.get(ii).ref.referent, com.pullenti.ner.date.DateReferent.class)).getDt() != null) 
                        hasDate++;
                    else if (dts.get(ii).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER || dts.get(ii).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG) 
                        hasOwn++;
                    else if (dts.get(ii).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                        hasTyp++;
                    else 
                        break;
                }
                if (ii >= dts.size() && hasOwn > 0 && ((hasDate == 1 || hasNum == 1))) {
                    DecreeReferent dr = new DecreeReferent();
                    for (com.pullenti.ner.decree.internal.DecreeToken dt : dts) {
                        if (dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) 
                            dr.addDate(dt);
                        else if (dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) 
                            dr.addNumber(dt);
                        else if (dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                            dr.addSlot(DecreeReferent.ATTR_TYPE, dt.value, false, 0);
                        else {
                            Object val = dt.value;
                            if (dt.ref != null && dt.ref.referent != null) 
                                val = dt.ref.referent;
                            com.pullenti.ner.Slot s = dr.addSlot(DecreeReferent.ATTR_SOURCE, val, false, 0);
                            s.setTag(dt.getSourceText());
                            s.addAnnotation(dt);
                            if (dt.ref != null && (dt.ref.referent instanceof com.pullenti.ner.person.PersonPropertyReferent)) 
                                dr.addExtReferent(dt.ref);
                        }
                    }
                    rt = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                    rt.add(new com.pullenti.ner.ReferentToken(dr, dts.get(0).getBeginToken(), dts.get(dts.size() - 1).getEndToken(), null));
                }
            }
            if (((rt == null && dts.size() == 1 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) && dts.get(0).ref != null && (dts.get(0).ref.referent instanceof com.pullenti.ner.date.DateReferent)) && ((com.pullenti.ner.date.DateReferent)com.pullenti.unisharp.Utils.cast(dts.get(0).ref.referent, com.pullenti.ner.date.DateReferent.class)).getDt() != null) {
                DecreeReferent dr = new DecreeReferent();
                dr.addDate(dts.get(0));
                rt = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                rt.add(new com.pullenti.ner.ReferentToken(dr, dts.get(0).getBeginToken(), dts.get(dts.size() - 1).getEndToken(), null));
            }
            if ((rt == null && dts.size() == 1 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) && aliases != null) {
                com.pullenti.ner.core.TerminToken tok = aliases.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO);
                if (tok != null) {
                    DecreeReferent dr = new DecreeReferent();
                    dr.setOwner((DecreeReferent)com.pullenti.unisharp.Utils.cast(tok.termin.tag, DecreeReferent.class));
                    rt = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                    rt.add(new com.pullenti.ner.ReferentToken(dr, dts.get(0).getBeginToken(), tok.getEndToken(), null));
                }
            }
            if (rt == null && dts.size() == 1 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                com.pullenti.ner.Token tt2 = dts.get(0).getEndToken().getNext();
                if (tt2 != null && tt2.isCharOf(";:,")) 
                    tt2 = tt2.getNext();
                if (tt2 == null || tt2.isNewlineBefore()) {
                    for (tt2 = tt2.getPrevious(); tt2 != null; tt2 = tt2.getPrevious()) {
                        DecreeReferent dr1 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt2.getReferent(), DecreeReferent.class);
                        if (dr1 == null) 
                            continue;
                        if (dr1.getOwner() != null) 
                            dr1 = dr1.getOwner();
                        if (com.pullenti.unisharp.Utils.stringsNe(dr1.getTyp(), dts.get(0).value)) 
                            continue;
                        DecreeReferent dr = new DecreeReferent();
                        dr.setOwner(dr1);
                        rt = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                        rt.add(new com.pullenti.ner.ReferentToken(dr, dts.get(0).getBeginToken(), dts.get(0).getEndToken(), null));
                        break;
                    }
                }
            }
            if (rt == null) 
                return null;
            if (t0.isChar('(') && rt.get(0).getEndToken().getNext() != null && rt.get(0).getEndToken().getNext().isChar(')')) 
                rt.get(0).setEndToken(rt.get(0).getEndToken().getNext());
            rt.get(0).setBeginToken(t0);
            return rt.get(0);
        } finally {
            lev--;
            if (lev < 0) 
                lev = 0;
            kit.miscData.put("dovr", lev);
        }
    }

    private java.util.ArrayList<com.pullenti.ner.ReferentToken> tryAttachPulishers(java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts) {
        int i = 0;
        com.pullenti.ner.Token t1 = null;
        com.pullenti.ner.decree.internal.DecreeToken typ = null;
        com.pullenti.ner.ReferentToken geo = null;
        com.pullenti.ner.ReferentToken _org = null;
        com.pullenti.ner.decree.internal.DecreeToken _date = null;
        for (i = 0; i < dts.size(); i++) {
            if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && com.pullenti.ner.decree.internal.DecreeToken.getKind(dts.get(i).value, null) == DecreeKind.PUBLISHER) {
                if (typ != null) 
                    break;
                typ = dts.get(i);
                if (dts.get(i).ref != null && (dts.get(i).ref.getReferent() instanceof com.pullenti.ner.geo.GeoReferent)) 
                    geo = dts.get(i).ref;
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TERR) {
                geo = dts.get(i).ref;
                t1 = dts.get(i).getEndToken();
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                _date = dts.get(i);
                t1 = dts.get(i).getEndToken();
            }
            else if (dts.get(i).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG) {
                _org = dts.get(i).ref;
                t1 = dts.get(i).getEndToken();
            }
            else 
                break;
        }
        if (typ == null) 
            return null;
        com.pullenti.ner.Token t = dts.get(i - 1).getEndToken().getNext();
        java.util.ArrayList<com.pullenti.ner.ReferentToken> res = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
        com.pullenti.ner.decree.internal.DecreeToken num = null;
        com.pullenti.ner.Token t0 = dts.get(0).getBeginToken();
        if (com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(t, true, null, false)) {
            t = t.getNext();
            if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t0.getPrevious(), true, false)) 
                t0 = t0.getPrevious();
        }
        DecreeReferent pub0 = null;
        DecreePartReferent pubPart0 = null;
        for (; t != null; t = t.getNext()) {
            if (t.isCharOf(",;.") || t.isAnd()) 
                continue;
            com.pullenti.ner.decree.internal.DecreeToken dt = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(t, dts.get(0), false);
            if ((dt == null && (t instanceof com.pullenti.ner.NumberToken) && !t.isNewlineBefore()) && res.size() == 0) 
                dt = com.pullenti.ner.decree.internal.DecreeToken._new1121(t, t, com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER, ((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue());
            if (dt != null) {
                if (dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER) {
                    num = dt;
                    pub0 = null;
                    pubPart0 = null;
                    if (t0 == null) 
                        t0 = t;
                    t1 = (t = dt.getEndToken());
                    continue;
                }
                if (dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                    if (t0 == null) 
                        t0 = t;
                    _date = dt;
                    pub0 = null;
                    pubPart0 = null;
                    t1 = (t = dt.getEndToken());
                    continue;
                }
                if (dt.typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.MISC && t.getLengthChar() > 2) 
                    break;
            }
            com.pullenti.ner.decree.internal.PartToken pt = com.pullenti.ner.decree.internal.PartToken.tryAttach(t, null, false, false);
            if (pt == null && t.isChar('(')) {
                pt = com.pullenti.ner.decree.internal.PartToken.tryAttach(t.getNext(), null, false, false);
                if (pt != null) {
                    if (pt.getEndToken().getNext() != null && pt.getEndToken().getNext().isChar(')')) 
                        pt.setEndToken(pt.getEndToken().getNext());
                    else 
                        pt = null;
                }
            }
            if (pt != null) {
                if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PAGE) {
                    t = pt.getEndToken();
                    continue;
                }
                if (pt.typ != com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE && pt.typ != com.pullenti.ner.decree.internal.PartToken.ItemType.PART && pt.typ != com.pullenti.ner.decree.internal.PartToken.ItemType.PAGE) 
                    break;
                if (num == null) 
                    break;
                if (pubPart0 != null) {
                    if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PART && pubPart0.getPart() == null) {
                    }
                    else if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE && pubPart0.getClause() == null) {
                    }
                    else 
                        pubPart0 = null;
                }
                DecreeReferent pub = pub0;
                DecreePartReferent pubPart = pubPart0;
                if (pub == null) {
                    pub = new DecreeReferent();
                    pub.addTyp(typ);
                    if (geo != null) {
                        com.pullenti.ner.Slot ss = pub.addSlot(DecreeReferent.ATTR_GEO, geo.referent, false, 0);
                        ss.addAnnotation(geo);
                    }
                    if (_org != null) {
                        com.pullenti.ner.Slot ss = pub.addSlot(DecreeReferent.ATTR_SOURCE, _org.referent, false, 0);
                        ss.setTag(_org.getSourceText());
                        ss.addAnnotation(_org);
                    }
                    if (_date != null) 
                        pub.addDate(_date);
                    pub.addNumber(num);
                    res.add(new com.pullenti.ner.ReferentToken(pub, (t0 != null ? t0 : t), pt.getBeginToken().getPrevious(), null));
                }
                if (pubPart == null) {
                    pubPart = DecreePartReferent._new1460(pub);
                    res.add(new com.pullenti.ner.ReferentToken(pubPart, pt.getBeginToken(), pt.getEndToken(), null));
                }
                pub0 = pub;
                if (pt.values.size() == 1) {
                    if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE) 
                        pubPart.addSlot(DecreePartReferent.ATTR_CLAUSE, pt.values.get(0).value, false, 0).setTag(pt.values.get(0).getSourceValue());
                    else if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PART) 
                        pubPart.addSlot(DecreePartReferent.ATTR_PART, pt.values.get(0).value, false, 0).setTag(pt.values.get(0).getSourceValue());
                }
                else if (pt.values.size() > 1) {
                    for (int ii = 0; ii < pt.values.size(); ii++) {
                        if (ii > 0) {
                            pubPart = DecreePartReferent._new1460(pub);
                            res.add(new com.pullenti.ner.ReferentToken(pubPart, pt.values.get(ii).getBeginToken(), pt.values.get(ii).getEndToken(), null));
                        }
                        else 
                            res.get(res.size() - 1).setEndToken(pt.values.get(ii).getEndToken());
                        if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE) 
                            pubPart.addSlot(DecreePartReferent.ATTR_CLAUSE, pt.values.get(ii).value, false, 0).setTag(pt.values.get(ii).getSourceValue());
                        else if (pt.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PART) 
                            pubPart.addSlot(DecreePartReferent.ATTR_PART, pt.values.get(ii).value, false, 0).setTag(pt.values.get(ii).getSourceValue());
                    }
                }
                if (com.pullenti.unisharp.Utils.stringsEq(pubPart.getClause(), "6878")) {
                }
                pubPart0 = pubPart;
                res.get(res.size() - 1).setEndToken(pt.getEndToken());
                t0 = null;
                t = pt.getEndToken();
                continue;
            }
            if (t instanceof com.pullenti.ner.NumberToken) {
                com.pullenti.ner.ReferentToken rt = t.kit.processReferent("DATE", t, "YEAR");
                if (rt != null) {
                    _date = com.pullenti.ner.decree.internal.DecreeToken._new1122(rt.getBeginToken(), rt.getEndToken(), com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE);
                    _date.ref = rt;
                    pub0 = null;
                    pubPart0 = null;
                    if (t0 == null) 
                        t0 = t;
                    t1 = (t = rt.getEndToken());
                    continue;
                }
                if (t.getNext() != null && t.getNext().isChar(';')) {
                    if (pubPart0 != null && pubPart0.getClause() != null && pub0 != null) {
                        DecreePartReferent pubPart = new DecreePartReferent();
                        for (com.pullenti.ner.Slot s : pubPart0.getSlots()) {
                            pubPart.addSlot(s.getTypeName(), s.getValue(), false, 0);
                        }
                        pubPart0 = pubPart;
                        pubPart0.setClause(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue().toString());
                        res.add(new com.pullenti.ner.ReferentToken(pubPart0, t, t, null));
                        continue;
                    }
                }
            }
            if (((t instanceof com.pullenti.ner.TextToken) && t.chars.isLetter() && (t.getLengthChar() < 3)) && (t.getNext() instanceof com.pullenti.ner.NumberToken)) {
                t = t.getNext();
                continue;
            }
            if ((t.isChar('(') && t.getNext() != null && t.getNext().getNext() != null) && t.getNext().getNext().isChar(')')) {
                t = t.getNext().getNext();
                continue;
            }
            break;
        }
        if ((res.size() == 0 && _date != null && ((num != null || typ.value.endsWith("ГАЗЕТА")))) && t1 != null) {
            DecreeReferent pub = new DecreeReferent();
            pub.addTyp(typ);
            if (geo != null) 
                pub.addSlot(DecreeReferent.ATTR_GEO, geo.referent, false, 0);
            if (_org != null) 
                pub.addSlot(DecreeReferent.ATTR_SOURCE, _org.referent, false, 0).setTag(_org.getSourceText());
            if (_date != null) 
                pub.addDate(_date);
            pub.addNumber(num);
            res.add(new com.pullenti.ner.ReferentToken(pub, t0, t1, null));
        }
        return res;
    }

    public static java.util.ArrayList<com.pullenti.ner.MetaToken> tryAttachParts(java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> parts, com.pullenti.ner.decree.internal.DecreeToken baseTyp, com.pullenti.ner.Referent _defOwner, boolean inChanges) throws Exception {
        if (parts == null || parts.size() == 0) 
            return null;
        int i;
        int j;
        if (baseTyp != null) {
            if (com.pullenti.unisharp.Utils.stringsEq(baseTyp.value, "ПОЛОЖЕНИЕ") || com.pullenti.unisharp.Utils.stringsEq(baseTyp.value, "ОПРЕДЕЛЕНИЕ")) 
                baseTyp = null;
        }
        if (parts.size() == 1 && parts.get(0).getMorph().getNumber() == com.pullenti.morph.MorphNumber.PLURAL) {
            if (parts.get(0).values.size() == 0 && parts.get(0).name == null) 
                return null;
        }
        if ((parts.size() == 1 && parts.get(0).getBeginToken().getPrevious() != null && parts.get(0).getBeginToken().getPrevious().isChar('(')) && parts.get(0).getBeginToken().getPrevious().isNewlineBefore()) {
            com.pullenti.ner.Token tt2 = parts.get(0).getEndToken().getNext();
            if (tt2 != null) {
                if (tt2.isValue("В", null) || tt2.isValue("ВВЕДЕН", null)) 
                    return null;
            }
        }
        for (int jj = 0; jj < (parts.size() - 1); jj++) {
            if (parts.get(jj).decree == null) 
                continue;
            boolean br = false;
            if (parts.get(jj).delimAfter) 
                br = true;
            else 
                for (int kk = jj + 1; kk < parts.size(); kk++) {
                    if (parts.get(kk).decree != null && parts.get(kk).decree != parts.get(jj).decree) 
                        br = true;
                }
            if (!br) 
                continue;
            java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> parts1 = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken>(parts);
            for(int jjj = jj + 1 + parts.size() - jj - 1 - 1, mmm = jj + 1; jjj >= mmm; jjj--) parts1.remove(jjj);
            java.util.ArrayList<com.pullenti.ner.MetaToken> res11 = tryAttachParts(parts1, baseTyp, _defOwner, inChanges);
            if (res11 == null) 
                break;
            java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> parts2 = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken>(parts);
            for(int jjj = 0 + jj + 1 - 1, mmm = 0; jjj >= mmm; jjj--) parts2.remove(jjj);
            java.util.ArrayList<com.pullenti.ner.MetaToken> res22 = tryAttachParts(parts2, baseTyp, _defOwner, inChanges);
            if (res22 != null) 
                com.pullenti.unisharp.Utils.addToArrayList(res11, res22);
            return res11;
        }
        for (int jj = 0; jj < (parts.size() - 1); jj++) {
            if (parts.get(jj).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.NAME && parts.get(jj).delimAfter && ((jj == 0 || parts.get(jj - 1).delimAfter))) {
                java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> parts0 = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken>(parts);
                if (jj > 0) 
                    for(int jjj = 0 + jj - 1, mmm = 0; jjj >= mmm; jjj--) parts0.remove(jjj);
                parts0.remove(0);
                java.util.ArrayList<com.pullenti.ner.MetaToken> res11 = tryAttachParts(parts0, baseTyp, _defOwner, inChanges);
                if (res11 != null) {
                    java.util.ArrayList<DecreePartReferent> named = new java.util.ArrayList<DecreePartReferent>();
                    java.util.ArrayList<String> snamed = new java.util.ArrayList<String>();
                    for (com.pullenti.ner.MetaToken rr : res11) {
                        java.util.ArrayList<DecreePartReferent> pli = (java.util.ArrayList<DecreePartReferent>)com.pullenti.unisharp.Utils.cast(rr.tag, java.util.ArrayList.class);
                        if (pli != null) {
                            for (DecreePartReferent ppp : pli) {
                                DecreePartReferent pp2 = new DecreePartReferent();
                                pp2.setNameAsItem("0");
                                pp2.addNamedLevelInfo(ppp);
                                if (!snamed.contains(pp2.toString())) {
                                    named.add(pp2);
                                    snamed.add(pp2.toString());
                                }
                            }
                        }
                    }
                    res11.add(0, new com.pullenti.ner.MetaToken(parts.get(0).getBeginToken(), parts.get(0).getEndToken(), null));
                    res11.get(0).tag = named;
                    if (jj > 0) {
                        parts0.clear();
                        com.pullenti.unisharp.Utils.addToArrayList(parts0, parts);
                        for(int jjj = jj + parts.size() - jj - 1, mmm = jj; jjj >= mmm; jjj--) parts0.remove(jjj);
                        java.util.ArrayList<com.pullenti.ner.MetaToken> res00 = tryAttachParts(parts0, baseTyp, _defOwner, false);
                        if (res00 != null) 
                            com.pullenti.unisharp.Utils.insertToArrayList(res11, res00, 0);
                    }
                    return res11;
                }
            }
        }
        if ((parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.NAME && parts.get(0).getMorph().getNumber() == com.pullenti.morph.MorphNumber.PLURAL && parts.size() > 2) && parts.get(1).delimAfter) {
            java.util.ArrayList<com.pullenti.ner.MetaToken> res0 = new java.util.ArrayList<com.pullenti.ner.MetaToken>();
            for (i = 1; i < parts.size(); i++) {
                java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> parts0 = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken>();
                for (j = i; j < parts.size(); j++) {
                    parts0.add(parts.get(j));
                    if (parts.get(j).delimAfter) 
                        break;
                }
                i = j;
                java.util.ArrayList<com.pullenti.ner.MetaToken> res11 = tryAttachParts(parts0, baseTyp, _defOwner, inChanges);
                if (res11 != null) {
                    for (com.pullenti.ner.MetaToken rr : res11) {
                        java.util.ArrayList<DecreePartReferent> pli = (java.util.ArrayList<DecreePartReferent>)com.pullenti.unisharp.Utils.cast(rr.tag, java.util.ArrayList.class);
                        if (pli != null) {
                            for (DecreePartReferent ppp : pli) {
                                ppp.setNameAsItem("0");
                            }
                        }
                        if (rr.getBeginToken() == parts.get(1).getBeginToken()) 
                            rr.setBeginToken(parts.get(0).getBeginToken());
                        res0.add(rr);
                    }
                }
            }
            return res0;
        }
        if (parts.size() == 1 && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.NAME && !inChanges) 
            return null;
        if ((parts.size() == 1 && parts.get(0).decree == null && parts.get(0).isNewlineBefore()) && ((parts.get(0).isNewlineAfter() || ((parts.get(0).getEndToken().isValue("К", null) && parts.get(0).getEndToken().isNewlineBefore()))))) {
            if ((parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX || parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE || parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SECTION) || parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CHAPTER) 
                return null;
        }
        com.pullenti.ner.Token tt = parts.get(parts.size() - 1).getEndToken().getNext();
        if (_defOwner == null) 
            _defOwner = parts.get(parts.size() - 1).decree;
        if (_defOwner != null && tt != 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 && br.getEndToken().getNext() != null) 
                    tt = br.getEndToken().getNext();
            }
            if (tt.getReferent() instanceof DecreeReferent) 
                _defOwner = null;
            else if (tt.isValue("К", null) && tt.getNext() != null) {
                if (tt.getNext().getReferent() instanceof DecreeReferent) 
                    _defOwner = null;
            }
        }
        if ((parts.size() == 1 && parts.get(0).decree == null && ((parts.get(0).isNewlineBefore() || parts.get(0).getBeginToken().getPrevious().isTableControlChar()))) && parts.get(0).getBeginToken().chars.isLetter() && !parts.get(0).getBeginToken().chars.isAllLower()) {
            com.pullenti.ner.Token t1 = parts.get(0).getEndToken().getNext();
            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(t1, com.pullenti.ner.core.BracketParseAttr.NO, 100);
            if (br != null) 
                t1 = br.getEndToken().getNext();
            if (t1 != null && (t1.getReferent() instanceof DecreeReferent) && !parts.get(0).isNewlineAfter()) {
            }
            else if ((t1 != null && t1.isValue("К", null) && t1.getNext() != null) && (t1.getNext().getReferent() instanceof DecreeReferent) && !parts.get(0).isNewlineAfter()) {
            }
            else {
                com.pullenti.ner.instrument.internal.InstrToken1 li = com.pullenti.ner.instrument.internal.InstrToken1.parse(parts.get(0).getBeginToken(), true, null, 0, null, false, 0, false, false);
                if (li != null && (li.hasVerb)) {
                    if ((parts.size() == 1 && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PART && (parts.get(0).toString().indexOf("резолют") >= 0)) && parts.get(0).isNewlineBefore()) 
                        return null;
                }
                else 
                    return null;
            }
        }
        ThisDecree thisDec = null;
        boolean isProgram = false;
        boolean isAddAgree = false;
        if (parts.get(parts.size() - 1).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.SUBPROGRAM && parts.get(parts.size() - 1).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.ADDAGREE) {
            thisDec = ThisDecree.tryAttach(parts.get(parts.size() - 1), baseTyp);
            if (thisDec != null) {
                if (thisDec.checkDecree((DecreeReferent)com.pullenti.unisharp.Utils.cast(_defOwner, DecreeReferent.class))) {
                }
                else if ((_defOwner instanceof DecreeReferent) && ((parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX || parts.get(parts.size() - 1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX))) {
                }
                else 
                    _defOwner = null;
            }
            if (thisDec == null && _defOwner == null) {
                if (parts.size() == 1 && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX && parts.get(0).getBeginToken() == parts.get(0).getEndToken()) 
                    return null;
                thisDec = ThisDecree.tryAttachBack(parts.get(0).getBeginToken(), baseTyp);
            }
            if (thisDec == null && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.NAME && !inChanges) 
                return null;
            if (thisDec == null) {
                for (com.pullenti.ner.decree.internal.PartToken p : parts) {
                    if (p.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PART) {
                        boolean hasClause = false;
                        for (com.pullenti.ner.decree.internal.PartToken pp : parts) {
                            if (pp != p) {
                                if (com.pullenti.ner.decree.internal.PartToken._getRank(pp.typ) >= com.pullenti.ner.decree.internal.PartToken._getRank(com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE)) 
                                    hasClause = true;
                            }
                        }
                        if (_defOwner instanceof DecreePartReferent) {
                            if (((DecreePartReferent)com.pullenti.unisharp.Utils.cast(_defOwner, DecreePartReferent.class)).getClause() != null) 
                                hasClause = true;
                        }
                        if (!hasClause) 
                            p.typ = com.pullenti.ner.decree.internal.PartToken.ItemType.DOCPART;
                        else if ((((p == parts.get(parts.size() - 1) && p.getEndToken().getNext() != null && p.values.size() == 1) && (p.getEndToken().getNext().getReferent() instanceof DecreeReferent) && (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, "ЧАСТИ") && (p.getEndToken() instanceof com.pullenti.ner.NumberToken)) && p.getBeginToken().getNext() == p.getEndToken()) 
                            p.typ = com.pullenti.ner.decree.internal.PartToken.ItemType.DOCPART;
                    }
                }
            }
        }
        else if (parts.get(parts.size() - 1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ADDAGREE) 
            isAddAgree = true;
        else {
            if (parts.size() > 1) {
            }
            isProgram = true;
        }
        DecreeReferent defOwner = (DecreeReferent)com.pullenti.unisharp.Utils.cast(_defOwner, DecreeReferent.class);
        if (defOwner == null && thisDec != null && thisDec.real != null) 
            defOwner = thisDec.real;
        String docPart = null;
        if (_defOwner instanceof DecreePartReferent) {
            defOwner = ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(_defOwner, DecreePartReferent.class)).getOwner();
            docPart = ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(_defOwner, DecreePartReferent.class)).getDocPart();
        }
        String curTyp = null;
        com.pullenti.ner.Token curTypToken = null;
        if (parts.get(parts.size() - 1).getEndToken().getNext() != null && parts.get(parts.size() - 1).getEndToken().getNext().isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ")) {
            com.pullenti.ner.core.NounPhraseToken npt = com.pullenti.ner.core.NounPhraseHelper.tryParse(parts.get(parts.size() - 1).getEndToken().getNext().getNext(), com.pullenti.ner.core.NounPhraseParseAttr.NO, 0, null);
            if (npt != null) {
                curTyp = npt.getNormalCaseText(null, com.pullenti.morph.MorphNumber.UNDEFINED, com.pullenti.morph.MorphGender.UNDEFINED, false);
                curTypToken = npt.getEndToken();
                thisDec = null;
            }
        }
        java.util.ArrayList<com.pullenti.ner.ReferentToken> res = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
        boolean hasPrefix = false;
        if (parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PREFIX) {
            parts.remove(0);
            hasPrefix = true;
            if (parts.size() == 0) 
                return null;
        }
        if ((parts.size() == 1 && thisDec == null && parts.get(0).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.SUBPROGRAM) && parts.get(0).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.ADDAGREE) {
            if (parts.get(0).isDoubt) 
                return null;
            if (parts.get(0).isNewlineBefore() && ((parts.get(0).values.size() <= 1 || ((parts.get(0).values.size() == 2 && parts.get(0).values.get(0).getEndToken().getNext().isHiphen()))))) {
                com.pullenti.ner.Token tt1 = parts.get(0).getEndToken();
                if (tt1.getNext() == null) 
                    return null;
                tt1 = tt1.getNext();
                if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt1, false, false)) {
                    com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt1, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                    if (br != null && br.getEndToken().getNext() != null) 
                        tt1 = br.getEndToken().getNext();
                }
                if (tt1.isChar(',')) {
                }
                else if (tt1.getReferent() instanceof DecreeReferent) {
                }
                else if (tt1.isValue("К", null) && tt1.getNext() != null && (tt1.getNext().getReferent() instanceof DecreeReferent)) {
                }
                else if (_checkOtherTyp(tt1, true) != null) {
                }
                else if (_defOwner == null) 
                    return null;
                else if (com.pullenti.ner.core.MiscHelper.canBeStartOfSentence(tt1)) 
                    return null;
                else if (tt1.isChar('.')) 
                    return null;
            }
        }
        java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> asc = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken>();
        java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> desc = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken>();
        java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken.ItemType> typs = new java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken.ItemType>();
        for (i = 1; i < (parts.size() - 1); i++) {
            if (parts.get(i).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SENTENCE || parts.get(i).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.FOOTNOTE) {
                parts.add(parts.get(i));
                parts.remove(i);
            }
        }
        for (i = 0; i < (parts.size() - 2); i++) {
            if ((parts.get(i).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ITEM && parts.get(i + 1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.INDENTION && parts.get(i + 2).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SUBITEM) && !parts.get(i + 1).delimAfter && !parts.get(i).delimAfter) {
                com.pullenti.ner.decree.internal.PartToken pp = parts.get(i + 1);
                com.pullenti.unisharp.Utils.putArrayValue(parts, i + 1, parts.get(i + 2));
                com.pullenti.unisharp.Utils.putArrayValue(parts, i + 2, pp);
                if (parts.get(i + 1).delimAfter) {
                    parts.get(i + 1).delimAfter = false;
                    pp.delimAfter = true;
                }
            }
        }
        int ascCount = 0;
        int descCount = 0;
        int terminators = 0;
        for (i = 0; i < (parts.size() - 1); i++) {
            if (!parts.get(i).hasTerminator) {
                if (parts.get(i).canBeNextNarrow(parts.get(i + 1), parts)) {
                    ascCount++;
                    if (parts.get(i).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE && parts.get(i + 1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ITEM) {
                        for (com.pullenti.ner.decree.internal.PartToken p : parts) {
                            if (p.typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLEROW) {
                                ascCount--;
                                descCount++;
                                break;
                            }
                        }
                    }
                }
                if (parts.get(i + 1).canBeNextNarrow(parts.get(i), parts)) 
                    descCount++;
            }
            else if ((ascCount > 0 && parts.get(i).values.size() == 1 && parts.get(i + 1).values.size() == 1) && parts.get(i).canBeNextNarrow(parts.get(i + 1), parts)) 
                ascCount++;
            else if ((descCount > 0 && parts.get(i).values.size() == 1 && parts.get(i + 1).values.size() == 1) && parts.get(i + 1).canBeNextNarrow(parts.get(i), parts)) 
                descCount++;
            else 
                terminators++;
        }
        if (terminators == 0 && ((((descCount > 0 && ascCount == 0)) || ((descCount == 0 && ascCount > 0))))) {
            for (i = 0; i < (parts.size() - 1); i++) {
                parts.get(i).hasTerminator = false;
            }
        }
        for (i = 0; i < parts.size(); i++) {
            if (parts.get(i).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PREFIX) 
                continue;
            asc.clear();
            asc.add(parts.get(i));
            typs.clear();
            typs.add(parts.get(i).typ);
            for (j = i + 1; j < parts.size(); j++) {
                if (((parts.get(j).values.size() == 0 && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.PREAMBLE) && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.NOTICE && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE) && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.FOOTNOTE && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.FORM) 
                    break;
                else if (!typs.contains(parts.get(j).typ) && parts.get(j - 1).canBeNextNarrow(parts.get(j), parts)) {
                    if (parts.get(j - 1).delimAfter && terminators == 0) {
                        if (descCount > ascCount) 
                            break;
                        if (((j + 1) < parts.size()) && !parts.get(j).delimAfter && !parts.get(j).hasTerminator) 
                            break;
                        if (parts.get(j - 1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ITEM && parts.get(j).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SUBITEM) {
                            if (parts.get(j).values.size() > 0 && (parts.get(j).values.get(0).toString().indexOf(".") >= 0)) 
                                break;
                        }
                    }
                    asc.add(parts.get(j));
                    typs.add(parts.get(j).typ);
                    if (parts.get(j).hasTerminator) 
                        break;
                }
                else 
                    break;
            }
            desc.clear();
            desc.add(parts.get(i));
            typs.clear();
            typs.add(parts.get(i).typ);
            for (j = i + 1; j < parts.size(); j++) {
                if ((((parts.get(j).values.size() == 0 && parts.get(j).name == null && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX) && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.PREAMBLE && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.NOTICE) && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.FOOTNOTE && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE) && parts.get(j).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.FORM) 
                    break;
                else if (((!typs.contains(parts.get(j).typ) || parts.get(j).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SUBITEM)) && parts.get(j).canBeNextNarrow(parts.get(j - 1), parts)) {
                    if (parts.get(j - 1).delimAfter && terminators == 0) {
                        if (descCount <= ascCount) 
                            break;
                    }
                    desc.add(parts.get(j));
                    typs.add(parts.get(j).typ);
                    if (parts.get(j).hasTerminator) 
                        break;
                }
                else if (((!typs.contains(parts.get(j).typ) && parts.get(j - 1).canBeNextNarrow(parts.get(j), parts) && (j + 1) == (parts.size() - 1)) && parts.get(j + 1).canBeNextNarrow(parts.get(j), parts) && parts.get(j + 1).canBeNextNarrow(parts.get(j - 1), parts)) && !parts.get(j).hasTerminator) {
                    desc.add(desc.size() - 1, parts.get(j));
                    typs.add(parts.get(j).typ);
                }
                else if (!typs.contains(parts.get(j).typ) && parts.get(j).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SENTENCE) {
                    desc.add(0, parts.get(j));
                    typs.add(parts.get(j).typ);
                    break;
                }
                else if ((!typs.contains(parts.get(j).typ) && j == (parts.size() - 1) && parts.get(0).canBeNextNarrow(parts.get(j), parts)) && j == 2) {
                    desc.add(0, parts.get(j));
                    typs.add(parts.get(j).typ);
                    break;
                }
                else if ((parts.get(j).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ITEM && desc.size() > 1 && desc.get(desc.size() - 1).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLE) && desc.get(desc.size() - 2).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.TABLEROW) {
                    desc.add(parts.get(j));
                    typs.add(parts.get(j).typ);
                    break;
                }
                else 
                    break;
            }
            java.util.Collections.reverse(desc);
            java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> li = (asc.size() < desc.size() ? desc : asc);
            for (j = 0; j < li.size(); j++) {
                li.get(j).ind = 0;
            }
            while (true) {
                DecreePartReferent dr = new DecreePartReferent();
                com.pullenti.ner.Token tt00 = parts.get(i).getBeginToken();
                com.pullenti.ner.Token tt11 = parts.get((i + li.size()) - 1).getEndToken();
                for (int jj = i; jj < (i + li.size()); jj++) {
                    if (parts.get(jj).getBeginChar() < tt00.getBeginChar()) 
                        tt00 = parts.get(jj).getBeginToken();
                    if (parts.get(jj).getEndChar() > tt11.getEndChar()) 
                        tt11 = parts.get(jj).getEndToken();
                }
                com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(dr, tt00, tt11, null);
                if (parts.get(i).name != null) 
                    dr.addName(parts.get(i), null);
                rt.setMorph(parts.get(i).getMorph());
                res.add(rt);
                java.util.ArrayList<com.pullenti.ner.Slot> slList = new java.util.ArrayList<com.pullenti.ner.Slot>();
                for (com.pullenti.ner.decree.internal.PartToken p : li) {
                    if (p.name != null) 
                        dr.addName(p, null);
                    String nam = com.pullenti.ner.decree.internal.PartToken._getAttrNameByTyp(p.typ);
                    if (nam != null) {
                        com.pullenti.ner.Slot sl = com.pullenti.ner.Slot._new1463(nam, p, 1);
                        slList.add(sl);
                        if (p.ind < p.values.size()) {
                            sl.setValue(p.values.get(p.ind));
                            if (com.pullenti.unisharp.Utils.isNullOrEmpty(p.values.get(p.ind).value)) 
                                sl.setValue("0");
                        }
                        else 
                            sl.setValue("0");
                    }
                    if (p.ind > 0) 
                        rt.setBeginToken(p.values.get(p.ind).getBeginToken());
                    if ((p.ind + 1) < p.values.size()) 
                        rt.setEndToken(p.values.get(p.ind).getEndToken());
                }
                for (com.pullenti.ner.decree.internal.PartToken p : parts) {
                    for (com.pullenti.ner.Slot s : slList) {
                        if (s.getTag() == p) {
                            dr.addSlot(s.getTypeName(), s.getValue(), false, 0);
                            break;
                        }
                    }
                }
                for (j = li.size() - 1; j >= 0; j--) {
                    if ((++li.get(j).ind) >= li.get(j).values.size()) 
                        li.get(j).ind = 0;
                    else 
                        break;
                }
                if (j < 0) 
                    break;
            }
            if (res.size() == 1) {
                for (int ii = i; ii < li.size(); ii++) {
                    if (res.get(0).getBeginChar() > li.get(ii).getBeginChar()) 
                        res.get(0).setBeginToken(li.get(ii).getBeginToken());
                    if (res.get(0).getEndChar() < li.get(ii).getEndChar()) 
                        res.get(0).setEndToken(li.get(ii).getEndToken());
                }
            }
            i += (li.size() - 1);
        }
        if (res.size() == 0) 
            return null;
        for (j = res.size() - 1; j > 0; j--) {
            DecreePartReferent d0 = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(j).referent, DecreePartReferent.class);
            DecreePartReferent d = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(j - 1).referent, DecreePartReferent.class);
            if (d0.getAppendix() != null && d.getAppendix() == null) {
                d.setAppendix(d0.getAppendix());
                d.setAppendixName(d0.getAppendixName());
            }
            if (d0.getAppendix2() != null && d.getAppendix2() == null) {
                d.setAppendix2(d0.getAppendix2());
                d.setAppendix2Name(d0.getAppendix2Name());
            }
            if (d0.getDocPart() != null && d.getDocPart() == null) 
                d.setDocPart(d0.getDocPart());
            else if (docPart != null && d.getDocPart() == null) 
                d.setDocPart(docPart);
            if (d0.getChapter() != null && d.getChapter() == null) {
                d.setChapter(d0.getChapter());
                d.setChapterName(d0.getChapterName());
            }
            if (d0.getSection() != null && d.getSection() == null) {
                d.setSection(d0.getSection());
                d.setSectionName(d0.getSectionName());
            }
            if (d0.getSubSection() != null && d.getSubSection() == null) {
                d.setSubSection(d0.getSubSection());
                d.setSubSectionName(d0.getSubSectionName());
            }
            if (d0.getClause() != null && d.getClause() == null) {
                d.setClause(d0.getClause());
                d.setClauseName(d0.getClauseName());
            }
            if (d0.getItem() != null && d.getItem() == null && ((d.getSubItem() != null || d.getIndention() != null))) {
                if (d0.getClause() != null && com.pullenti.unisharp.Utils.stringsNe(d0.getClause(), d.getClause())) {
                }
                else 
                    d.setItem(d0.getItem());
            }
            if (d0.getForm() != null && d.getForm() == null) {
                d.setForm(d0.getForm());
                d.setFormName(d0.getFormName());
            }
            if (d0.getTable() != null && d.getTable() == null) {
                d.setTable(d0.getTable());
                d.setTableName(d0.getTableName());
            }
            if ((d0.getSubItem() != null && d.getSubItem() == null && d.getIndention() != null) && com.pullenti.unisharp.Utils.stringsEq(d.getItem(), d0.getItem())) 
                d.setSubItem(d0.getSubItem());
        }
        if (res.size() == 1 && docPart != null && ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent, DecreePartReferent.class)).getDocPart() == null) 
            ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent, DecreePartReferent.class)).setDocPart(docPart);
        if (((parts.size() > 2 && res.size() == 2 && parts.get(parts.size() - 2).delimAfter) && parts.get(parts.size() - 2).typ == parts.get(parts.size() - 1).typ && res.get(1).referent.getSlots().size() == 1) && res.get(1).getMorph().getCase().isGenitive() && parts.get(parts.size() - 2).getEndToken().getNext().isAnd()) {
            DecreePartReferent pp = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent.clone(), DecreePartReferent.class);
            String nam = com.pullenti.ner.decree.internal.PartToken._getAttrNameByTyp(parts.get(parts.size() - 1).typ);
            com.pullenti.ner.Slot sl = res.get(1).referent.findSlot(nam, null, true);
            if (sl != null) {
                com.pullenti.ner.Slot sl1 = pp.findSlot(nam, null, true);
                if (sl1 != null) {
                    sl1.setValue(sl.getValue());
                    sl1.setTag(sl.getTag());
                    sl1.setCount(sl.getCount());
                    res.get(1).referent = pp;
                }
            }
        }
        tt = parts.get(i - 1).getEndToken();
        DecreeReferent owner = defOwner;
        if (owner != null && !inChanges && parts.get(0).anaforRef != null) {
            for (com.pullenti.ner.Token tt3 = parts.get(0).getBeginToken().getPrevious(); tt3 != null; tt3 = tt3.getPrevious()) {
                if (tt3.isComma()) 
                    continue;
                if (tt3.getReferent() instanceof DecreeReferent) 
                    owner = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt3.getReferent(), DecreeReferent.class);
                break;
            }
        }
        com.pullenti.ner.Token te = tt.getNext();
        if ((te != null && owner == null && te.isChar('(')) && parts.get(0).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.SUBPROGRAM && parts.get(0).typ != com.pullenti.ner.decree.internal.PartToken.ItemType.ADDAGREE) {
            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(te, com.pullenti.ner.core.BracketParseAttr.NO, 100);
            if (br != null) {
                if (te.getNext().getMorph()._getClass().isAdverb()) {
                }
                else if (te.getNext().getReferent() instanceof DecreeReferent) {
                    if (owner == null && te.getNext().getNext() == br.getEndToken()) {
                        owner = (DecreeReferent)com.pullenti.unisharp.Utils.cast(te.getNext().getReferent(), DecreeReferent.class);
                        te = br.getEndToken();
                    }
                }
                else {
                    String s = com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(br, com.pullenti.ner.core.GetTextAttr.KEEPREGISTER);
                    if (s != null) {
                        com.pullenti.ner.ReferentToken rt = res.get(res.size() - 1);
                        rt.setEndToken(br.getEndToken());
                        te = br.getEndToken().getNext();
                    }
                }
            }
        }
        if (te != null && te.isCharOf(",;")) 
            te = te.getNext();
        if (owner == null && (te instanceof com.pullenti.ner.ReferentToken)) {
            if ((((owner = (DecreeReferent)com.pullenti.unisharp.Utils.cast(te.getReferent(), DecreeReferent.class)))) != null) 
                res.get(res.size() - 1).setEndToken(te);
        }
        if (owner == null) {
            for (j = 0; j < i; j++) {
                if ((((owner = parts.get(j).decree))) != null) 
                    break;
            }
        }
        if (te != null && te.isValue("К", null) && te.getNext() != null) {
            if (te.getNext().getReferent() instanceof DecreeReferent) {
                te = te.getNext();
                if (te.getEndChar() > res.get(res.size() - 1).getEndChar()) 
                    res.get(res.size() - 1).setEndToken(te);
                owner = (DecreeReferent)com.pullenti.unisharp.Utils.cast(te.getReferent(), DecreeReferent.class);
            }
            else if ((owner != null && thisDec != null && thisDec.getEndChar() > te.getEndChar()) && (res.get(res.size() - 1).getEndChar() < thisDec.getEndChar())) {
                if (com.pullenti.unisharp.Utils.stringsNe(thisDec.typ, "ТИПОВОЙ ДОГОВОР")) 
                    res.get(res.size() - 1).setEndToken(thisDec.getEndToken());
            }
        }
        if (owner == null && thisDec != null) {
            com.pullenti.ner.Token tt0 = res.get(0).getBeginToken();
            if (tt0.getPrevious() != null && tt0.getPrevious().isChar('(')) 
                tt0 = tt0.getPrevious();
            if (tt0.getPrevious() != null) {
                if ((((owner = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt0.getPrevious().getReferent(), DecreeReferent.class)))) != null) {
                    if (com.pullenti.unisharp.Utils.stringsEq(thisDec.typ, owner.getTyp0())) 
                        thisDec = null;
                    else 
                        owner = null;
                }
            }
        }
        if (owner == null && thisDec != null && thisDec.real != null) 
            owner = thisDec.real;
        if (owner != null && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SUBPROGRAM && owner.getKind() != DecreeKind.PROGRAM) 
            owner = null;
        if (owner != null && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ADDAGREE && owner.getKind() != DecreeKind.CONTRACT) 
            owner = null;
        DecreePartReferent ownerPaer = null;
        String locTyp = curTyp;
        if ((((thisDec == null || !thisDec.hasThisRef)) && !inChanges && locTyp == null) && owner == null) {
            com.pullenti.ner.TextToken anaforRef = null;
            for (com.pullenti.ner.decree.internal.PartToken p : parts) {
                if ((((anaforRef = p.anaforRef))) != null) 
                    break;
            }
            boolean isChangeWordAfter = false;
            com.pullenti.ner.Token tt2 = res.get(res.size() - 1).getEndToken().getNext();
            if (tt2 != null) {
                if (((tt2.isChar(':') || tt2.isValue("ДОПОЛНИТЬ", null) || tt2.isValue("СЛОВО", null)) || tt2.isValue("ИСКЛЮЧИТЬ", null) || tt2.isValue("ИЗЛОЖИТЬ", null)) || tt2.isValue("СЧИТАТЬ", null) || tt2.isValue("ПРИЗНАТЬ", null)) 
                    isChangeWordAfter = true;
            }
            tt2 = parts.get(0).getBeginToken().getPrevious();
            if (tt2 != null) {
                if (((tt2.isValue("ДОПОЛНИТЬ", null) || tt2.isValue("ИСКЛЮЧИТЬ", null) || tt2.isValue("ИЗЛОЖИТЬ", null)) || tt2.isValue("СЧИТАТЬ", null) || tt2.isValue("УСТАНОВЛЕННЫЙ", null)) || tt2.isValue("ОПРЕДЕЛЕННЫЙ", null)) 
                    isChangeWordAfter = true;
            }
            int cou = 0;
            boolean ugolDelo = false;
            int brackLevel = 0;
            com.pullenti.ner.Token bt = null;
            int coefBefore = 0;
            boolean isOverBrr = false;
            if (parts.get(0).getBeginToken().getPrevious() != null && parts.get(0).getBeginToken().getPrevious().isChar('(')) {
                if (parts.get(parts.size() - 1).getEndToken().getNext() != null && parts.get(parts.size() - 1).getEndToken().getNext().isChar(')')) {
                    if (parts.size() == 1 && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX) {
                    }
                    else {
                        isOverBrr = true;
                        if (owner != null && _getDecree(parts.get(0).getBeginToken().getPrevious().getPrevious()) != null) 
                            owner = null;
                    }
                }
            }
            for (tt = parts.get(0).getBeginToken().getPrevious(); tt != null; tt = tt.getPrevious(),coefBefore++) {
                if (tt.isNewlineAfter()) {
                    coefBefore += 2;
                    if (((anaforRef == null && !isOverBrr && !ugolDelo) && !isChangeWordAfter && !isProgram) && !isAddAgree) {
                        if (thisDec == null) {
                            if (!tt.isTableControlChar()) {
                                if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt.getNext(), false, false)) 
                                    break;
                                if (com.pullenti.ner.core.ComplexNumToken.tryParse(tt.getNext(), null, false, false) != null) 
                                    break;
                                if (tt.isCharOf(".;")) 
                                    break;
                            }
                        }
                    }
                }
                if (thisDec != null && thisDec.hasThisRef) 
                    break;
                if (tt.isTableControlChar()) 
                    break;
                if (tt.getMorph()._getClass().isPreposition()) {
                    coefBefore--;
                    continue;
                }
                if (tt instanceof com.pullenti.ner.TextToken) {
                    if (com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(tt, false, null, false)) {
                        brackLevel++;
                        continue;
                    }
                    if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, false, false)) {
                        if (tt.isChar('(') && tt == parts.get(0).getBeginToken().getPrevious()) {
                        }
                        else {
                            brackLevel--;
                            coefBefore--;
                        }
                        continue;
                    }
                }
                if (tt.isNewlineBefore()) 
                    brackLevel = 0;
                if ((++cou) > 100) {
                    if (((ugolDelo || isProgram || isAddAgree) || anaforRef != null || thisDec != null) || isOverBrr) {
                        if (cou > 1000) 
                            break;
                    }
                    else if (isChangeWordAfter) {
                        if (cou > 250) 
                            break;
                    }
                    else 
                        break;
                }
                if (cou < 4) {
                    if (tt.isValue("УГОЛОВНЫЙ", "КРИМІНАЛЬНИЙ") && tt.getNext() != null && tt.getNext().isValue("ДЕЛО", "СПРАВА")) 
                        ugolDelo = true;
                }
                if (tt.isCharOf(".")) {
                    coefBefore += 50;
                    if (tt.isNewlineAfter()) 
                        coefBefore += 100;
                    continue;
                }
                if (brackLevel > 0) 
                    continue;
                DecreeReferent dr = _getDecree(tt);
                if (dr != null) {
                    if (dr.getKind() == DecreeKind.PUBLISHER) {
                        if ((tt.getEndChar() + 3) < parts.get(0).getBeginChar()) 
                            continue;
                    }
                    if (ugolDelo && ((com.pullenti.unisharp.Utils.stringsEq(dr.getName(), "УГОЛОВНЫЙ КОДЕКС") || com.pullenti.unisharp.Utils.stringsEq(dr.getName(), "КРИМІНАЛЬНИЙ КОДЕКС")))) 
                        coefBefore = 0;
                    if (dr.getKind() == DecreeKind.PROGRAM) {
                        if (isProgram) {
                            bt = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    if (dr.getKind() == DecreeKind.CONTRACT) {
                        if (isAddAgree) {
                            bt = tt;
                            break;
                        }
                        else if (thisDec != null && ((com.pullenti.unisharp.Utils.stringsEq(dr.getTyp(), thisDec.typ) || com.pullenti.unisharp.Utils.stringsEq(dr.getTyp0(), thisDec.typ)))) {
                            bt = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    if (thisDec != null) {
                        DecreePartReferent dpr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreePartReferent.class);
                        if (com.pullenti.unisharp.Utils.stringsEq(thisDec.typ, dr.getTyp()) || com.pullenti.unisharp.Utils.stringsEq(thisDec.typ, dr.getTyp0())) 
                            thisDec.real = dr;
                        else if (dr.getName() != null && thisDec.typ != null && dr.getName().startsWith(thisDec.typ.substring(0, 0 + thisDec.typ.length() - 1))) {
                            thisDec.real = dr;
                            String[] words = com.pullenti.unisharp.Utils.split(dr.getName(), String.valueOf(' '), false);
                            for (int ii = 1; ii < words.length; ii++) {
                                if (thisDec.getEndToken().getNext() != null && thisDec.getEndToken().getNext().isValue(words[ii], null)) 
                                    thisDec.setEndToken(thisDec.getEndToken().getNext());
                                else 
                                    break;
                            }
                        }
                        else if ((thisDec.hasOtherRef && dpr != null && dpr.getClause() != null) && ((com.pullenti.unisharp.Utils.stringsEq(thisDec.typ, "СТАТЬЯ") || com.pullenti.unisharp.Utils.stringsEq(thisDec.typ, "СТАТТЯ")))) {
                            for (com.pullenti.ner.ReferentToken r : res) {
                                DecreePartReferent dpr0 = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(r.referent, DecreePartReferent.class);
                                if (dpr0.getClause() == null) {
                                    dpr0.setClause(dpr.getClause());
                                    owner = dpr0.setOwner(dpr.getOwner());
                                }
                            }
                        }
                        else 
                            continue;
                    }
                    else if (isChangeWordAfter) {
                        if (owner == null) 
                            coefBefore = 0;
                        else if (owner == _getDecree(tt)) 
                            coefBefore = 0;
                    }
                    bt = tt;
                    break;
                }
                if (dr != null) 
                    continue;
                if (tt.getReferent() instanceof DecreeChangeReferent) 
                    break;
                DecreePartReferent dpr2 = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreePartReferent.class);
                if (dpr2 != null) {
                    if (thisDec != null) {
                        if (com.pullenti.unisharp.Utils.stringsNe(thisDec.typ, dpr2.getLocalTyp())) 
                            continue;
                    }
                    bt = tt;
                    break;
                }
                com.pullenti.ner.decree.internal.DecreeToken dit = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(tt, null, false);
                if (dit != null && dit.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                    if (thisDec != null) 
                        continue;
                    if (dit.chars.isCapitalUpper() || anaforRef != null) {
                        bt = tt;
                        break;
                    }
                }
            }
            cou = 0;
            com.pullenti.ner.Token at = null;
            int coefAfter = 0;
            String alocTyp = null;
            com.pullenti.ner.Token tt0 = parts.get(parts.size() - 1).getEndToken().getNext();
            boolean hasNewline = false;
            for (com.pullenti.ner.Token ttt = parts.get(parts.size() - 1).getBeginToken(); ttt.getEndChar() < parts.get(parts.size() - 1).getEndChar(); ttt = ttt.getNext()) {
                if (ttt.isNewlineAfter()) 
                    hasNewline = true;
            }
            for (tt = tt0; tt != null; tt = tt.getNext(),coefAfter++) {
                if (owner != null && coefAfter > 0) 
                    break;
                if (tt.isNewlineBefore()) 
                    break;
                if (tt.isTableControlChar()) 
                    break;
                if (tt.isValue("СМ", null)) 
                    break;
                if (anaforRef != null) 
                    break;
                if (thisDec != null) {
                    if (tt != tt0) 
                        break;
                    if (thisDec.real != null) 
                        break;
                }
                if (com.pullenti.ner.instrument.internal.InstrToken._checkEntered(tt) != null) 
                    break;
                if ((tt instanceof com.pullenti.ner.TextToken) && ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).isPureVerb()) 
                    break;
                if (tt.getMorph()._getClass().isPreposition() || tt.isCommaAnd()) {
                    coefAfter--;
                    continue;
                }
                if (tt.getMorph()._getClass().equals(com.pullenti.morph.MorphClass.VERB)) 
                    break;
                if (com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(tt, false, null, false)) 
                    break;
                java.util.ArrayList<com.pullenti.ner.decree.internal.PartToken> pts = com.pullenti.ner.decree.internal.PartToken.tryAttachList(tt, false, 40);
                if (pts != null) {
                    tt = pts.get(pts.size() - 1).getEndToken();
                    coefAfter--;
                    com.pullenti.ner.Token ttnn = tt.getNext();
                    if (ttnn != null && ttnn.isChar('.')) 
                        ttnn = ttnn.getNext();
                    com.pullenti.ner.decree.internal.DecreeToken dit = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(ttnn, null, false);
                    if (dit != null && dit.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                        locTyp = dit.value;
                        break;
                    }
                    continue;
                }
                if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, false, false)) {
                    com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                    if (br != null) {
                        coefAfter--;
                        tt = br.getEndToken();
                        continue;
                    }
                }
                if ((++cou) > 100) 
                    break;
                if (cou > 1 && hasNewline) 
                    break;
                if (tt.isCharOf(".")) {
                    coefAfter += 50;
                    if (tt.isNewlineAfter()) 
                        coefAfter += 100;
                    continue;
                }
                if (tt.getReferent() instanceof DecreeChangeReferent) 
                    break;
                DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), DecreeReferent.class);
                if (dr != null && dr.getKind() != DecreeKind.PUBLISHER) {
                    if (dr.getKind() == DecreeKind.PROGRAM) {
                        if (isProgram) {
                            at = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    if (dr.getKind() == DecreeKind.CONTRACT) {
                        if (isAddAgree) {
                            at = tt;
                            break;
                        }
                        else 
                            continue;
                    }
                    at = tt;
                    break;
                }
                if (isProgram || isAddAgree) 
                    break;
                if (dr != null) 
                    continue;
                com.pullenti.ner.Token tte2 = _checkOtherTyp(tt, tt == tt0);
                if (tte2 != null) {
                    at = tte2;
                    if (tt == tt0 && thisDec != null && thisDec.real == null) {
                        if (com.pullenti.unisharp.Utils.stringsEq(thisDec.typ, (String)com.pullenti.unisharp.Utils.cast(at.tag, String.class))) 
                            at = null;
                        else 
                            thisDec = null;
                    }
                    break;
                }
            }
            if (bt != null && at != null) {
                if (coefBefore < coefAfter) 
                    at = null;
                else if ((bt instanceof com.pullenti.ner.ReferentToken) && (at instanceof com.pullenti.ner.TextToken)) 
                    at = null;
                else 
                    bt = null;
            }
            if (owner == null) {
                if (at != null) {
                    owner = _getDecree(at);
                    if (at instanceof com.pullenti.ner.TextToken) {
                        if (at.tag instanceof String) 
                            locTyp = (String)com.pullenti.unisharp.Utils.cast(at.tag, String.class);
                        else 
                            locTyp = ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(at, com.pullenti.ner.TextToken.class)).lemma;
                    }
                }
                else if (bt != null) {
                    owner = _getDecree(bt);
                    ownerPaer = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(bt.getReferent(), DecreePartReferent.class);
                    if (ownerPaer != null && locTyp == null) 
                        locTyp = ownerPaer.getLocalTyp();
                }
            }
            else if (coefAfter == 0 && at != null) {
                DecreeReferent owner1 = _getDecree(at);
                if (owner1 != null) 
                    owner = owner1;
            }
            else if (coefBefore == 0 && bt != null) {
                owner = _getDecree(bt);
                ownerPaer = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(bt.getReferent(), DecreePartReferent.class);
                if (ownerPaer != null && locTyp == null) 
                    locTyp = ownerPaer.getLocalTyp();
            }
            if (((bt != null && parts.size() == 1 && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.DOCPART) && (bt.getReferent() instanceof DecreePartReferent) && ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(bt.getReferent(), DecreePartReferent.class)).getClause() != null) && res.size() == 1 && owner == ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(bt.getReferent(), DecreePartReferent.class)).getOwner()) {
                for (com.pullenti.ner.Slot s : res.get(0).referent.getSlots()) {
                    if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), DecreePartReferent.ATTR_DOCPART)) 
                        s.setTypeName(DecreePartReferent.ATTR_PART);
                }
                ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent, DecreePartReferent.class)).addHighLevelInfo((DecreePartReferent)com.pullenti.unisharp.Utils.cast(bt.getReferent(), DecreePartReferent.class));
            }
        }
        if (owner == null) {
            if (thisDec == null && locTyp == null) {
                if ((parts.size() == 1 && parts.get(0).values.size() == 1 && parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX) && parts.get(0).getBeginToken().chars.isCapitalUpper()) {
                }
                else if ((parts.get(0).getBeginToken().getPrevious() != null && parts.get(0).getBeginToken().getPrevious().isChar('(') && parts.get(parts.size() - 1).getEndToken().getNext() != null) && parts.get(parts.size() - 1).getEndToken().getNext().isChar(')')) {
                    if (parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.PAGE) 
                        return null;
                }
                else if (inChanges) {
                }
                else if (parts.size() > 1 && ((parts.get(0).values.size() > 0 || parts.get(1).values.size() > 0))) {
                }
                else if (((parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.CLAUSE || parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ITEM || parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.APPENDIX)) && parts.get(0).values.size() > 0) {
                    if (parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.ITEM && parts.get(0).getBeginToken().isValue("П", null)) {
                        if (!(parts.get(0).values.get(0).getBeginToken() instanceof com.pullenti.ner.NumberToken)) 
                            return null;
                        if (!parts.get(0).isWhitespaceBefore()) {
                            if (!parts.get(0).getBeginToken().getPrevious().isCharOf("(,")) 
                                return null;
                        }
                    }
                }
                else 
                    return null;
            }
            for (com.pullenti.ner.ReferentToken r : res) {
                DecreePartReferent dr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(r.referent, DecreePartReferent.class);
                if (thisDec != null) {
                    dr.setLocalTyp(thisDec.typ);
                    if (thisDec.getBeginChar() > r.getEndChar() && r == res.get(res.size() - 1)) 
                        r.setEndToken(thisDec.getEndToken());
                }
                else if (locTyp != null) {
                    if (com.pullenti.unisharp.Utils.stringsEq(locTyp, "СТАТЬЯ") && dr.getClause() != null) {
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(locTyp, "ГЛАВА") && dr.getChapter() != null) {
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(locTyp, "ПАРАГРАФ") && dr.getParagraph() != null) {
                    }
                    else if (com.pullenti.unisharp.Utils.stringsEq(locTyp, "ЧАСТЬ") && dr.getPart() != null) {
                    }
                    else {
                        dr.setLocalTyp(locTyp);
                        if (r == res.get(res.size() - 1) && !r.isNewlineAfter()) {
                            com.pullenti.ner.Token ttt1 = r.getEndToken().getNext();
                            if (ttt1 != null && ttt1.isComma()) 
                                ttt1 = ttt1.getNext();
                            com.pullenti.ner.Token at = _checkOtherTyp(ttt1, true);
                            if (at != null && com.pullenti.unisharp.Utils.stringsEq((String)com.pullenti.unisharp.Utils.cast(at.tag, String.class), locTyp)) 
                                r.setEndToken(at);
                        }
                    }
                }
            }
        }
        else 
            for (com.pullenti.ner.ReferentToken r : res) {
                DecreePartReferent dr = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(r.referent, DecreePartReferent.class);
                dr.setOwner(owner);
                if (thisDec != null && thisDec.real == owner) {
                    if (thisDec.getBeginChar() > r.getEndChar() && r == res.get(res.size() - 1)) 
                        r.setEndToken(thisDec.getEndToken());
                }
            }
        if (res.size() > 0) {
            com.pullenti.ner.ReferentToken rt = res.get(res.size() - 1);
            if (curTypToken != null && curTypToken.getEndChar() > rt.getEndChar()) 
                rt.setEndToken(curTypToken);
            tt = rt.getEndToken().getNext();
            if (owner != null && tt != null && tt.getReferent() == owner) {
                rt.setEndToken(tt);
                tt = tt.getNext();
            }
            if (tt != null && ((tt.isHiphen() || tt.isChar(':')))) 
                tt = tt.getNext();
            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt, (isProgram ? com.pullenti.ner.core.BracketParseAttr.CANBEMANYLINES : com.pullenti.ner.core.BracketParseAttr.NO), 100);
            if (br != null && ((tt.isNewlineBefore() || br.getOpenChar() == '('))) 
                br = null;
            if (br != null) {
                boolean ok = true;
                if (br.getOpenChar() == '(') {
                    if (parts.get(0).typ == com.pullenti.ner.decree.internal.PartToken.ItemType.SUBPROGRAM) 
                        ok = false;
                    else if (com.pullenti.ner.decree.internal.PartToken.tryAttach(tt.getNext(), null, false, false) != null) 
                        ok = false;
                    else 
                        for (com.pullenti.ner.Token ttt = tt.getNext(); ttt != null && (ttt.getEndChar() < br.getEndChar()); ttt = ttt.getNext()) {
                            if (ttt == tt.getNext() && tt.getNext().getMorph()._getClass().isAdverb()) 
                                ok = false;
                            if ((ttt.getReferent() instanceof DecreeReferent) || (ttt.getReferent() instanceof DecreePartReferent)) 
                                ok = false;
                            if (ttt.isValue("РЕДАКЦИЯ", null) && ttt == br.getEndToken().getPrevious()) 
                                ok = false;
                        }
                }
                if (br.getEndToken().getNext() != null) {
                    if (br.getEndToken().getNext().isValue("ЗАМЕНИТЬ", null) || br.getEndToken().getNext().isValue("ИСКЛЮЧИТЬ", null)) 
                        ok = false;
                }
                if (ok && (tt.getNext().getReferent() instanceof DecreeReferent)) 
                    ok = false;
                if (ok && (tt.getNext() instanceof com.pullenti.ner.ReferentToken) && tt.isChar('<')) 
                    ok = false;
                if (ok) {
                    String s = com.pullenti.ner.core.MiscHelper.getTextValueOfMetaToken(br, com.pullenti.ner.core.GetTextAttr.KEEPREGISTER);
                    if (s != null) {
                        if (br.getOpenChar() == '(') 
                            ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreePartReferent.class)).setDescription(s);
                        else 
                            ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreePartReferent.class)).addName(parts.get(parts.size() - 1), br);
                        rt.setEndToken(br.getEndToken());
                        if ((rt.getEndToken().getNext() instanceof com.pullenti.ner.ReferentToken) && rt.getEndToken().getNext().getReferent() == owner) 
                            rt.setEndToken(rt.getEndToken().getNext());
                    }
                }
            }
            else if ((isProgram && parts.get(0).values.size() > 0 && tt != null) && tt.isTableControlChar() && com.pullenti.ner.core.MiscHelper.canBeStartOfSentence(tt.getNext())) {
                for (com.pullenti.ner.Token tt1 = tt.getNext(); tt1 != null; tt1 = tt1.getNext()) {
                    if (tt1.isTableControlChar()) {
                        String s = com.pullenti.ner.core.MiscHelper.getTextValue(tt.getNext(), tt1.getPrevious(), com.pullenti.ner.core.GetTextAttr.KEEPREGISTER);
                        if (s != null) {
                            ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreePartReferent.class)).setDescription(s);
                            rt.setEndToken(tt1);
                        }
                        break;
                    }
                    else if (tt1.isNewlineBefore()) 
                        break;
                }
            }
            if (thisDec != null) {
                if (thisDec.getEndChar() > res.get(res.size() - 1).getEndChar()) {
                    if (com.pullenti.unisharp.Utils.stringsNe(thisDec.typ, "ТИПОВОЙ ДОГОВОР")) 
                        res.get(res.size() - 1).setEndToken(thisDec.getEndToken());
                }
            }
        }
        if (ownerPaer != null && thisDec == null) {
            for (int ii = 0; ii < res.size(); ii++) {
                ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(ii).referent, DecreePartReferent.class)).addHighLevelInfo((ii == 0 ? ownerPaer : (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(ii - 1).referent, DecreePartReferent.class)));
            }
        }
        if (res.size() == 1 && ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent, DecreePartReferent.class)).getDescription() == null) {
            if ((res.get(0).getBeginToken().getPrevious() != null && res.get(0).getBeginToken().getPrevious().isChar('(') && res.get(0).getEndToken().getNext() != null) && res.get(0).getEndToken().getNext().isChar(')')) {
                if (com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(res.get(0).getBeginToken().getPrevious().getPrevious(), false, null, false)) {
                    com.pullenti.ner.Token beg = null;
                    for (tt = res.get(0).getBeginToken().getPrevious().getPrevious().getPrevious(); tt != null; tt = tt.getPrevious()) {
                        if (tt.isNewlineAfter()) 
                            break;
                        if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, false, false)) {
                            com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(tt, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                            if (br != null && ((br.getEndChar() + 10) < res.get(0).getBeginChar())) 
                                break;
                            if (tt.getNext().chars.isLetter() && !tt.getNext().chars.isAllLower()) 
                                beg = tt;
                        }
                    }
                    if (beg != null) {
                        if (com.pullenti.ner.core.BracketHelper.isBracket(res.get(0).getBeginToken().getPrevious().getPrevious(), true) && parts.size() == 1) 
                            ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent, DecreePartReferent.class)).addName(parts.get(0), new com.pullenti.ner.MetaToken(beg, res.get(0).getBeginToken().getPrevious().getPrevious(), null));
                        else 
                            ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent, DecreePartReferent.class)).setDescription(com.pullenti.ner.core.MiscHelper.getTextValue(beg, res.get(0).getBeginToken().getPrevious().getPrevious(), com.pullenti.ner.core.GetTextAttr.KEEPREGISTER));
                        res.get(0).setBeginToken(beg);
                        res.get(0).setEndToken(res.get(0).getEndToken().getNext());
                    }
                }
            }
        }
        if (isProgram) {
            for (i = res.size() - 1; i >= 0; i--) {
                DecreePartReferent pa = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(i).referent, DecreePartReferent.class);
                if (pa.getSubprogram() == null) 
                    continue;
                if (pa.getOwner() == null || pa.getOwner().getKind() != DecreeKind.PROGRAM) 
                    res.remove(i);
            }
        }
        if (isAddAgree) {
            for (i = res.size() - 1; i >= 0; i--) {
                DecreePartReferent pa = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(i).referent, DecreePartReferent.class);
                if (pa.getAddagree() == null) 
                    continue;
                if (pa.getOwner() == null || pa.getOwner().getKind() != DecreeKind.CONTRACT) 
                    res.remove(i);
            }
        }
        if (!inChanges) {
            for (i = res.size() - 1; i >= 0; i--) {
                DecreePartReferent pa = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(i).referent, DecreePartReferent.class);
                if (pa.getNameAsItem() == null && pa.getFormula() == null) 
                    continue;
                if (pa.getSlots().size() == 2 && pa.getOwner() == null) 
                    res.remove(i);
            }
        }
        if (res.size() == 1 && parts.size() == 1 && parts.get(0).addNames != null) {
            res.get(0).setEndToken(parts.get(0).addNames.get(0).getBeginToken().getPrevious());
            for (com.pullenti.ner.MetaToken br : parts.get(0).addNames) {
                DecreePartReferent dp = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(0).referent.clone(), DecreePartReferent.class);
                dp.addName(parts.get(0), br);
                res.add(new com.pullenti.ner.ReferentToken(dp, br.getBeginToken(), br.getEndToken(), null));
            }
        }
        for (com.pullenti.ner.ReferentToken r : res) {
            DecreePartReferent p = (DecreePartReferent)com.pullenti.unisharp.Utils.cast(r.referent, DecreePartReferent.class);
            if (((p.getTableItem() != null || p.getTableSubItem() != null)) && p.getItem() != null && p.getTableRow() == null) {
                p.setTableRow(p.getItem());
                p.setItem(null);
            }
        }
        java.util.ArrayList<com.pullenti.ner.MetaToken> res1 = new java.util.ArrayList<com.pullenti.ner.MetaToken>();
        for (i = 0; i < res.size(); i++) {
            java.util.ArrayList<DecreePartReferent> li = new java.util.ArrayList<DecreePartReferent>();
            for (j = i; j < res.size(); j++) {
                if (res.get(j).getBeginToken() != res.get(i).getBeginToken()) 
                    break;
                else 
                    li.add((DecreePartReferent)com.pullenti.unisharp.Utils.cast(res.get(j).referent, DecreePartReferent.class));
            }
            com.pullenti.ner.Token et;
            if (j < res.size()) 
                et = res.get(j).getBeginToken().getPrevious();
            else 
                et = res.get(res.size() - 1).getEndToken();
            while (et != null && et.getBeginChar() > res.get(i).getBeginChar()) {
                if ((et.isChar(',') || et.getMorph()._getClass().isConjunction() || et.isHiphen()) || et.isValue("ПО", null)) 
                    et = et.getPrevious();
                else if (com.pullenti.ner.core.MiscHelper.checkNumberPrefix(et) != null) 
                    et = et.getPrevious();
                else 
                    break;
            }
            res1.add(com.pullenti.ner.MetaToken._new1464(res.get(i).getBeginToken(), (et != null && et.getBeginChar() >= res.get(i).getBeginChar() ? et : res.get(i).getBeginToken()), li, res.get(i).getMorph()));
            i = j - 1;
        }
        return res1;
    }

    public static class ThisDecree extends com.pullenti.ner.MetaToken {
    
        public ThisDecree(com.pullenti.ner.Token b, com.pullenti.ner.Token e) {
            super(b, e, null);
        }
    
        public String typ;
    
        public boolean hasThisRef;
    
        public boolean hasOtherRef;
    
        public com.pullenti.ner.decree.DecreeReferent real;
    
        @Override
        public String toString() {
            return (((typ != null ? typ : "?")) + " (" + (hasThisRef ? "This" : (hasOtherRef ? "Other" : "?")) + ")");
        }
    
        public boolean checkDecree(com.pullenti.ner.decree.DecreeReferent r) throws Exception {
            if (r == null) 
                return false;
            if (real == r) 
                return true;
            if (typ != null) {
                if (com.pullenti.unisharp.Utils.stringsEq(r.getTyp(), typ) || com.pullenti.unisharp.Utils.stringsEq(r.getTyp0(), typ)) 
                    return true;
                if (r.getKind() == com.pullenti.ner.decree.DecreeKind.KODEX && com.pullenti.unisharp.Utils.stringsEq(typ, "КОДЕКС")) 
                    return true;
                for (com.pullenti.ner.Slot s : r.getSlots()) {
                    if (com.pullenti.unisharp.Utils.stringsEq(s.getTypeName(), com.pullenti.ner.decree.DecreeReferent.ATTR_NAME)) {
                        String n = (String)com.pullenti.unisharp.Utils.cast(s.getValue(), String.class);
                        if (com.pullenti.unisharp.Utils.startsWithString(n, typ, true)) 
                            return true;
                        com.pullenti.ner.AnalysisResult arr = com.pullenti.ner.ProcessorService.getEmptyProcessor().process(new com.pullenti.ner.SourceOfAnalysis(n), null, null);
                        if (arr != null && arr.firstToken != null) {
                            if (arr.firstToken.isValue(typ, null)) 
                                return true;
                            if (arr.firstToken.getNext() != null) {
                                if (arr.firstToken.getNext().isValue(typ, null)) 
                                    return true;
                            }
                        }
                    }
                }
            }
            return false;
        }
    
        public static ThisDecree tryAttachBack(com.pullenti.ner.Token t, com.pullenti.ner.decree.internal.DecreeToken baseTyp) {
            if (t == null) 
                return null;
            com.pullenti.ner.Token ukaz = null;
            for (com.pullenti.ner.Token tt = t; tt != null; tt = tt.getPrevious()) {
                if (tt.isCharOf(",") || tt.getMorph()._getClass().isPreposition() || tt.getMorph()._getClass().isConjunction()) 
                    continue;
                if ((((((tt.isValue("ОПРЕДЕЛЕННЫЙ", "ПЕВНИЙ") || tt.isValue("ЗАДАННЫЙ", "ЗАДАНИЙ") || tt.isValue("ПРЕДУСМОТРЕННЫЙ", "ПЕРЕДБАЧЕНИЙ")) || tt.isValue("УКАЗАННЫЙ", "ЗАЗНАЧЕНИЙ") || tt.isValue("ПЕРЕЧИСЛЕННЫЙ", "ПЕРЕРАХОВАНИЙ")) || tt.isValue("ОПРЕДЕЛИТЬ", "ВИЗНАЧИТИ") || tt.isValue("ОПРЕДЕЛЯТЬ", null)) || tt.isValue("ЗАДАВАТЬ", "ЗАДАВАТИ") || tt.isValue("ПРЕДУСМАТРИВАТЬ", "ПЕРЕДБАЧАТИ")) || tt.isValue("УКАЗЫВАТЬ", "ВКАЗУВАТИ") || tt.isValue("УКАЗАТЬ", "ВКАЗАТИ")) || tt.isValue("СИЛА", "ЧИННІСТЬ")) {
                    ukaz = tt;
                    continue;
                }
                if (tt == t) 
                    continue;
                com.pullenti.ner.Token ttt = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(tt, false);
                if (tt != ttt || !(tt instanceof com.pullenti.ner.TextToken)) 
                    break;
                if (ttt.isValue("УСЛОВИЕ", null) || ttt.isValue("ПОЛОЖЕНИЕ", null) || ttt.isValue("ОПРЕДЕЛЕНИЕ", null)) 
                    continue;
                if (com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, true) != null) 
                    break;
                if (ttt.isValue("ПОРЯДОК", null) && ukaz != null) 
                    return null;
                ThisDecree res = new ThisDecree(tt, tt);
                res.typ = ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).lemma;
                t = tt.getPrevious();
                if (t != null && ((t.getMorph()._getClass().isAdjective() || t.getMorph()._getClass().isPronoun()))) {
                    if (t.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ") || t.isValue("ТЕКУЩИЙ", "ПОТОЧНИЙ") || t.isValue("ДАННЫЙ", "ДАНИЙ")) {
                        res.hasThisRef = true;
                        res.setBeginToken(t);
                    }
                    else if ((t.isValue("ЭТОТ", "ЦЕЙ") || t.isValue("ВЫШЕУКАЗАННЫЙ", "ВИЩЕВКАЗАНИЙ") || t.isValue("УКАЗАННЫЙ", "ЗАЗНАЧЕНИЙ")) || t.isValue("НАЗВАННЫЙ", "НАЗВАНИЙ")) {
                        res.hasOtherRef = true;
                        res.setBeginToken(t);
                    }
                }
                if (!res.hasThisRef && tt.isNewlineAfter()) 
                    return null;
                if (baseTyp != null && com.pullenti.unisharp.Utils.stringsEq(baseTyp.value, res.typ)) 
                    res.hasThisRef = true;
                return res;
            }
            if (ukaz != null) {
                if (baseTyp != null && baseTyp.value != null && (((baseTyp.value.indexOf("ДОГОВОР") >= 0) || (baseTyp.value.indexOf("ДОГОВІР") >= 0)))) 
                    return _new1465(ukaz, ukaz, true, baseTyp.value);
            }
            return null;
        }
    
        public static ThisDecree tryAttach(com.pullenti.ner.decree.internal.PartToken dtok, com.pullenti.ner.decree.internal.DecreeToken baseTyp) {
            if (dtok.decree != null) 
                return _new1466(dtok.getEndToken(), dtok.getEndToken(), dtok.decree);
            com.pullenti.ner.Token t = dtok.getEndToken().getNext();
            if (t == null) 
                return null;
            if (t.isNewlineBefore()) {
                if (t.chars.isCyrillicLetter() && t.chars.isAllLower()) {
                }
                else 
                    return null;
            }
            com.pullenti.ner.Token t0 = t;
            if (t.isChar('.') && t.getNext() != null && !t.isNewlineAfter()) {
                if (dtok.isNewlineBefore()) 
                    return null;
                t = t.getNext();
            }
            if (t.isValue("К", null) && t.getNext() != null) {
                t = t.getNext();
                if (t.getReferent() instanceof com.pullenti.ner.decree.DecreeReferent) 
                    return _new1466(t, t, (com.pullenti.ner.decree.DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), com.pullenti.ner.decree.DecreeReferent.class));
            }
            if (t != null && (t.getReferent() instanceof com.pullenti.ner.decree.DecreeReferent)) 
                return null;
            if (t.isValue("НОВЫЙ", null)) 
                return null;
            com.pullenti.ner.Token tt = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t, false);
            boolean br = false;
            if (tt == null && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t, true, false)) {
                tt = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t.getNext(), false);
                if ((tt instanceof com.pullenti.ner.TextToken) && com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(tt.getNext(), false, null, false)) 
                    br = true;
                else 
                    tt = null;
            }
            if (!(tt instanceof com.pullenti.ner.TextToken)) {
                if ((tt instanceof com.pullenti.ner.ReferentToken) && (tt.getReferent() instanceof com.pullenti.ner.decree.DecreeReferent)) 
                    return _new1466(t, tt, (com.pullenti.ner.decree.DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getReferent(), com.pullenti.ner.decree.DecreeReferent.class));
                return null;
            }
            if (tt.chars.isAllLower()) {
                if (com.pullenti.ner.decree.internal.DecreeToken.isKeyword(tt, true) != null) {
                    if (tt != t && t.chars.isCapitalUpper()) {
                    }
                    else 
                        return null;
                }
            }
            if (!(t instanceof com.pullenti.ner.TextToken)) 
                return null;
            ThisDecree res = new ThisDecree(t0, (br ? tt.getNext() : tt));
            res.typ = ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.TextToken.class)).lemma;
            if (tt.getPrevious() instanceof com.pullenti.ner.TextToken) {
                com.pullenti.ner.Token tt1 = tt.getPrevious();
                com.pullenti.morph.MorphClass mc = tt1.getMorphClassInDictionary();
                if (mc.isAdjective() && !mc.isVerb() && !tt1.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ")) {
                    com.pullenti.ner.core.NounPhraseToken nnn = com.pullenti.ner.core.NounPhraseHelper.tryParse(tt1, com.pullenti.ner.core.NounPhraseParseAttr.NO, 0, null);
                    if (nnn != null) 
                        res.typ = nnn.getNormalCaseText(null, com.pullenti.morph.MorphNumber.UNDEFINED, com.pullenti.morph.MorphGender.UNDEFINED, false);
                    if (tt1.getPrevious() instanceof com.pullenti.ner.TextToken) {
                        tt1 = tt1.getPrevious();
                        mc = tt1.getMorphClassInDictionary();
                        if (mc.isAdjective() && !mc.isVerb() && !tt1.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ")) {
                            nnn = com.pullenti.ner.core.NounPhraseHelper.tryParse(tt1, com.pullenti.ner.core.NounPhraseParseAttr.NO, 0, null);
                            if (nnn != null) 
                                res.typ = nnn.getNormalCaseText(null, com.pullenti.morph.MorphNumber.UNDEFINED, com.pullenti.morph.MorphGender.UNDEFINED, false);
                        }
                    }
                }
            }
            if (tt.isChar('.') && (tt.getPrevious() instanceof com.pullenti.ner.TextToken)) 
                res.typ = ((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(tt.getPrevious(), com.pullenti.ner.TextToken.class)).lemma;
            if (t.getMorph()._getClass().isAdjective() || t.getMorph()._getClass().isPronoun()) {
                if (t.isValue("НАСТОЯЩИЙ", "СПРАВЖНІЙ") || t.isValue("ТЕКУЩИЙ", "ПОТОЧНИЙ") || t.isValue("ДАННЫЙ", "ДАНИЙ")) 
                    res.hasThisRef = true;
                else if ((t.isValue("ЭТОТ", "ЦЕЙ") || t.isValue("ВЫШЕУКАЗАННЫЙ", "ВИЩЕВКАЗАНИЙ") || t.isValue("УКАЗАННЫЙ", "ЗАЗНАЧЕНИЙ")) || t.isValue("НАЗВАННЫЙ", "НАЗВАНИЙ")) 
                    res.hasOtherRef = true;
            }
            if (!tt.isNewlineAfter() && !res.hasThisRef) {
                com.pullenti.ner.decree.internal.DecreeToken dt = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(tt.getNext(), null, false);
                if (dt != null && dt.typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.MISC) {
                    if (dt.typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME && dt.typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG && dt.typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.TERR) 
                        return null;
                }
            }
            if (baseTyp != null && com.pullenti.unisharp.Utils.stringsEq(baseTyp.value, res.typ)) 
                res.hasThisRef = true;
            return res;
        }
    
        public static ThisDecree _new1465(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, boolean _arg3, String _arg4) {
            ThisDecree res = new ThisDecree(_arg1, _arg2);
            res.hasThisRef = _arg3;
            res.typ = _arg4;
            return res;
        }
    
        public static ThisDecree _new1466(com.pullenti.ner.Token _arg1, com.pullenti.ner.Token _arg2, com.pullenti.ner.decree.DecreeReferent _arg3) {
            ThisDecree res = new ThisDecree(_arg1, _arg2);
            res.real = _arg3;
            return res;
        }
        public ThisDecree() {
            super();
        }
    }


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

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


    @Override
    public String getCaption() {
        return "Законы и указы";
    }


    @Override
    public String getDescription() {
        return "Законы, указы, постановления, распоряжения и т.п.";
    }


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

    @Override
    public java.util.Collection<com.pullenti.ner.metadata.ReferentClass> getTypeSystem() {
        return java.util.Arrays.asList(new com.pullenti.ner.metadata.ReferentClass[] {com.pullenti.ner.decree.internal.MetaDecree.GLOBALMETA, com.pullenti.ner.decree.internal.MetaDecreePart.GLOBALMETA, com.pullenti.ner.decree.internal.MetaDecreeChange.GLOBALMETA, com.pullenti.ner.decree.internal.MetaDecreeChangeValue.GLOBALMETA});
    }


    @Override
    public java.util.HashMap<String, byte[]> getImages() {
        java.util.HashMap<String, byte[]> res = new java.util.HashMap<String, byte[]>();
        res.put(com.pullenti.ner.decree.internal.MetaDecree.DECREEIMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("decree.png"));
        res.put(com.pullenti.ner.decree.internal.MetaDecree.STANDADRIMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("decreestd.png"));
        res.put(com.pullenti.ner.decree.internal.MetaDecreePart.PARTIMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("part.png"));
        res.put(com.pullenti.ner.decree.internal.MetaDecreePart.PARTLOCIMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("document_into.png"));
        res.put(com.pullenti.ner.decree.internal.MetaDecree.PUBLISHIMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("publish.png"));
        res.put(com.pullenti.ner.decree.internal.MetaDecreeChange.IMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("decreechange.png"));
        res.put(com.pullenti.ner.decree.internal.MetaDecreeChangeValue.IMAGEID, com.pullenti.ner.core.internal.ResourceHelper.getBytes("decreechangevalue.png"));
        return res;
    }


    @Override
    public Iterable<String> getUsedExternObjectTypes() {
        return java.util.Arrays.asList(new String[] {com.pullenti.ner.date.DateReferent.OBJ_TYPENAME, com.pullenti.ner.geo.GeoReferent.OBJ_TYPENAME, com.pullenti.ner._org.OrganizationReferent.OBJ_TYPENAME, com.pullenti.ner.person.PersonReferent.OBJ_TYPENAME});
    }


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

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


    public static com.pullenti.ner.core.AnalyzerData getData(com.pullenti.ner.Token t) {
        if (t == null) 
            return null;
        return t.kit.getAnalyzerDataByAnalyzerName(ANALYZER_NAME);
    }

    @Override
    public void process(com.pullenti.ner.core.AnalysisKit kit) {
        try {
            com.pullenti.ner.core.AnalyzerData ad = kit.getAnalyzerData(this);
            com.pullenti.ner.decree.internal.DecreeToken baseTyp = null;
            com.pullenti.ner.Referent ref0 = null;
            for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
                com.pullenti.ner.Referent r = t.getReferent();
                if (r == null) 
                    continue;
                if (!(r instanceof com.pullenti.ner._org.OrganizationReferent)) 
                    continue;
                com.pullenti.ner.ReferentToken rt = (com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.ReferentToken.class);
                if (t != null && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(rt.getBeginToken(), true, false) && com.pullenti.ner.core.BracketHelper.canBeEndOfSequence(rt.getEndToken(), true, null, false)) {
                    t = kit.debedToken(rt);
                    com.pullenti.ner.ReferentToken rt1 = new com.pullenti.ner.ReferentToken(rt.referent, rt.getBeginToken().getNext(), rt.getEndToken().getPrevious(), null);
                    if (rt.referent.getOccurrence().size() == 0) 
                        rt1.referent = ad.registerReferent(rt.referent);
                    kit.embedToken(rt1);
                    t = rt1;
                    continue;
                }
                if (!rt.getBeginToken().chars.isAllUpper() || rt.getBeginToken().getLengthChar() > 4) 
                    continue;
                com.pullenti.ner.decree.internal.DecreeToken dtr = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(rt.getBeginToken(), null, false);
                if (dtr == null || dtr.typKind != DecreeKind.KODEX) 
                    continue;
                if (rt.getBeginToken() == rt.getEndToken()) {
                }
                else if (rt.getBeginToken().getNext() == rt.getEndToken() && (rt.getEndToken().getReferent() instanceof com.pullenti.ner.geo.GeoReferent)) {
                }
                else 
                    continue;
                int cou = 0;
                for (com.pullenti.ner.Token tt = t.getPrevious(); tt != null; tt = tt.getPrevious()) {
                    com.pullenti.ner.decree.internal.PartToken pt = com.pullenti.ner.decree.internal.PartToken.tryAttach(tt, null, false, false);
                    if (pt != null && pt.values.size() > 0) {
                        t = kit.debedToken(rt);
                        break;
                    }
                    if ((++cou) > 10) 
                        break;
                }
            }
            java.util.ArrayList<String> keywords = new java.util.ArrayList<String>(java.util.Arrays.asList(new String[] {"ИЗЛОЖИТЬ", "ВВЕСТИ", "ДОПОЛНИТЬ", "УДАЛИТЬ", "РЕДАКЦИИ"}));
            for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
                com.pullenti.ner.TextToken tt = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class);
                if (tt == null) 
                    continue;
                if (com.pullenti.unisharp.Utils.stringsEq(tt.term, "СТАТЮ") || com.pullenti.unisharp.Utils.stringsEq(tt.term, "СТАТИ") || com.pullenti.unisharp.Utils.stringsEq(tt.term, "СТАТЯ")) {
                    if (tt.getNext() instanceof com.pullenti.ner.NumberToken) {
                        tt.correctWord(tt.term.substring(0, 0 + 4) + "Ь" + tt.term.substring(tt.term.length() - 1));
                        continue;
                    }
                }
                if (com.pullenti.unisharp.Utils.stringsEq(tt.term, "СТАТЬЮ")) {
                    tt.getMorph().removeItems(com.pullenti.morph.MorphCase.ACCUSATIVE);
                    continue;
                }
                if (com.pullenti.unisharp.Utils.stringsEq(tt.term, "СРОКИ") && tt.getPrevious() != null && tt.getPrevious().isValue("ПОСЛЕ", null)) {
                    tt.correctWord("СТРОКИ");
                    continue;
                }
                if (tt.getLengthChar() < 6) 
                    continue;
                com.pullenti.morph.MorphClass mc = tt.getMorphClassInDictionary();
                if (!mc.isUndefined()) 
                    continue;
                if (tt.term.startsWith("РЕД") && t.getPrevious() != null && t.getPrevious().isValue("СЛЕДУЮЩИЙ", null)) {
                    tt.correctWord("РЕДАКЦИИ");
                    continue;
                }
                java.util.ArrayList<String> vars = com.pullenti.morph.MorphologyService.correctWordEx(tt.term, null);
                if (vars == null || vars.size() == 0) 
                    continue;
                for (String v : vars) {
                    if (keywords.contains(v)) {
                        tt.correctWord(v);
                        break;
                    }
                }
            }
            com.pullenti.ner.NumberToken prevClause = null;
            for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
                t.tag = null;
                com.pullenti.ner.TextToken tt = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class);
                if (tt == null) 
                    continue;
                if (com.pullenti.unisharp.Utils.stringsEq(tt.term, "СТАТЬЯ") && !tt.chars.isAllLower() && (tt.getNext() instanceof com.pullenti.ner.NumberToken)) {
                }
                else 
                    continue;
                com.pullenti.ner.NumberToken num = (com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(tt.getNext(), com.pullenti.ner.NumberToken.class);
                if (num.getIntValue() == null) 
                    continue;
                com.pullenti.ner.Token t1 = tt.getNext();
                if (t1.getNext() != null && t1.getNext().isChar('.')) 
                    t1 = t1.getNext();
                if (tt.isNewlineBefore() || ((tt.getPrevious() != null && tt.getPrevious().isTableControlChar()))) {
                    if (t1.isNewlineAfter() || ((t1.getNext() != null && t1.getNext().isTableControlChar()))) {
                        if (prevClause == null) 
                            prevClause = num;
                        else if ((prevClause.getIntValue() + 1) == num.getIntValue()) {
                            tt.tag = prevClause;
                            prevClause = num;
                        }
                        else 
                            prevClause = null;
                    }
                }
            }
            int lastDecDist = 0;
            int ignoreMaxPos = 0;
            for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext(),lastDecDist++) {
                if (t.isNewlineBefore() && (t instanceof com.pullenti.ner.NumberToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.NumberToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.NumberToken.class)).getValue(), "88")) {
                }
                if (t.isIgnored()) 
                    continue;
                if (t.isValue2("СЛЕДУЮЩЕГО", "СОДЕРЖАНИЯ") || t.isValue2("СЛЕДУЮЩЕЙ", "РЕДАКЦИИ") || ((t.isValue2("НОВОЙ", "РЕДАКЦИИ") && t.getNext().getNext() != null && t.getNext().getNext().isChar(':')))) {
                    com.pullenti.ner.Token tt = t.getNext().getNext();
                    if (tt != null && tt.isChar(':')) 
                        tt = tt.getNext();
                    if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, true, false)) {
                        com.pullenti.ner.decree.internal.DecreeChangeToken txt = com.pullenti.ner.decree.internal.DecreeChangeToken._tryParseText(tt, false, false, null);
                        if (txt != null) {
                            t = txt.getEndToken();
                            continue;
                        }
                    }
                }
                if (t.isValue("СЛОВО", null) && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t.getNext(), true, false)) {
                    com.pullenti.ner.decree.internal.DecreeChangeToken txt = com.pullenti.ner.decree.internal.DecreeChangeToken._tryParseText(t.getNext(), false, false, null);
                    if (txt != null) {
                        if (txt.getLengthChar() > 500) {
                        }
                        else 
                            ignoreMaxPos = txt.getEndChar();
                    }
                }
                if (t.isValue("УТВЕРЖДЕННЫЙ", null)) {
                }
                java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(t, null, 10, lastDecDist > 1000);
                if (dts == null || dts.size() == 0) 
                    continue;
                if (dts.get(0).isNewlineAfter() && dts.get(0).isNewlineBefore()) {
                    boolean ignore = false;
                    if (t == kit.firstToken) 
                        ignore = true;
                    else if ((dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG && dts.size() > 1 && dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) && dts.get(1).isWhitespaceAfter()) 
                        ignore = true;
                    if (ignore) {
                        t = dts.get(dts.size() - 1).getEndToken();
                        continue;
                    }
                }
                if (dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && com.pullenti.ner.decree.internal.DecreeToken.getKind(dts.get(0).value, null) == DecreeKind.PUBLISHER) {
                    java.util.ArrayList<com.pullenti.ner.ReferentToken> rts = this.tryAttachPulishers(dts);
                    if (rts != null) {
                        for (int i = 0; i < rts.size(); i++) {
                            com.pullenti.ner.ReferentToken rtt = rts.get(i);
                            if (rtt.referent instanceof DecreePartReferent) 
                                ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(rtt.referent, DecreePartReferent.class)).setOwner((DecreeReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(((DecreePartReferent)com.pullenti.unisharp.Utils.cast(rtt.referent, DecreePartReferent.class)).getOwner()), DecreeReferent.class));
                            rtt.referent = ad.registerReferent(rtt.referent);
                            if (rtt.getBeginChar() < ignoreMaxPos) 
                                rtt.tag = "ignored";
                            kit.embedToken(rtt);
                            t = rtt;
                            if ((rtt.referent instanceof DecreeReferent) && ((i + 1) < rts.size()) && (rts.get(i + 1).referent instanceof DecreePartReferent)) 
                                rts.get(i + 1).setBeginToken(t);
                            lastDecDist = 0;
                        }
                        com.pullenti.ner.Token tt1 = t.getNext();
                        if (tt1 != null && tt1.isChar(')')) 
                            tt1 = tt1.getNext();
                    }
                    continue;
                }
                if (baseTyp == null) {
                    for (com.pullenti.ner.decree.internal.DecreeToken dd : dts) {
                        if (dd.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                            baseTyp = dd;
                            break;
                        }
                    }
                }
                if ((dts.size() == 1 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP && com.pullenti.unisharp.Utils.stringsNe(dts.get(0).value, "КОНСТИТУЦИЯ")) && !dts.get(0).typRefBack) 
                    continue;
                if (com.pullenti.unisharp.Utils.stringsEq(dts.get(0).value, "РЕГЛАМЕНТ")) {
                    if (dts.size() < 3) 
                        continue;
                    if (dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
                        continue;
                }
                java.util.ArrayList<com.pullenti.ner.ReferentToken> rtli = tryAttach(dts, baseTyp, ad);
                boolean multi = false;
                if ((rtli == null && dts.size() == 2 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) && ((dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.ORG || dts.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.OWNER))) {
                    for (com.pullenti.ner.Token tt2 = dts.get(1).getEndToken().getNext(); tt2 != null; tt2 = tt2.getNext()) {
                        if (tt2.isCharOf(";:-")) 
                            continue;
                        if (tt2.isNewlineBefore()) {
                            com.pullenti.ner.core.ComplexNumToken cn = com.pullenti.ner.core.ComplexNumToken.tryParse(tt2, null, false, false);
                            if (cn != null) 
                                tt2 = cn.getEndToken().getNext();
                            if (tt2 == null) 
                                break;
                        }
                        java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts2 = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(tt2, null, 4, false);
                        if (dts2 == null || dts2.size() != 3) 
                            break;
                        if (dts2.get(2).typ != com.pullenti.ner.decree.internal.DecreeToken.ItemType.NAME) 
                            break;
                        if (dts2.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && dts2.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                        }
                        else if (dts2.get(1).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.NUMBER && dts2.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) {
                        }
                        else 
                            break;
                        java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> ddd = new java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken>();
                        com.pullenti.unisharp.Utils.addToArrayList(ddd, dts);
                        com.pullenti.unisharp.Utils.addToArrayList(ddd, dts2);
                        java.util.ArrayList<com.pullenti.ner.ReferentToken> rtli2 = tryAttach(ddd, baseTyp, ad);
                        if (rtli2 == null || rtli2.size() != 1) 
                            break;
                        rtli2.get(0).setBeginToken(tt2);
                        if (rtli == null) 
                            rtli = new java.util.ArrayList<com.pullenti.ner.ReferentToken>();
                        rtli.add(rtli2.get(0));
                        tt2 = rtli2.get(0).getEndToken();
                        multi = true;
                    }
                }
                if (rtli != null) {
                    for (int ii = 0; ii < rtli.size(); ii++) {
                        com.pullenti.ner.ReferentToken rt = rtli.get(ii);
                        lastDecDist = 0;
                        com.pullenti.ner.Referent dec0 = rt.referent;
                        rt.referent = ad.registerReferent(rt.referent);
                        if (!multi) {
                            for (int jj = ii + 1; jj < rtli.size(); jj++) {
                                for (com.pullenti.ner.Slot s : rtli.get(jj).referent.getSlots()) {
                                    if (s.getValue() == dec0) 
                                        s.setValue(rt.referent);
                                }
                            }
                        }
                        ref0 = rt.referent;
                        kit.embedToken(rt);
                        t = rt;
                        if (rt.getBeginChar() < ignoreMaxPos) 
                            rt.tag = "ignored";
                        if ((ii + 1) < rtli.size()) {
                            if (rt.getEndToken().getNext() == rtli.get(ii + 1).getBeginToken()) 
                                rtli.get(ii + 1).setBeginToken(rt);
                        }
                    }
                }
                else if (dts.size() == 1 && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                    if (dts.get(0).chars.isCapitalUpper() && !dts.get(0).isDoubtful) {
                        lastDecDist = 0;
                        if (baseTyp != null && dts.get(0).ref != null) {
                            DecreeReferent drr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(dts.get(0).ref.getReferent(), DecreeReferent.class);
                            if (drr != null) {
                                if (com.pullenti.unisharp.Utils.stringsEq(baseTyp.value, drr.getTyp0()) || com.pullenti.unisharp.Utils.stringsEq(baseTyp.value, drr.getTyp())) 
                                    continue;
                            }
                        }
                        com.pullenti.ner.ReferentToken rt0 = com.pullenti.ner.decree.internal.DecreeToken._findBackTyp(dts.get(0).getBeginToken().getPrevious(), dts.get(0).value);
                        if (rt0 != null) {
                            com.pullenti.ner.ReferentToken rt = new com.pullenti.ner.ReferentToken(rt0.referent, dts.get(0).getBeginToken(), dts.get(0).getEndToken(), null);
                            kit.embedToken(rt);
                            t = rt;
                            rt.tag = rt0.referent;
                        }
                    }
                }
            }
            if (ad.getReferents().size() > 0) {
                for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
                    if (t.isIgnored()) 
                        continue;
                    DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getReferent(), DecreeReferent.class);
                    if (dr == null) 
                        continue;
                    java.util.ArrayList<DecreeReferent> li = null;
                    for (com.pullenti.ner.Token tt = t.getNext(); tt != null; tt = tt.getNext()) {
                        if (!tt.isCommaAnd()) 
                            break;
                        if (tt.getNext() == null || !(tt.getNext().getReferent() instanceof DecreeReferent)) 
                            break;
                        if (li == null) {
                            li = new java.util.ArrayList<DecreeReferent>();
                            li.add(dr);
                        }
                        dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tt.getNext().getReferent(), DecreeReferent.class);
                        li.add(dr);
                        dr.tag = null;
                        tt = tt.getNext();
                        if (dr.getDate() != null) {
                            java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(((com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(tt, com.pullenti.ner.ReferentToken.class)).getBeginToken(), null, 10, false);
                            if (dts != null) {
                                for (com.pullenti.ner.decree.internal.DecreeToken dt : dts) {
                                    if (dt.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.DATE) 
                                        dr.tag = dr;
                                }
                            }
                        }
                    }
                    if (li == null) 
                        continue;
                    int i;
                    for (i = li.size() - 1; i > 0; i--) {
                        if (com.pullenti.unisharp.Utils.stringsEq(li.get(i).getTyp(), li.get(i - 1).getTyp())) {
                            if (li.get(i).getDate() != null && li.get(i).tag != null && li.get(i - 1).getDate() == null) 
                                li.get(i - 1).addSlot(DecreeReferent.ATTR_DATE, li.get(i).getSlotValue(DecreeReferent.ATTR_DATE), false, 0);
                        }
                    }
                    for (i = 0; i < (li.size() - 1); i++) {
                        if (com.pullenti.unisharp.Utils.stringsEq(li.get(i).getTyp(), li.get(i + 1).getTyp())) {
                            com.pullenti.ner.Slot sl = li.get(i).findSlot(DecreeReferent.ATTR_SOURCE, null, true);
                            if (sl != null && li.get(i + 1).findSlot(DecreeReferent.ATTR_SOURCE, null, true) == null) 
                                li.get(i + 1).addSlot(sl.getTypeName(), sl.getValue(), false, 0);
                        }
                    }
                    for (i = 0; i < li.size(); i++) {
                        if (li.get(i).getName() != null) 
                            break;
                    }
                    if (i == (li.size() - 1)) {
                        for (i = li.size() - 1; i > 0; i--) {
                            if (com.pullenti.unisharp.Utils.stringsEq(li.get(i - 1).getTyp(), li.get(i).getTyp())) 
                                li.get(i - 1).addName(li.get(i));
                        }
                    }
                }
            }
            com.pullenti.ner.core.TerminCollection aliases = new com.pullenti.ner.core.TerminCollection();
            com.pullenti.ner.core.TerminCollection attachednames = new com.pullenti.ner.core.TerminCollection();
            for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext(),lastDecDist++) {
                if (t.isIgnored()) 
                    continue;
                if (t.isValue2("СЛЕДУЮЩЕГО", "СОДЕРЖАНИЯ") || t.isValue2("СЛЕДУЮЩЕЙ", "РЕДАКЦИИ") || ((t.isValue2("НОВОЙ", "РЕДАКЦИИ") && t.getNext().getNext() != null && t.getNext().getNext().isChar(':')))) {
                    com.pullenti.ner.Token tt = t.getNext().getNext();
                    if (tt != null && tt.isChar(':')) 
                        tt = tt.getNext();
                    if (com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(tt, true, false)) {
                        com.pullenti.ner.decree.internal.DecreeChangeToken txt = com.pullenti.ner.decree.internal.DecreeChangeToken._tryParseText(tt, false, false, null);
                        if (txt != null) {
                            t = txt.getEndToken();
                            continue;
                        }
                    }
                }
                if (t.isValue("СЛОВО", null) && com.pullenti.ner.core.BracketHelper.canBeStartOfSequence(t.getNext(), true, false)) {
                    com.pullenti.ner.decree.internal.DecreeChangeToken txt = com.pullenti.ner.decree.internal.DecreeChangeToken._tryParseText(t.getNext(), false, false, null);
                    if (txt != null) {
                        if (txt.getLengthChar() > 500) {
                        }
                        else {
                            t = txt.getEndToken();
                            continue;
                        }
                    }
                }
                com.pullenti.ner.Token checkAliasToken = null;
                com.pullenti.ner.ReferentToken rt = tryAttachApproved(t, ad, aliases, attachednames, false);
                if (t.isValue("ВНЕСТИ", null)) {
                }
                if (rt != null) {
                    if (t.isNewlineBefore() && (t instanceof com.pullenti.ner.TextToken) && com.pullenti.unisharp.Utils.stringsEq(((com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.TextToken.class)).term, "ПРАВИЛА")) {
                    }
                    rt.referent = ad.registerReferent(rt.referent);
                    kit.embedToken(rt);
                    t = rt;
                    if (rt.tag instanceof com.pullenti.ner.MetaToken) {
                        com.pullenti.ner.core.Termin term = new com.pullenti.ner.core.Termin(null, null, false);
                        term.initBy(((com.pullenti.ner.MetaToken)com.pullenti.unisharp.Utils.cast(rt.tag, com.pullenti.ner.MetaToken.class)).getBeginToken(), ((com.pullenti.ner.MetaToken)com.pullenti.unisharp.Utils.cast(rt.tag, com.pullenti.ner.MetaToken.class)).getEndToken().getPrevious(), rt.referent, false);
                        aliases.add(term);
                    }
                    for (String nam : rt.referent.getStringValues(DecreeReferent.ATTR_NAME)) {
                        attachednames.add(com.pullenti.ner.core.Termin._new1469(nam, nam));
                    }
                }
                if (t.getReferent() instanceof DecreeReferent) {
                    rt = (com.pullenti.ner.ReferentToken)com.pullenti.unisharp.Utils.cast(t, com.pullenti.ner.ReferentToken.class);
                    if (((DecreeReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreeReferent.class)).getKind() == DecreeKind.PUBLISHER) 
                        continue;
                    if ((t.getNext() != null && t.getNext().isCharOf("(,") && (t.getNext().getNext() instanceof com.pullenti.ner.ReferentToken)) && (t.getNext().getNext().getReferent() instanceof DecreeReferent) && ((DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getNext().getNext().getReferent(), DecreeReferent.class)).getKind() == DecreeKind.PUBLISHER) {
                        checkAliasToken = t.getNext().getNext().getNext();
                        if (checkAliasToken != null && checkAliasToken.isChar(')')) 
                            checkAliasToken = checkAliasToken.getNext();
                    }
                }
                else if (t instanceof com.pullenti.ner.TextToken) {
                    com.pullenti.ner.core.TerminToken tok = aliases.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO);
                    if (tok != null) {
                        DecreeReferent dec0 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(tok.termin.tag, DecreeReferent.class);
                        com.pullenti.ner.ReferentToken rt0 = new com.pullenti.ner.ReferentToken((com.pullenti.ner.Referent)com.pullenti.unisharp.Utils.cast(tok.termin.tag, com.pullenti.ner.Referent.class), tok.getBeginToken(), tok.getEndToken(), null);
                        if (dec0 != null && (rt0.getEndToken().getNext() instanceof com.pullenti.ner.ReferentToken) && (rt0.getEndToken().getNext().getReferent() instanceof com.pullenti.ner.geo.GeoReferent)) {
                            com.pullenti.ner.geo.GeoReferent geo0 = (com.pullenti.ner.geo.GeoReferent)com.pullenti.unisharp.Utils.cast(dec0.getSlotValue(DecreeReferent.ATTR_GEO), com.pullenti.ner.geo.GeoReferent.class);
                            com.pullenti.ner.geo.GeoReferent geo1 = (com.pullenti.ner.geo.GeoReferent)com.pullenti.unisharp.Utils.cast(rt0.getEndToken().getNext().getReferent(), com.pullenti.ner.geo.GeoReferent.class);
                            if (geo0 == null) {
                                dec0.addSlot(DecreeReferent.ATTR_GEO, geo1, false, 0);
                                rt0.setEndToken(rt0.getEndToken().getNext());
                            }
                            else if (geo0 == geo1) 
                                rt0.setEndToken(rt0.getEndToken().getNext());
                            else 
                                continue;
                        }
                        if (rt0.isNewlineBefore() && rt0.isNewlineAfter()) 
                            continue;
                        kit.embedToken(rt0);
                        t = rt0;
                        rt0.miscAttrs = 1;
                        lastDecDist = 0;
                        continue;
                    }
                    java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dts = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(t, null, 2, false);
                    if (dts != null && dts.get(0).typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
                        java.util.ArrayList<com.pullenti.ner.ReferentToken> rtli = tryAttach(dts, null, ad);
                        if (rtli != null && rtli.size() == 1) {
                            rt = rtli.get(0);
                            rt.referent = ad.registerReferent(rt.referent);
                            kit.embedToken(rt);
                            t = rt;
                        }
                    }
                }
                if (rt != null) {
                    com.pullenti.ner.MetaToken mt = _checkAliasAfter((checkAliasToken != null ? checkAliasToken : t.getNext()));
                    if (mt != null) {
                        if (mt.tag instanceof DecreeReferent) {
                            DecreeReferent dr0 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(mt.tag, DecreeReferent.class);
                            DecreeReferent dr1 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreeReferent.class);
                            if (dr1 != dr0 && dr1.getOwner() != dr0) {
                                if (dr0.getNumber() != null) {
                                    if (dr1.getNumber() != null && ((com.pullenti.unisharp.Utils.stringsEq(dr1.getNumber(), dr0.getNumber()) || dr0.getNumber().startsWith(dr1.getNumber() + "/")))) {
                                    }
                                    else if (dr1.getOwner() != null && com.pullenti.unisharp.Utils.stringsEq(dr1.getOwner().getNumber(), dr0.getNumber())) {
                                    }
                                    else 
                                        continue;
                                }
                                kit.replaceReferent((DecreeReferent)com.pullenti.unisharp.Utils.cast(mt.tag, DecreeReferent.class), rt.referent);
                            }
                            if (checkAliasToken == null) {
                                rt = new com.pullenti.ner.ReferentToken(t.getReferent(), t, mt.getEndToken(), null);
                                kit.embedToken(rt);
                                t = rt;
                            }
                        }
                        else {
                            com.pullenti.ner.Token eTok = mt.getEndToken().getPrevious();
                            if ((mt.getBeginToken().getNext() != null && mt.getBeginToken().getNext().isCommaAnd() && mt.getBeginToken().getNext().getNext() == mt.getEndToken().getPrevious().getPrevious()) && mt.getEndToken().getPrevious().isValue("СООТВЕТСТВЕННО", null)) {
                                com.pullenti.ner.TextToken tt = (com.pullenti.ner.TextToken)com.pullenti.unisharp.Utils.cast(mt.getBeginToken().getNext().getNext(), com.pullenti.ner.TextToken.class);
                                String nam = (String)com.pullenti.unisharp.Utils.notnull(rt.referent.getStringValue("NAME"), "");
                                if (nam.startsWith("ОБ УТВЕРЖДЕНИИ ") && tt != null) {
                                    com.pullenti.ner.AnalysisResult ar0 = com.pullenti.ner.ProcessorService.getEmptyProcessor().process(new com.pullenti.ner.SourceOfAnalysis(nam), null, null);
                                    nam = com.pullenti.ner.core.MiscHelper.getTextValue(ar0.firstToken.getNext().getNext(), ar0.findTokenByPos(nam.length() - 1, null), com.pullenti.ner.core.GetTextAttr.FIRSTNOUNGROUPTONOMINATIVE);
                                    if (nam.startsWith(tt.term)) {
                                        DecreeReferent r1 = new DecreeReferent();
                                        r1.setOwner((DecreeReferent)com.pullenti.unisharp.Utils.cast(rt.referent, DecreeReferent.class));
                                        r1.addSlot(DecreeReferent.ATTR_NAME, nam, false, 0);
                                        r1 = (DecreeReferent)com.pullenti.unisharp.Utils.cast(ad.registerReferent(r1), DecreeReferent.class);
                                        com.pullenti.ner.ReferentToken rt1 = new com.pullenti.ner.ReferentToken(r1, tt, tt, null);
                                        kit.embedToken(rt1);
                                        com.pullenti.ner.core.Termin term1 = new com.pullenti.ner.core.Termin(null, null, false);
                                        term1.initBy(tt, tt, r1, false);
                                        aliases.add(term1);
                                        eTok = mt.getBeginToken().getNext();
                                    }
                                }
                            }
                            com.pullenti.ner.core.Termin term = new com.pullenti.ner.core.Termin(null, null, false);
                            term.initBy(mt.getBeginToken(), eTok, rt.referent, false);
                            aliases.add(term);
                            if (checkAliasToken == null) {
                                rt = new com.pullenti.ner.ReferentToken(t.getReferent(), t, mt.getEndToken(), null);
                                kit.embedToken(rt);
                                t = rt;
                            }
                        }
                    }
                    else {
                        com.pullenti.ner.core.TerminToken aa = aliases.tryParse(t, com.pullenti.ner.core.TerminParseAttr.NO);
                        if (aa != null) 
                            aa.termin.tag = rt.referent;
                    }
                }
            }
            this._processPartsAndChanges(kit, baseTyp);
            for (com.pullenti.ner.Token t = kit.firstToken; t != null; t = t.getNext()) {
                if (t.tag != null && (t instanceof com.pullenti.ner.ReferentToken) && (t.tag instanceof DecreeReferent)) {
                    t = kit.debedToken(t);
                    if (t == null) 
                        break;
                }
            }
        } catch (Exception ex123) {
        }
    }

    public static com.pullenti.ner.MetaToken _checkAliasAfter(com.pullenti.ner.Token t) {
        if ((t != null && t.isChar('<') && t.getNext() != null) && t.getNext().getNext() != null && t.getNext().getNext().isChar('>')) 
            t = t.getNext().getNext().getNext();
        if (t == null || t.getNext() == null || !t.isChar('(')) 
            return null;
        if (t.getNext().getReferent() != null) {
            DecreeReferent dr = (DecreeReferent)com.pullenti.unisharp.Utils.cast(t.getNext().getReferent(), DecreeReferent.class);
            if (dr == null && (t.getNext().getReferent() instanceof DecreePartReferent)) 
                dr = ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(t.getNext().getReferent(), DecreePartReferent.class)).getOwner();
            if (dr != null && dr.getKind() == DecreeKind.PUBLISHER) {
                com.pullenti.ner.core.BracketSequenceToken br = com.pullenti.ner.core.BracketHelper.tryParse(t, com.pullenti.ner.core.BracketParseAttr.NO, 100);
                if (br != null && br.getEndToken().getNext() != null && br.getEndToken().getNext().isChar('(')) {
                    t = br.getEndToken().getNext();
                    if (t.getNext() == null) 
                        return null;
                }
            }
        }
        t = t.getNext();
        if (t.isValue("ДАЛЕЕ", "ДАЛІ")) {
        }
        else 
            return null;
        t = t.getNext();
        if (t != null && !t.chars.isLetter()) 
            t = t.getNext();
        if (t == null) 
            return null;
        if ((t.getReferent() instanceof DecreeReferent) && t.getNext() != null && t.getNext().isChar(')')) 
            return com.pullenti.ner.MetaToken._new663(t, t.getNext(), t.getReferent());
        com.pullenti.ner.Token t1 = null;
        int lev = 0;
        for (com.pullenti.ner.Token tt = t; tt != null; tt = tt.getNext()) {
            if (tt.isNewlineBefore()) 
                break;
            else if (tt.isChar('(')) 
                lev++;
            else if (tt.isChar(')')) {
                lev--;
                if (lev < 0) {
                    t1 = tt.getPrevious();
                    break;
                }
            }
        }
        if (t1 == null) 
            return null;
        return new com.pullenti.ner.MetaToken(t, t1.getNext(), null);
    }

    public static DecreeReferent _getDecree(com.pullenti.ner.Token t) {
        if (!(t instanceof com.pullenti.ner.ReferentToken)) 
            return null;
        com.pullenti.ner.Referent r = t.getReferent();
        if (r instanceof DecreeReferent) 
            return (DecreeReferent)com.pullenti.unisharp.Utils.cast(r, DecreeReferent.class);
        if (r instanceof DecreePartReferent) 
            return ((DecreePartReferent)com.pullenti.unisharp.Utils.cast(r, DecreePartReferent.class)).getOwner();
        return null;
    }

    public static com.pullenti.ner.Token _checkOtherTyp(com.pullenti.ner.Token t, boolean first) {
        if (t == null) 
            return null;
        com.pullenti.ner.decree.internal.DecreeToken dit = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(t, null, false);
        com.pullenti.ner.core.NounPhraseToken npt = null;
        if (dit == null) {
            npt = com.pullenti.ner.core.NounPhraseHelper.tryParse(t, com.pullenti.ner.core.NounPhraseParseAttr.NO, 0, null);
            if (npt != null && npt.getBeginToken() != npt.getEndToken()) 
                dit = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(npt.getEndToken(), null, false);
        }
        if (dit != null && dit.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) {
            if (dit.chars.isCapitalUpper() || first) {
                dit.getEndToken().tag = dit.value;
                return dit.getEndToken();
            }
            else 
                return null;
        }
        if (npt != null) 
            t = npt.getEndToken();
        if (t.chars.isCapitalUpper() || first) {
            if (t.getPrevious() != null && t.getPrevious().isChar('.') && !first) 
                return null;
            com.pullenti.ner.Token tt = com.pullenti.ner.decree.internal.DecreeToken.isKeyword(t, false);
            if (tt != null) 
                return tt;
        }
        return null;
    }

    @Override
    public com.pullenti.ner.ReferentToken processReferent(com.pullenti.ner.Token begin, String param) {
        com.pullenti.ner.ReferentToken rt = tryAttachApproved(begin, null, null, null, false);
        if (rt != null) 
            return rt;
        java.util.ArrayList<com.pullenti.ner.decree.internal.DecreeToken> dpli = com.pullenti.ner.decree.internal.DecreeToken.tryAttachList(begin, null, 10, true);
        if (dpli != null) {
            java.util.ArrayList<com.pullenti.ner.ReferentToken> lii = tryAttach(dpli, null, null);
            if (lii != null && lii.size() > 0) 
                return lii.get(0);
        }
        com.pullenti.ner.decree.internal.DecreeToken dp = com.pullenti.ner.decree.internal.DecreeToken.tryAttach(begin, null, false);
        if (dp != null && dp.typ == com.pullenti.ner.decree.internal.DecreeToken.ItemType.TYP) 
            return new com.pullenti.ner.ReferentToken(null, dp.getBeginToken(), dp.getEndToken(), null);
        return null;
    }

    private static boolean m_Inited;

    public static void initialize() throws Exception {
        if (m_Inited) 
            return;
        m_Inited = true;
        com.pullenti.ner.decree.internal.MetaDecree.initialize();
        com.pullenti.ner.decree.internal.MetaDecreePart.initialize();
        com.pullenti.ner.decree.internal.MetaDecreeChange.initialize();
        com.pullenti.ner.decree.internal.MetaDecreeChangeValue.initialize();
        try {
            com.pullenti.ner.core.Termin.ASSIGNALLTEXTSASNORMAL = false;
            com.pullenti.ner.decree.internal.DecreeChangeToken.initialize();
            com.pullenti.ner.decree.internal.DecreeToken.initialize();
            com.pullenti.ner.core.Termin.ASSIGNALLTEXTSASNORMAL = false;
        } catch (Exception ex) {
            throw new Exception(ex.getMessage(), ex);
        }
        com.pullenti.ner.ProcessorService.registerAnalyzer(new DecreeAnalyzer());
    }
    public DecreeAnalyzer() {
        super();
    }
    public static DecreeAnalyzer _globalInstance;
    
    static {
        try { _globalInstance = new DecreeAnalyzer(); } 
        catch(Exception e) { }
    }
}
