Esempio n. 1
0
        public override bool CanBeEquals(Pullenti.Ner.Referent obj, Pullenti.Ner.Core.ReferentsEqualType typ = Pullenti.Ner.Core.ReferentsEqualType.WithinOneText)
        {
            BankDataReferent bd = obj as BankDataReferent;

            if (bd == null)
            {
                return(false);
            }
            foreach (Pullenti.Ner.Slot s in Slots)
            {
                if (s.TypeName == ATTR_ITEM)
                {
                    Pullenti.Ner.Uri.UriReferent ur = s.Value as Pullenti.Ner.Uri.UriReferent;
                    string val = bd.FindValue(ur.Scheme);
                    if (val != null)
                    {
                        if (val != ur.Value)
                        {
                            return(false);
                        }
                    }
                }
                else if (s.TypeName == ATTR_BANK)
                {
                    Pullenti.Ner.Referent b1 = s.Value as Pullenti.Ner.Referent;
                    Pullenti.Ner.Referent b2 = bd.GetSlotValue(ATTR_BANK) as Pullenti.Ner.Referent;
                    if (b2 != null)
                    {
                        if (b1 != b2 && !b1.CanBeEquals(b2, Pullenti.Ner.Core.ReferentsEqualType.WithinOneText))
                        {
                            return(false);
                        }
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        Pullenti.Ner.ReferentToken TryAttach(Pullenti.Ner.Token t, bool keyWord)
        {
            if (t == null)
            {
                return(null);
            }
            Pullenti.Ner.Token t0       = t;
            Pullenti.Ner.Token t1       = t;
            List <string>      urisKeys = null;
            List <Pullenti.Ner.Uri.UriReferent> uris = null;

            Pullenti.Ner.Referent org    = null;
            Pullenti.Ner.Referent corOrg = null;
            bool orgIsBank = false;
            int  empty     = 0;

            Pullenti.Ner.Uri.UriReferent lastUri = null;
            for (; t != null; t = t.Next)
            {
                if (t.IsTableControlChar && t != t0)
                {
                    break;
                }
                if (t.IsComma || t.Morph.Class.IsPreposition || t.IsCharOf("/\\"))
                {
                    continue;
                }
                bool bankKeyword = false;
                if (t.IsValue("ПОЛНЫЙ", null) && t.Next != null && ((t.Next.IsValue("НАИМЕНОВАНИЕ", null) || t.Next.IsValue("НАЗВАНИЕ", null))))
                {
                    t = t.Next.Next;
                    if (t == null)
                    {
                        break;
                    }
                }
                if (t.IsValue("БАНК", null))
                {
                    if ((t is Pullenti.Ner.ReferentToken) && t.GetReferent().TypeName == "ORGANIZATION")
                    {
                        bankKeyword = true;
                    }
                    Pullenti.Ner.Token tt = t.Next;
                    Pullenti.Ner.Core.NounPhraseToken npt = Pullenti.Ner.Core.NounPhraseHelper.TryParse(tt, Pullenti.Ner.Core.NounPhraseParseAttr.No, 0, null);
                    if (npt != null)
                    {
                        tt = npt.EndToken.Next;
                    }
                    if (tt != null && tt.IsChar(':'))
                    {
                        tt = tt.Next;
                    }
                    if (tt != null)
                    {
                        if (!bankKeyword)
                        {
                            t           = tt;
                            bankKeyword = true;
                        }
                        else if (tt.GetReferent() != null && tt.GetReferent().TypeName == "ORGANIZATION")
                        {
                            t = tt;
                        }
                    }
                }
                Pullenti.Ner.Referent r = t.GetReferent();
                if (r != null && r.TypeName == "ORGANIZATION")
                {
                    bool isBank = false;
                    int  kk     = 0;
                    for (Pullenti.Ner.Referent rr = r; rr != null && (kk < 4); rr = rr.ParentReferent, kk++)
                    {
                        isBank = string.Compare(rr.GetStringValue("KIND") ?? "", "Bank", true) == 0;
                        if (isBank)
                        {
                            break;
                        }
                    }
                    if (!isBank && bankKeyword)
                    {
                        isBank = true;
                    }
                    if (!isBank && uris != null && urisKeys.Contains("ИНН"))
                    {
                        return(null);
                    }
                    if ((lastUri != null && lastUri.Scheme == "К/С" && t.Previous != null) && t.Previous.IsValue("В", null))
                    {
                        corOrg = r;
                        t1     = t;
                    }
                    else if (org == null || ((!orgIsBank && isBank)))
                    {
                        org       = r;
                        t1        = t;
                        orgIsBank = isBank;
                        if (isBank)
                        {
                            continue;
                        }
                    }
                    if (uris == null && !keyWord)
                    {
                        return(null);
                    }
                    continue;
                }
                if (r is Pullenti.Ner.Uri.UriReferent)
                {
                    Pullenti.Ner.Uri.UriReferent u = r as Pullenti.Ner.Uri.UriReferent;
                    if (uris == null)
                    {
                        if (!_isBankReq(u.Scheme))
                        {
                            return(null);
                        }
                        if (u.Scheme == "ИНН" && t.IsNewlineAfter)
                        {
                            return(null);
                        }
                        uris     = new List <Pullenti.Ner.Uri.UriReferent>();
                        urisKeys = new List <string>();
                    }
                    else
                    {
                        if (!_isBankReq(u.Scheme))
                        {
                            break;
                        }
                        if (urisKeys.Contains(u.Scheme))
                        {
                            break;
                        }
                        if (u.Scheme == "ИНН")
                        {
                            if (empty > 0)
                            {
                                break;
                            }
                        }
                    }
                    urisKeys.Add(u.Scheme);
                    uris.Add(u);
                    lastUri = u;
                    t1      = t;
                    empty   = 0;
                    continue;
                }
                else if (uris == null && !keyWord && !orgIsBank)
                {
                    return(null);
                }
                if (r != null && ((r.TypeName == "GEO" || r.TypeName == "ADDRESS")))
                {
                    empty++;
                    continue;
                }
                if (t is Pullenti.Ner.TextToken)
                {
                    if (t.IsValue("ПОЛНЫЙ", null) || t.IsValue("НАИМЕНОВАНИЕ", null) || t.IsValue("НАЗВАНИЕ", null))
                    {
                    }
                    else if (t.Chars.IsLetter)
                    {
                        Pullenti.Ner.Core.TerminToken tok = m_Ontology.TryParse(t, Pullenti.Ner.Core.TerminParseAttr.No);
                        if (tok != null)
                        {
                            t     = tok.EndToken;
                            empty = 0;
                        }
                        else
                        {
                            empty++;
                            if (t.IsNewlineBefore)
                            {
                                Pullenti.Ner.Core.NounPhraseToken nnn = Pullenti.Ner.Core.NounPhraseHelper.TryParse(t, Pullenti.Ner.Core.NounPhraseParseAttr.No, 0, null);
                                if (nnn != null && nnn.EndToken.Next != null && nnn.EndToken.Next.IsChar(':'))
                                {
                                    break;
                                }
                            }
                        }
                        if (uris == null)
                        {
                            break;
                        }
                    }
                }
                if (empty > 2)
                {
                    break;
                }
                if (empty > 0 && t.IsChar(':') && t.IsNewlineAfter)
                {
                    break;
                }
                if (((t is Pullenti.Ner.NumberToken) && t.IsNewlineBefore && t.Next != null) && !t.Next.Chars.IsLetter)
                {
                    break;
                }
            }
            if (uris == null)
            {
                return(null);
            }
            if (!urisKeys.Contains("Р/С") && !urisKeys.Contains("Л/С"))
            {
                return(null);
            }
            bool ok = false;

            if ((uris.Count < 2) && org == null)
            {
                return(null);
            }
            BankDataReferent bdr = new BankDataReferent();

            foreach (Pullenti.Ner.Uri.UriReferent u in uris)
            {
                bdr.AddSlot(BankDataReferent.ATTR_ITEM, u, false, 0);
            }
            if (org != null)
            {
                bdr.AddSlot(BankDataReferent.ATTR_BANK, org, false, 0);
            }
            if (corOrg != null)
            {
                bdr.AddSlot(BankDataReferent.ATTR_CORBANK, corOrg, false, 0);
            }
            Pullenti.Ner.Referent org0 = (t0.Previous == null ? null : t0.Previous.GetReferent());
            if (org0 != null && org0.TypeName == "ORGANIZATION")
            {
                foreach (Pullenti.Ner.Slot s in org0.Slots)
                {
                    if (s.Value is Pullenti.Ner.Uri.UriReferent)
                    {
                        Pullenti.Ner.Uri.UriReferent u = s.Value as Pullenti.Ner.Uri.UriReferent;
                        if (_isBankReq(u.Scheme))
                        {
                            if (!urisKeys.Contains(u.Scheme))
                            {
                                bdr.AddSlot(BankDataReferent.ATTR_ITEM, u, false, 0);
                            }
                        }
                    }
                }
            }
            return(new Pullenti.Ner.ReferentToken(bdr, t0, t1));
        }