public static Pullenti.Ner.ReferentToken TryAttachOrg(Pullenti.Ner.Token t, bool canBeCyr = false) { if (t == null) { return(null); } bool br = false; if (t.IsChar('(') && t.Next != null) { t = t.Next; br = true; } if (t is Pullenti.Ner.NumberToken) { if ((t as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Words && t.Morph.Class.IsAdjective && t.Chars.IsCapitalUpper) { } else { return(null); } } else { if (t.Chars.IsAllLower) { return(null); } if ((t.LengthChar < 3) && !t.Chars.IsLetter) { return(null); } if (!t.Chars.IsLatinLetter) { if (!canBeCyr || !t.Chars.IsCyrillicLetter) { return(null); } } } Pullenti.Ner.Token t0 = t; Pullenti.Ner.Token t1 = t0; int namWo = 0; OrgItemEngItem tok = null; Pullenti.Ner.Geo.GeoReferent geo = null; OrgItemTypeToken addTyp = null; for (; t != null; t = t.Next) { if (t != t0 && t.WhitespacesBeforeCount > 1) { break; } if (t.IsChar(')')) { break; } if (t.IsChar('(') && t.Next != null) { if ((t.Next.GetReferent() is Pullenti.Ner.Geo.GeoReferent) && t.Next.Next != null && t.Next.Next.IsChar(')')) { geo = t.Next.GetReferent() as Pullenti.Ner.Geo.GeoReferent; t = t.Next.Next; continue; } OrgItemTypeToken typ = OrgItemTypeToken.TryAttach(t.Next, true, null); if ((typ != null && typ.EndToken.Next != null && typ.EndToken.Next.IsChar(')')) && typ.Chars.IsLatinLetter) { addTyp = typ; t = typ.EndToken.Next; continue; } if (((t.Next is Pullenti.Ner.TextToken) && t.Next.Next != null && t.Next.Next.IsChar(')')) && t.Next.Chars.IsCapitalUpper) { t1 = (t = t.Next.Next); continue; } break; } tok = TryAttach(t, canBeCyr); if (tok == null && t.IsCharOf(".,") && t.Next != null) { tok = TryAttach(t.Next, canBeCyr); if (tok == null && t.Next.IsCharOf(",.")) { tok = TryAttach(t.Next.Next, canBeCyr); } } if (tok != null) { if (tok.LengthChar == 1 && t0.Chars.IsCyrillicLetter) { return(null); } break; } if (t.IsHiphen && !t.IsWhitespaceAfter && !t.IsWhitespaceBefore) { continue; } if (t.IsCharOf("&+") || t.IsAnd) { continue; } if (t.IsChar('.')) { if (t.Previous != null && t.Previous.LengthChar == 1) { continue; } else if (Pullenti.Ner.Core.MiscHelper.CanBeStartOfSentence(t.Next)) { break; } } if (!t.Chars.IsLatinLetter) { if (!canBeCyr || !t.Chars.IsCyrillicLetter) { break; } } if (t.Chars.IsAllLower) { if (t.Morph.Class.IsPreposition || t.Morph.Class.IsConjunction) { continue; } if (br) { continue; } break; } Pullenti.Morph.MorphClass mc = t.GetMorphClassInDictionary(); if (mc.IsVerb) { if (t.Next != null && t.Next.Morph.Class.IsPreposition) { break; } } if (t.Next != null && t.Next.IsValue("OF", null)) { break; } if (t is Pullenti.Ner.TextToken) { namWo++; } t1 = t; } if (tok == null) { return(null); } if (t0 == tok.BeginToken) { Pullenti.Ner.Core.BracketSequenceToken br2 = Pullenti.Ner.Core.BracketHelper.TryParse(tok.EndToken.Next, Pullenti.Ner.Core.BracketParseAttr.No, 100); if (br2 != null) { Pullenti.Ner.Org.OrganizationReferent org1 = new Pullenti.Ner.Org.OrganizationReferent(); if (tok.ShortValue != null) { org1.AddTypeStr(tok.ShortValue); } org1.AddTypeStr(tok.FullValue); string nam1 = Pullenti.Ner.Core.MiscHelper.GetTextValue(br2.BeginToken, br2.EndToken, Pullenti.Ner.Core.GetTextAttr.No); if (nam1 != null) { org1.AddName(nam1, true, null); return(new Pullenti.Ner.ReferentToken(org1, t0, br2.EndToken)); } } return(null); } Pullenti.Ner.Org.OrganizationReferent org = new Pullenti.Ner.Org.OrganizationReferent(); Pullenti.Ner.Token te = tok.EndToken; if (tok.IsBank) { t1 = tok.EndToken; } if (tok.FullValue == "company" && (tok.WhitespacesAfterCount < 3)) { OrgItemEngItem tok1 = TryAttach(tok.EndToken.Next, canBeCyr); if (tok1 != null) { t1 = tok.EndToken; tok = tok1; te = tok.EndToken; } } if (tok.FullValue == "company") { if (namWo == 0) { return(null); } } string nam = Pullenti.Ner.Core.MiscHelper.GetTextValue(t0, t1, Pullenti.Ner.Core.GetTextAttr.IgnoreArticles); if (nam == "STOCK" && tok.FullValue == "company") { return(null); } string altNam = null; if (string.IsNullOrEmpty(nam)) { return(null); } if (nam.IndexOf('(') > 0) { int i1 = nam.IndexOf('('); int i2 = nam.IndexOf(')'); if (i1 < i2) { altNam = nam; string tai = null; if ((i2 + 1) < nam.Length) { tai = nam.Substring(i2).Trim(); } nam = nam.Substring(0, i1).Trim(); if (tai != null) { nam = string.Format("{0} {1}", nam, tai); } } } if (tok.IsBank) { org.AddTypeStr((tok.Kit.BaseLanguage.IsEn ? "bank" : "банк")); org.AddProfile(Pullenti.Ner.Org.OrgProfile.Finance); if ((t1.Next != null && t1.Next.IsValue("OF", null) && t1.Next.Next != null) && t1.Next.Next.Chars.IsLatinLetter) { OrgItemNameToken nam0 = OrgItemNameToken.TryAttach(t1.Next, null, false, false); if (nam0 != null) { te = nam0.EndToken; } else { te = t1.Next.Next; } nam = Pullenti.Ner.Core.MiscHelper.GetTextValue(t0, te, Pullenti.Ner.Core.GetTextAttr.No); if (te.GetReferent() is Pullenti.Ner.Geo.GeoReferent) { org.AddGeoObject(te.GetReferent() as Pullenti.Ner.Geo.GeoReferent); } } else if (t0 == t1) { return(null); } } else { if (tok.ShortValue != null) { org.AddTypeStr(tok.ShortValue); } org.AddTypeStr(tok.FullValue); } if (string.IsNullOrEmpty(nam)) { return(null); } org.AddName(nam, true, null); if (altNam != null) { org.AddName(altNam, true, null); } Pullenti.Ner.ReferentToken res = new Pullenti.Ner.ReferentToken(org, t0, te); t = te; while (t.Next != null) { if (t.Next.IsCharOf(",.")) { t = t.Next; } else { break; } } if (t.WhitespacesAfterCount < 2) { tok = TryAttach(t.Next, canBeCyr); if (tok != null) { if (tok.ShortValue != null) { org.AddTypeStr(tok.ShortValue); } org.AddTypeStr(tok.FullValue); res.EndToken = tok.EndToken; } } if (geo != null) { org.AddGeoObject(geo); } if (addTyp != null) { org.AddType(addTyp, false); } if (!br) { return(res); } t = res.EndToken; if (t.Next == null || t.Next.IsChar(')')) { res.EndToken = t.Next; } else { return(null); } return(res); }
public static void Initialize() { if (GlobalOrgs != null) { return; } GlobalOrgs = new Pullenti.Ner.Core.IntOntologyCollection(); Pullenti.Ner.Org.OrganizationReferent org; Pullenti.Ner.Core.IntOntologyItem oi; using (Pullenti.Ner.Processor geoProc = Pullenti.Ner.ProcessorService.CreateEmptyProcessor()) { geoProc.AddAnalyzer(new Pullenti.Ner.Geo.GeoAnalyzer()); Dictionary <string, Pullenti.Ner.Geo.GeoReferent> geos = new Dictionary <string, Pullenti.Ner.Geo.GeoReferent>(); for (int k = 0; k < 3; k++) { Pullenti.Morph.MorphLang lang = (k == 0 ? Pullenti.Morph.MorphLang.RU : (k == 1 ? Pullenti.Morph.MorphLang.EN : Pullenti.Morph.MorphLang.UA)); string name = (k == 0 ? "Orgs_ru.dat" : (k == 1 ? "Orgs_en.dat" : "Orgs_ua.dat")); byte[] dat = ResourceHelper.GetBytes(name); if (dat == null) { throw new Exception(string.Format("Can't file resource file {0} in Organization analyzer", name)); } using (MemoryStream tmp = new MemoryStream(OrgItemTypeToken.Deflate(dat))) { tmp.Position = 0; XmlDocument xml = new XmlDocument(); xml.Load(tmp); foreach (XmlNode x in xml.DocumentElement.ChildNodes) { org = new Pullenti.Ner.Org.OrganizationReferent(); string abbr = null; foreach (XmlNode xx in x.ChildNodes) { if (xx.LocalName == "typ") { org.AddSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_TYPE, xx.InnerText, false, 0); } else if (xx.LocalName == "nam") { org.AddSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, xx.InnerText, false, 0); } else if (xx.LocalName == "epo") { org.AddSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_EPONYM, xx.InnerText, false, 0); } else if (xx.LocalName == "prof") { org.AddSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_PROFILE, xx.InnerText, false, 0); } else if (xx.LocalName == "abbr") { abbr = xx.InnerText; } else if (xx.LocalName == "geo") { Pullenti.Ner.Geo.GeoReferent geo; if (!geos.TryGetValue(xx.InnerText, out geo)) { Pullenti.Ner.AnalysisResult ar = geoProc.Process(new Pullenti.Ner.SourceOfAnalysis(xx.InnerText), null, lang); if (ar != null && ar.Entities.Count == 1 && (ar.Entities[0] is Pullenti.Ner.Geo.GeoReferent)) { geo = ar.Entities[0] as Pullenti.Ner.Geo.GeoReferent; geos.Add(xx.InnerText, geo); } else { } } if (geo != null) { org.AddSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_GEO, geo, false, 0); } } } oi = org.CreateOntologyItemEx(2, true, true); if (oi == null) { continue; } if (abbr != null) { oi.Termins.Add(new Pullenti.Ner.Core.Termin(abbr, null, true)); } if (k == 2) { GlobalOrgsUa.AddItem(oi); } else { GlobalOrgs.AddItem(oi); } } } } } return; }
internal static TitlePageReferent _process(Pullenti.Ner.Token begin, int maxCharPos, Pullenti.Ner.Core.AnalysisKit kit, out Pullenti.Ner.Token endToken) { endToken = begin; TitlePageReferent res = new TitlePageReferent(); Pullenti.Ner.Core.Termin term = null; List <Pullenti.Ner.Titlepage.Internal.Line> lines = Pullenti.Ner.Titlepage.Internal.Line.Parse(begin, 30, 1500, maxCharPos); if (lines.Count < 1) { return(null); } int cou = lines.Count; int minNewlinesCount = 10; Dictionary <int, int> linesCountStat = new Dictionary <int, int>(); for (int i = 0; i < lines.Count; i++) { if (Pullenti.Ner.Titlepage.Internal.TitleNameToken.CanBeStartOfTextOrContent(lines[i].BeginToken, lines[i].EndToken)) { cou = i; break; } int j = lines[i].NewlinesBeforeCount; if (i > 0 && j > 0) { if (!linesCountStat.ContainsKey(j)) { linesCountStat.Add(j, 1); } else { linesCountStat[j]++; } } } int max = 0; foreach (KeyValuePair <int, int> kp in linesCountStat) { if (kp.Value > max) { max = kp.Value; minNewlinesCount = kp.Key; } } int endChar = (cou > 0 ? lines[cou - 1].EndChar : 0); if (maxCharPos > 0 && endChar > maxCharPos) { endChar = maxCharPos; } List <Pullenti.Ner.Titlepage.Internal.TitleNameToken> names = new List <Pullenti.Ner.Titlepage.Internal.TitleNameToken>(); for (int i = 0; i < cou; i++) { if (i == 6) { } for (int j = i; (j < cou) && (j < (i + 5)); j++) { if (i == 6 && j == 8) { } if (j > i) { if (lines[j - 1].IsPureEn && lines[j].IsPureRu) { break; } if (lines[j - 1].IsPureRu && lines[j].IsPureEn) { break; } if (lines[j].NewlinesBeforeCount >= (minNewlinesCount * 2)) { break; } } Pullenti.Ner.Titlepage.Internal.TitleNameToken ttt = Pullenti.Ner.Titlepage.Internal.TitleNameToken.TryParse(lines[i].BeginToken, lines[j].EndToken, minNewlinesCount); if (ttt != null) { if (lines[i].IsPureEn) { ttt.Morph.Language = Pullenti.Morph.MorphLang.EN; } else if (lines[i].IsPureRu) { ttt.Morph.Language = Pullenti.Morph.MorphLang.RU; } names.Add(ttt); } } } Pullenti.Ner.Titlepage.Internal.TitleNameToken.Sort(names); Pullenti.Ner.ReferentToken nameRt = null; if (names.Count > 0) { int i0 = 0; if (names[i0].Morph.Language.IsEn) { for (int ii = 1; ii < names.Count; ii++) { if (names[ii].Morph.Language.IsRu && names[ii].Rank > 0) { i0 = ii; break; } } } term = res.AddName(names[i0].BeginNameToken, names[i0].EndNameToken); if (names[i0].TypeValue != null) { res.AddType(names[i0].TypeValue); } if (names[i0].Speciality != null) { res.Speciality = names[i0].Speciality; } Pullenti.Ner.ReferentToken rt = new Pullenti.Ner.ReferentToken(res, names[i0].BeginToken, names[i0].EndToken); if (kit != null) { kit.EmbedToken(rt); } else { res.AddOccurence(new Pullenti.Ner.TextAnnotation(rt.BeginToken, rt.EndToken)); } endToken = rt.EndToken; nameRt = rt; if (begin.BeginChar == rt.BeginChar) { begin = rt; } } if (term != null && kit != null) { for (Pullenti.Ner.Token t = kit.FirstToken; t != null; t = t.Next) { Pullenti.Ner.Core.TerminToken tok = term.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No); if (tok == null) { continue; } Pullenti.Ner.Token t0 = t; Pullenti.Ner.Token t1 = tok.EndToken; if (t1.Next != null && t1.Next.IsChar('.')) { t1 = t1.Next; } if (Pullenti.Ner.Core.BracketHelper.CanBeStartOfSequence(t0.Previous, false, false) && Pullenti.Ner.Core.BracketHelper.CanBeEndOfSequence(t1.Next, false, null, false)) { t0 = t0.Previous; t1 = t1.Next; } Pullenti.Ner.ReferentToken rt = new Pullenti.Ner.ReferentToken(res, t0, t1); kit.EmbedToken(rt); t = rt; } } Pullenti.Ner.Titlepage.Internal.PersonRelations pr = new Pullenti.Ner.Titlepage.Internal.PersonRelations(); Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined; List <Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types> persTypes = pr.RelTypes; for (Pullenti.Ner.Token t = begin; t != null; t = t.Next) { if (maxCharPos > 0 && t.BeginChar > maxCharPos) { break; } if (t == nameRt) { continue; } Pullenti.Ner.Titlepage.Internal.TitleItemToken tpt = Pullenti.Ner.Titlepage.Internal.TitleItemToken.TryAttach(t); if (tpt != null) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined; if (tpt.Typ == Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Typ) { if (res.Types.Count == 0) { res.AddType(tpt.Value); } else if (res.Types.Count == 1) { string ty = res.Types[0].ToUpper(); if (ty == "РЕФЕРАТ") { res.AddType(tpt.Value); } else if (ty == "АВТОРЕФЕРАТ") { if (tpt.Value == "КАНДИДАТСКАЯ ДИССЕРТАЦИЯ") { res.AddSlot(TitlePageReferent.ATTR_TYPE, "автореферат кандидатской диссертации", true, 0); } else if (tpt.Value == "ДОКТОРСКАЯ ДИССЕРТАЦИЯ") { res.AddSlot(TitlePageReferent.ATTR_TYPE, "автореферат докторской диссертации", true, 0); } else if (tpt.Value == "МАГИСТЕРСКАЯ ДИССЕРТАЦИЯ") { res.AddSlot(TitlePageReferent.ATTR_TYPE, "автореферат магистерской диссертации", true, 0); } else if (tpt.Value == "КАНДИДАТСЬКА ДИСЕРТАЦІЯ") { res.AddSlot(TitlePageReferent.ATTR_TYPE, "автореферат кандидатської дисертації", true, 0); } else if (tpt.Value == "ДОКТОРСЬКА ДИСЕРТАЦІЯ") { res.AddSlot(TitlePageReferent.ATTR_TYPE, "автореферат докторської дисертації", true, 0); } else if (tpt.Value == "МАГІСТЕРСЬКА ДИСЕРТАЦІЯ") { res.AddSlot(TitlePageReferent.ATTR_TYPE, "автореферат магістерської дисертації", true, 0); } else { res.AddType(tpt.Value); } } else if (tpt.Value == "РЕФЕРАТ" || tpt.Value == "АВТОРЕФЕРАТ") { if (!ty.Contains(tpt.Value)) { res.AddType(tpt.Value); } } } } else if (tpt.Typ == Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Speciality) { if (res.Speciality == null) { res.Speciality = tpt.Value; } } else if (persTypes.Contains(tpt.Typ)) { persTyp = tpt.Typ; } t = tpt.EndToken; if (t.EndChar > endToken.EndChar) { endToken = t; } if (t.Next != null && t.Next.IsCharOf(":-")) { t = t.Next; } continue; } if (t.EndChar > endChar) { break; } List <Pullenti.Ner.Referent> rli = t.GetReferents(); if (rli == null) { continue; } if (!t.IsNewlineBefore && (t.Previous is Pullenti.Ner.TextToken)) { string s = (t.Previous as Pullenti.Ner.TextToken).Term; if (s == "ИМЕНИ" || s == "ИМ") { continue; } if (s == "." && t.Previous.Previous != null && t.Previous.Previous.IsValue("ИМ", null)) { continue; } } foreach (Pullenti.Ner.Referent r in rli) { if (r is Pullenti.Ner.Person.PersonReferent) { if (r != rli[0]) { continue; } Pullenti.Ner.Person.PersonReferent p = r as Pullenti.Ner.Person.PersonReferent; if (persTyp != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined) { if (t.Previous != null && t.Previous.IsChar('.')) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined; } } Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types typ = pr.CalcTypFromAttrs(p); if (typ != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined) { pr.Add(p, typ, 1); persTyp = typ; } else if (persTyp != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined) { pr.Add(p, persTyp, 1); } else if (t.Previous != null && t.Previous.IsChar('©')) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Worker; pr.Add(p, persTyp, 1); } else { for (Pullenti.Ner.Token tt = t.Next; tt != null; tt = tt.Next) { Pullenti.Ner.Referent rr = tt.GetReferent(); if (rr == res) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Worker; break; } if (rr is Pullenti.Ner.Person.PersonReferent) { if (pr.CalcTypFromAttrs(r as Pullenti.Ner.Person.PersonReferent) != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined) { break; } else { continue; } } if (rr != null) { break; } tpt = Pullenti.Ner.Titlepage.Internal.TitleItemToken.TryAttach(tt); if (tpt != null) { if (tpt.Typ != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Typ && tpt.Typ != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.TypAndTheme) { break; } tt = tpt.EndToken; if (tt.EndChar > endToken.EndChar) { endToken = tt; } continue; } } if (persTyp == Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined) { for (Pullenti.Ner.Token tt = t.Previous; tt != null; tt = tt.Previous) { Pullenti.Ner.Referent rr = tt.GetReferent(); if (rr == res) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Worker; break; } if (rr != null) { break; } if ((tt.IsValue("СТУДЕНТ", null) || tt.IsValue("СТУДЕНТКА", null) || tt.IsValue("СЛУШАТЕЛЬ", null)) || tt.IsValue("ДИПЛОМНИК", null) || tt.IsValue("ИСПОЛНИТЕЛЬ", null)) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Worker; break; } tpt = Pullenti.Ner.Titlepage.Internal.TitleItemToken.TryAttach(tt); if (tpt != null && tpt.Typ != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Typ) { break; } } } if (persTyp != Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined) { pr.Add(p, persTyp, 1); } else { pr.Add(p, persTyp, (float)0.5); } if (t.EndChar > endToken.EndChar) { endToken = t; } } continue; } if (r == rli[0]) { persTyp = Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined; } if (r is Pullenti.Ner.Date.DateReferent) { if (res.Date == null) { res.Date = r as Pullenti.Ner.Date.DateReferent; if (t.EndChar > endToken.EndChar) { endToken = t; } } } else if (r is Pullenti.Ner.Geo.GeoReferent) { if (res.City == null && (r as Pullenti.Ner.Geo.GeoReferent).IsCity) { res.City = r as Pullenti.Ner.Geo.GeoReferent; if (t.EndChar > endToken.EndChar) { endToken = t; } } } if (r is Pullenti.Ner.Org.OrganizationReferent) { Pullenti.Ner.Org.OrganizationReferent org = r as Pullenti.Ner.Org.OrganizationReferent; if (org.Types.Contains("курс") && org.Number != null) { int i; if (int.TryParse(org.Number, out i)) { if (i > 0 && (i < 8)) { res.StudentYear = i; } } } for (; org.Higher != null; org = org.Higher) { if (org.Kind != Pullenti.Ner.Org.OrganizationKind.Department) { break; } } if (org.Kind != Pullenti.Ner.Org.OrganizationKind.Department) { if (res.Org == null) { res.Org = org; } else if (Pullenti.Ner.Org.OrganizationReferent.CanBeHigher(res.Org, org)) { res.Org = org; } } if (t.EndChar > endToken.EndChar) { endToken = t; } } if ((r is Pullenti.Ner.Uri.UriReferent) || (r is Pullenti.Ner.Geo.GeoReferent)) { if (t.EndChar > endToken.EndChar) { endToken = t; } } } } foreach (Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types ty in persTypes) { foreach (Pullenti.Ner.Person.PersonReferent p in pr.GetPersons(ty)) { if (pr.GetAttrNameForType(ty) != null) { res.AddSlot(pr.GetAttrNameForType(ty), p, false, 0); } } } if (res.GetSlotValue(TitlePageReferent.ATTR_AUTHOR) == null) { foreach (Pullenti.Ner.Person.PersonReferent p in pr.GetPersons(Pullenti.Ner.Titlepage.Internal.TitleItemToken.Types.Undefined)) { res.AddSlot(TitlePageReferent.ATTR_AUTHOR, p, false, 0); break; } } if (res.City == null && res.Org != null) { Pullenti.Ner.Slot s = res.Org.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_GEO, null, true); if (s != null && (s.Value is Pullenti.Ner.Geo.GeoReferent)) { if ((s.Value as Pullenti.Ner.Geo.GeoReferent).IsCity) { res.City = s.Value as Pullenti.Ner.Geo.GeoReferent; } } } if (res.Date == null) { for (Pullenti.Ner.Token t = begin; t != null && t.EndChar <= endChar; t = t.Next) { Pullenti.Ner.Geo.GeoReferent city = t.GetReferent() as Pullenti.Ner.Geo.GeoReferent; if (city == null) { continue; } if (t.Next is Pullenti.Ner.TextToken) { if (t.Next.IsCharOf(":,") || t.Next.IsHiphen) { t = t.Next; } } Pullenti.Ner.ReferentToken rt = t.Kit.ProcessReferent(Pullenti.Ner.Date.DateAnalyzer.ANALYZER_NAME, t.Next); if (rt != null) { rt.SaveToLocalOntology(); res.Date = rt.Referent as Pullenti.Ner.Date.DateReferent; if (kit != null) { kit.EmbedToken(rt); } break; } } } if (res.Slots.Count == 0) { return(null); } else { return(res); } }
static BookLinkToken _tryParse(Pullenti.Ner.Token t, int lev) { if (t == null || lev > 3) { return(null); } if (t.IsChar('[')) { BookLinkToken re = _tryParse(t.Next, lev + 1); if (re != null && re.EndToken.Next != null && re.EndToken.Next.IsChar(']')) { re.BeginToken = t; re.EndToken = re.EndToken.Next; return(re); } if (re != null && re.EndToken.IsChar(']')) { re.BeginToken = t; return(re); } if (re != null) { if (re.Typ == BookLinkTyp.Sostavitel || re.Typ == BookLinkTyp.Editors) { return(re); } } Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(t, Pullenti.Ner.Core.BracketParseAttr.No, 100); if (br != null) { if ((br.EndToken.Previous is Pullenti.Ner.NumberToken) && (br.LengthChar < 30)) { return new BookLinkToken(t, br.EndToken) { Typ = BookLinkTyp.Number, Value = Pullenti.Ner.Core.MiscHelper.GetTextValue(br.BeginToken.Next, br.EndToken.Previous, Pullenti.Ner.Core.GetTextAttr.No) } } ; } } Pullenti.Ner.Token t0 = t; if (t is Pullenti.Ner.ReferentToken) { if (t.GetReferent() is Pullenti.Ner.Person.PersonReferent) { return(TryParseAuthor(t, Pullenti.Ner.Person.Internal.FioTemplateType.Undefined)); } if (t.GetReferent() is Pullenti.Ner.Geo.GeoReferent) { return new BookLinkToken(t, t) { Typ = BookLinkTyp.Geo, Ref = t.GetReferent() } } ; if (t.GetReferent() is Pullenti.Ner.Date.DateReferent) { Pullenti.Ner.Date.DateReferent dr = t.GetReferent() as Pullenti.Ner.Date.DateReferent; if (dr.Slots.Count == 1 && dr.Year > 0) { return new BookLinkToken(t, t) { Typ = BookLinkTyp.Year, Value = dr.Year.ToString() } } ; if (dr.Year > 0 && t.Previous != null && t.Previous.IsComma) { return new BookLinkToken(t, t) { Typ = BookLinkTyp.Year, Value = dr.Year.ToString() } } ; } if (t.GetReferent() is Pullenti.Ner.Org.OrganizationReferent) { Pullenti.Ner.Org.OrganizationReferent org = t.GetReferent() as Pullenti.Ner.Org.OrganizationReferent; if (org.Kind == Pullenti.Ner.Org.OrganizationKind.Press) { return new BookLinkToken(t, t) { Typ = BookLinkTyp.Press, Ref = org } } ; } if (t.GetReferent() is Pullenti.Ner.Uri.UriReferent) { Pullenti.Ner.Uri.UriReferent uri = t.GetReferent() as Pullenti.Ner.Uri.UriReferent; if ((uri.Scheme == "http" || uri.Scheme == "https" || uri.Scheme == "ftp") || uri.Scheme == null) { return new BookLinkToken(t, t) { Typ = BookLinkTyp.Url, Ref = uri } } ; } } Pullenti.Ner.Core.TerminToken tok = m_Termins.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No); if (tok != null) { BookLinkTyp typ = (BookLinkTyp)tok.Termin.Tag; bool ok = true; if (typ == BookLinkTyp.Type || typ == BookLinkTyp.NameTail || typ == BookLinkTyp.ElectronRes) { if (t.Previous != null && ((t.Previous.IsCharOf(".:[") || t.Previous.IsHiphen))) { } else { ok = false; } } if (ok) { return new BookLinkToken(t, tok.EndToken) { Typ = typ, Value = tok.Termin.CanonicText } } ; if (typ == BookLinkTyp.ElectronRes) { for (Pullenti.Ner.Token tt = tok.EndToken.Next; tt != null; tt = tt.Next) { if ((tt is Pullenti.Ner.TextToken) && !tt.Chars.IsLetter) { continue; } if (tt.GetReferent() is Pullenti.Ner.Uri.UriReferent) { return new BookLinkToken(t, tt) { Typ = BookLinkTyp.ElectronRes, Ref = tt.GetReferent() } } ; break; } } } if (t.IsChar('/')) { BookLinkToken res = new BookLinkToken(t, t) { Typ = BookLinkTyp.Delimeter, Value = "/" }; if (t.Next != null && t.Next.IsChar('/')) { res.EndToken = t.Next; res.Value = "//"; } if (!t.IsWhitespaceBefore && !t.IsWhitespaceAfter) { int coo = 3; bool no = true; for (Pullenti.Ner.Token tt = t.Next; tt != null && coo > 0; tt = tt.Next, coo--) { BookLinkToken vvv = TryParse(tt, lev + 1); if (vvv != null && vvv.Typ != BookLinkTyp.Number) { no = false; break; } } if (no) { return(null); } } return(res); } if ((t is Pullenti.Ner.NumberToken) && (t as Pullenti.Ner.NumberToken).IntValue != null && (t as Pullenti.Ner.NumberToken).Typ == Pullenti.Ner.NumberSpellingType.Digit) { BookLinkToken res = new BookLinkToken(t, t) { Typ = BookLinkTyp.Number, Value = (t as Pullenti.Ner.NumberToken).Value.ToString() }; int val = (t as Pullenti.Ner.NumberToken).IntValue.Value; if (val >= 1930 && (val < 2030)) { res.Typ = BookLinkTyp.Year; } if (t.Next != null && t.Next.IsChar('.')) { res.EndToken = t.Next; } else if ((t.Next != null && t.Next.LengthChar == 1 && !t.Next.Chars.IsLetter) && t.Next.IsWhitespaceAfter) { res.EndToken = t.Next; } else if (t.Next is Pullenti.Ner.TextToken) { string term = (t.Next as Pullenti.Ner.TextToken).Term; if (((term == "СТР" || term == "C" || term == "С") || term == "P" || term == "S") || term == "PAGES") { res.EndToken = t.Next; res.Typ = BookLinkTyp.Pages; res.Value = (t as Pullenti.Ner.NumberToken).Value.ToString(); } } return(res); } if (t is Pullenti.Ner.TextToken) { string term = (t as Pullenti.Ner.TextToken).Term; if (((((((term == "СТР" || term == "C" || term == "С") || term == "ТОМ" || term == "T") || term == "Т" || term == "P") || term == "PP" || term == "V") || term == "VOL" || term == "S") || term == "СТОР" || t.IsValue("PAGE", null)) || t.IsValue("СТРАНИЦА", "СТОРІНКА")) { Pullenti.Ner.Token tt = t.Next; while (tt != null) { if (tt.IsCharOf(".:~")) { tt = tt.Next; } else { break; } } if (tt is Pullenti.Ner.NumberToken) { BookLinkToken res = new BookLinkToken(t, tt) { Typ = BookLinkTyp.PageRange }; Pullenti.Ner.Token tt0 = tt; Pullenti.Ner.Token tt1 = tt; for (tt = tt.Next; tt != null; tt = tt.Next) { if (tt.IsCharOf(",") || tt.IsHiphen) { if (tt.Next is Pullenti.Ner.NumberToken) { tt = tt.Next; res.EndToken = tt; tt1 = tt; continue; } } break; } res.Value = Pullenti.Ner.Core.MiscHelper.GetTextValue(tt0, tt1, Pullenti.Ner.Core.GetTextAttr.No); return(res); } } if ((term == "M" || term == "М" || term == "СПБ") || term == "K" || term == "К") { if (t.Next != null && t.Next.IsCharOf(":;")) { BookLinkToken re = new BookLinkToken(t, t.Next) { Typ = BookLinkTyp.Geo }; return(re); } if (t.Next != null && t.Next.IsCharOf(".")) { BookLinkToken res = new BookLinkToken(t, t.Next) { Typ = BookLinkTyp.Geo }; if (t.Next.Next != null && t.Next.Next.IsCharOf(":;")) { res.EndToken = t.Next.Next; } else if (t.Next.Next != null && (t.Next.Next is Pullenti.Ner.NumberToken)) { } else if (t.Next.Next != null && t.Next.Next.IsComma && (t.Next.Next.Next is Pullenti.Ner.NumberToken)) { } else { return(null); } return(res); } } if (term == "ПЕР" || term == "ПЕРЕВ" || term == "ПЕРЕВОД") { Pullenti.Ner.Token tt = t; if (tt.Next != null && tt.Next.IsChar('.')) { tt = tt.Next; } if (tt.Next != null && ((tt.Next.IsValue("C", null) || tt.Next.IsValue("С", null)))) { tt = tt.Next; if (tt.Next == null || tt.WhitespacesAfterCount > 2) { return(null); } BookLinkToken re = new BookLinkToken(t, tt.Next) { Typ = BookLinkTyp.Translate }; return(re); } } if (term == "ТАМ" || term == "ТАМЖЕ") { BookLinkToken res = new BookLinkToken(t, t) { Typ = BookLinkTyp.Tamze }; if (t.Next != null && t.Next.IsValue("ЖЕ", null)) { res.EndToken = t.Next; } return(res); } if (((term == "СМ" || term == "CM" || term == "НАПР") || term == "НАПРИМЕР" || term == "SEE") || term == "ПОДРОБНЕЕ" || term == "ПОДРОБНО") { BookLinkToken res = new BookLinkToken(t, t) { Typ = BookLinkTyp.See }; for (t = t.Next; t != null; t = t.Next) { if (t.IsCharOf(".:") || t.IsValue("ALSO", null)) { res.EndToken = t; continue; } if (t.IsValue("В", null) || t.IsValue("IN", null)) { res.EndToken = t; continue; } BookLinkToken vvv = _tryParse(t, lev + 1); if (vvv != null && vvv.Typ == BookLinkTyp.See) { res.EndToken = vvv.EndToken; break; } break; } return(res); } if (term == "БОЛЕЕ") { BookLinkToken vvv = _tryParse(t.Next, lev + 1); if (vvv != null && vvv.Typ == BookLinkTyp.See) { vvv.BeginToken = t; return(vvv); } } Pullenti.Ner.Token no = Pullenti.Ner.Core.MiscHelper.CheckNumberPrefix(t); if (no is Pullenti.Ner.NumberToken) { return new BookLinkToken(t, no) { Typ = BookLinkTyp.N } } ; if (((term == "B" || term == "В")) && (t.Next is Pullenti.Ner.NumberToken) && (t.Next.Next is Pullenti.Ner.TextToken)) { string term2 = (t.Next.Next as Pullenti.Ner.TextToken).Term; if (((term2 == "Т" || term2 == "T" || term2.StartsWith("ТОМ")) || term2 == "TT" || term2 == "ТТ") || term2 == "КН" || term2.StartsWith("КНИГ")) { return new BookLinkToken(t, t.Next.Next) { Typ = BookLinkTyp.Volume } } ; } } if (t.IsChar('(')) { if (((t.Next is Pullenti.Ner.NumberToken) && (t.Next as Pullenti.Ner.NumberToken).IntValue != null && t.Next.Next != null) && t.Next.Next.IsChar(')')) { int num = (t.Next as Pullenti.Ner.NumberToken).IntValue.Value; if (num > 1900 && num <= 2040) { if (num <= DateTime.Now.Year) { return new BookLinkToken(t, t.Next.Next) { Typ = BookLinkTyp.Year, Value = num.ToString() } } ; } } if (((t.Next is Pullenti.Ner.ReferentToken) && (t.Next.GetReferent() is Pullenti.Ner.Date.DateReferent) && t.Next.Next != null) && t.Next.Next.IsChar(')')) { int num = (t.Next.GetReferent() as Pullenti.Ner.Date.DateReferent).Year; if (num > 0) { return new BookLinkToken(t, t.Next.Next) { Typ = BookLinkTyp.Year, Value = num.ToString() } } ; } } return(null); }
public static bool CanBeHigher(Pullenti.Ner.Org.OrganizationReferent higher, Pullenti.Ner.Org.OrganizationReferent lower, bool robust = false) { if (higher == null || lower == null || higher == lower) { return(false); } if (lower.Owner != null) { return(false); } Pullenti.Ner.Org.OrganizationKind hk = higher.Kind; Pullenti.Ner.Org.OrganizationKind lk = lower.Kind; if (higher.CanBeEquals(lower, Pullenti.Ner.Core.ReferentsEqualType.WithinOneText)) { return(false); } if (lower.Higher == null && lower.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_HIGHER, null, true) != null) { return(false); } ICollection <string> hTyps = (ICollection <string>)higher.Types; ICollection <string> lTyps = (ICollection <string>)lower.Types; if (hk != Pullenti.Ner.Org.OrganizationKind.Bank) { foreach (string v in hTyps) { if (lTyps.Contains(v)) { return(false); } } } if (hk != Pullenti.Ner.Org.OrganizationKind.Department && lk == Pullenti.Ner.Org.OrganizationKind.Department) { if (_Contains(lTyps, "курс", null) || _Contains(lTyps, "группа", "група")) { return(hk == Pullenti.Ner.Org.OrganizationKind.Study || _Contains(hTyps, "институт", "інститут")); } if (_Contains(lTyps, "епархия", "єпархія") || _Contains(lTyps, "патриархия", "патріархія")) { return(hk == Pullenti.Ner.Org.OrganizationKind.Church); } if (hk == Pullenti.Ner.Org.OrganizationKind.Undefined) { if (_Contains(hTyps, "управление", "управління")) { return(false); } } return(true); } if (lower.ContainsProfile(Pullenti.Ner.Org.OrgProfile.Unit) || _Contains(lTyps, "department", null)) { if (!higher.ContainsProfile(Pullenti.Ner.Org.OrgProfile.Unit) && lk != Pullenti.Ner.Org.OrganizationKind.Department) { return(true); } } if (_Contains(hTyps, "правительство", "уряд")) { if (lk == Pullenti.Ner.Org.OrganizationKind.Govenment) { return((((lTyps.Contains("агентство") || lTyps.Contains("федеральная служба") || lTyps.Contains("федеральна служба")) || lTyps.Contains("департамент") || lTyps.Contains("комиссия")) || lTyps.Contains("комитет") || lTyps.Contains("комісія")) || lTyps.Contains("комітет")); } } if (hk == Pullenti.Ner.Org.OrganizationKind.Govenment) { if (lk == Pullenti.Ner.Org.OrganizationKind.Govenment) { if (_Contains(lTyps, "комиссия", "комісія") || _Contains(lTyps, "инспекция", "інспекція") || _Contains(lTyps, "комитет", "комітет")) { if ((!_Contains(hTyps, "комиссия", "комісія") && !_Contains(hTyps, "инспекция", "інспекція") && !_Contains(lTyps, "государственный комитет", null)) && !_Contains(hTyps, "комитет", "комітет") && ((!_Contains(hTyps, "совет", "рада") || higher.ToString().Contains("Верховн")))) { return(true); } } if (higher.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, "ФЕДЕРАЛЬНОЕ СОБРАНИЕ", true) != null || hTyps.Contains("конгресс") || hTyps.Contains("парламент")) { if ((lower.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, "СОВЕТ ФЕДЕРАЦИИ", true) != null || lower.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, "ГОСУДАРСТВЕННАЯ ДУМА", true) != null || lower.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, "ВЕРХОВНА РАДА", true) != null) || _Contains(lTyps, "палата", null) || _Contains(lTyps, "совет", null)) { return(true); } } if (higher.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, "ФСБ", true) != null) { if (lower.FindSlot(Pullenti.Ner.Org.OrganizationReferent.ATTR_NAME, "ФПС", true) != null) { return(true); } } if (_Contains(hTyps, "государственный комитет", null)) { if ((_Contains(lTyps, "комиссия", "комісія") || _Contains(lTyps, "инспекция", "інспекція") || _Contains(lTyps, "комитет", "комітет")) || _Contains(lTyps, "департамент", null)) { return(true); } } } else if (lk == Pullenti.Ner.Org.OrganizationKind.Undefined) { if ((_Contains(lTyps, "комиссия", "комісія") || _Contains(lTyps, "инспекция", "інспекція") || _Contains(lTyps, "комитет", "комітет")) || _Contains(lTyps, "управление", "управління") || _Contains(lTyps, "служба", null)) { return(true); } } else if (lk == Pullenti.Ner.Org.OrganizationKind.Bank) { } } if (_Contains(hTyps, "министерство", "міністерство")) { if ((((((_Contains(lTyps, "институт", "інститут") || _Contains(lTyps, "университет", "університет") || _Contains(lTyps, "училище", null)) || _Contains(lTyps, "школа", null) || _Contains(lTyps, "лицей", "ліцей")) || _Contains(lTyps, "НИИ", "НДІ") || _Contains(lTyps, "Ф", null)) || _Contains(lTyps, "департамент", null) || _Contains(lTyps, "управление", "управління")) || _Contains(lTyps, "комитет", "комітет") || _Contains(lTyps, "комиссия", "комісія")) || _Contains(lTyps, "инспекция", "інспекція") || _Contains(lTyps, "центр", null)) { return(true); } if (_Contains(lTyps, "академия", "академія")) { } if (_Contains(lTyps, "служба", null) && !_Contains(lTyps, "федеральная служба", "федеральна служба")) { return(true); } if (lk == Pullenti.Ner.Org.OrganizationKind.Culture || lk == Pullenti.Ner.Org.OrganizationKind.Medical) { return(true); } } if (_Contains(hTyps, "академия", "академія")) { if (_Contains(lTyps, "институт", "інститут") || _Contains(lTyps, "научн", "науков") || _Contains(lTyps, "НИИ", "НДІ")) { return(true); } } if (_Contains(hTyps, "факультет", null)) { if (_Contains(lTyps, "курс", null) || _Contains(lTyps, "кафедра", null)) { return(true); } } if (_Contains(hTyps, "university", null)) { if (_Contains(lTyps, "school", null) || _Contains(lTyps, "college", null)) { return(true); } } int hr = _militaryRank(hTyps); int lr = _militaryRank(lTyps); if (hr > 0) { if (lr > 0) { return(hr < lr); } else if (hr == 3 && ((lTyps.Contains("войсковая часть") || lTyps.Contains("військова частина")))) { return(true); } } else if (hTyps.Contains("войсковая часть") || hTyps.Contains("військова частина")) { if (lr >= 6) { return(true); } } if (lr >= 6) { if (higher.ContainsProfile(Pullenti.Ner.Org.OrgProfile.Policy) || higher.ContainsProfile(Pullenti.Ner.Org.OrgProfile.Union)) { return(true); } } if (hk == Pullenti.Ner.Org.OrganizationKind.Study || _Contains(hTyps, "институт", "інститут") || _Contains(hTyps, "академия", "академія")) { if (((_Contains(lTyps, "магистратура", "магістратура") || _Contains(lTyps, "аспирантура", "аспірантура") || _Contains(lTyps, "докторантура", null)) || _Contains(lTyps, "факультет", null) || _Contains(lTyps, "кафедра", null)) || _Contains(lTyps, "курс", null)) { return(true); } } if (hk != Pullenti.Ner.Org.OrganizationKind.Department) { if (((((_Contains(lTyps, "департамент", null) || _Contains(lTyps, "центр", null))) && hk != Pullenti.Ner.Org.OrganizationKind.Medical && hk != Pullenti.Ner.Org.OrganizationKind.Science) && !_Contains(hTyps, "центр", null) && !_Contains(hTyps, "департамент", null)) && !_Contains(hTyps, "управление", "управління")) { return(true); } if (_Contains(hTyps, "департамент", null) || robust) { if (_Contains(lTyps, "центр", null)) { return(true); } if (lk == Pullenti.Ner.Org.OrganizationKind.Study) { return(true); } } if (_Contains(hTyps, "служба", null) || _Contains(hTyps, "штаб", null)) { if (_Contains(lTyps, "управление", "управління")) { return(true); } } if (hk == Pullenti.Ner.Org.OrganizationKind.Bank) { if (_Contains(lTyps, "управление", "управління") || _Contains(lTyps, "департамент", null)) { return(true); } } if (hk == Pullenti.Ner.Org.OrganizationKind.Party || hk == Pullenti.Ner.Org.OrganizationKind.Federation) { if (_Contains(lTyps, "комитет", "комітет")) { return(true); } } if ((lk == Pullenti.Ner.Org.OrganizationKind.Federation && hk != Pullenti.Ner.Org.OrganizationKind.Federation && hk != Pullenti.Ner.Org.OrganizationKind.Govenment) && hk != Pullenti.Ner.Org.OrganizationKind.Party) { if (!_Contains(hTyps, "фонд", null) && hk != Pullenti.Ner.Org.OrganizationKind.Undefined) { return(true); } } } else if (_Contains(hTyps, "управление", "управління") || _Contains(hTyps, "департамент", null)) { if (!_Contains(lTyps, "управление", "управління") && !_Contains(lTyps, "департамент", null) && lk == Pullenti.Ner.Org.OrganizationKind.Department) { return(true); } if (_Contains(hTyps, "главное", "головне") && _Contains(hTyps, "управление", "управління")) { if (_Contains(lTyps, "департамент", null)) { return(true); } if (_Contains(lTyps, "управление", "управління")) { if (!lTyps.Contains("главное управление") && !lTyps.Contains("головне управління") && !lTyps.Contains("пограничное управление")) { return(true); } } } if (_Contains(hTyps, "управление", "управління") && _Contains(lTyps, "центр", null)) { return(true); } if (_Contains(hTyps, "департамент", null) && _Contains(lTyps, "управление", "управління")) { return(true); } } else if ((lk == Pullenti.Ner.Org.OrganizationKind.Govenment && _Contains(lTyps, "служба", null) && higher.Higher != null) && higher.Higher.Kind == Pullenti.Ner.Org.OrganizationKind.Govenment) { return(true); } else if (_Contains(hTyps, "отдел", "відділ") && lk == Pullenti.Ner.Org.OrganizationKind.Department && ((_Contains(lTyps, "стол", "стіл") || _Contains(lTyps, "направление", "напрямок") || _Contains(lTyps, "отделение", "відділ")))) { return(true); } if (hk == Pullenti.Ner.Org.OrganizationKind.Bank) { if (higher.Names.Contains("СБЕРЕГАТЕЛЬНЫЙ БАНК")) { if (lk == Pullenti.Ner.Org.OrganizationKind.Bank && !lower.Names.Contains("СБЕРЕГАТЕЛЬНЫЙ БАНК")) { return(true); } } } if (lk == Pullenti.Ner.Org.OrganizationKind.Medical) { if (hTyps.Contains("департамент")) { return(true); } } if (lk == Pullenti.Ner.Org.OrganizationKind.Department) { if (hk == Pullenti.Ner.Org.OrganizationKind.Department && higher.Higher != null && hTyps.Count == 0) { if (CanBeHigher(higher.Higher, lower, false)) { if (_Contains(lTyps, "управление", "управління") || _Contains(lTyps, "отдел", "відділ")) { return(true); } } } if (_Contains(lTyps, "офис", "офіс")) { if (_Contains(hTyps, "филиал", "філіал") || _Contains(hTyps, "отделение", "відділення")) { return(true); } } } if (_Contains(lTyps, "управление", "управління") || _Contains(lTyps, "отдел", "відділ")) { string str = higher.ToString(true, null, 0); if (str.StartsWith("ГУ", StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }