ABB.Swum.ConservativeIdSplitter.Split C# (CSharp) Метод

Split() публичный Метод

Splits an identifier on non-alphabetic characters and easy camelcase transitions (lowercase to uppercase).
public Split ( string identifier ) : string[]
identifier string The identifier to split
Результат string[]
        public override string[] Split(string identifier) {



            //remove any non-word or non-digit characters
            var id = nonWord.Replace(identifier, " ");                

            //split numbers from letters
            id = numLet.Replace(id, "$1 $2");
            id = numLet2.Replace(id, "$1 $2");

            //split lowercase to uppercase
            id = lowerUpper.Replace(id, "$1 $2");

            //split uppercase to lowercase
            //final uppercase letter is put with lowercase ones
            id = upperLower.Replace(id, "$1 $2");


            return id.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Counts the number of occurrences of words within the identifiers in the given srcml files.
        /// </summary>
        /// <param name="archive">An archive containing the srcml files to analyze.</param>
        /// <returns>A dictionary mapping words to the number of occurrences within identifiers.</returns>
        public static Dictionary <string, int> CountProgramWords(ISrcMLArchive archive)
        {
            if (archive == null)
            {
                throw new ArgumentNullException("archive");
            }

            var splitter     = new ConservativeIdSplitter();
            var observations = new Dictionary <string, int>();

            foreach (var fileUnit in archive.FileUnits)
            {
                //query for all the identifiers
                var identifiers = from id in fileUnit.Descendants(SRC.Name)
                                  where !id.Elements().Any()
                                  select id.Value;

                foreach (var id in identifiers)
                {
                    string[] words = splitter.Split(id);
                    foreach (string word in words)
                    {
                        int    obs;
                        string lowWord = word.ToLower();
                        observations.TryGetValue(lowWord, out obs); //gets the number of observations for the word. If it is new, obs is set to 0
                        observations[lowWord] = obs + 1;
                    }
                }
            }

            return(observations);
        }
All Usage Examples Of ABB.Swum.ConservativeIdSplitter::Split