Exemple #1
0
        public static List <SentItem> ParseNearItems(Pullenti.Ner.Token t, Pullenti.Ner.Token t1, int lev, List <SentItem> prev)
        {
            if (lev > 100)
            {
                return(null);
            }
            if (t == null || t.BeginChar > t1.EndChar)
            {
                return(null);
            }
            List <SentItem> res = new List <SentItem>();

            if (t is Pullenti.Ner.ReferentToken)
            {
                res.Add(new SentItem(t as Pullenti.Ner.MetaToken));
                return(res);
            }
            DelimToken delim = DelimToken.TryParse(t);

            if (delim != null)
            {
                res.Add(new SentItem(delim));
                return(res);
            }
            Pullenti.Ner.Core.ConjunctionToken conj = Pullenti.Ner.Core.ConjunctionHelper.TryParse(t);
            if (conj != null)
            {
                res.Add(new SentItem(conj));
                return(res);
            }
            Pullenti.Ner.Core.PrepositionToken prep = Pullenti.Ner.Core.PrepositionHelper.TryParse(t);
            Pullenti.Ner.Token t111 = (prep == null ? t : prep.EndToken.Next);
            if ((t111 is Pullenti.Ner.NumberToken) && ((t111.Morph.Class.IsAdjective && !t111.Morph.Class.IsNoun)))
            {
                t111 = null;
            }
            Pullenti.Ner.Measure.Internal.NumbersWithUnitToken num = (t111 == null ? null : Pullenti.Ner.Measure.Internal.NumbersWithUnitToken.TryParse(t111, null, false, false, false, false));
            if (num != null)
            {
                if (num.Units.Count == 0)
                {
                    Pullenti.Ner.Core.NounPhraseToken npt1 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(num.EndToken.Next, m_NptAttrs, 0, null);
                    if (npt1 == null && num.EndToken.Next != null && num.EndToken.Next.IsValue("РАЗ", null))
                    {
                        npt1      = new Pullenti.Ner.Core.NounPhraseToken(num.EndToken.Next, num.EndToken.Next);
                        npt1.Noun = new Pullenti.Ner.MetaToken(num.EndToken.Next, num.EndToken.Next);
                    }
                    if (npt1 != null && prep != null)
                    {
                        if (npt1.Noun.EndToken.IsValue("РАЗ", null))
                        {
                            npt1.Morph.RemoveItems(prep.NextCase);
                        }
                        else if (((npt1.Morph.Case & prep.NextCase)).IsUndefined)
                        {
                            npt1 = null;
                        }
                        else
                        {
                            npt1.Morph.RemoveItems(prep.NextCase);
                        }
                    }
                    if ((npt1 != null && npt1.EndToken.IsValue("ОНИ", null) && npt1.Preposition != null) && npt1.Preposition.Normal == "ИЗ")
                    {
                        npt1.Morph       = new Pullenti.Ner.MorphCollection(num.EndToken.Morph);
                        npt1.Preposition = null;
                        string   nn  = num.ToString();
                        SentItem si1 = new SentItem(npt1);
                        if (nn == "1" && (num.EndToken is Pullenti.Ner.NumberToken) && (num.EndToken as Pullenti.Ner.NumberToken).EndToken.IsValue("ОДИН", null))
                        {
                            Pullenti.Semantic.SemAttribute a = new Pullenti.Semantic.SemAttribute()
                            {
                                Typ = Pullenti.Semantic.SemAttributeType.OneOf, Spelling = (num.EndToken as Pullenti.Ner.NumberToken).EndToken.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Singular, Pullenti.Morph.MorphGender.Undefined, false)
                            };
                            SemAttributeEx aex = new SemAttributeEx(num)
                            {
                                Attr = a
                            };
                            si1.Attrs = new List <SemAttributeEx>();
                            si1.Attrs.Add(aex);
                        }
                        else
                        {
                            si1.Quant = new Pullenti.Semantic.SemQuantity(nn, num.BeginToken, num.EndToken);
                        }
                        if (prep != null)
                        {
                            si1.Prep = prep.Normal;
                        }
                        res.Add(si1);
                        return(res);
                    }
                    if (npt1 != null)
                    {
                        SentItem si1 = new SentItem(npt1)
                        {
                            Quant = new Pullenti.Semantic.SemQuantity(num.ToString(), num.BeginToken, num.EndToken)
                        };
                        if (prep != null)
                        {
                            si1.Prep = prep.Normal;
                        }
                        if (npt1.EndToken.IsValue("РАЗ", null))
                        {
                            si1.Typ = SentItemType.Formula;
                        }
                        if (((npt1.Morph.Number & Pullenti.Morph.MorphNumber.Plural)) == Pullenti.Morph.MorphNumber.Undefined && si1.Quant.Spelling != "1")
                        {
                            bool ok = false;
                            if (si1.Quant.Spelling.EndsWith("1"))
                            {
                                ok = true;
                            }
                            else if (si1.Typ == SentItemType.Formula)
                            {
                                ok = true;
                            }
                            else if (si1.Quant.Spelling.EndsWith("2") && npt1.Morph.Case.IsGenitive)
                            {
                                ok = true;
                            }
                            else if (si1.Quant.Spelling.EndsWith("3") && npt1.Morph.Case.IsGenitive)
                            {
                                ok = true;
                            }
                            else if (si1.Quant.Spelling.EndsWith("4") && npt1.Morph.Case.IsGenitive)
                            {
                                ok = true;
                            }
                            if (ok)
                            {
                                npt1.Morph        = new Pullenti.Ner.MorphCollection();
                                npt1.Morph.Number = Pullenti.Morph.MorphNumber.Plural;
                            }
                        }
                        res.Add(si1);
                        return(res);
                    }
                }
                num.BeginToken = t;
                num.Morph      = new Pullenti.Ner.MorphCollection(num.EndToken.Morph);
                SentItem si = new SentItem(num);
                if (prep != null)
                {
                    si.Prep = prep.Normal;
                }
                res.Add(si);
                if (si.Prep == "НА")
                {
                    AdverbToken aa = AdverbToken.TryParse(si.EndToken.Next);
                    if (aa != null && ((aa.Typ == Pullenti.Semantic.SemAttributeType.Less || aa.Typ == Pullenti.Semantic.SemAttributeType.Great)))
                    {
                        si.AddAttr(aa);
                        si.EndToken = aa.EndToken;
                    }
                }
                return(res);
            }
            Pullenti.Morph.MorphClass mc = t.GetMorphClassInDictionary();
            AdverbToken adv = AdverbToken.TryParse(t);

            Pullenti.Ner.Core.NounPhraseToken npt = Pullenti.Ner.Core.NounPhraseHelper.TryParse(t, m_NptAttrs, 0, null);
            if (npt != null && (npt.EndToken is Pullenti.Ner.TextToken) && (npt.EndToken as Pullenti.Ner.TextToken).Term == "БЫЛИ")
            {
                npt = null;
            }
            if (npt != null && adv != null)
            {
                if (adv.EndChar > npt.EndChar)
                {
                    npt = null;
                }
                else if (adv.EndChar == npt.EndChar)
                {
                    res.Add(new SentItem(npt));
                    res.Add(new SentItem(adv));
                    return(res);
                }
            }
            if (npt != null && npt.Adjectives.Count == 0)
            {
                if (npt.EndToken.IsValue("КОТОРЫЙ", null) && t.Previous != null && t.Previous.IsCommaAnd)
                {
                    List <SentItem> res1 = ParseSubsent(npt, t1, lev + 1, prev);
                    if (res1 != null)
                    {
                        return(res1);
                    }
                }
                if (npt.EndToken.IsValue("СКОЛЬКО", null))
                {
                    Pullenti.Ner.Token tt1 = npt.EndToken.Next;
                    if (tt1 != null && tt1.IsValue("ВСЕГО", null))
                    {
                        tt1 = tt1.Next;
                    }
                    Pullenti.Ner.Core.NounPhraseToken npt1 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt1, Pullenti.Ner.Core.NounPhraseParseAttr.No, 0, null);
                    if (npt1 != null && !npt1.Morph.Case.IsUndefined && prep != null)
                    {
                        if (((prep.NextCase & npt1.Morph.Case)).IsUndefined)
                        {
                            npt1 = null;
                        }
                        else
                        {
                            npt1.Morph.RemoveItems(prep.NextCase);
                        }
                    }
                    if (npt1 != null)
                    {
                        npt1.BeginToken  = npt.BeginToken;
                        npt1.Preposition = npt.Preposition;
                        npt1.Adjectives.Add(new Pullenti.Ner.MetaToken(npt.EndToken, npt.EndToken));
                        npt = npt1;
                    }
                }
                if (npt.EndToken.Morph.Class.IsAdjective)
                {
                    if (Pullenti.Ner.Core.VerbPhraseHelper.TryParse(t, true, false, false) != null)
                    {
                        npt = null;
                    }
                }
            }
            Pullenti.Ner.Core.VerbPhraseToken vrb = null;
            if (npt != null && npt.Adjectives.Count > 0)
            {
                vrb = Pullenti.Ner.Core.VerbPhraseHelper.TryParse(t, true, false, false);
                if (vrb != null && vrb.FirstVerb.IsParticiple)
                {
                    npt = null;
                }
            }
            else if (adv == null || npt != null)
            {
                vrb = Pullenti.Ner.Core.VerbPhraseHelper.TryParse(t, true, false, false);
            }
            if (npt != null)
            {
                res.Add(new SentItem(npt));
            }
            if (vrb != null && !vrb.FirstVerb.IsParticiple && !vrb.FirstVerb.IsDeeParticiple)
            {
                List <Pullenti.Morph.MorphWordForm> vars = new List <Pullenti.Morph.MorphWordForm>();
                foreach (Pullenti.Morph.MorphBaseInfo wf in vrb.FirstVerb.Morph.Items)
                {
                    if (wf.Class.IsVerb && (wf is Pullenti.Morph.MorphWordForm) && (wf as Pullenti.Morph.MorphWordForm).IsInDictionary)
                    {
                        vars.Add(wf as Pullenti.Morph.MorphWordForm);
                    }
                }
                if (vars.Count < 2)
                {
                    res.Add(new SentItem(vrb));
                }
                else
                {
                    vrb.FirstVerb.VerbMorph = vars[0];
                    res.Add(new SentItem(vrb));
                    for (int i = 1; i < vars.Count; i++)
                    {
                        vrb = Pullenti.Ner.Core.VerbPhraseHelper.TryParse(t, false, false, false);
                        if (vrb == null)
                        {
                            break;
                        }
                        vrb.FirstVerb.VerbMorph = vars[i];
                        res.Add(new SentItem(vrb));
                    }
                    if (vars[0].Misc.Mood == Pullenti.Morph.MorphMood.Imperative && vars[1].Misc.Mood != Pullenti.Morph.MorphMood.Imperative)
                    {
                        SentItem rr = res[0];
                        res[0] = res[1];
                        res[1] = rr;
                    }
                }
                return(res);
            }
            if (vrb != null)
            {
                List <SentItem> res1 = ParseParticiples(vrb, t1, lev + 1);
                if (res1 != null)
                {
                    res.AddRange(res1);
                }
            }
            if (res.Count > 0)
            {
                return(res);
            }
            if (adv != null)
            {
                if (adv.Typ == Pullenti.Semantic.SemAttributeType.Other)
                {
                    Pullenti.Ner.Core.NounPhraseToken npt1 = Pullenti.Ner.Core.NounPhraseHelper.TryParse(adv.EndToken.Next, m_NptAttrs, 0, null);
                    if (npt1 != null && npt1.EndToken.IsValue("ОНИ", null) && npt1.Preposition != null)
                    {
                        SentItem si1 = new SentItem(npt1);
                        Pullenti.Semantic.SemAttribute a = new Pullenti.Semantic.SemAttribute()
                        {
                            Typ = Pullenti.Semantic.SemAttributeType.Other, Spelling = adv.EndToken.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false)
                        };
                        SemAttributeEx aex = new SemAttributeEx(num)
                        {
                            Attr = a
                        };
                        si1.Attrs = new List <SemAttributeEx>();
                        si1.Attrs.Add(aex);
                        if (prep != null)
                        {
                            si1.Prep = prep.Normal;
                        }
                        res.Add(si1);
                        return(res);
                    }
                    for (int i = prev.Count - 1; i >= 0; i--)
                    {
                        if (prev[i].Attrs != null)
                        {
                            foreach (SemAttributeEx a in prev[i].Attrs)
                            {
                                if (a.Attr.Typ == Pullenti.Semantic.SemAttributeType.OneOf)
                                {
                                    SentItem si1 = new SentItem(prev[i].Source);
                                    Pullenti.Semantic.SemAttribute aa = new Pullenti.Semantic.SemAttribute()
                                    {
                                        Typ = Pullenti.Semantic.SemAttributeType.Other, Spelling = adv.EndToken.GetNormalCaseText(null, Pullenti.Morph.MorphNumber.Undefined, Pullenti.Morph.MorphGender.Undefined, false)
                                    };
                                    SemAttributeEx aex = new SemAttributeEx(adv)
                                    {
                                        Attr = aa
                                    };
                                    si1.Attrs = new List <SemAttributeEx>();
                                    si1.Attrs.Add(aex);
                                    if (prep != null)
                                    {
                                        si1.Prep = prep.Normal;
                                    }
                                    si1.BeginToken = adv.BeginToken;
                                    si1.EndToken   = adv.EndToken;
                                    res.Add(si1);
                                    return(res);
                                }
                            }
                        }
                    }
                }
                res.Add(new SentItem(adv));
                return(res);
            }
            if (mc.IsAdjective)
            {
                npt = new Pullenti.Ner.Core.NounPhraseToken(t, t)
                {
                    Morph = new Pullenti.Ner.MorphCollection(t.Morph)
                };
                npt.Noun = new Pullenti.Ner.MetaToken(t, t);
                res.Add(new SentItem(npt));
                return(res);
            }
            return(null);
        }
Exemple #2
0
        static WeaponItemToken _TryParse(Pullenti.Ner.Token t, WeaponItemToken prev, bool afterConj, bool attachHigh = false)
        {
            if (t == null)
            {
                return(null);
            }
            if (Pullenti.Ner.Core.BracketHelper.IsBracket(t, true))
            {
                WeaponItemToken wit = _TryParse(t.Next, prev, afterConj, attachHigh);
                if (wit != null)
                {
                    if (wit.EndToken.Next == null)
                    {
                        wit.BeginToken = t;
                        return(wit);
                    }
                    if (Pullenti.Ner.Core.BracketHelper.IsBracket(wit.EndToken.Next, true))
                    {
                        wit.BeginToken = t;
                        wit.EndToken   = wit.EndToken.Next;
                        return(wit);
                    }
                }
            }
            Pullenti.Ner.Core.TerminToken tok = m_Ontology.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No);
            if (tok != null)
            {
                WeaponItemToken res = new WeaponItemToken(t, tok.EndToken);
                res.Typ = (Typs)tok.Termin.Tag;
                if (res.Typ == Typs.Noun)
                {
                    res.Value = tok.Termin.CanonicText;
                    if (tok.Termin.Tag2 != null)
                    {
                        res.IsDoubt = true;
                    }
                    for (Pullenti.Ner.Token tt = res.EndToken.Next; tt != null; tt = tt.Next)
                    {
                        if (tt.WhitespacesBeforeCount > 2)
                        {
                            break;
                        }
                        WeaponItemToken wit = _TryParse(tt, null, false, false);
                        if (wit != null)
                        {
                            if (wit.Typ == Typs.Brand)
                            {
                                res.InnerTokens.Add(wit);
                                res.EndToken = (tt = wit.EndToken);
                                continue;
                            }
                            break;
                        }
                        if (!(tt is Pullenti.Ner.TextToken))
                        {
                            break;
                        }
                        Pullenti.Morph.MorphClass mc = tt.GetMorphClassInDictionary();
                        if (mc == Pullenti.Morph.MorphClass.Adjective)
                        {
                            if (res.AltValue == null)
                            {
                                res.AltValue = res.Value;
                            }
                            if (res.AltValue.EndsWith(res.Value))
                            {
                                res.AltValue = res.AltValue.Substring(0, res.AltValue.Length - res.Value.Length);
                            }
                            res.AltValue = string.Format("{0}{1} {2}", res.AltValue, (tt as Pullenti.Ner.TextToken).Term, res.Value);
                            res.EndToken = tt;
                            continue;
                        }
                        break;
                    }
                    return(res);
                }
                if (res.Typ == Typs.Brand || res.Typ == Typs.Name)
                {
                    res.Value = tok.Termin.CanonicText;
                    return(res);
                }
                if (res.Typ == Typs.Model)
                {
                    res.Value = tok.Termin.CanonicText;
                    if (tok.Termin.Tag2 is List <Pullenti.Ner.Core.Termin> )
                    {
                        List <Pullenti.Ner.Core.Termin> li = tok.Termin.Tag2 as List <Pullenti.Ner.Core.Termin>;
                        foreach (Pullenti.Ner.Core.Termin to in li)
                        {
                            WeaponItemToken wit = new WeaponItemToken(t, tok.EndToken)
                            {
                                Typ = (Typs)to.Tag, Value = to.CanonicText, IsInternal = tok.BeginToken == tok.EndToken
                            };
                            res.InnerTokens.Add(wit);
                            if (to.AdditionalVars != null && to.AdditionalVars.Count > 0)
                            {
                                wit.AltValue = to.AdditionalVars[0].CanonicText;
                            }
                        }
                    }
                    res._correctModel();
                    return(res);
                }
            }
            Pullenti.Ner.Token nnn = Pullenti.Ner.Core.MiscHelper.CheckNumberPrefix(t);
            if (nnn != null)
            {
                Pullenti.Ner.Transport.Internal.TransItemToken tit = Pullenti.Ner.Transport.Internal.TransItemToken._attachNumber(nnn, true);
                if (tit != null)
                {
                    WeaponItemToken res = new WeaponItemToken(t, tit.EndToken)
                    {
                        Typ = Typs.Number
                    };
                    res.Value    = tit.Value;
                    res.AltValue = tit.AltValue;
                    return(res);
                }
            }
            if (((t is Pullenti.Ner.TextToken) && t.Chars.IsLetter && t.Chars.IsAllUpper) && (t.LengthChar < 4))
            {
                if ((t.Next != null && ((t.Next.IsHiphen || t.Next.IsChar('.'))) && (t.Next.WhitespacesAfterCount < 2)) && (t.Next.Next is Pullenti.Ner.NumberToken))
                {
                    WeaponItemToken res = new WeaponItemToken(t, t.Next)
                    {
                        Typ = Typs.Model, IsDoubt = true
                    };
                    res.Value = (t as Pullenti.Ner.TextToken).Term;
                    res._correctModel();
                    return(res);
                }
                if ((t.Next is Pullenti.Ner.NumberToken) && !t.IsWhitespaceAfter)
                {
                    WeaponItemToken res = new WeaponItemToken(t, t)
                    {
                        Typ = Typs.Model, IsDoubt = true
                    };
                    res.Value = (t as Pullenti.Ner.TextToken).Term;
                    res._correctModel();
                    return(res);
                }
                if ((t as Pullenti.Ner.TextToken).Term == "СП" && (t.WhitespacesAfterCount < 3) && (t.Next is Pullenti.Ner.TextToken))
                {
                    WeaponItemToken pp = _TryParse(t.Next, null, false, false);
                    if (pp != null && ((pp.Typ == Typs.Model || pp.Typ == Typs.Brand)))
                    {
                        WeaponItemToken res = new WeaponItemToken(t, t)
                        {
                            Typ = Typs.Noun
                        };
                        res.Value    = "ПИСТОЛЕТ";
                        res.AltValue = "СЛУЖЕБНЫЙ ПИСТОЛЕТ";
                        return(res);
                    }
                }
            }
            if (((t is Pullenti.Ner.TextToken) && t.Chars.IsLetter && !t.Chars.IsAllLower) && t.LengthChar > 2)
            {
                bool ok = false;
                if (prev != null && ((prev.Typ == Typs.Noun || prev.Typ == Typs.Model || prev.Typ == Typs.Brand)))
                {
                    ok = true;
                }
                else if (prev == null && t.Previous != null && t.Previous.IsCommaAnd)
                {
                    ok = true;
                }
                if (ok)
                {
                    WeaponItemToken res = new WeaponItemToken(t, t)
                    {
                        Typ = Typs.Name, IsDoubt = true
                    };
                    res.Value = (t as Pullenti.Ner.TextToken).Term;
                    if ((t.Next != null && t.Next.IsHiphen && (t.Next.Next is Pullenti.Ner.TextToken)) && t.Next.Next.Chars == t.Chars)
                    {
                        res.Value    = string.Format("{0}-{1}", res.Value, (t.Next.Next as Pullenti.Ner.TextToken).Term);
                        res.EndToken = t.Next.Next;
                    }
                    if (prev != null && prev.Typ == Typs.Noun)
                    {
                        res.Typ = Typs.Brand;
                    }
                    if (res.EndToken.Next != null && res.EndToken.Next.IsHiphen && (res.EndToken.Next.Next is Pullenti.Ner.NumberToken))
                    {
                        res.Typ = Typs.Model;
                        res._correctModel();
                    }
                    else if (!res.EndToken.IsWhitespaceAfter && (res.EndToken.Next is Pullenti.Ner.NumberToken))
                    {
                        res.Typ = Typs.Model;
                        res._correctModel();
                    }
                    return(res);
                }
            }
            if (t.IsValue("МАРКА", null))
            {
                WeaponItemToken res = _TryParse(t.Next, prev, afterConj, false);
                if (res != null && res.Typ == Typs.Brand)
                {
                    res.BeginToken = t;
                    return(res);
                }
                if (Pullenti.Ner.Core.BracketHelper.CanBeStartOfSequence(t.Next, true, false))
                {
                    Pullenti.Ner.Core.BracketSequenceToken br = Pullenti.Ner.Core.BracketHelper.TryParse(t.Next, Pullenti.Ner.Core.BracketParseAttr.No, 100);
                    if (br != null)
                    {
                        return new WeaponItemToken(t, br.EndToken)
                               {
                                   Typ = Typs.Brand, Value = Pullenti.Ner.Core.MiscHelper.GetTextValue(br.BeginToken, br.EndToken, Pullenti.Ner.Core.GetTextAttr.No)
                               }
                    }
                    ;
                }
                if (((t is Pullenti.Ner.TextToken) && (t.Next is Pullenti.Ner.TextToken) && t.Next.LengthChar > 1) && !t.Next.Chars.IsAllLower)
                {
                    return new WeaponItemToken(t, t.Next)
                           {
                               Typ = Typs.Brand, Value = (t as Pullenti.Ner.TextToken).Term
                           }
                }
                ;
            }
            if (t.IsValue("КАЛИБР", "КАЛІБР"))
            {
                Pullenti.Ner.Token tt1 = t.Next;
                if (tt1 != null && ((tt1.IsHiphen || tt1.IsChar(':'))))
                {
                    tt1 = tt1.Next;
                }
                Pullenti.Ner.Measure.Internal.NumbersWithUnitToken num = Pullenti.Ner.Measure.Internal.NumbersWithUnitToken.TryParse(tt1, null, false, false, false, false);
                if (num != null && num.SingleVal != null)
                {
                    return new WeaponItemToken(t, num.EndToken)
                           {
                               Typ = Typs.Caliber, Value = Pullenti.Ner.Core.NumberHelper.DoubleToString(num.SingleVal.Value)
                           }
                }
                ;
            }
            if (t is Pullenti.Ner.NumberToken)
            {
                Pullenti.Ner.Measure.Internal.NumbersWithUnitToken num = Pullenti.Ner.Measure.Internal.NumbersWithUnitToken.TryParse(t, null, false, false, false, false);
                if (num != null && num.SingleVal != null)
                {
                    if (num.Units.Count == 1 && num.Units[0].Unit != null && num.Units[0].Unit.NameCyr == "мм")
                    {
                        return new WeaponItemToken(t, num.EndToken)
                               {
                                   Typ = Typs.Caliber, Value = Pullenti.Ner.Core.NumberHelper.DoubleToString(num.SingleVal.Value)
                               }
                    }
                    ;

                    if (num.EndToken.Next != null && num.EndToken.Next.IsValue("КАЛИБР", "КАЛІБР"))
                    {
                        return new WeaponItemToken(t, num.EndToken.Next)
                               {
                                   Typ = Typs.Caliber, Value = Pullenti.Ner.Core.NumberHelper.DoubleToString(num.SingleVal.Value)
                               }
                    }
                    ;
                }
            }
            if (t.IsValue("ПРОИЗВОДСТВО", "ВИРОБНИЦТВО"))
            {
                Pullenti.Ner.Token tt1 = t.Next;
                if (tt1 != null && ((tt1.IsHiphen || tt1.IsChar(':'))))
                {
                    tt1 = tt1.Next;
                }
                if (tt1 is Pullenti.Ner.ReferentToken)
                {
                    if ((tt1.GetReferent() is Pullenti.Ner.Org.OrganizationReferent) || (tt1.GetReferent() is Pullenti.Ner.Geo.GeoReferent))
                    {
                        return new WeaponItemToken(t, tt1)
                               {
                                   Typ = Typs.Developer, Ref = tt1.GetReferent()
                               }
                    }
                    ;
                }
            }
            return(null);
        }

        void _correctModel()
        {
            Pullenti.Ner.Token tt = EndToken.Next;
            if (tt == null || tt.WhitespacesBeforeCount > 2)
            {
                return;
            }
            if (tt.IsValue(":\\/.", null) || tt.IsHiphen)
            {
                tt = tt.Next;
            }
            if (tt is Pullenti.Ner.NumberToken)
            {
                StringBuilder tmp = new StringBuilder();
                tmp.Append((tt as Pullenti.Ner.NumberToken).Value);
                bool isLat = Pullenti.Morph.LanguageHelper.IsLatinChar(Value[0]);
                EndToken = tt;
                for (tt = tt.Next; tt != null; tt = tt.Next)
                {
                    if ((tt is Pullenti.Ner.TextToken) && tt.LengthChar == 1 && tt.Chars.IsLetter)
                    {
                        if (!tt.IsWhitespaceBefore || ((tt.Previous != null && tt.Previous.IsHiphen)))
                        {
                            char ch = (tt as Pullenti.Ner.TextToken).Term[0];
                            EndToken = tt;
                            char ch2 = (char)0;
                            if (Pullenti.Morph.LanguageHelper.IsLatinChar(ch) && !isLat)
                            {
                                ch2 = Pullenti.Morph.LanguageHelper.GetCyrForLat(ch);
                                if (ch2 != ((char)0))
                                {
                                    ch = ch2;
                                }
                            }
                            else if (Pullenti.Morph.LanguageHelper.IsCyrillicChar(ch) && isLat)
                            {
                                ch2 = Pullenti.Morph.LanguageHelper.GetLatForCyr(ch);
                                if (ch2 != ((char)0))
                                {
                                    ch = ch2;
                                }
                            }
                            tmp.Append(ch);
                            continue;
                        }
                    }
                    break;
                }
                Value    = string.Format("{0}-{1}", Value, tmp.ToString());
                AltValue = Pullenti.Ner.Core.MiscHelper.CreateCyrLatAlternative(Value);
            }
            if (!EndToken.IsWhitespaceAfter && EndToken.Next != null && ((EndToken.Next.IsHiphen || EndToken.Next.IsCharOf("\\/"))))
            {
                if (!EndToken.Next.IsWhitespaceAfter && (EndToken.Next.Next is Pullenti.Ner.NumberToken))
                {
                    EndToken = EndToken.Next.Next;
                    Value    = string.Format("{0}-{1}", Value, (EndToken as Pullenti.Ner.NumberToken).Value);
                    if (AltValue != null)
                    {
                        AltValue = string.Format("{0}-{1}", AltValue, (EndToken as Pullenti.Ner.NumberToken).Value);
                    }
                }
            }
        }
Exemple #3
0
        void _calcGenetive()
        {
            if (!From.Source.CanBeNoun)
            {
                return;
            }
            if (From.Source.Typ == SentItemType.Formula)
            {
                if (To.Source.Typ != SentItemType.Noun)
                {
                    return;
                }
                Coef = Pullenti.Semantic.SemanticService.Params.TransitiveCoef;
                return;
            }
            Pullenti.Ner.MorphCollection frmorph = FromMorph;
            if (To.Source.Typ == SentItemType.Formula)
            {
                if (From.Source.Typ != SentItemType.Noun)
                {
                    return;
                }
                if (frmorph.Case.IsGenitive)
                {
                    Coef = Pullenti.Semantic.SemanticService.Params.TransitiveCoef;
                }
                else if (frmorph.Case.IsUndefined)
                {
                    Coef = 0;
                }
                return;
            }
            if (From.Source.Source is Pullenti.Ner.Measure.Internal.NumbersWithUnitToken)
            {
                if (From.Order != (To.Order + 1))
                {
                    return;
                }
                Pullenti.Ner.Measure.Internal.NumbersWithUnitToken num = From.Source.Source as Pullenti.Ner.Measure.Internal.NumbersWithUnitToken;
                Pullenti.Ner.Measure.MeasureKind ki = Pullenti.Ner.Measure.Internal.UnitToken.CalcKind(num.Units);
                if (ki != Pullenti.Ner.Measure.MeasureKind.Undefined)
                {
                    if (Pullenti.Ner.Measure.Internal.UnitsHelper.CheckKeyword(ki, To.Source.Source))
                    {
                        Coef = Pullenti.Semantic.SemanticService.Params.NextModel * 3;
                        return;
                    }
                }
                if (To.Source.Source is Pullenti.Ner.Measure.Internal.NumbersWithUnitToken)
                {
                    return;
                }
            }
            bool nonGenText = false;

            if (string.IsNullOrEmpty(FromPrep) && !(From.Source.Source is Pullenti.Ner.Core.VerbPhraseToken))
            {
                if (From.Order != (To.Order + 1))
                {
                    nonGenText = true;
                }
            }
            if (To.Source.DrGroups != null)
            {
                foreach (Pullenti.Semantic.Utils.DerivateGroup gr in To.Source.DrGroups)
                {
                    if (gr.Cm.Transitive && string.IsNullOrEmpty(FromPrep))
                    {
                        bool ok = false;
                        if (To.Source.Source is Pullenti.Ner.Core.VerbPhraseToken)
                        {
                            if (frmorph.Case.IsAccusative)
                            {
                                ok           = true;
                                CanBePacient = true;
                            }
                        }
                        else if (frmorph.Case.IsGenitive && From.Order == (To.Order + 1))
                        {
                            ok = true;
                        }
                        if (ok)
                        {
                            Coef = Pullenti.Semantic.SemanticService.Params.TransitiveCoef;
                            return;
                        }
                    }
                    if (((gr.Cm.Questions & Pullenti.Semantic.Utils.QuestionType.WhatToDo)) != Pullenti.Semantic.Utils.QuestionType.Undefined && (From.Source.Source is Pullenti.Ner.Core.VerbPhraseToken))
                    {
                        Coef = Pullenti.Semantic.SemanticService.Params.TransitiveCoef;
                        return;
                    }
                    if (gr.Cm.Nexts != null)
                    {
                        if (gr.Cm.Nexts.ContainsKey(FromPrep))
                        {
                            Pullenti.Morph.MorphCase cas = gr.Cm.Nexts[FromPrep];
                            if (!((cas & frmorph.Case)).IsUndefined)
                            {
                                if (string.IsNullOrEmpty(FromPrep) && From.Order != (To.Order + 1) && ((cas & frmorph.Case)).IsGenitive)
                                {
                                }
                                else
                                {
                                    Coef = Pullenti.Semantic.SemanticService.Params.NextModel;
                                    return;
                                }
                            }
                        }
                    }
                }
            }
            if (nonGenText || !string.IsNullOrEmpty(FromPrep))
            {
                return;
            }
            Pullenti.Morph.MorphCase cas0 = frmorph.Case;
            if (cas0.IsGenitive || cas0.IsInstrumental || cas0.IsDative)
            {
                if ((To.Source.Source is Pullenti.Ner.Measure.Internal.NumbersWithUnitToken) && cas0.IsGenitive)
                {
                    Coef = Pullenti.Semantic.SemanticService.Params.TransitiveCoef;
                }
                else
                {
                    Coef = Pullenti.Semantic.SemanticService.Params.NgLink;
                    if (cas0.IsNominative || From.Source.Typ == SentItemType.PartBefore)
                    {
                        Coef /= 2;
                    }
                    if (!cas0.IsGenitive)
                    {
                        Coef /= 2;
                    }
                }
            }
            else if (From.Source.Source is Pullenti.Ner.Core.VerbPhraseToken)
            {
                Coef = 0.1;
            }
            if ((To.Source.Source is Pullenti.Ner.Measure.Internal.NumbersWithUnitToken) && To.Source.EndToken.IsValue("ЧЕМ", null))
            {
                Coef = Pullenti.Semantic.SemanticService.Params.TransitiveCoef * 2;
            }
        }
Exemple #4
0
        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);
        }