Exemplo n.º 1
0
        private IndexedString[] splitByEntry(IndexedString source, string entry)
        {
            int indexofentry = source.Text.IndexOf(entry, System.StringComparison.Ordinal);
            var result       = new IndexedString[3];

            //
            // Compute realitve indexes
            //
            int leftindex  = source.Index;
            int entryindex = source.Index + indexofentry;
            int rightindex = source.Index + indexofentry + entry.Length;

            //
            // Generate substrings
            //
            string leftstring  = source.Text.Substring(0, indexofentry);
            string entrystring = entry;
            string rightstring = source.Text.Substring(indexofentry + entry.Length);

            //
            // Generate results
            //
            result[0] = new IndexedString(leftindex, leftstring, false);
            result[1] = new IndexedString(entryindex, entrystring, true);
            result[2] = new IndexedString(rightindex, rightstring, false);
            return(result);
        }
Exemplo n.º 2
0
    public static IEnumerable InitMethod(String Source, String Delimiter)
    {
        /* bja: ok the reason i didn't just do String.Split and call it a day, is this...
         * i'm denormalizing a comma delimited list of addresscodes into Session.NearestStores (e.g. '403,430,603')
         * and naturally they need to be sorted by distance when the "nearest stores" list is displayed to the user.
         * so rather than carrying around the distance and complicating my storage of those values,
         * i wanted to simply depend on the original sort order of the stores determined by distance at the time they were calculated
         * the annoying thing is, sql server is non deterministic about the sequence of calling the FillRow method so that it has the option to parallelize the query if it wants
         * and in practice, i noticed the sort order of the results from this function as being in exactly the opposite order when returned (i.e. 603 was row 1, 430 row 2 & 403 row 3, rather than the other way around)
         */

        if (Source == null)
        {
            return(new IndexedString[] { });
        }

        string[] strings = Source.Split(new String[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries);

        IndexedString[] indexedStrings = new IndexedString[strings.Length];
        for (int i = 0; i < strings.Length; i++)
        {
            indexedStrings[i].index = i;
            indexedStrings[i].str   = strings[i].Trim();
        }

        return(indexedStrings);
    }
Exemplo n.º 3
0
        public string SplitToWords(string input)
        {
            _substringsbuffer = new List <IndexedString> [input.Length + 1, input.Length + 1];

            var stringtosplit = new IndexedString(0, input, false);


            var sortedlist = RecursiveWordSearch(stringtosplit, _dictionary).OrderBy(x => x.Index);

            return(sortedlist.Aggregate("", (current, word) => current + word.Text + " "));
        }
Exemplo n.º 4
0
        public string SplitToWords(string Input)
        {
            substringBuffer = new List <IndexedString> [Input.Length + 1, Input.Length + 1];
            IndexedString stringToSplit = new IndexedString(0, Input, false);

            var    sortedList = recursiveWordSearch(stringToSplit, Dictionary).OrderBy(x => x.index);
            string result     = "";

            foreach (var word in sortedList)
            {
                result = result + word.text + " ";
            }
            return(result);
        }
Exemplo n.º 5
0
        //-------------------------------------------------------------------------------------------------------------
        public int getSelectedStringIndex()
        {
            int index = SelectedIndex;

            if (index == -1)
            {
                return(-1);
            }
            IndexedString indexedString = Items[index] as IndexedString;

            if (indexedString == null)
            {
                return(-1);
            }
            return(indexedString.m_index);
        }
Exemplo n.º 6
0
        private List <IndexedString> recursiveWordSearch(IndexedString stringToSplit, string[] Dictionary)
        {
            int len = stringToSplit.text.Length;

            if (substringBuffer[stringToSplit.index, len + stringToSplit.index] != null)
            {
                return(substringBuffer[stringToSplit.index, len + stringToSplit.index]);
            }

            List <IndexedString> result = new List <IndexedString>();

            result.Add(stringToSplit);

            string[] newDictionary = Dictionary.Where(x => stringToSplit.text.Contains(x)).ToArray();

            if (newDictionary.Length < 1)
            {
                return(result);
            }

            foreach (string entry in newDictionary)
            {
                List <IndexedString> temp = new List <IndexedString>();

                IndexedString[] divByEntry = splitByEntry(stringToSplit, entry);

                IndexedString left   = divByEntry[0];
                IndexedString middle = divByEntry[1];
                IndexedString right  = divByEntry[2];

                temp.Add(middle);
                temp.AddRange(recursiveWordSearch(left, newDictionary));
                temp.AddRange(recursiveWordSearch(right, newDictionary));

                var tempScore    = temp.Where(x => x.word == true);
                var currentScore = result.Where(x => x.word == true);

                if (tempScore.Select(x => x.text.Length).Sum() > currentScore.Select(x => x.text.Length).Sum())
                {
                    result = temp;
                }
            }
            substringBuffer[stringToSplit.index, len + stringToSplit.index] = result;
            return(result);
        }
Exemplo n.º 7
0
        private IndexedString[] splitByEntry(IndexedString source, string entry)
        {
            int indexOfEntry = source.text.IndexOf(entry);

            IndexedString[] result = new IndexedString[3];

            int leftIndex  = source.index;
            int entryIndex = source.index + indexOfEntry;
            int rightIndex = source.index + indexOfEntry + entry.Length;

            string leftString  = source.text.Substring(0, indexOfEntry);
            string entryString = entry;
            string rightString = source.text.Substring(indexOfEntry + entry.Length);

            result[0] = new IndexedString(leftIndex, leftString, false);
            result[1] = new IndexedString(entryIndex, entryString, true);
            result[2] = new IndexedString(rightIndex, rightString, false);

            return(result);
        }
Exemplo n.º 8
0
  public static IEnumerable InitMethod(String Source, String Delimiter) {

    /* bja: ok the reason i didn't just do String.Split and call it a day, is this...
     * i'm denormalizing a comma delimited list of addresscodes into Session.NearestStores (e.g. '403,430,603')
     * and naturally they need to be sorted by distance when the "nearest stores" list is displayed to the user.
     * so rather than carrying around the distance and complicating my storage of those values,
     * i wanted to simply depend on the original sort order of the stores determined by distance at the time they were calculated
     * the annoying thing is, sql server is non deterministic about the sequence of calling the FillRow method so that it has the option to parallelize the query if it wants
     * and in practice, i noticed the sort order of the results from this function as being in exactly the opposite order when returned (i.e. 603 was row 1, 430 row 2 & 403 row 3, rather than the other way around)
     */

    if (Source == null)
      return (new IndexedString[] { });

    string[] strings = Source.Split(new String[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries);

    IndexedString[] indexedStrings = new IndexedString[strings.Length];
    for (int i = 0; i < strings.Length; i++) {
      indexedStrings[i].index = i;
      indexedStrings[i].str = strings[i].Trim();
    }

    return indexedStrings;
  }
Exemplo n.º 9
0
        //
        // Private Methods
        //
        private IEnumerable <IndexedString> RecursiveWordSearch(
            IndexedString stringtosplit,
            IEnumerable <string> dictionary)
        {
            //
            // Checking the buffer
            //
            int length = stringtosplit.Text.Length;

            if (_substringsbuffer[stringtosplit.Index, length + stringtosplit.Index] != null)
            {
                return(_substringsbuffer[stringtosplit.Index, length + stringtosplit.Index]);
            }

            //
            // Initializing result list
            //
            var result = new List <IndexedString> {
                stringtosplit
            };

            //
            // Narrowing the dictionary
            //
            string[] newdictionary = dictionary.Where(x => stringtosplit.Text.Contains(x)).ToArray();

            //
            // Trivial case
            //
            if (newdictionary.Length < 1)
            {
                return(result);
            }

            //
            // Non trivial case
            //
            foreach (string entry in newdictionary)
            {
                var temporarylist = new List <IndexedString>();

                //
                // Deviding the string to 3 parts: the entry, left and right
                //
                IndexedString[] devidedBytheEntry = splitByEntry(stringtosplit, entry);

                IndexedString left   = devidedBytheEntry[0];
                IndexedString middle = devidedBytheEntry[1];
                IndexedString right  = devidedBytheEntry[2];

                //
                // Calling the method on the other two parts recursively
                //
                temporarylist.Add(middle);
                temporarylist.AddRange(RecursiveWordSearch(left, newdictionary));
                temporarylist.AddRange(RecursiveWordSearch(right, newdictionary));

                //
                // Comparing current score and temporary score
                //
                var temporaryScore = temporarylist.Where(x => x.Word);
                var currentScore   = result.Where(x => x.Word);

                if (temporaryScore.Select(
                        x => x.Text.Length).Sum() > currentScore.Select(
                        x => x.Text.Length).Sum())
                {
                    result = temporarylist;
                }
            }
            _substringsbuffer[stringtosplit.Index, length + stringtosplit.Index] = result;
            return(result);
        }