public static List <BlockTitleToken> TryAttachList(Pullenti.Ner.Token t) { BlockTitleToken content = null; BlockTitleToken intro = null; List <BlockTitleToken> lits = null; for (Pullenti.Ner.Token tt = t; tt != null; tt = tt.Next) { if (tt.IsNewlineBefore) { BlockTitleToken btt = TryAttach(tt, false, null); if (btt == null) { continue; } if (btt.Typ == BlkTyps.Index) { content = btt; break; } if (btt.Typ == BlkTyps.Intro) { Pullenti.Ner.Token tt2 = btt.EndToken.Next; for (int k = 0; k < 5; k++) { BlockLine li = BlockLine.Create(tt2, null); if (li == null) { break; } if (li.HasContentItemTail || li.Typ == BlkTyps.IndexItem) { content = btt; break; } if (li.HasVerb) { break; } if (li.Typ != BlkTyps.Undefined) { if ((li.BeginChar - btt.EndChar) < 400) { content = btt; break; } } tt2 = li.EndToken.Next; } if (content == null) { intro = btt; } break; } if (btt.Typ == BlkTyps.Literature) { if (lits == null) { lits = new List <BlockTitleToken>(); } lits.Add(btt); } } } if (content == null && intro == null && ((lits == null || lits.Count != 1))) { return(null); } List <BlockTitleToken> res = new List <BlockTitleToken>(); Pullenti.Ner.Core.TerminCollection chapterNames = new Pullenti.Ner.Core.TerminCollection(); Pullenti.Ner.Token t0 = null; if (content != null) { res.Add(content); int cou = 0; int err = 0; for (Pullenti.Ner.Token tt = content.EndToken.Next; tt != null; tt = tt.Next) { if (!tt.IsNewlineBefore) { continue; } BlockLine li = BlockLine.Create(tt, null); if (li == null) { break; } if (li.HasVerb) { if (li.EndToken.IsChar('.')) { break; } if (li.LengthChar > 100) { break; } } BlockTitleToken btt = TryAttach(tt, true, null); if (btt == null) { continue; } err = 0; if (btt.Typ == BlkTyps.Intro) { if (content.Typ == BlkTyps.Intro || cou > 2) { break; } } cou++; tt = (content.EndToken = btt.EndToken); if (btt.Value != null) { chapterNames.AddString(btt.Value, null, null, false); } } content.Typ = BlkTyps.Index; t0 = content.EndToken.Next; } else if (intro != null) { t0 = intro.BeginToken; } else if (lits != null) { t0 = t; } else { return(null); } bool first = true; for (Pullenti.Ner.Token tt = t0; tt != null; tt = tt.Next) { if (!tt.IsNewlineBefore) { continue; } if (tt.IsValue("СЛАБОЕ", null)) { } BlockTitleToken btt = TryAttach(tt, false, chapterNames); if (btt == null) { continue; } if (res.Count == 104) { } tt = btt.EndToken; if (content != null && btt.Typ == BlkTyps.Index) { continue; } if (res.Count > 0 && res[res.Count - 1].Typ == BlkTyps.Literature) { if (btt.Typ != BlkTyps.Appendix && btt.Typ != BlkTyps.Misc && btt.Typ != BlkTyps.Literature) { if (btt.Typ == BlkTyps.Chapter && (res[res.Count - 1].EndChar < ((tt.Kit.Sofa.Text.Length * 3) / 4))) { } else { continue; } } } if (first) { if ((tt.BeginChar - t0.BeginChar) > 300) { BlockTitleToken btt0 = new BlockTitleToken(t0, (t0.Previous == null ? t0 : t0.Previous)); btt0.Typ = BlkTyps.Chapter; btt0.Value = "Похоже на начало"; res.Add(btt0); } } res.Add(btt); tt = btt.EndToken; first = false; } for (int i = 0; i < (res.Count - 1); i++) { if (res[i].Typ == BlkTyps.Literature && res[i + 1].Typ == res[i].Typ) { res.RemoveAt(i + 1); i--; } } return(res); }
public override void Process(Pullenti.Ner.Core.AnalysisKit kit) { Pullenti.Ner.Core.AnalyzerData ad = kit.GetAnalyzerData(this); Pullenti.Ner.Core.TerminCollection models = new Pullenti.Ner.Core.TerminCollection(); Dictionary <string, List <Pullenti.Ner.Referent> > objsByModel = new Dictionary <string, List <Pullenti.Ner.Referent> >(); Pullenti.Ner.Core.TerminCollection objByNames = new Pullenti.Ner.Core.TerminCollection(); for (Pullenti.Ner.Token t = kit.FirstToken; t != null; t = t.Next) { List <Pullenti.Ner.Weapon.Internal.WeaponItemToken> its = Pullenti.Ner.Weapon.Internal.WeaponItemToken.TryParseList(t, 10); if (its == null) { continue; } List <Pullenti.Ner.ReferentToken> rts = this.TryAttach(its, false); if (rts != null) { foreach (Pullenti.Ner.ReferentToken rt in rts) { rt.Referent = ad.RegisterReferent(rt.Referent); kit.EmbedToken(rt); t = rt; foreach (Pullenti.Ner.Slot s in rt.Referent.Slots) { if (s.TypeName == WeaponReferent.ATTR_MODEL) { string mod = s.Value.ToString(); for (int k = 0; k < 2; k++) { if (!char.IsDigit(mod[0])) { List <Pullenti.Ner.Referent> li; if (!objsByModel.TryGetValue(mod, out li)) { objsByModel.Add(mod, (li = new List <Pullenti.Ner.Referent>())); } if (!li.Contains(rt.Referent)) { li.Add(rt.Referent); } models.AddString(mod, li, null, false); } if (k > 0) { break; } string brand = rt.Referent.GetStringValue(WeaponReferent.ATTR_BRAND); if (brand == null) { break; } mod = string.Format("{0} {1}", brand, mod); } } else if (s.TypeName == WeaponReferent.ATTR_NAME) { objByNames.Add(new Pullenti.Ner.Core.Termin(s.Value.ToString()) { Tag = rt.Referent }); } } } } } if (objsByModel.Count == 0 && objByNames.Termins.Count == 0) { return; } for (Pullenti.Ner.Token t = kit.FirstToken; t != null; t = t.Next) { Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(t, Pullenti.Ner.Core.BracketParseAttr.No, 10); if (br != null) { Pullenti.Ner.Core.TerminToken toks = objByNames.TryParse(t.Next, Pullenti.Ner.Core.TerminParseAttr.No); if (toks != null && toks.EndToken.Next == br.EndToken) { Pullenti.Ner.ReferentToken rt0 = new Pullenti.Ner.ReferentToken(toks.Termin.Tag as Pullenti.Ner.Referent, br.BeginToken, br.EndToken); kit.EmbedToken(rt0); t = rt0; continue; } } if (!(t is Pullenti.Ner.TextToken)) { continue; } if (!t.Chars.IsLetter) { continue; } Pullenti.Ner.Core.TerminToken tok = models.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No); if (tok == null) { if (!t.Chars.IsAllLower) { tok = objByNames.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No); } if (tok == null) { continue; } } if (!tok.IsWhitespaceAfter) { if (tok.EndToken.Next == null || !tok.EndToken.Next.IsCharOf(",.)")) { if (!Pullenti.Ner.Core.BracketHelper.IsBracket(tok.EndToken.Next, false)) { continue; } } } Pullenti.Ner.Referent tr = null; List <Pullenti.Ner.Referent> li = tok.Termin.Tag as List <Pullenti.Ner.Referent>; if (li != null && li.Count == 1) { tr = li[0]; } else { tr = tok.Termin.Tag as Pullenti.Ner.Referent; } if (tr != null) { Pullenti.Ner.Weapon.Internal.WeaponItemToken tit = Pullenti.Ner.Weapon.Internal.WeaponItemToken.TryParse(tok.BeginToken.Previous, null, false, true); if (tit != null && tit.Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Brand) { tr.AddSlot(WeaponReferent.ATTR_BRAND, tit.Value, false, 0); tok.BeginToken = tit.BeginToken; } Pullenti.Ner.ReferentToken rt0 = new Pullenti.Ner.ReferentToken(tr, tok.BeginToken, tok.EndToken); kit.EmbedToken(rt0); t = rt0; continue; } } }