예제 #1
0
        static void _createRoles(Pullenti.Semantic.Utils.ControlModelItem cit, string prep, Pullenti.Morph.MorphCase cas, List <SemanticLink> res, bool ignoreNominCase = false, bool ignoreInstrCase = false)
        {
            if (cit == null)
            {
                return;
            }
            Dictionary <Pullenti.Semantic.Utils.ControlModelQuestion, SemanticRole> roles = null;

            foreach (KeyValuePair <Pullenti.Semantic.Utils.ControlModelQuestion, SemanticRole> li in cit.Links)
            {
                Pullenti.Semantic.Utils.ControlModelQuestion q = li.Key;
                if (q.Check(prep, cas))
                {
                    if (ignoreNominCase && q.Case.IsNominative && q.Preposition == null)
                    {
                        continue;
                    }
                    if (ignoreInstrCase && q.Case.IsInstrumental && q.Preposition == null)
                    {
                        continue;
                    }
                    if (roles == null)
                    {
                        roles = new Dictionary <Pullenti.Semantic.Utils.ControlModelQuestion, SemanticRole>();
                    }
                    SemanticRole r = li.Value;
                    if (q.IsAbstract)
                    {
                        Pullenti.Semantic.Utils.ControlModelQuestion qq = q.CheckAbstract(prep, cas);
                        if (qq != null)
                        {
                            q = qq;
                            r = SemanticRole.Common;
                        }
                    }
                    if (!roles.ContainsKey(q))
                    {
                        roles.Add(q, r);
                    }
                    else if (r != SemanticRole.Common)
                    {
                        roles[q] = r;
                    }
                }
            }
            if (roles != null)
            {
                foreach (KeyValuePair <Pullenti.Semantic.Utils.ControlModelQuestion, SemanticRole> kp in roles)
                {
                    SemanticLink sl = new SemanticLink()
                    {
                        Role = kp.Value, Rank = 2, Question = kp.Key
                    };
                    if (kp.Value == SemanticRole.Agent)
                    {
                        if (!kp.Key.IsBase)
                        {
                            sl.Role = SemanticRole.Common;
                        }
                    }
                    if (sl.Role == SemanticRole.Strong)
                    {
                        sl.Rank += 2;
                    }
                    res.Add(sl);
                }
            }
        }
예제 #2
0
        static List <SemanticLink> _tryCreateVerb(Pullenti.Ner.Core.VerbPhraseToken vpt1, Pullenti.Ner.MetaToken slave, Pullenti.Semantic.Utils.DerivateGroup gr)
        {
            if (slave is Pullenti.Ner.Core.VerbPhraseToken)
            {
                return(_tryCreateInf(vpt1, slave as Pullenti.Ner.Core.VerbPhraseToken, gr));
            }
            SemanticAbstractSlave sla2 = slave as SemanticAbstractSlave;
            List <SemanticLink>   res  = new List <SemanticLink>();

            if (sla2 == null)
            {
                return(res);
            }
            Pullenti.Semantic.Utils.ControlModelItem cit = FindControlItem(vpt1.LastVerb, gr);
            string prep = sla2.Preposition;

            Pullenti.Morph.MorphBaseInfo morph = (Pullenti.Morph.MorphBaseInfo)sla2.Morph;
            bool isRev1  = vpt1.LastVerb.IsVerbReversive || vpt1.LastVerb.IsVerbPassive;
            bool noNomin = false;
            bool noInstr = false;

            if (prep == null && morph.Case.IsNominative && !vpt1.FirstVerb.IsParticiple)
            {
                bool ok  = true;
                bool err = false;
                Pullenti.Morph.MorphWordForm vm = vpt1.FirstVerb.VerbMorph;
                if (vm == null)
                {
                    return(res);
                }
                if (vm.Number == Pullenti.Morph.MorphNumber.Singular)
                {
                    if (morph.Number == Pullenti.Morph.MorphNumber.Plural)
                    {
                        if (!vpt1.FirstVerb.IsVerbInfinitive)
                        {
                            ok = false;
                        }
                    }
                }
                if (!CheckMorphAccord(morph, false, vm, false))
                {
                    if (!err && !vpt1.FirstVerb.IsVerbInfinitive)
                    {
                        ok = false;
                    }
                }
                else if (vm.Misc.Person != Pullenti.Morph.MorphPerson.Undefined)
                {
                    if (((vm.Misc.Person & Pullenti.Morph.MorphPerson.Third)) == Pullenti.Morph.MorphPerson.Undefined)
                    {
                        if (((vm.Misc.Person & Pullenti.Morph.MorphPerson.First)) == Pullenti.Morph.MorphPerson.First)
                        {
                            if (!morph.ContainsAttr("1 л.", null))
                            {
                                ok = false;
                            }
                        }
                        if (((vm.Misc.Person & Pullenti.Morph.MorphPerson.Second)) == Pullenti.Morph.MorphPerson.Second)
                        {
                            if (!morph.ContainsAttr("2 л.", null))
                            {
                                ok = false;
                            }
                        }
                    }
                }
                noNomin = true;
                if (ok)
                {
                    Pullenti.Semantic.Utils.ControlModelItem cit00 = cit;
                    bool isRev0 = isRev1;
                    if (vpt1.FirstVerb != vpt1.LastVerb && ((vpt1.FirstVerb.IsVerbReversive || vpt1.FirstVerb.IsVerbPassive || vpt1.FirstVerb.Normal == "ИМЕТЬ")))
                    {
                        cit00  = null;
                        isRev0 = true;
                        List <Pullenti.Semantic.Utils.DerivateGroup> grs = FindDerivates(vpt1.FirstVerb);
                        if (grs != null)
                        {
                            foreach (Pullenti.Semantic.Utils.DerivateGroup gg in grs)
                            {
                                if ((((cit00 = FindControlItem(vpt1.FirstVerb, gg)))) != null)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    SemanticLink sl       = null;
                    bool         addagent = false;
                    if (cit00 == null)
                    {
                        sl = new SemanticLink()
                        {
                            Modelled = true, Role = (isRev0 ? SemanticRole.Pacient : SemanticRole.Agent), Rank = 1, Question = Pullenti.Semantic.Utils.ControlModelQuestion.BaseNominative, IsPassive = isRev0
                        }
                    }
                    ;
                    else
                    {
                        foreach (KeyValuePair <Pullenti.Semantic.Utils.ControlModelQuestion, SemanticRole> kp in cit00.Links)
                        {
                            Pullenti.Semantic.Utils.ControlModelQuestion q = kp.Key;
                            if (q.Check(null, Pullenti.Morph.MorphCase.Nominative))
                            {
                                sl = new SemanticLink()
                                {
                                    Role = kp.Value, Rank = 2, Question = q, IsPassive = isRev0
                                };
                                if (sl.Role == SemanticRole.Agent)
                                {
                                    sl.IsPassive = false;
                                }
                                else if (sl.Role == SemanticRole.Pacient && cit00.NominativeCanBeAgentAndPacient && vpt1.LastVerb.IsVerbReversive)
                                {
                                    addagent = true;
                                }
                                break;
                            }
                        }
                    }
                    if (sl != null)
                    {
                        if (cit00 == null && morph.Case.IsInstrumental && isRev0)
                        {
                            sl.Rank -= 0.5;
                        }
                        if (morph.Case.IsAccusative)
                        {
                            sl.Rank -= 0.5;
                        }
                        if (sla2.BeginChar > vpt1.BeginChar)
                        {
                            sl.Rank -= 0.5;
                        }
                        if (err)
                        {
                            sl.Rank -= 0.5;
                        }
                        res.Add(sl);
                        if (addagent)
                        {
                            res.Add(new SemanticLink()
                            {
                                Role = SemanticRole.Agent, Rank = sl.Rank, Question = sl.Question
                            });
                        }
                    }
                }
            }
            if (prep == null && isRev1 && morph.Case.IsInstrumental)
            {
                noInstr = true;
                Pullenti.Semantic.Utils.ControlModelItem cit00 = cit;
                SemanticLink sl = null;
                if (cit00 == null)
                {
                    sl = new SemanticLink()
                    {
                        Modelled = true, Role = SemanticRole.Agent, Rank = 1, Question = Pullenti.Semantic.Utils.ControlModelQuestion.BaseInstrumental, IsPassive = true
                    }
                }
                ;
                else
                {
                    foreach (KeyValuePair <Pullenti.Semantic.Utils.ControlModelQuestion, SemanticRole> kp in cit00.Links)
                    {
                        Pullenti.Semantic.Utils.ControlModelQuestion q = kp.Key;
                        if (q.Check(null, Pullenti.Morph.MorphCase.Instrumental))
                        {
                            sl = new SemanticLink()
                            {
                                Role = kp.Value, Rank = 2, Question = q
                            };
                            if (sl.Role == SemanticRole.Agent)
                            {
                                sl.IsPassive = true;
                            }
                            break;
                        }
                    }
                }
                if (sl != null)
                {
                    if (cit00 == null && morph.Case.IsNominative)
                    {
                        sl.Rank -= 0.5;
                    }
                    if (morph.Case.IsAccusative)
                    {
                        sl.Rank -= 0.5;
                    }
                    if (sla2.BeginChar < vpt1.BeginChar)
                    {
                        sl.Rank -= 0.5;
                    }
                    res.Add(sl);
                    if ((gr != null && gr.Model.Items.Count > 0 && gr.Model.Items[0].Typ == Pullenti.Semantic.Utils.ControlModelItemType.Verb) && gr.Model.Items[0].Links.ContainsKey(Pullenti.Semantic.Utils.ControlModelQuestion.BaseInstrumental))
                    {
                        sl.Rank = 0;
                        SemanticLink sl0 = new SemanticLink()
                        {
                            Question = sl.Question, Rank = 1, Role = gr.Model.Items[0].Links[Pullenti.Semantic.Utils.ControlModelQuestion.BaseInstrumental]
                        };
                        res.Insert(0, sl0);
                    }
                }
            }
            if (prep == null && morph.Case.IsDative && ((cit == null || !cit.Links.ContainsKey(Pullenti.Semantic.Utils.ControlModelQuestion.BaseDative))))
            {
                SemanticLink sl = new SemanticLink()
                {
                    Modelled = cit == null, Role = SemanticRole.Strong, Rank = 1, Question = Pullenti.Semantic.Utils.ControlModelQuestion.BaseDative
                };
                if (morph.Case.IsAccusative || morph.Case.IsNominative)
                {
                    sl.Rank -= 0.5;
                }
                if (vpt1.EndToken.Next != sla2.BeginToken)
                {
                    sl.Rank -= 0.5;
                }
                if (cit != null)
                {
                    sl.Rank -= 0.5;
                }
                res.Add(sl);
            }
            _createRoles(cit, prep, morph.Case, res, noNomin, noInstr);
            if (gr != null && gr.Model.Pacients.Count > 0)
            {
                bool ok = false;
                foreach (string n in gr.Model.Pacients)
                {
                    if (sla2.Source != null)
                    {
                        if (sla2.Source.EndToken.IsValue(n, null))
                        {
                            ok = true;
                            break;
                        }
                    }
                    else if (sla2.EndToken.IsValue(n, null))
                    {
                        ok = true;
                        break;
                    }
                }
                if (ok)
                {
                    if (res.Count == 0)
                    {
                        ok = false;
                        if (prep == null && isRev1 && morph.Case.IsNominative)
                        {
                            ok = true;
                        }
                        else if (prep == null && !isRev1 && morph.Case.IsAccusative)
                        {
                            ok = true;
                        }
                        if (ok)
                        {
                            res.Add(new SemanticLink()
                            {
                                Role = SemanticRole.Pacient, Question = (isRev1 ? Pullenti.Semantic.Utils.ControlModelQuestion.BaseNominative : Pullenti.Semantic.Utils.ControlModelQuestion.BaseAccusative), Idiom = true
                            });
                        }
                    }
                    else
                    {
                        foreach (SemanticLink r in res)
                        {
                            r.Rank += 4;
                            if (r.Role == SemanticRole.Common)
                            {
                                r.Role = SemanticRole.Strong;
                            }
                            if (vpt1.EndToken.Next == sla2.BeginToken)
                            {
                                r.Rank += 2;
                            }
                            r.Idiom = true;
                        }
                    }
                }
            }
            return(res);
        }