static FragToken _getLastChild(FragToken fr) { if (fr.Children.Count == 0) { return(fr); } return(_getLastChild(fr.Children[fr.Children.Count - 1])); }
static int _calcNewlineBetweenCoef(FragToken fr1, FragToken fr2) { if (fr1.NewlinesAfterCount > 1) { return(1); } for (Pullenti.Ner.Token tt = fr1.BeginToken; tt != null && tt.EndChar <= fr1.EndChar; tt = tt.Next) { if (Pullenti.Ner.Core.BracketHelper.CanBeStartOfSequence(tt, false, false)) { Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(tt, Pullenti.Ner.Core.BracketParseAttr.CanBeManyLines, 100); if (br != null && br.EndChar >= fr2.BeginChar) { return(-1); } } } Pullenti.Ner.Token t = fr1.EndToken; if (t.IsCharOf(":;.")) { return(1); } if ((t is Pullenti.Ner.TextToken) && ((t.Morph.Class.IsPreposition || t.Morph.Class.IsConjunction))) { return(-1); } Pullenti.Ner.Token t1 = fr2.BeginToken; if (t1 is Pullenti.Ner.TextToken) { if (t1.Chars.IsAllLower) { return(-1); } if (Pullenti.Ner.Core.BracketHelper.CanBeStartOfSequence(t1, false, false)) { if (t.Chars.IsAllLower) { return(-1); } } } else if (t1 is Pullenti.Ner.NumberToken) { if (t.Chars.IsAllLower) { return(-1); } } if (t.Chars.IsAllLower) { if (fr2.EndToken.IsChar(';')) { return(-1); } } return(0); }
public static void CreateNumber(FragToken owner, InstrToken1 itok) { if (itok.NumBeginToken == null || itok.NumEndToken == null) { return; } FragToken num = new FragToken(itok.NumBeginToken, itok.NumEndToken) { Kind = Pullenti.Ner.Instrument.InstrumentKind.Number, DefVal = true, Itok = itok }; owner.Children.Add(num); if (itok.NumTyp == NumberTypes.TwoDigits) { owner.Number = itok.FirstNumber; owner.SubNumber = itok.LastNumber; } else if (itok.NumTyp == NumberTypes.ThreeDigits) { owner.Number = itok.FirstNumber; owner.SubNumber = itok.MiddleNumber; owner.SubNumber2 = itok.LastNumber; } else if (itok.NumTyp == NumberTypes.FourDigits && itok.Numbers.Count == 4) { owner.Number = itok.FirstNumber; owner.SubNumber = Pullenti.Ner.Decree.Internal.PartToken.GetNumber(itok.Numbers[1]); owner.SubNumber2 = Pullenti.Ner.Decree.Internal.PartToken.GetNumber(itok.Numbers[2]); owner.SubNumber3 = itok.LastNumber; } else { owner.Number = itok.LastNumber; } owner.MinNumber = itok.LastMinNumber; owner.Itok = itok; }
static int _canBeEditionFor(FragToken fr, FragToken edt) { if (edt == null || edt.Kind != Pullenti.Ner.Instrument.InstrumentKind.Editions || edt.Referents == null) { return(-1); } if (fr.SubNumber3 == 67) { } Pullenti.Ner.Token t = edt.BeginToken; if (t.IsChar('(') && t.Next != null) { t = t.Next; } if (t.IsValue("АБЗАЦ", null)) { return(fr.Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention ? 1 : -1); } Pullenti.Ner.Decree.Internal.PartToken pt = Pullenti.Ner.Decree.Internal.PartToken.TryAttach(t, null, false, false); if (pt == null) { pt = Pullenti.Ner.Decree.Internal.PartToken.TryAttach(t, null, false, true); } if (pt == null) { return(0); } if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Clause) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Clause) { return(-1); } } else if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Part) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.ClausePart && fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.DocPart && fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Item) { return(-1); } } else if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Item) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.ClausePart && fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Item && fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Subitem) { return(-1); } } else if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.SubItem) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Subitem) { if (fr.Kind == Pullenti.Ner.Instrument.InstrumentKind.Item && t.IsValue("ПП", null)) { } else { return(-1); } } } else if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Chapter) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Chapter) { return(-1); } } else if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Paragraph) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Paragraph) { return(-1); } } else if (pt.Typ == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Subparagraph) { if (fr.Kind != Pullenti.Ner.Instrument.InstrumentKind.Subparagraph) { return(-1); } } if (pt.Values.Count == 0) { return(0); } if (fr.Number == 0) { return(-1); } if (fr.NumberString == pt.Values[0].Value) { return(1); } if (pt.Values[0].Value.EndsWith("." + fr.NumberString)) { return(0); } if (fr.Number == Pullenti.Ner.Decree.Internal.PartToken.GetNumber(pt.Values[0].Value)) { if (fr.SubNumber == 0) { return(1); } } return(-1); }
public static void AnalizeEditions(FragToken root) { if (root.Number == 6 && root.Kind == Pullenti.Ner.Instrument.InstrumentKind.Subitem) { } if (root.SubNumber == 67) { } if (root.Children.Count > 1 && root.Children[0].Kind == Pullenti.Ner.Instrument.InstrumentKind.Number && root.Children[1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Content) { if (root.Children[1].BeginToken.IsValue("УТРАТИТЬ", "ВТРАТИТИ") && root.Children[1].BeginToken.Next != null && root.Children[1].BeginToken.Next.IsValue("СИЛА", "ЧИННІСТЬ")) { root.IsExpired = true; } } if ((!root.IsExpired && root.Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention && root.BeginToken.IsValue("АБЗАЦ", null)) && root.BeginToken.Next != null && root.BeginToken.Next.IsValue("УТРАТИТЬ", "ВТРАТИТИ")) { root.IsExpired = true; } if (root.IsExpired || ((root.Itok != null && root.Itok.IsExpired))) { root.IsExpired = true; if (root.Referents == null) { root.Referents = new List <Pullenti.Ner.Referent>(); } for (Pullenti.Ner.Token tt = root.BeginToken; tt != null && tt.EndChar <= root.EndChar; tt = tt.Next) { Pullenti.Ner.Decree.DecreeReferent dec = tt.GetReferent() as Pullenti.Ner.Decree.DecreeReferent; if (dec != null) { if (!root.Referents.Contains(dec)) { root.Referents.Add(dec); } } } return; } int i0; for (i0 = 0; i0 < root.Children.Count; i0++) { FragToken ch = root.Children[i0]; if (((ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Comment || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Keyword || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Number) || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Name || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content) || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention) { } else { break; } } if (root.Number > 0) { FragToken edt1 = _getLastChild(root); if (edt1 != null && edt1.Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions && edt1.Tag == null) { if (_canBeEditionFor(root, edt1) > 0) { if (root.Referents == null) { root.Referents = edt1.Referents; } else { foreach (Pullenti.Ner.Referent r in edt1.Referents) { if (!root.Referents.Contains(r)) { root.Referents.Add(r); } } } edt1.Tag = edt1; } } } if (i0 >= root.Children.Count) { foreach (FragToken ch in root.Children) { AnalizeEditions(ch); } return; } FragToken ch0 = root.Children[i0]; bool ok = false; if (_canBeEditionFor(root, ch0) >= 0) { ok = true; if (i0 > 0 && ((root.Children[i0 - 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Content || root.Children[i0 - 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention)) && ((i0 + 1) < root.Children.Count)) { if (_canBeEditionFor(root.Children[i0 - 1], ch0) >= 0) { ok = false; } } } if (((i0 + 1) < root.Children.Count) && _canBeEditionFor(root, root.Children[root.Children.Count - 1]) >= 0 && (_canBeEditionFor(root.Children[root.Children.Count - 1], root.Children[root.Children.Count - 1]) < 0)) { ok = true; ch0 = root.Children[root.Children.Count - 1]; } if (ok && ch0.Tag == null) { if (root.Referents == null) { root.Referents = ch0.Referents; } else { foreach (Pullenti.Ner.Referent r in ch0.Referents) { if (!root.Referents.Contains(r)) { root.Referents.Add(r); } } } ch0.Tag = ch0; } for (int i = 0; i < root.Children.Count; i++) { FragToken ch = root.Children[i]; FragToken edt = null; FragToken edt2 = null; if (ch.Number > 0 && i > 0) { edt = _getLastChild(root.Children[i - 1]); } if (((i + 1) < root.Children.Count) && root.Children[i + 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions) { edt2 = root.Children[i + 1]; } if (edt != null) { if (_canBeEditionFor(ch, edt) < 1) { edt = null; } } if (edt2 != null) { if (_canBeEditionFor(ch, edt2) < 0) { edt2 = null; } } if (edt != null && edt.Tag == null) { if (ch.Referents == null) { ch.Referents = edt.Referents; } else { foreach (Pullenti.Ner.Referent r in edt.Referents) { if (!ch.Referents.Contains(r)) { ch.Referents.Add(r); } } } edt.Tag = ch; } if (edt2 != null && edt2.Tag == null) { if (ch.Referents == null) { ch.Referents = edt2.Referents; } else { foreach (Pullenti.Ner.Referent r in edt2.Referents) { if (!ch.Referents.Contains(r)) { ch.Referents.Add(r); } } } edt2.Tag = ch; } } foreach (FragToken ch in root.Children) { AnalizeEditions(ch); } }
public static void CorrectDummyNewlines(FragToken fr) { int i; for (i = 0; i < fr.Children.Count; i++) { FragToken ch = fr.Children[i]; if ((ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Keyword || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Number || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Name) || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Comment) { } else { break; } } if ((i < fr.Children.Count) && fr.Children[i].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention) { int j; for (j = i + 1; j < fr.Children.Count; j++) { if (fr.Children[j].Kind != Pullenti.Ner.Instrument.InstrumentKind.Indention) { break; } else if (_calcNewlineBetweenCoef(fr.Children[j - 1], fr.Children[j]) > 0) { break; } } if (j >= fr.Children.Count) { j--; fr.Children[i].Kind = Pullenti.Ner.Instrument.InstrumentKind.Content; fr.Children[i].Number = 0; fr.Children[i].EndToken = fr.Children[j].EndToken; if ((i + 1) < fr.Children.Count) { fr.Children.RemoveRange(i + 1, fr.Children.Count - i - 1); } if (fr.Kind == Pullenti.Ner.Instrument.InstrumentKind.Preamble && fr.Children.Count == 1) { fr.Children.Clear(); } } else { bool ch = false; for (j = i + 1; j < fr.Children.Count; j++) { if (fr.Children[j - 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention && fr.Children[j].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention && (_calcNewlineBetweenCoef(fr.Children[j - 1], fr.Children[j]) < 0)) { fr.Children[j - 1].EndToken = fr.Children[j].EndToken; fr.Children.RemoveAt(j); j--; ch = true; } } if (ch) { int num = 1; for (j = i; j < fr.Children.Count; j++) { if (fr.Children[j].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention) { fr.Children[j].Number = num++; } } } } } foreach (FragToken ch in fr.Children) { CorrectDummyNewlines(ch); } }
static int _analizeListItems(List <FragToken> chi, int ind) { if (ind >= chi.Count) { return(-1); } FragToken res = chi[ind]; Pullenti.Ner.Instrument.InstrumentKind ki = res.Kind; if (((ki == Pullenti.Ner.Instrument.InstrumentKind.Chapter || ki == Pullenti.Ner.Instrument.InstrumentKind.Clause || ki == Pullenti.Ner.Instrument.InstrumentKind.Content) || ki == Pullenti.Ner.Instrument.InstrumentKind.Item || ki == Pullenti.Ner.Instrument.InstrumentKind.Subitem) || ki == Pullenti.Ner.Instrument.InstrumentKind.ClausePart || ki == Pullenti.Ner.Instrument.InstrumentKind.Indention) { } else { return(-1); } if (res.HasChanges && res.MultilineChangesValue != null) { Pullenti.Ner.MetaToken ci = res.MultilineChangesValue; FragToken cit = new FragToken(ci.BeginToken, ci.EndToken) { Kind = Pullenti.Ner.Instrument.InstrumentKind.Citation }; res.Children.Add(cit); if (Pullenti.Ner.Core.BracketHelper.IsBracket(cit.BeginToken.Previous, true)) { cit.BeginToken = cit.BeginToken.Previous; } if (Pullenti.Ner.Core.BracketHelper.IsBracket(cit.EndToken.Next, true)) { cit.EndToken = cit.EndToken.Next; if (cit.EndToken.Next != null && cit.EndToken.Next.IsCharOf(";.")) { cit.EndToken = cit.EndToken.Next; } } res.FillByContentChildren(); if (res.Children[0].HasChanges) { } Pullenti.Ner.Instrument.InstrumentKind citKind = Pullenti.Ner.Instrument.InstrumentKind.Undefined; if (ci.Tag is Pullenti.Ner.Decree.DecreeChangeReferent) { Pullenti.Ner.Decree.DecreeChangeReferent dcr = ci.Tag as Pullenti.Ner.Decree.DecreeChangeReferent; if (dcr.Value != null && dcr.Value.NewItems.Count > 0) { string mnem = dcr.Value.NewItems[0]; int i; if ((((i = mnem.IndexOf(' ')))) > 0) { mnem = mnem.Substring(0, i); } citKind = Pullenti.Ner.Decree.Internal.PartToken._getInstrKindByTyp(Pullenti.Ner.Decree.Internal.PartToken._getTypeByAttrName(mnem)); } else if (dcr.Owners.Count > 0 && (dcr.Owners[0] is Pullenti.Ner.Decree.DecreePartReferent) && dcr.Kind == Pullenti.Ner.Decree.DecreeChangeKind.New) { Pullenti.Ner.Decree.DecreePartReferent pat = dcr.Owners[0] as Pullenti.Ner.Decree.DecreePartReferent; int min = 0; foreach (Pullenti.Ner.Slot s in pat.Slots) { Pullenti.Ner.Decree.Internal.PartToken.ItemType ty = Pullenti.Ner.Decree.Internal.PartToken._getTypeByAttrName(s.TypeName); if (ty == Pullenti.Ner.Decree.Internal.PartToken.ItemType.Undefined) { continue; } int l = Pullenti.Ner.Decree.Internal.PartToken._getRank(ty); if (l == 0) { continue; } if (l > min || min == 0) { min = l; citKind = Pullenti.Ner.Decree.Internal.PartToken._getInstrKindByTyp(ty); } } } } FragToken sub = null; if (citKind != Pullenti.Ner.Instrument.InstrumentKind.Undefined && citKind != Pullenti.Ner.Instrument.InstrumentKind.Appendix) { sub = new FragToken(ci.BeginToken, ci.EndToken); ContentAnalyzeWhapper wr = new ContentAnalyzeWhapper(); wr.Analyze(sub, null, true, citKind); sub.Kind = Pullenti.Ner.Instrument.InstrumentKind.Content; } else { sub = FragToken.CreateDocument(ci.BeginToken, ci.EndChar, citKind); } if (sub == null || sub.Children.Count == 0) { } else if ((sub.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content && sub.Children.Count > 0 && sub.Children[0].BeginToken == sub.BeginToken) && sub.Children[sub.Children.Count - 1].EndToken == sub.EndToken) { cit.Children.AddRange(sub.Children); } else { cit.Children.Add(sub); } return(1); } int endChar = res.EndChar; if (res.Itok == null) { res.Itok = InstrToken1.Parse(res.BeginToken, true, null, 0, null, false, res.EndChar, false, false); } List <LineToken> lines = LineToken.ParseList(res.BeginToken, endChar, null); if (lines == null || (lines.Count < 1)) { return(-1); } int ret = 1; if (res.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content) { for (int j = ind + 1; j < chi.Count; j++) { if (chi[j].Kind == Pullenti.Ner.Instrument.InstrumentKind.Content) { List <LineToken> lines2 = LineToken.ParseList(chi[j].BeginToken, chi[j].EndChar, lines[lines.Count - 1]); if (lines2 == null || (lines2.Count < 1)) { break; } if (!lines2[0].IsListItem) { if ((lines2.Count > 1 && lines2[1].IsListItem && lines2[0].EndToken.IsCharOf(":")) && !lines2[0].BeginToken.Chars.IsCapitalUpper) { lines2[0].IsListItem = true; } else { break; } } lines.AddRange(lines2); ret = (j - ind) + 1; } else if (chi[j].Kind != Pullenti.Ner.Instrument.InstrumentKind.Editions && chi[j].Kind != Pullenti.Ner.Instrument.InstrumentKind.Comment) { break; } } } if (lines.Count < 2) { return(-1); } if ((lines.Count > 1 && lines[0].IsListItem && lines[1].IsListItem) && lines[0].Number != 1) { if (lines.Count == 2 || !lines[2].IsListItem) { lines[0].IsListItem = (lines[1].IsListItem = false); } } for (int i = 0; i < lines.Count; i++) { if (lines[i].IsListItem) { if (i > 0 && lines[i - 1].IsListItem) { continue; } if (((i + 1) < lines.Count) && lines[i + 1].IsListItem) { } else { lines[i].IsListItem = false; continue; } int j; bool newLine = false; for (j = i + 1; j < lines.Count; j++) { if (!lines[j].IsListItem) { break; } else if (lines[j].IsNewlineBefore) { newLine = true; } } if (newLine) { continue; } if (i > 0 && lines[i - 1].EndToken.IsChar(':')) { continue; } for (j = i; j < lines.Count; j++) { if (!lines[j].IsListItem) { break; } else { lines[j].IsListItem = false; } } } } if (lines.Count > 2) { LineToken last = lines[lines.Count - 1]; LineToken last2 = lines[lines.Count - 2]; if ((!last.IsListItem && last.EndToken.IsChar('.') && last2.IsListItem) && last2.EndToken.IsChar(';')) { if ((last.LengthChar < (last2.LengthChar * 2)) || last.BeginToken.Chars.IsAllLower) { last.IsListItem = true; } } } for (int i = 0; i < (lines.Count - 1); i++) { if (!lines[i].IsListItem && !lines[i + 1].IsListItem) { if (((i + 2) < lines.Count) && lines[i + 2].IsListItem && lines[i + 1].EndToken.IsChar(':')) { } else { lines[i].EndToken = lines[i + 1].EndToken; lines.RemoveAt(i + 1); i--; } } } for (int i = 0; i < (lines.Count - 1); i++) { if (lines[i].IsListItem) { if (lines[i].Number == 1) { bool ok = true; int num = 1; int nonum = 0; for (int j = i + 1; j < lines.Count; j++) { if (!lines[j].IsListItem) { ok = false; break; } else if (lines[j].Number > 0) { num++; if (lines[j].Number != num) { ok = false; break; } } else { nonum++; } } if (!ok || nonum == 0 || (num < 2)) { break; } LineToken lt = lines[i]; for (int j = i + 1; j < lines.Count; j++) { if (lines[j].Number > 0) { lt = lines[j]; } else { List <LineToken> chli = lt.Tag as List <LineToken>; if (chli == null) { lt.Tag = (chli = new List <LineToken>()); } lt.EndToken = lines[j].EndToken; chli.Add(lines[j]); lines.RemoveAt(j); j--; } } } } } int cou = 0; foreach (LineToken li in lines) { if (li.IsListItem) { cou++; } } if (cou < 2) { return(-1); } for (int i = 0; i < lines.Count; i++) { if (lines[i].IsListItem) { int i0 = i; bool ok = true; cou = 1; for (; i < lines.Count; i++, cou++) { if (!lines[i].IsListItem) { break; } else if (lines[i].Number != cou) { ok = false; } } if (!ok) { for (i = i0; i < lines.Count; i++) { if (!lines[i].IsListItem) { break; } else { lines[i].Number = 0; } } } if (cou > 3 && lines[i0].BeginToken.GetSourceText() != lines[i0 + 1].BeginToken.GetSourceText() && lines[i0 + 1].BeginToken.GetSourceText() == lines[i0 + 2].BeginToken.GetSourceText()) { string pref = lines[i0 + 1].BeginToken.GetSourceText(); ok = true; for (int j = i0 + 2; j < i; j++) { if (pref != lines[j].BeginToken.GetSourceText()) { ok = false; break; } } if (!ok) { continue; } Pullenti.Ner.Token tt = null; ok = false; for (tt = lines[i0].EndToken.Previous; tt != null && tt != lines[i0].BeginToken; tt = tt.Previous) { if (tt.GetSourceText() == pref) { ok = true; break; } } if (ok) { LineToken li0 = new LineToken(lines[i0].BeginToken, tt.Previous); lines[i0].BeginToken = tt; lines.Insert(i0, li0); i++; } } } } foreach (LineToken li in lines) { li.CorrectBeginToken(); FragToken ch = new FragToken(li.BeginToken, li.EndToken) { Kind = (li.IsListItem ? Pullenti.Ner.Instrument.InstrumentKind.ListItem : Pullenti.Ner.Instrument.InstrumentKind.Content), Number = li.Number }; if (ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Content && ch.EndToken.IsChar(':')) { ch.Kind = Pullenti.Ner.Instrument.InstrumentKind.ListHead; } res.Children.Add(ch); List <LineToken> chli = li.Tag as List <LineToken>; if (chli != null) { foreach (LineToken lt in chli) { ch.Children.Add(new FragToken(lt.BeginToken, lt.EndToken) { Kind = Pullenti.Ner.Instrument.InstrumentKind.ListItem }); } if (ch.BeginChar < ch.Children[0].BeginChar) { ch.Children.Insert(0, new FragToken(ch.BeginToken, ch.Children[0].BeginToken.Previous) { Kind = Pullenti.Ner.Instrument.InstrumentKind.Content }); } } } return(ret); }
public static void Analyze(FragToken res) { if (res.Number == 4) { } if (res.Children.Count == 0) { Pullenti.Ner.Instrument.InstrumentKind ki = res.Kind; if (((ki == Pullenti.Ner.Instrument.InstrumentKind.Chapter || ki == Pullenti.Ner.Instrument.InstrumentKind.Clause || ki == Pullenti.Ner.Instrument.InstrumentKind.Content) || ki == Pullenti.Ner.Instrument.InstrumentKind.Item || ki == Pullenti.Ner.Instrument.InstrumentKind.Subitem) || ki == Pullenti.Ner.Instrument.InstrumentKind.ClausePart || ki == Pullenti.Ner.Instrument.InstrumentKind.Indention) { List <FragToken> tmp = new List <FragToken>(); tmp.Add(res); _analizeListItems(tmp, 0); } return; } if (res.Kind == Pullenti.Ner.Instrument.InstrumentKind.Clause && res.Number == 12) { } for (int i = 0; i < res.Children.Count; i++) { if (res.Children[i].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention && ((res.Children[i].EndToken.IsCharOf(":;") || ((((i + 1) < res.Children.Count) && res.Children[i + 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions && res.Children[i + 1].EndToken.IsCharOf(":;")))))) { int j; int cou = 1; char listBullet = (char)0; for (j = i + 1; j < res.Children.Count; j++) { FragToken ch = res.Children[j]; if (ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Comment || ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions) { continue; } if (ch.Kind != Pullenti.Ner.Instrument.InstrumentKind.Indention) { break; } if (ch.EndToken.IsCharOf(";") || ((((j + 1) < res.Children.Count) && res.Children[j + 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions && res.Children[j + 1].EndToken.IsChar(';')))) { cou++; if ((ch.BeginToken is Pullenti.Ner.TextToken) && !ch.Chars.IsLetter) { listBullet = ch.Kit.GetTextCharacter(ch.BeginChar); } continue; } if (ch.EndToken.IsCharOf(".")) { cou++; j++; break; } if (ch.EndToken.IsCharOf(":")) { if (listBullet != 0 && ch.BeginToken.IsChar(listBullet)) { for (Pullenti.Ner.Token tt = ch.BeginToken.Next; tt != null && (tt.EndChar < ch.EndChar); tt = tt.Next) { if (tt.Previous.IsChar('.') && Pullenti.Ner.Core.MiscHelper.CanBeStartOfSentence(tt)) { FragToken ch2 = new FragToken(tt, ch.EndToken) { Kind = Pullenti.Ner.Instrument.InstrumentKind.Indention, Number = ch.Number }; ch.EndToken = tt.Previous; res.Children.Insert(j + 1, ch2); for (int k = j + 1; k < res.Children.Count; k++) { if (res.Children[k].Kind == Pullenti.Ner.Instrument.InstrumentKind.Indention) { res.Children[k].Number++; } } cou++; j++; break; } } } break; } cou++; j++; break; } if (cou < 3) { i = j; continue; } if ((i > 0 && !res.Children[i].EndToken.IsChar(':') && res.Children[i - 1].Kind2 == Pullenti.Ner.Instrument.InstrumentKind.Undefined) && res.Children[i - 1].EndToken.IsChar(':')) { res.Children[i - 1].Kind2 = Pullenti.Ner.Instrument.InstrumentKind.ListHead; } for (; i < j; i++) { FragToken ch = res.Children[i]; if (ch.Kind != Pullenti.Ner.Instrument.InstrumentKind.Indention) { continue; } if (ch.EndToken.IsChar(':')) { ch.Kind2 = Pullenti.Ner.Instrument.InstrumentKind.ListHead; } else if (((i + 1) < j) && res.Children[i + 1].Kind == Pullenti.Ner.Instrument.InstrumentKind.Editions && res.Children[i + 1].EndToken.IsChar(':')) { ch.Kind2 = Pullenti.Ner.Instrument.InstrumentKind.ListHead; } else { ch.Kind2 = Pullenti.Ner.Instrument.InstrumentKind.ListItem; } } } } List <FragToken> changed = new List <FragToken>(); for (int i = 0; i < res.Children.Count; i++) { if (res.Number == 7) { } if (res.Children[i].Children.Count > 0) { Analyze(res.Children[i]); } else { int co = _analizeListItems(res.Children, i); if (co > 0) { changed.Add(res.Children[i]); if (co > 1) { res.Children.RemoveRange(i + 1, co - 1); } i += (co - 1); } } } for (int i = changed.Count - 1; i >= 0; i--) { if (changed[i].Kind == Pullenti.Ner.Instrument.InstrumentKind.Content) { int j = res.Children.IndexOf(changed[i]); if (j < 0) { continue; } res.Children.RemoveAt(j); res.Children.InsertRange(j, changed[i].Children); } } }
public static bool CorrectChildNumbers(FragToken root, List <FragToken> children) { bool hasNum = false; if (root.Number > 0) { foreach (FragToken ch in root.Children) { if (ch.Kind == Pullenti.Ner.Instrument.InstrumentKind.Number) { hasNum = true; break; } else if (ch.Kind != Pullenti.Ner.Instrument.InstrumentKind.Keyword) { break; } } } if (!hasNum) { return(false); } if (root.SubNumber == 0) { bool ok = true; foreach (FragToken ch in children) { if (ch.Number > 0) { if (ch.Number == root.Number && ch.SubNumber > 0) { } else { ok = false; } } } if (ok) { foreach (FragToken ch in children) { if (ch.Number > 0) { ch.Number = ch.SubNumber; ch.SubNumber = ch.SubNumber2; ch.SubNumber2 = ch.SubNumber3; ch.SubNumber3 = 0; } } } return(ok); } if (root.SubNumber > 0 && root.SubNumber2 == 0) { bool ok = true; foreach (FragToken ch in children) { if (ch.Number > 0) { if (ch.Number == root.Number && ch.SubNumber == root.SubNumber && ch.SubNumber2 > 0) { } else { ok = false; } } } if (ok) { foreach (FragToken ch in children) { if (ch.Number > 0) { ch.Number = ch.SubNumber2; ch.SubNumber = ch.SubNumber3; ch.SubNumber2 = (ch.SubNumber3 = 0); } } } return(ok); } if (root.SubNumber > 0 && root.SubNumber2 > 0 && root.SubNumber3 == 0) { bool ok = true; foreach (FragToken ch in children) { if (ch.Number > 0) { if ((ch.Number == root.Number && ch.SubNumber == root.SubNumber && ch.SubNumber2 == root.SubNumber2) && ch.SubNumber3 > 0) { } else { ok = false; } } } if (ok) { foreach (FragToken ch in children) { if (ch.Number > 0) { ch.Number = ch.SubNumber3; ch.SubNumber = (ch.SubNumber2 = (ch.SubNumber3 = 0)); } } } return(ok); } return(false); }