Пример #1
0
        List <Pullenti.Ner.ReferentToken> TryAttach(List <Pullenti.Ner.Weapon.Internal.WeaponItemToken> its, bool attach)
        {
            WeaponReferent tr = new WeaponReferent();
            int            i;

            Pullenti.Ner.Token t1 = null;
            Pullenti.Ner.Weapon.Internal.WeaponItemToken noun  = null;
            Pullenti.Ner.Weapon.Internal.WeaponItemToken brand = null;
            Pullenti.Ner.Weapon.Internal.WeaponItemToken model = null;
            for (i = 0; i < its.Count; i++)
            {
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Noun)
                {
                    if (its.Count == 1)
                    {
                        return(null);
                    }
                    if (tr.FindSlot(WeaponReferent.ATTR_TYPE, null, true) != null)
                    {
                        if (tr.FindSlot(WeaponReferent.ATTR_TYPE, its[i].Value, true) == null)
                        {
                            break;
                        }
                    }
                    if (!its[i].IsInternal)
                    {
                        noun = its[i];
                    }
                    tr.AddSlot(WeaponReferent.ATTR_TYPE, its[i].Value, false, 0);
                    if (its[i].AltValue != null)
                    {
                        tr.AddSlot(WeaponReferent.ATTR_TYPE, its[i].AltValue, false, 0);
                    }
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Brand)
                {
                    if (tr.FindSlot(WeaponReferent.ATTR_BRAND, null, true) != null)
                    {
                        if (tr.FindSlot(WeaponReferent.ATTR_BRAND, its[i].Value, true) == null)
                        {
                            break;
                        }
                    }
                    if (!its[i].IsInternal)
                    {
                        if (noun != null && noun.IsDoubt)
                        {
                            noun.IsDoubt = false;
                        }
                    }
                    brand = its[i];
                    tr.AddSlot(WeaponReferent.ATTR_BRAND, its[i].Value, false, 0);
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Model)
                {
                    if (tr.FindSlot(WeaponReferent.ATTR_MODEL, null, true) != null)
                    {
                        if (tr.FindSlot(WeaponReferent.ATTR_MODEL, its[i].Value, true) == null)
                        {
                            break;
                        }
                    }
                    model = its[i];
                    tr.AddSlot(WeaponReferent.ATTR_MODEL, its[i].Value, false, 0);
                    if (its[i].AltValue != null)
                    {
                        tr.AddSlot(WeaponReferent.ATTR_MODEL, its[i].AltValue, false, 0);
                    }
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Name)
                {
                    if (tr.FindSlot(WeaponReferent.ATTR_NAME, null, true) != null)
                    {
                        break;
                    }
                    tr.AddSlot(WeaponReferent.ATTR_NAME, its[i].Value, false, 0);
                    if (its[i].AltValue != null)
                    {
                        tr.AddSlot(WeaponReferent.ATTR_NAME, its[i].AltValue, false, 0);
                    }
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Number)
                {
                    if (tr.FindSlot(WeaponReferent.ATTR_NUMBER, null, true) != null)
                    {
                        break;
                    }
                    tr.AddSlot(WeaponReferent.ATTR_NUMBER, its[i].Value, false, 0);
                    if (its[i].AltValue != null)
                    {
                        tr.AddSlot(WeaponReferent.ATTR_NUMBER, its[i].AltValue, false, 0);
                    }
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Caliber)
                {
                    if (tr.FindSlot(WeaponReferent.ATTR_CALIBER, null, true) != null)
                    {
                        break;
                    }
                    tr.AddSlot(WeaponReferent.ATTR_CALIBER, its[i].Value, false, 0);
                    if (its[i].AltValue != null)
                    {
                        tr.AddSlot(WeaponReferent.ATTR_CALIBER, its[i].AltValue, false, 0);
                    }
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Developer)
                {
                    tr.AddSlot(WeaponReferent.ATTR_REF, its[i].Ref, false, 0);
                    t1 = its[i].EndToken;
                    continue;
                }
                if (its[i].Typ == Pullenti.Ner.Weapon.Internal.WeaponItemToken.Typs.Date)
                {
                    if (tr.FindSlot(WeaponReferent.ATTR_DATE, null, true) != null)
                    {
                        break;
                    }
                    tr.AddSlot(WeaponReferent.ATTR_DATE, its[i].Ref, true, 0);
                    t1 = its[i].EndToken;
                    continue;
                }
            }
            bool           hasGoodNoun = (noun == null ? false : !noun.IsDoubt);
            WeaponReferent prev        = null;

            if (noun == null)
            {
                for (Pullenti.Ner.Token tt = its[0].BeginToken.Previous; tt != null; tt = tt.Previous)
                {
                    if ((((prev = tt.GetReferent() as WeaponReferent))) != null)
                    {
                        List <Pullenti.Ner.Slot> addSlots = new List <Pullenti.Ner.Slot>();
                        foreach (Pullenti.Ner.Slot s in prev.Slots)
                        {
                            if (s.TypeName == WeaponReferent.ATTR_TYPE)
                            {
                                tr.AddSlot(s.TypeName, s.Value, false, 0);
                            }
                            else if (s.TypeName == WeaponReferent.ATTR_BRAND || s.TypeName == WeaponReferent.ATTR_BRAND || s.TypeName == WeaponReferent.ATTR_MODEL)
                            {
                                if (tr.FindSlot(s.TypeName, null, true) == null)
                                {
                                    addSlots.Add(s);
                                }
                            }
                        }
                        foreach (Pullenti.Ner.Slot s in addSlots)
                        {
                            tr.AddSlot(s.TypeName, s.Value, false, 0);
                        }
                        hasGoodNoun = true;
                        break;
                    }
                    else if ((tt is Pullenti.Ner.TextToken) && ((!tt.Chars.IsLetter || tt.Morph.Class.IsConjunction)))
                    {
                    }
                    else
                    {
                        break;
                    }
                }
            }
            if (noun == null && model != null)
            {
                int cou = 0;
                for (Pullenti.Ner.Token tt = its[0].BeginToken.Previous; tt != null && (cou < 100); tt = tt.Previous, cou++)
                {
                    if ((((prev = tt.GetReferent() as WeaponReferent))) != null)
                    {
                        if (prev.FindSlot(WeaponReferent.ATTR_MODEL, model.Value, true) == null)
                        {
                            continue;
                        }
                        List <Pullenti.Ner.Slot> addSlots = new List <Pullenti.Ner.Slot>();
                        foreach (Pullenti.Ner.Slot s in prev.Slots)
                        {
                            if (s.TypeName == WeaponReferent.ATTR_TYPE)
                            {
                                tr.AddSlot(s.TypeName, s.Value, false, 0);
                            }
                            else if (s.TypeName == WeaponReferent.ATTR_BRAND || s.TypeName == WeaponReferent.ATTR_BRAND)
                            {
                                if (tr.FindSlot(s.TypeName, null, true) == null)
                                {
                                    addSlots.Add(s);
                                }
                            }
                        }
                        foreach (Pullenti.Ner.Slot s in addSlots)
                        {
                            tr.AddSlot(s.TypeName, s.Value, false, 0);
                        }
                        hasGoodNoun = true;
                        break;
                    }
                }
            }
            if (hasGoodNoun)
            {
            }
            else if (noun != null)
            {
                if (model != null || ((brand != null && !brand.IsDoubt)))
                {
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                if (model == null)
                {
                    return(null);
                }
                int  cou = 0;
                bool ok  = false;
                for (Pullenti.Ner.Token tt = t1.Previous; tt != null && (cou < 20); tt = tt.Previous, cou++)
                {
                    if ((tt.IsValue("ОРУЖИЕ", null) || tt.IsValue("ВООРУЖЕНИЕ", null) || tt.IsValue("ВЫСТРЕЛ", null)) || tt.IsValue("ВЫСТРЕЛИТЬ", null))
                    {
                        ok = true;
                        break;
                    }
                }
                if (!ok)
                {
                    return(null);
                }
            }
            List <Pullenti.Ner.ReferentToken> res = new List <Pullenti.Ner.ReferentToken>();

            res.Add(new Pullenti.Ner.ReferentToken(tr, its[0].BeginToken, t1));
            return(res);
        }
Пример #2
0
        public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ = Pullenti.Ner.Core.ReferentsEqualType.WithinOneText)
        {
            WeaponReferent tr = obj as WeaponReferent;

            if (tr == 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);
                    }
                    return(true);
                }
            }
            bool eqTypes = false;

            foreach (string t in this.GetStringValues(ATTR_TYPE))
            {
                if (tr.FindSlot(ATTR_TYPE, t, true) != null)
                {
                    eqTypes = true;
                    break;
                }
            }
            if (!eqTypes)
            {
                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 (this.FindSlot(ATTR_MODEL, s2, true) != null)
                    {
                        return(true);
                    }
                    if (tr.FindSlot(ATTR_MODEL, s1, true) != null)
                    {
                        return(true);
                    }
                    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);
        }