Beispiel #1
0
        private float[] stringToVector(string s)
        {
            ShortDoubleMetaphone metaphone = new ShortDoubleMetaphone(s);

            float[] v = new float[size];
            for (int i = 0; i < metaphone.PrimaryKey.Length; i++)
            {
                v[i] = phoneToFloat(metaphone.PrimaryKey[i]);
            }
            return(v);
        }
 /// <summary>Initializes the base class with the given word, then computes
 ///     ushort representations of the metaphone keys computed by the
 ///     base class</summary>
 ///
 /// <param name="word">Word for which to compute metaphone keys</param>
 public ShortDoubleMetaphone(string word) : base(word)
 {
     m_primaryShortKey = ShortDoubleMetaphone.MetaphoneKeyToShort(this.PrimaryKey);
     if (this.AlternateKey != null)
     {
         m_alternateShortKey = ShortDoubleMetaphone.MetaphoneKeyToShort(this.AlternateKey);
     }
     else
     {
         m_alternateShortKey = METAPHONE_INVALID_KEY;
     }
 }
        /// <summary>Sets a new current word, computing the string and ushort representations
        ///     of the metaphone keys of the given word.
        ///
        ///     Note that this uses the new modifier, which hides the base class
        ///     computeKeys.  The base class's computeKeys is then explicitly
        ///     called as part of the function body.  It is important to note that
        ///     this is NOT equivalent to overriding a virtual function, in that
        ///     polymorphism is not provided.  In this case, polymorphism is of no
        ///     value, while the potential efficiency gained by not using virtual
        ///     methods is quite valuable.</summary>
        ///
        /// <param name="word">New current word for which to compute metaphone keys</param>
        public override void ComputeKeys(string word)
        {
            base.ComputeKeys(word);

            m_primaryShortKey = ShortDoubleMetaphone.MetaphoneKeyToShort(this.PrimaryKey);
            if (this.AlternateKey != null)
            {
                m_alternateShortKey = ShortDoubleMetaphone.MetaphoneKeyToShort(this.AlternateKey);
            }
            else
            {
                m_alternateShortKey = METAPHONE_INVALID_KEY;
            }
        }
Beispiel #4
0
        public async Task <IEnumerable <User> > SearchUsers(string searchString)
        {
            List <User> results = new List <User>();

            if (string.IsNullOrEmpty(searchString))
            {
                return(results);
            }

            if (searchString.IsValidEmail())
            {
                var exactMatch = await UserDomain.RetrieveUserByEmail(searchString);

                if (exactMatch != null)
                {
                    results.Add(exactMatch);
                }
            }
            else
            {
                var topResult = await UserDomain.RetrieveUserByUsername(searchString);

                if (topResult != null)
                {
                    results.Add(topResult);
                }

                try
                {
                    var metaphone = new ShortDoubleMetaphone(searchString);

                    results.AddRange(await UserDomain.RetrieveUsersBySoundsLike(metaphone.PrimaryShortKey));
                    if (metaphone.AlternateShortKey != ShortDoubleMetaphone.METAPHONE_INVALID_KEY && metaphone.AlternateShortKey != metaphone.PrimaryShortKey)
                    {
                        results.AddRange((await UserDomain.RetrieveUsersBySoundsLike(metaphone.AlternateShortKey)));
                    }
                }
                catch (Exception) { }
            }
            return(results.Distinct());
        }