Пример #1
0
 /// <summary>
 /// Compare this content instance to another instance. Compares by name.
 /// </summary>
 /// <param name="obj">Object to compare this instance to</param>
 /// <returns>Comparison results</returns>
 public int CompareTo(object obj)
 {
     if (obj is SimplifyStringResults)
     {
         SimplifyStringResults t2 = (SimplifyStringResults)obj;
         return(((int)this.Modifications).CompareTo((int)t2.Modifications));
     }
     else
     {
         throw new ArgumentException("Object is not a SimplifyStringResults type.");
     }
 }
Пример #2
0
        /// <summary>
        /// Creates of list of simplified strings from an input string (multiple results created from enabling various optional word removals).
        /// </summary>
        /// <param name="input">String to be simplified</param>
        /// <returns>List of simplified string results</returns>
        public static List <SimplifyStringResults> SimplifyString(string input)
        {
            // Create list of simplified strings
            List <SimplifyStringResults> simpliedStrings = new List <SimplifyStringResults>();

            // Set number of optional combinations for simplifying string with
            int optionCombinations = (int)Math.Pow(2, OptionalRemoveWords.Length + 2);

            // Loop twice: with and without word splitting
            for (int i = 0; i < 2; i++)
            {
                // Go through all combinations of optional removes
                for (int j = 0; j < optionCombinations; j++)
                {
                    // With and without breack content removal
                    for (int k = 0; k < 2; k++)
                    {
                        // Build options
                        OptionalSimplifyRemoves options = (OptionalSimplifyRemoves)(j >> 2);

                        // Don't do both year removes
                        if ((options & OptionalSimplifyRemoves.Year) > 0 && (options & OptionalSimplifyRemoves.YearAndFollowing) > 0)
                        {
                            continue;
                        }

                        // Get results
                        bool removeFirst = (j & 1) > 0;
                        bool removeLast  = (j & 2) > 0;
                        SimplifyStringResults simpleRes = BuildSimplifyResults(input, removeFirst, removeLast, options, false, i == 1, true, k == 1);

                        // Don't allow result that is only the year
                        if (Regex.IsMatch(simpleRes.SimplifiedString, @"^(19|20)\d{2}$") && !simpleRes.RemovedWords.ContainsKey(FileWordType.Year))
                        {
                            continue;
                        }

                        // Don't let common single words through
                        if (!simpleRes.SimplifiedString.Contains(' ') && simpleRes.SimplifiedString.Length < 3 && WordHelper.IsWord(simpleRes.SimplifiedString))
                        {
                            continue;
                        }

                        // Add to list of simplified strings
                        bool exists = false;
                        foreach (SimplifyStringResults simplifyRes in simpliedStrings)
                        {
                            if (simplifyRes.SimplifiedString == simpleRes.SimplifiedString)
                            {
                                exists = true;
                                break;
                            }
                        }

                        // Check that simplification doesn't already exist!
                        if (!exists && !string.IsNullOrEmpty(simpleRes.SimplifiedString))
                        {
                            simpliedStrings.Add(simpleRes);
                        }
                    }
                }
            }

            return(simpliedStrings);
        }