예제 #1
0
 void CopyFrom(OrgItemTypeTermin it)
 {
     Profiles.AddRange(it.Profiles);
     IsPurePrefix       = it.IsPurePrefix;
     CanBeNormalDep     = it.CanBeNormalDep;
     CanHasNumber       = it.CanHasNumber;
     CanHasSingleName   = it.CanHasSingleName;
     CanHasLatinName    = it.CanHasLatinName;
     MustBePartofName   = it.MustBePartofName;
     MustHasCapitalName = it.MustHasCapitalName;
     IsTop          = it.IsTop;
     CanBeNormalDep = it.CanBeNormalDep;
     CanBeSingleGeo = it.CanBeSingleGeo;
     IsDoubtWord    = it.IsDoubtWord;
     Coeff          = it.Coeff;
 }
예제 #2
0
        public static List <OrgItemTypeTermin> DeserializeSrc(XmlNode xml, OrgItemTypeTermin set)
        {
            List <OrgItemTypeTermin> res = new List <OrgItemTypeTermin>();
            bool isSet = xml.LocalName == "set";

            if (isSet)
            {
                res.Add((set = new OrgItemTypeTermin(null)));
            }
            if (xml.Attributes == null)
            {
                return(res);
            }
            foreach (XmlAttribute a in xml.Attributes)
            {
                string nam = a.LocalName;
                if (!nam.StartsWith("name"))
                {
                    continue;
                }
                Pullenti.Morph.MorphLang lang = Pullenti.Morph.MorphLang.RU;
                if (nam == "nameUa")
                {
                    lang = Pullenti.Morph.MorphLang.UA;
                }
                else if (nam == "nameEn")
                {
                    lang = Pullenti.Morph.MorphLang.EN;
                }
                OrgItemTypeTermin it = null;
                foreach (string s in a.Value.Split(';'))
                {
                    if (!string.IsNullOrEmpty(s))
                    {
                        if (it == null)
                        {
                            res.Add((it = new OrgItemTypeTermin(s, lang)));
                            if (set != null)
                            {
                                it.CopyFrom(set);
                            }
                        }
                        else
                        {
                            it.AddVariant(s, false);
                        }
                    }
                }
            }
            foreach (XmlAttribute a in xml.Attributes)
            {
                string nam = a.LocalName;
                if (nam.StartsWith("name"))
                {
                    continue;
                }
                if (nam.StartsWith("abbr"))
                {
                    Pullenti.Morph.MorphLang lang = Pullenti.Morph.MorphLang.RU;
                    if (nam == "abbrUa")
                    {
                        lang = Pullenti.Morph.MorphLang.UA;
                    }
                    else if (nam == "abbrEn")
                    {
                        lang = Pullenti.Morph.MorphLang.EN;
                    }
                    foreach (OrgItemTypeTermin r in res)
                    {
                        if (r.Lang == lang)
                        {
                            r.Acronym = a.Value;
                        }
                    }
                    continue;
                }
                if (nam == "profile")
                {
                    List <Pullenti.Ner.Org.OrgProfile> li = new List <Pullenti.Ner.Org.OrgProfile>();
                    foreach (string s in a.Value.Split(';'))
                    {
                        try
                        {
                            Pullenti.Ner.Org.OrgProfile p = (Pullenti.Ner.Org.OrgProfile)Enum.Parse(typeof(Pullenti.Ner.Org.OrgProfile), s, true);
                            if (p != Pullenti.Ner.Org.OrgProfile.Undefined)
                            {
                                li.Add(p);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.Profiles = li;
                    }
                    continue;
                }
                if (nam == "coef")
                {
                    float v = float.Parse(a.Value);
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.Coeff = v;
                    }
                    continue;
                }
                if (nam == "partofname")
                {
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.MustBePartofName = a.Value == "true";
                    }
                    continue;
                }
                if (nam == "top")
                {
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.IsTop = a.Value == "true";
                    }
                    continue;
                }
                if (nam == "geo")
                {
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.CanBeSingleGeo = a.Value == "true";
                    }
                    continue;
                }
                if (nam == "purepref")
                {
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.IsPurePrefix = a.Value == "true";
                    }
                    continue;
                }
                if (nam == "number")
                {
                    foreach (OrgItemTypeTermin r in res)
                    {
                        r.CanHasNumber = a.Value == "true";
                    }
                    continue;
                }
                throw new Exception("Unknown Org Type Tag: " + a.Name);
            }
            return(res);
        }