Esempio n. 1
0
        /// <summary>
        /// Ajout des attributs dans le dictionnaire de mot clé
        /// </summary>
        /// <param name="type"></param>
        /// <param name="synonymesByProduct"></param>
        public void AddAttributes(ProductType type, string attributeTypeName, Dictionary <string, string> synonymesByAttribute)
        {
            try
            {
                // Pour chaque attribut
                foreach (var pair in synonymesByAttribute)
                {
                    var attribute = pair.Key;

                    // Gestion des attributs inversés
                    var isInvert = attribute.StartsWith("!");
                    if (isInvert)
                    {
                        attribute = attribute.Substring(1);
                    }

                    var synonymes = pair.Value.Split(';');

                    // Pour chaque synonyme
                    foreach (var synonyme in synonymes)
                    {
                        if (String.IsNullOrEmpty(synonyme))
                        {
                            continue;
                        }

                        // Pour chaque déclinaison du synonyme
                        var declinations = GetDeclinations(synonyme.Simplify());
                        foreach (var declination in declinations)
                        {
                            TagValue value = attribute;
                            value.IsInvert = isInvert;

                            this[declination].Attributes[type] = new ProductAttribute()
                            {
                                AttributeTypeName = attributeTypeName,
                                ProductType       = type,
                                Value             = value,
                            };
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception($"Error in AddAttributes({type}, {attributeTypeName}, ...)", ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Récupère le score pour un type de produit
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public int GetScore(ProductType type)
        {
            // Calcule le score lors du 1er appel
            var score = 0;

            // Pour chaque mot de la définition
            foreach (var word in Words)
            {
                // Récupère le mot clé du mot
                var tag = word.Tag;

                // Si le mot clé possède un attribut lié au type de produit.
                ProductAttribute attr;
                if (tag.Attributes.TryGetValue(type, out attr))
                {
                    score += attr.Value.Score;
                    continue;
                }

                // Si le mot clé est un nombre
                TagValue number = word.Tag.Number;
                if (!number.IsEmpty)
                {
                    score += number.Score;
                    continue;
                }

                // Si le mot clé est un produit
                TagValue product;
                if (word.Tag.Products.TryGetValue(type, out product))
                {
                    score += product.Score;
                    continue;
                }
            }

            return(score);
        }
Esempio n. 3
0
 /// <summary>
 /// Si 2 mots clés sont égaux
 /// </summary>
 /// <param name="obj"></param>
 /// <returns></returns>
 public bool Equals(TagValue obj)
 {
     return(Value.Equals(obj.Value));
 }