ABB.Swum.SamuraiIdSplitter.CountProgramWords C# (CSharp) Метод

CountProgramWords() публичный статический Метод

Counts the number of occurrences of words within the identifiers in the given srcml files.
public static CountProgramWords ( ISrcMLArchive archive ) : int>.Dictionary
archive ISrcMLArchive An archive containing the srcml files to analyze.
Результат int>.Dictionary
        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;
        }