public override void MergeSlots(Pullenti.Ner.Referent obj, bool mergeStatistic = true) { base.MergeSlots(obj, mergeStatistic); for (int i = 0; i < (Slots.Count - 1); i++) { for (int j = i + 1; j < Slots.Count; j++) { if (Slots[i].TypeName == Slots[j].TypeName && Slots[i].Value == Slots[j].Value) { Slots.RemoveAt(j); j--; } } } List <string> nums = this.GetStringValues(ATTR_NUMBER); if (nums.Count > 1) { nums.Sort(); for (int i = 0; i < (nums.Count - 1); i++) { if (nums[i + 1].StartsWith(nums[i]) && nums[i + 1].Length > nums[i].Length && !char.IsDigit(nums[i + 1][nums[i].Length])) { Pullenti.Ner.Slot s = this.FindSlot(ATTR_NUMBER, nums[i], true); if (s != null) { Slots.Remove(s); } nums.RemoveAt(i); i--; } } } }
internal void AddNameStr(string name) { if (name == null || name.Length == 0) { return; } if (name[name.Length - 1] == '.') { if (name.Length > 5 && char.IsLetter(name[name.Length - 2]) && !char.IsLetter(name[name.Length - 3])) { } else { name = name.Substring(0, name.Length - 1); } } name = name.Trim(); string uname = name.ToUpper(); Pullenti.Ner.Slot s = this.AddSlot(ATTR_NAME, uname, false, 0); if (uname != name) { s.Tag = name; } }
public override void MergeSlots(Pullenti.Ner.Referent obj, bool mergeStatistic = true) { string nam = Name; string nam1 = (obj as PersonPropertyReferent).Name; base.MergeSlots(obj, mergeStatistic); if (nam != nam1 && nam1 != null && nam != null) { Pullenti.Ner.Slot s = null; if (nam.StartsWith(nam1)) { s = this.FindSlot(ATTR_NAME, nam1, true); } else if (nam1.StartsWith(nam)) { s = this.FindSlot(ATTR_NAME, nam, true); } else if (m_Bosses0.Contains(nam) && m_Bosses1.Contains(nam1)) { s = this.FindSlot(ATTR_NAME, nam, true); } else if (m_Bosses0.Contains(nam1) && m_Bosses1.Contains(nam)) { s = this.FindSlot(ATTR_NAME, nam1, true); } if (s != null) { Slots.Remove(s); } } }
public static DecreePartReferent CreateRangeReferent(DecreePartReferent min, DecreePartReferent max) { DecreePartReferent res = min.Clone() as DecreePartReferent; int cou = 0; foreach (Pullenti.Ner.Slot s in res.Slots) { Pullenti.Ner.Slot ss = max.FindSlot(s.TypeName, null, true); if (ss == null) { return(null); } if (ss.Value == s.Value) { continue; } if (max.FindSlot(s.TypeName, s.Value, true) != null) { continue; } if ((++cou) > 1) { return(null); } res.UploadSlot(s, string.Format("{0}-{1}", s.Value, ss.Value)); } if (cou != 1) { return(null); } return(res); }
internal void AddName(DecreeReferent dr) { Pullenti.Ner.Slot s = dr.FindSlot(ATTR_NAME, null, true); if (s == null) { return; } Pullenti.Ner.Slot ss = this.AddSlot(ATTR_NAME, s.Value, false, 0); if (ss != null && ss.Tag == null) { ss.Tag = s.Tag; } }
public override Pullenti.Ner.Slot AddSlot(string attrName, object attrValue, bool clearOldValue, int statCount = 0) { if (attrValue is Pullenti.Ner.Decree.Internal.PartToken.PartValue) { attrValue = (attrValue as Pullenti.Ner.Decree.Internal.PartToken.PartValue).Value; } Pullenti.Ner.Slot s = base.AddSlot(attrName, attrValue, clearOldValue, statCount); if (attrValue is Pullenti.Ner.Decree.Internal.PartToken.PartValue) { s.Tag = (attrValue as Pullenti.Ner.Decree.Internal.PartToken.PartValue).SourceValue; } return(s); }
bool _CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ, bool ignoreGeo) { DecreeReferent dr = obj as DecreeReferent; if (dr == null) { return(false); } if (dr.Typ0 != null && Typ0 != null) { if (dr.Typ0 != Typ0) { return(false); } } int numEq = 0; if (Number != null || dr.Number != null) { if (Number != null && dr.Number != null) { List <string> di1 = this._allNumberDigits(); List <string> di2 = dr._allNumberDigits(); foreach (string d1 in di1) { if (di2.Contains(d1)) { numEq = 1; break; } } if (numEq == 0 && !IsLaw) { return(false); } foreach (Pullenti.Ner.Slot s in Slots) { if (s.TypeName == ATTR_NUMBER) { if (dr.FindSlot(s.TypeName, s.Value, true) != null) { numEq = 2; break; } } } if (numEq == 0) { return(false); } } } if (CaseNumber != null && dr.CaseNumber != null) { if (CaseNumber != dr.CaseNumber) { return(false); } } if (this.FindSlot(ATTR_GEO, null, true) != null && dr.FindSlot(ATTR_GEO, null, true) != null) { if (this.GetStringValue(ATTR_GEO) != dr.GetStringValue(ATTR_GEO)) { return(false); } } bool srcEq = false; bool srcNotEq = false; Pullenti.Ner.Slot src = this.FindSlot(ATTR_SOURCE, null, true); if (src != null && dr.FindSlot(ATTR_SOURCE, null, true) != null) { if (dr.FindSlot(src.TypeName, src.Value, true) == null) { srcNotEq = true; } else { srcEq = true; } } bool dateNotEq = false; bool dateIsEqu = false; bool yearsIsEqu = false; string date1 = this.GetStringValue(ATTR_DATE); string date2 = dr.GetStringValue(ATTR_DATE); if (date1 != null || date2 != null) { if (IsLaw) { List <int> ys1 = this._allYears(); List <int> ys2 = dr._allYears(); foreach (int y1 in ys1) { if (ys2.Contains(y1)) { yearsIsEqu = true; break; } } if (yearsIsEqu) { List <DateTime> dts1 = this._allDates(); List <DateTime> dts2 = dr._allDates(); foreach (DateTime d1 in dts1) { if (dts2.Contains(d1)) { dateIsEqu = true; break; } } } if (!dateIsEqu) { if (Typ == "КОНСТИТУЦИЯ") { return(false); } if (Date != null && dr.Date != null) { dateNotEq = true; } } } else if (date1 == date2 || ((Date != null && dr.Date != null && Date == dr.Date))) { if (numEq > 1) { return(true); } dateIsEqu = true; } else if (Date != null && dr.Date != null) { if (Date.Value.Year != dr.Date.Value.Year) { return(false); } if (numEq >= 1) { if (srcEq) { return(true); } if (srcNotEq) { return(false); } } else { return(false); } } else if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts || Kind == DecreeKind.Publisher) { dateNotEq = true; } } if (this.FindSlot(ATTR_NAME, null, true) != null && dr.FindSlot(ATTR_NAME, null, true) != null) { foreach (Pullenti.Ner.Slot s in Slots) { if (s.TypeName == ATTR_NAME) { if (dr.FindSlot(s.TypeName, s.Value, true) != null) { return(true); } foreach (Pullenti.Ner.Slot ss in dr.Slots) { if (ss.TypeName == s.TypeName) { string n0 = s.Value.ToString(); string n1 = ss.Value.ToString(); if (n0.StartsWith(n1) || n1.StartsWith(n0)) { return(true); } } } } } if (dateNotEq) { return(false); } if (IsLaw && !dateIsEqu) { return(false); } if (numEq > 0) { if (srcEq) { return(true); } if (srcNotEq && typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts) { return(false); } else if ((!srcNotEq && numEq > 1 && Date == null) && dr.Date == null) { return(true); } return(false); } } else if (IsLaw && dateNotEq) { return(false); } if (dateNotEq) { return(false); } string ty = Typ; if (ty == null) { return(numEq > 0); } DecreeKind t = Pullenti.Ner.Decree.Internal.DecreeToken.GetKind(ty); if (t == DecreeKind.Ustav || ty == "КОНСТИТУЦИЯ") { return(true); } if (numEq > 0) { return(true); } if (this.ToString() == obj.ToString()) { return(true); } return(false); }
internal void Correct() { List <Pullenti.Ner.Geo.GeoReferent> geos = new List <Pullenti.Ner.Geo.GeoReferent>(); foreach (Pullenti.Ner.Slot a in Slots) { if (a.TypeName == ATTR_GEO && (a.Value is Pullenti.Ner.Geo.GeoReferent)) { geos.Add(a.Value as Pullenti.Ner.Geo.GeoReferent); } else if (a.TypeName == ATTR_STREET && (a.Value is Pullenti.Ner.Referent)) { foreach (Pullenti.Ner.Slot s in (a.Value as Pullenti.Ner.Referent).Slots) { if (s.Value is Pullenti.Ner.Geo.GeoReferent) { geos.Add(s.Value as Pullenti.Ner.Geo.GeoReferent); } } } } for (int i = geos.Count - 1; i > 0; i--) { for (int j = i - 1; j >= 0; j--) { if (_isHigher(geos[i], geos[j])) { Pullenti.Ner.Slot s = this.FindSlot(ATTR_GEO, geos[i], true); if (s != null) { Slots.Remove(s); } geos.RemoveAt(i); break; } else if (_isHigher(geos[j], geos[i])) { Pullenti.Ner.Slot s = this.FindSlot(ATTR_GEO, geos[j], true); if (s != null) { Slots.Remove(s); } geos.RemoveAt(j); i--; } } } if (geos.Count == 2) { Pullenti.Ner.Geo.GeoReferent reg = null; Pullenti.Ner.Geo.GeoReferent cit = null; for (int ii = 0; ii < geos.Count; ii++) { if (geos[ii].IsTerritory && geos[ii].Higher != null) { geos[ii] = geos[ii].Higher; } } if (geos[0].IsCity && geos[1].IsRegion) { cit = geos[0]; reg = geos[1]; } else if (geos[1].IsCity && geos[0].IsRegion) { cit = geos[1]; reg = geos[0]; } if (cit != null && cit.Higher == null && Pullenti.Ner.Geo.Internal.GeoOwnerHelper.CanBeHigher(reg, cit)) { cit.Higher = reg; Pullenti.Ner.Slot ss = this.FindSlot(ATTR_GEO, reg, true); if (ss != null) { Slots.Remove(ss); } geos = Geos; } else { Pullenti.Ner.Geo.GeoReferent stat = null; Pullenti.Ner.Geo.GeoReferent geo = null; if (geos[0].IsState && !geos[1].IsState) { stat = geos[0]; geo = geos[1]; } else if (geos[1].IsState && !geos[0].IsState) { stat = geos[1]; geo = geos[0]; } if (stat != null) { geo = geo.TopHigher; if (geo.Higher == null) { geo.Higher = stat; Pullenti.Ner.Slot s = this.FindSlot(ATTR_GEO, stat, true); if (s != null) { Slots.Remove(s); } } } } } }
internal void MergeSlots2(Pullenti.Ner.Referent obj, Pullenti.Morph.MorphLang lang) { bool mergeStatistic = true; foreach (Pullenti.Ner.Slot s in obj.Slots) { if (s.TypeName == ATTR_NAME || s.TypeName == ATTR_TYPE) { string nam = (string)s.Value; if (Pullenti.Morph.LanguageHelper.IsLatinChar(nam[0])) { if (!lang.IsEn) { continue; } } else if (lang.IsEn) { continue; } if (Pullenti.Morph.LanguageHelper.EndsWith(nam, " ССР")) { continue; } } this.AddSlot(s.TypeName, s.Value, false, (mergeStatistic ? s.Count : 0)); } if (this.FindSlot(ATTR_NAME, null, true) == null && obj.FindSlot(ATTR_NAME, null, true) != null) { foreach (Pullenti.Ner.Slot s in obj.Slots) { if (s.TypeName == ATTR_NAME) { this.AddSlot(s.TypeName, s.Value, false, (mergeStatistic ? s.Count : 0)); } } } if (this.FindSlot(ATTR_TYPE, null, true) == null && obj.FindSlot(ATTR_TYPE, null, true) != null) { foreach (Pullenti.Ner.Slot s in obj.Slots) { if (s.TypeName == ATTR_TYPE) { this.AddSlot(s.TypeName, s.Value, false, (mergeStatistic ? s.Count : 0)); } } } if (IsTerritory) { if (((Alpha2 != null || this.FindSlot(ATTR_TYPE, "государство", true) != null || this.FindSlot(ATTR_TYPE, "держава", true) != null) || this.FindSlot(ATTR_TYPE, "империя", true) != null || this.FindSlot(ATTR_TYPE, "імперія", true) != null) || this.FindSlot(ATTR_TYPE, "state", true) != null) { Pullenti.Ner.Slot s = this.FindSlot(ATTR_TYPE, "территория", true); if (s != null) { Slots.Remove(s); } } } if (IsState) { foreach (Pullenti.Ner.Slot s in Slots) { if (s.TypeName == ATTR_TYPE && ((s.Value.ToString() == "регион" || s.Value.ToString() == "регіон" || s.Value.ToString() == "region"))) { Slots.Remove(s); break; } } } if (IsCity) { Pullenti.Ner.Slot s = this.FindSlot(ATTR_TYPE, "город", true) ?? this.FindSlot(ATTR_TYPE, "місто", true) ?? this.FindSlot(ATTR_TYPE, "city", true); if (s != null) { foreach (Pullenti.Ner.Slot ss in Slots) { if (ss.TypeName == ATTR_TYPE && ss != s && _isCity((string)ss.Value)) { Slots.Remove(s); break; } } } } bool has = false; for (int i = 0; i < Slots.Count; i++) { if (Slots[i].TypeName == ATTR_HIGHER) { if (!has) { has = true; } else { Slots.RemoveAt(i); i--; } } } this._mergeExtReferents(obj); }
public override void UploadSlot(Pullenti.Ner.Slot slot, object newVal) { m_TmpBits = 0; base.UploadSlot(slot, newVal); }
public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ = Pullenti.Ner.Core.ReferentsEqualType.WithinOneText) { TransportReferent tr = obj as TransportReferent; if (tr == null) { return(false); } TransportKind k1 = Kind; TransportKind k2 = tr.Kind; if (k1 != k2) { if (k1 == TransportKind.Space && tr.FindSlot(ATTR_TYPE, "КОРАБЛЬ", true) != null) { } else if (k2 == TransportKind.Space && this.FindSlot(ATTR_TYPE, "КОРАБЛЬ", true) != null) { k1 = TransportKind.Space; } else { return(false); } } Pullenti.Ner.Slot sl = this.FindSlot(ATTR_ORG, null, true); if (sl != null && tr.FindSlot(ATTR_ORG, null, true) != null) { if (tr.FindSlot(ATTR_ORG, sl.Value, false) == null) { return(false); } } sl = this.FindSlot(ATTR_GEO, null, true); if (sl != null && tr.FindSlot(ATTR_GEO, null, true) != null) { if (tr.FindSlot(ATTR_GEO, sl.Value, true) == null) { return(false); } } string s1 = this.GetStringValue(ATTR_NUMBER); string s2 = tr.GetStringValue(ATTR_NUMBER); if (s1 != null || s2 != null) { if (s1 == null || s2 == null) { if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts) { return(false); } } else { if (s1 != s2) { return(false); } s1 = this.GetStringValue(ATTR_NUMBER_REGION); s2 = tr.GetStringValue(ATTR_NUMBER_REGION); if (s1 != null || s2 != null) { if (s1 == null || s2 == null) { if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts) { return(false); } } else if (s1 != s2) { return(false); } } } } s1 = this.GetStringValue(ATTR_BRAND); s2 = tr.GetStringValue(ATTR_BRAND); if (s1 != null || s2 != null) { if (s1 == null || s2 == null) { if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts) { return(false); } } else if (s1 != s2) { return(false); } } s1 = this.GetStringValue(ATTR_MODEL); s2 = tr.GetStringValue(ATTR_MODEL); if (s1 != null || s2 != null) { if (s1 == null || s2 == null) { if (typ == Pullenti.Ner.Core.ReferentsEqualType.DifferentTexts) { return(false); } } else if (s1 != s2) { return(false); } } foreach (Pullenti.Ner.Slot s in Slots) { if (s.TypeName == ATTR_NAME) { if (tr.FindSlot(ATTR_NAME, s.Value, true) != null) { return(true); } } } if (s1 != null && s2 != null) { return(true); } return(false); }
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); } }