static bool _processLinks(Pullenti.Semantic.SemGraph gr) { bool ret = false; for (int i = 0; i < gr.Objects.Count; i++) { Pullenti.Semantic.SemObject obj = gr.Objects[i]; for (int j = obj.LinksFrom.Count - 1; j >= 0; j--) { Pullenti.Semantic.SemLink li = obj.LinksFrom[j]; if (li.Typ != Pullenti.Semantic.SemLinkType.Pacient) { continue; } bool exi = false; foreach (Pullenti.Semantic.SemLink ll in obj.LinksFrom) { if (ll != li && ll.Typ == Pullenti.Semantic.SemLinkType.Agent && ll.Target == li.Target) { exi = true; } } if (exi) { if (obj.BeginChar > li.Target.BeginChar) { gr.RemoveLink(li); ret = true; } } } } return(ret); }
static void _optimizeTokens(Pullenti.Semantic.SemObject o) { for (int i = 0; i < o.Tokens.Count; i++) { bool ch = false; for (int j = 0; j < (o.Tokens.Count - 1); j++) { if (_compareToks(o.Tokens[j], o.Tokens[j + 1]) > 0) { Pullenti.Ner.MetaToken t = o.Tokens[j]; o.Tokens[j] = o.Tokens[j + 1]; o.Tokens[j + 1] = t; ch = true; } } if (!ch) { break; } } for (int i = 0; i < (o.Tokens.Count - 1); i++) { if (o.Tokens[i].EndToken.Next == o.Tokens[i + 1].BeginToken) { o.Tokens[i] = new Pullenti.Ner.MetaToken(o.Tokens[i].BeginToken, o.Tokens[i + 1].EndToken); o.Tokens.RemoveAt(i + 1); i--; } } }
public static bool ProcessAnafors(List <Pullenti.Semantic.SemObject> objs) { for (int i = objs.Count - 1; i >= 0; i--) { Pullenti.Semantic.SemObject it = objs[i]; if (it.Typ == Pullenti.Semantic.SemObjectType.PersonalPronoun) { } else if (it.Morph.NormalFull == "КОТОРЫЙ" && it.LinksFrom.Count == 0) { } else { continue; } List <AnaforLink> vars = new List <AnaforLink>(); for (int j = i - 1; j >= 0; j--) { AnaforLink a = AnaforLink.TryCreate(it, objs[j]); if (a == null) { continue; } vars.Add(a); a.Correct(); } if (vars.Count < 1) { continue; } AnaforLink.Sort(vars); if (vars[0].Coef <= 0.1) { continue; } if (vars[0].TargetList != null) { foreach (Pullenti.Semantic.SemObject tgt in vars[0].TargetList) { it.Graph.AddLink(Pullenti.Semantic.SemLinkType.Anafor, it, tgt, null, false, null); } } else { Pullenti.Semantic.SemLink li = it.Graph.AddLink(Pullenti.Semantic.SemLinkType.Anafor, it, vars[0].Target, null, false, null); if (vars.Count > 1 && vars[0].Coef <= (vars[1].Coef * 2) && vars[1].TargetList == null) { Pullenti.Semantic.SemLink li1 = it.Graph.AddLink(Pullenti.Semantic.SemLinkType.Anafor, it, vars[1].Target, null, false, null); li1.AltLink = li; li.AltLink = li1; } } } return(false); }
public static void _setMorph(Pullenti.Semantic.SemObject obj, Pullenti.Morph.MorphWordForm wf) { if (wf == null) { return; } obj.Morph.NormalCase = wf.NormalCase; obj.Morph.NormalFull = wf.NormalFull ?? wf.NormalCase; obj.Morph.Number = wf.Number; obj.Morph.Gender = wf.Gender; obj.Morph.Misc = wf.Misc; }
static bool _processFormulas(List <Pullenti.Semantic.SemObject> objs) { bool ret = false; for (int i = 0; i < objs.Count; i++) { Pullenti.Semantic.SemObject o = objs[i]; if (o.Typ != Pullenti.Semantic.SemObjectType.Noun || !o.IsValue("РАЗ", Pullenti.Semantic.SemObjectType.Undefined)) { continue; } if (o.Quantity == null) { continue; } if (o.LinksFrom.Count == 0 && o.LinksTo.Count == 1) { } else { continue; } Pullenti.Semantic.SemObject frm = o.LinksTo[0].Source; for (int k = 0; k < 5; k++) { bool brek = false; foreach (Pullenti.Semantic.SemLink li in frm.LinksFrom) { if (((li.Typ == Pullenti.Semantic.SemLinkType.Detail || li.Typ == Pullenti.Semantic.SemLinkType.Pacient)) && li.Target != o) { if (o.BeginChar > frm.EndChar && (o.BeginChar < li.Target.BeginChar)) { brek = true; o.Graph.AddLink(Pullenti.Semantic.SemLinkType.Detail, o, li.Target, "чего", false, null); o.Graph.RemoveLink(li); } else { frm = li.Target; } break; } } if (brek) { break; } } } return(ret); }
public static Pullenti.Semantic.SemObject CreateAdverb(Pullenti.Semantic.SemGraph gr, AdverbToken adv) { Pullenti.Semantic.SemObject res = new Pullenti.Semantic.SemObject(gr); gr.Objects.Add(res); res.Tokens.Add(adv); res.Typ = Pullenti.Semantic.SemObjectType.Adverb; res.Not = adv.Not; res.Morph.NormalCase = (res.Morph.NormalFull = adv.Spelling); List <Pullenti.Semantic.Utils.DerivateGroup> grs = Pullenti.Semantic.Utils.DerivateService.FindDerivates(res.Morph.NormalFull, true, null); if (grs != null && grs.Count > 0) { res.Concept = grs[0]; } return(res); }
static bool _collapseAnafors(Pullenti.Semantic.SemGraph gr) { bool ret = false; for (int i = 0; i < gr.Objects.Count; i++) { Pullenti.Semantic.SemObject obj = gr.Objects[i]; if (obj.Typ == Pullenti.Semantic.SemObjectType.PersonalPronoun || obj.Morph.NormalFull == "КОТОРЫЙ") { } else { continue; } if (obj.Attrs.Count > 0 || obj.Quantity != null) { continue; } if (obj.LinksFrom.Count == 1 && obj.LinksFrom[0].Typ == Pullenti.Semantic.SemLinkType.Anafor) { } else if (obj.LinksFrom.Count == 2 && obj.LinksFrom[0].Typ == Pullenti.Semantic.SemLinkType.Anafor && obj.LinksFrom[0].AltLink == obj.LinksFrom[1]) { } else { continue; } Pullenti.Semantic.SemLink alink = obj.LinksFrom[0]; foreach (Pullenti.Semantic.SemLink li in obj.LinksTo) { Pullenti.Semantic.SemLink nli = gr.AddLink(li.Typ, li.Source, alink.Target, li.Question, li.IsOr, li.Preposition); if (alink.AltLink != null) { Pullenti.Semantic.SemLink nli2 = gr.AddLink(li.Typ, li.Source, alink.AltLink.Target, li.Question, li.IsOr, li.Preposition); nli2.AltLink = nli; nli.AltLink = nli2; } } gr.RemoveObject(obj); i--; ret = true; } return(ret); }
static void _sortObjects(List <Pullenti.Semantic.SemObject> objs) { for (int i = 0; i < objs.Count; i++) { bool ch = false; for (int j = 0; j < (objs.Count - 1); j++) { if (objs[j].CompareTo(objs[j + 1]) > 0) { Pullenti.Semantic.SemObject o = objs[j]; objs[j] = objs[j + 1]; objs[j + 1] = o; ch = true; } } if (!ch) { break; } } }
public static Pullenti.Semantic.SemObject CreateNumber(Pullenti.Semantic.SemGraph gr, Pullenti.Ner.Measure.Internal.NumbersWithUnitToken num) { List <Pullenti.Ner.ReferentToken> rs = num.CreateRefenetsTokensWithRegister(null, null, false); if (rs == null || rs.Count == 0) { return(null); } Pullenti.Ner.Measure.MeasureReferent mr = rs[rs.Count - 1].Referent as Pullenti.Ner.Measure.MeasureReferent; Pullenti.Semantic.SemObject sem = new Pullenti.Semantic.SemObject(gr); gr.Objects.Add(sem); sem.Tokens.Add(num); sem.Morph.NormalFull = (sem.Morph.NormalCase = mr.ToString(true, null, 0)); sem.Typ = Pullenti.Semantic.SemObjectType.Noun; sem.Measure = mr.Kind; for (int i = 0; i < sem.Morph.NormalCase.Length; i++) { char ch = sem.Morph.NormalCase[i]; if (char.IsDigit(ch) || char.IsWhiteSpace(ch) || "[].+-".IndexOf(ch) >= 0) { continue; } sem.Quantity = new Pullenti.Semantic.SemQuantity(sem.Morph.NormalCase.Substring(0, i).Trim(), num.BeginToken, num.EndToken); sem.Morph.NormalCase = sem.Morph.NormalCase.Substring(i).Trim(); if (num.Units.Count == 1 && num.Units[0].Unit != null) { sem.Morph.NormalFull = num.Units[0].Unit.FullnameCyr; if (sem.Morph.NormalFull == "%") { sem.Morph.NormalFull = "процент"; } } break; } sem.Concept = mr; return(sem); }
public static AnaforLink TryCreate(Pullenti.Semantic.SemObject src, Pullenti.Semantic.SemObject tgt) { if (tgt.Typ != Pullenti.Semantic.SemObjectType.Noun) { return(null); } if (((src.Morph.Number & Pullenti.Morph.MorphNumber.Plural)) == Pullenti.Morph.MorphNumber.Plural) { if (((tgt.Morph.Number & Pullenti.Morph.MorphNumber.Plural)) != Pullenti.Morph.MorphNumber.Undefined) { return new AnaforLink() { Coef = 1, Target = tgt } } ; AnaforLink res = new AnaforLink() { Coef = 0.5, Target = tgt }; res.TargetList = new List <Pullenti.Semantic.SemObject>(); foreach (Pullenti.Semantic.SemLink li in tgt.LinksTo) { Pullenti.Semantic.SemObject frm = li.Source; for (int i = 0; i < frm.LinksFrom.Count; i++) { res.TargetList.Clear(); Pullenti.Semantic.SemLink li0 = frm.LinksFrom[i]; if (li0.Target.Typ != Pullenti.Semantic.SemObjectType.Noun) { continue; } res.TargetList.Add(li0.Target); for (int j = i + 1; j < frm.LinksFrom.Count; j++) { Pullenti.Semantic.SemLink li1 = frm.LinksFrom[j]; if (li1.Typ == li0.Typ && li1.Preposition == li0.Preposition && li1.Target.Typ == li0.Target.Typ) { res.TargetList.Add(li1.Target); } } if (res.TargetList.Count > 1) { return(res); } } } return(null); } if (tgt.Morph.Number != Pullenti.Morph.MorphNumber.Undefined && ((tgt.Morph.Number & Pullenti.Morph.MorphNumber.Singular)) == Pullenti.Morph.MorphNumber.Undefined) { return(null); } if (tgt.Morph.Gender != Pullenti.Morph.MorphGender.Undefined) { if (((tgt.Morph.Gender & src.Morph.Gender)) == Pullenti.Morph.MorphGender.Undefined) { return(null); } return(new AnaforLink() { Coef = 1, Target = tgt }); } return(new AnaforLink() { Coef = 0.1, Target = tgt }); }
public static Pullenti.Semantic.SemObject CreateNounGroup(Pullenti.Semantic.SemGraph gr, Pullenti.Ner.Core.NounPhraseToken npt) { Pullenti.Ner.Token noun = npt.Noun.BeginToken; Pullenti.Semantic.SemObject sem = new Pullenti.Semantic.SemObject(gr); sem.Tokens.Add(npt.Noun); sem.Typ = Pullenti.Semantic.SemObjectType.Noun; if (npt.Noun.Morph.Class.IsPersonalPronoun) { sem.Typ = Pullenti.Semantic.SemObjectType.PersonalPronoun; } else if (npt.Noun.Morph.Class.IsPronoun) { sem.Typ = Pullenti.Semantic.SemObjectType.Pronoun; } if (npt.Noun.BeginToken != npt.Noun.EndToken) { sem.Morph.NormalCase = npt.Noun.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false); sem.Morph.NormalFull = npt.Noun.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false); sem.Morph.Class = Pullenti.Morph.MorphClass.Noun; sem.Morph.Number = npt.Morph.Number; sem.Morph.Gender = npt.Morph.Gender; sem.Morph.Case = npt.Morph.Case; } else if (noun is Pullenti.Ner.TextToken) { foreach (Pullenti.Morph.MorphBaseInfo wf in noun.Morph.Items) { if (wf.CheckAccord(npt.Morph, false, false) && (wf is Pullenti.Morph.MorphWordForm)) { _setMorph(sem, wf as Pullenti.Morph.MorphWordForm); break; } } if (sem.Morph.NormalCase == null) { sem.Morph.NormalCase = noun.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false); sem.Morph.NormalFull = noun.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false); } List <Pullenti.Semantic.Utils.DerivateGroup> grs = Pullenti.Semantic.Utils.DerivateService.FindDerivates(sem.Morph.NormalFull, true, null); if (grs != null && grs.Count > 0) { sem.Concept = grs[0]; } } else if (noun is Pullenti.Ner.ReferentToken) { Pullenti.Ner.Referent r = (noun as Pullenti.Ner.ReferentToken).Referent; if (r == null) { return(null); } sem.Morph.NormalFull = (sem.Morph.NormalCase = r.ToString()); sem.Concept = r; } else if (noun is Pullenti.Ner.NumberToken) { Pullenti.Ner.NumberToken num = noun as Pullenti.Ner.NumberToken; sem.Morph.Gender = noun.Morph.Gender; sem.Morph.Number = noun.Morph.Number; if (num.IntValue != null) { sem.Morph.NormalCase = Pullenti.Ner.Core.NumberHelper.GetNumberAdjective(num.IntValue.Value, noun.Morph.Gender, noun.Morph.Number); sem.Morph.NormalFull = Pullenti.Ner.Core.NumberHelper.GetNumberAdjective(num.IntValue.Value, Pullenti.Morph.MorphGender.Masculine, Pullenti.Morph.MorphNumber.Singular); } else { sem.Morph.NormalFull = (sem.Morph.NormalCase = noun.GetSourceText().ToUpper()); } } noun.Tag = sem; if (npt.Adjectives.Count > 0) { foreach (Pullenti.Ner.MetaToken a in npt.Adjectives) { if (npt.MultiNouns && a != npt.Adjectives[0]) { break; } Pullenti.Semantic.SemObject asem = CreateNptAdj(gr, npt, a); if (asem != null) { gr.AddLink(Pullenti.Semantic.SemLinkType.Detail, sem, asem, "какой", false, null); } } } if (npt.InternalNoun != null) { Pullenti.Semantic.SemObject intsem = CreateNounGroup(gr, npt.InternalNoun); if (intsem != null) { gr.AddLink(Pullenti.Semantic.SemLinkType.Detail, sem, intsem, null, false, null); } } gr.Objects.Add(sem); return(sem); }
public static void _setMorph0(Pullenti.Semantic.SemObject obj, Pullenti.Morph.MorphBaseInfo bi) { obj.Morph.Number = bi.Number; obj.Morph.Gender = bi.Gender; }
public static Pullenti.Semantic.SemObject CreateVerbGroup(Pullenti.Semantic.SemGraph gr, Pullenti.Ner.Core.VerbPhraseToken vpt) { List <Pullenti.Semantic.SemObject> sems = new List <Pullenti.Semantic.SemObject>(); List <Pullenti.Semantic.SemAttribute> attrs = new List <Pullenti.Semantic.SemAttribute>(); List <Pullenti.Semantic.SemObject> adverbs = new List <Pullenti.Semantic.SemObject>(); for (int i = 0; i < vpt.Items.Count; i++) { Pullenti.Ner.Core.VerbPhraseItemToken v = vpt.Items[i]; if (v.IsAdverb) { AdverbToken adv = AdverbToken.TryParse(v.BeginToken); if (adv == null) { continue; } if (adv.Typ != Pullenti.Semantic.SemAttributeType.Undefined) { attrs.Add(new Pullenti.Semantic.SemAttribute() { Not = adv.Not, Typ = adv.Typ, Spelling = adv.Spelling }); continue; } Pullenti.Semantic.SemObject adverb = CreateAdverb(gr, adv); if (attrs.Count > 0) { adverb.Attrs.AddRange(attrs); attrs.Clear(); } adverbs.Add(adverb); continue; } if (v.Normal == "БЫТЬ") { int j; for (j = i + 1; j < vpt.Items.Count; j++) { if (!vpt.Items[j].IsAdverb) { break; } } if (j < vpt.Items.Count) { continue; } } Pullenti.Semantic.SemObject sem = new Pullenti.Semantic.SemObject(gr); gr.Objects.Add(sem); sem.Tokens.Add(v); v.Tag = sem; _setMorph(sem, v.VerbMorph); sem.Morph.NormalCase = (sem.Morph.NormalFull = v.Normal); if (v.IsParticiple || v.IsDeeParticiple) { sem.Typ = Pullenti.Semantic.SemObjectType.Participle; sem.Morph.NormalFull = v.EndToken.GetNormalCaseText(Pullenti.Morph.MorphClass.Verb, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false) ?? sem.Morph.NormalCase; sem.Morph.NormalCase = v.EndToken.GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false); if (sem.Morph.NormalCase == sem.Morph.NormalFull && v.Normal.EndsWith("Й")) { List <Pullenti.Semantic.Utils.DerivateGroup> grs2 = Pullenti.Semantic.Utils.DerivateService.FindDerivates(v.Normal, true, null); if (grs2 != null) { foreach (Pullenti.Semantic.Utils.DerivateGroup g in grs2) { foreach (Pullenti.Semantic.Utils.DerivateWord w in g.Words) { if (w.Lang == v.EndToken.Morph.Language && w.Class.IsVerb && !w.Class.IsAdjective) { sem.Morph.NormalFull = w.Spelling; break; } } } } } else if (sem.Morph.NormalCase == sem.Morph.NormalFull && v.IsParticiple && sem.Morph.NormalFull.EndsWith("Ь")) { foreach (Pullenti.Morph.MorphBaseInfo it in v.EndToken.Morph.Items) { Pullenti.Morph.MorphWordForm wf = it as Pullenti.Morph.MorphWordForm; if (wf == null) { continue; } if (wf.NormalCase.EndsWith("Й") || ((wf.NormalFull != null && wf.NormalFull.EndsWith("Й")))) { sem.Morph.NormalCase = wf.NormalFull ?? wf.NormalCase; break; } } if (sem.Morph.NormalCase == sem.Morph.NormalFull) { List <Pullenti.Semantic.Utils.DerivateGroup> grs2 = Pullenti.Semantic.Utils.DerivateService.FindDerivates(sem.Morph.NormalCase, true, null); if (grs2 != null) { foreach (Pullenti.Semantic.Utils.DerivateGroup g in grs2) { foreach (Pullenti.Semantic.Utils.DerivateWord w in g.Words) { if (w.Lang == v.EndToken.Morph.Language && w.Class.IsVerb && w.Class.IsAdjective) { sem.Morph.NormalCase = w.Spelling; break; } } break; } } } } } else { sem.Typ = Pullenti.Semantic.SemObjectType.Verb; } if (v.VerbMorph != null && v.VerbMorph.ContainsAttr("возвр.", null)) { if (sem.Morph.NormalFull.EndsWith("СЯ") || sem.Morph.NormalFull.EndsWith("СЬ")) { sem.Morph.NormalFull = sem.Morph.NormalFull.Substring(0, sem.Morph.NormalFull.Length - 2); } } List <Pullenti.Semantic.Utils.DerivateGroup> grs = Pullenti.Semantic.Utils.DerivateService.FindDerivates(sem.Morph.NormalFull, true, null); if (grs != null && grs.Count > 0) { sem.Concept = grs[0]; if (v.VerbMorph != null && v.VerbMorph.Misc.Aspect == Pullenti.Morph.MorphAspect.Imperfective) { foreach (Pullenti.Semantic.Utils.DerivateWord w in grs[0].Words) { if (w.Class.IsVerb && !w.Class.IsAdjective) { if (w.Aspect == Pullenti.Morph.MorphAspect.Perfective) { sem.Morph.NormalFull = w.Spelling; break; } } } } } sem.Not = v.Not; sems.Add(sem); if (attrs.Count > 0) { sem.Attrs.AddRange(attrs); attrs.Clear(); } if (adverbs.Count > 0) { foreach (Pullenti.Semantic.SemObject a in adverbs) { gr.AddLink(Pullenti.Semantic.SemLinkType.Detail, sem, a, "как", false, null); } } adverbs.Clear(); } if (sems.Count == 0) { return(null); } if (attrs.Count > 0) { sems[sems.Count - 1].Attrs.AddRange(attrs); } if (adverbs.Count > 0) { Pullenti.Semantic.SemObject sem = sems[sems.Count - 1]; foreach (Pullenti.Semantic.SemObject a in adverbs) { gr.AddLink(Pullenti.Semantic.SemLinkType.Detail, sem, a, "как", false, null); } } for (int i = sems.Count - 1; i > 0; i--) { gr.AddLink(Pullenti.Semantic.SemLinkType.Detail, sems[i - 1], sems[i], "что делать", false, null); } return(sems[0]); }
public static Pullenti.Semantic.SemObject CreateNptAdj(Pullenti.Semantic.SemGraph gr, Pullenti.Ner.Core.NounPhraseToken npt, Pullenti.Ner.MetaToken a) { if (a.Morph.Class.IsPronoun) { Pullenti.Semantic.SemObject asem = new Pullenti.Semantic.SemObject(gr); gr.Objects.Add(asem); asem.Tokens.Add(a); asem.Typ = (a.BeginToken.Morph.Class.IsPersonalPronoun ? Pullenti.Semantic.SemObjectType.PersonalPronoun : Pullenti.Semantic.SemObjectType.Pronoun); foreach (Pullenti.Morph.MorphBaseInfo it in a.BeginToken.Morph.Items) { Pullenti.Morph.MorphWordForm wf = it as Pullenti.Morph.MorphWordForm; if (wf == null) { continue; } if (!npt.Morph.Case.IsUndefined) { if (((npt.Morph.Case & wf.Case)).IsUndefined) { continue; } } _setMorph(asem, wf); if (asem.Morph.NormalFull == "КАКОВ") { asem.Morph.NormalFull = "КАКОЙ"; } break; } if (asem.Morph.NormalFull == null) { asem.Morph.NormalFull = (asem.Morph.NormalCase = a.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false)); } return(asem); } if (!a.Morph.Class.IsVerb) { Pullenti.Semantic.SemObject asem = new Pullenti.Semantic.SemObject(gr); gr.Objects.Add(asem); asem.Tokens.Add(a); asem.Typ = Pullenti.Semantic.SemObjectType.Adjective; foreach (Pullenti.Morph.MorphBaseInfo wf in a.BeginToken.Morph.Items) { if (wf.CheckAccord(npt.Morph, false, false) && wf.Class.IsAdjective && (wf is Pullenti.Morph.MorphWordForm)) { _setMorph(asem, wf as Pullenti.Morph.MorphWordForm); break; } } if (asem.Morph.NormalCase == null) { asem.Morph.NormalCase = a.GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false); asem.Morph.NormalFull = a.GetNormalCaseText(Pullenti.Morph.MorphClass.Adjective, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Masculine, false); _setMorph0(asem, a.BeginToken.Morph); } List <Pullenti.Semantic.Utils.DerivateGroup> grs = Pullenti.Semantic.Utils.DerivateService.FindDerivates(asem.Morph.NormalFull, true, null); if (grs != null && grs.Count > 0) { asem.Concept = grs[0]; } return(asem); } return(null); }
static bool _processPointers(List <Pullenti.Semantic.SemObject> objs) { bool ret = false; for (int i = 0; i < objs.Count; i++) { Pullenti.Semantic.SemObject o = objs[i]; if (o.Typ != Pullenti.Semantic.SemObjectType.Noun) { continue; } if (o.Quantity != null && o.Quantity.Spelling == "1") { } else { continue; } if (o.LinksFrom.Count > 0) { continue; } bool ok = false; for (int j = i - 1; j >= 0; j--) { Pullenti.Semantic.SemObject oo = objs[j]; if (oo.Typ != Pullenti.Semantic.SemObjectType.Noun) { continue; } if (oo.Morph.NormalFull != o.Morph.NormalFull) { continue; } if (oo.Quantity != null && oo.Quantity.Spelling != "1") { ok = true; break; } } if (!ok) { for (int j = i + 1; j < objs.Count; j++) { Pullenti.Semantic.SemObject oo = objs[j]; if (oo.Typ != Pullenti.Semantic.SemObjectType.Noun) { continue; } if (oo.Morph.NormalFull != o.Morph.NormalFull) { continue; } if (oo.FindFromObject("ДРУГОЙ", Pullenti.Semantic.SemLinkType.Undefined, Pullenti.Semantic.SemObjectType.Undefined) != null || oo.FindFromObject("ВТОРОЙ", Pullenti.Semantic.SemLinkType.Undefined, Pullenti.Semantic.SemObjectType.Undefined) != null) { ok = true; break; } } } if (!ok) { continue; } Pullenti.Semantic.SemObject first = new Pullenti.Semantic.SemObject(o.Graph) { Typ = Pullenti.Semantic.SemObjectType.Adjective }; first.Tokens.Add(o.Tokens[0]); first.Morph.NormalFull = "ПЕРВЫЙ"; first.Morph.NormalCase = (((o.Morph.Gender & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined ? "ПЕРВАЯ" : (((o.Morph.Gender & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined ? "ПЕРВОЕ" : "ПЕРВЫЙ")); first.Morph.Gender = o.Morph.Gender; o.Graph.Objects.Add(first); o.Graph.AddLink(Pullenti.Semantic.SemLinkType.Detail, o, first, "какой", false, null); o.Quantity = null; ret = true; } for (int i = 0; i < objs.Count; i++) { Pullenti.Semantic.SemObject o = objs[i]; if (o.Typ != Pullenti.Semantic.SemObjectType.Noun) { continue; } if (o.Quantity != null && o.Quantity.Spelling == "1") { } else { continue; } Pullenti.Semantic.SemObject other = o.FindFromObject("ДРУГОЙ", Pullenti.Semantic.SemLinkType.Undefined, Pullenti.Semantic.SemObjectType.Undefined); if (other == null) { continue; } bool ok = false; for (int j = i - 1; j >= 0; j--) { Pullenti.Semantic.SemObject oo = objs[j]; if (oo.Typ != Pullenti.Semantic.SemObjectType.Noun) { continue; } if (oo.Morph.NormalFull != o.Morph.NormalFull) { continue; } if (oo.FindFromObject("ПЕРВЫЙ", Pullenti.Semantic.SemLinkType.Undefined, Pullenti.Semantic.SemObjectType.Undefined) != null) { ok = true; break; } } if (ok) { other.Morph.NormalFull = "ВТОРОЙ"; other.Morph.NormalCase = (((o.Morph.Gender & Pullenti.Morph.MorphGender.Feminie)) != Pullenti.Morph.MorphGender.Undefined ? "ВТОРАЯ" : (((o.Morph.Gender & Pullenti.Morph.MorphGender.Neuter)) != Pullenti.Morph.MorphGender.Undefined ? "ВТОРОЕ" : "ВТОРОЙ")); } } return(ret); }
static bool _processParticiples(Pullenti.Semantic.SemGraph gr) { bool ret = false; for (int i = 0; i < gr.Objects.Count; i++) { Pullenti.Semantic.SemObject obj = gr.Objects[i]; if (obj.Typ != Pullenti.Semantic.SemObjectType.Participle) { continue; } Pullenti.Semantic.SemLink own = null; bool has = false; foreach (Pullenti.Semantic.SemLink li in obj.LinksTo) { if (li.Typ == Pullenti.Semantic.SemLinkType.Participle) { own = li; } else { has = true; } } if (!has) { continue; } if (own == null) { Pullenti.Semantic.SemObject dum = new Pullenti.Semantic.SemObject(gr) { Typ = Pullenti.Semantic.SemObjectType.Noun }; if (obj.Morph != null) { dum.Morph = new Pullenti.Morph.MorphWordForm() { Class = Pullenti.Morph.MorphClass.Noun, Number = obj.Morph.Number, Gender = obj.Morph.Gender, Case = obj.Morph.Case } } ; gr.Objects.Add(dum); own = gr.AddLink(Pullenti.Semantic.SemLinkType.Participle, dum, obj, "какой", false, null); ret = true; } for (int j = obj.LinksTo.Count - 1; j >= 0; j--) { Pullenti.Semantic.SemLink li = obj.LinksTo[j]; if (li.Typ == Pullenti.Semantic.SemLinkType.Participle) { continue; } bool exi = false; foreach (Pullenti.Semantic.SemLink ll in li.Source.LinksFrom) { if (ll.Target == own.Source) { exi = true; } } if (exi) { gr.RemoveLink(li); } else { obj.LinksTo.RemoveAt(j); li.m_Target = own.Source; } ret = true; } } return(ret); }