public TagConverter(ISettingsProvider settingsProvider) { using (var reader = new StreamReader(settingsProvider.Get<string>(SettingsKeys.TagMappingFile))) { normalizedTags = reader .ReadAllLines() .Where(x => !string.IsNullOrWhiteSpace(x)) .Select(ParseTagDescription) .ToDictionary(x => x.Name, x => x.RawTags); rawTagsMapping = normalizedTags .SelectMany(normalizedTag => normalizedTag.Value.Select(rawTag => new { Normalized = normalizedTag.Key, Raw = rawTag })) .ToDictionary(x => x.Raw, x => x.Normalized); } using (var reader = new StreamReader(settingsProvider.Get<string>(SettingsKeys.CorrectionsFile))) { correctionsByProblemUrl = reader .ReadAllLines() .Where(x => !string.IsNullOrWhiteSpace(x)) .SelectMany(ParseCorrections) .GroupBy(x => x.ProblemUrl) .ToDictionary(x => x.Key, x => x.ToArray()); } }
public DTDParser(string sourcedir) { ofdGetDTDName.InitialDirectory = sourcedir; ofdGetDTDName.Multiselect = false; ofdGetDTDName.CheckFileExists = true; ofdGetDTDName.DefaultExt = ".dtd"; ofdGetDTDName.Filter = @"DTD XML specifikáció (*.dtd)|*.dtd"; if (ofdGetDTDName.ShowDialog() == DialogResult.Cancel) { dtdFileName = sourcedir + @"17\appshelldata.dtd"; } else { dtdFileName = ofdGetDTDName.FileName; } if ( !File.Exists(dtdFileName )) { throw new ArgumentException("A megadott fájl nem létezik!!!! -> Objektum nem létrehozható"); } StreamReader dtdReader = new StreamReader(dtdFileName); dtdLines = dtdReader.ReadAllLines((x) => { return Regex.IsMatch(x,@"^<!ENTITY");}) ; foreach ( string ln in dtdLines ) { Match regMatch = Regex.Match( ln, @"(?<qtn>qtn_\w+)\s+" + "\"" + @"(?<kifejt>[^" + "\"" + @"]+)" + "\"" ); struParser ParserRec = new struParser { strKifejt = regMatch.Groups["kifejt"].Value, strRegex = @"\&"+regMatch.Groups["qtn"].Value+";" }; myParser.Add( ParserRec ); } }
public StopWordsFilter(ISettingsProvider settingsProvider) { var stopwordsFile = settingsProvider.Get<string>(SettingsKeys.StopwordsFile); using (var reader = new StreamReader(stopwordsFile)) { stopwords = new HashSet<string>(reader.ReadAllLines()); } }
static void Main(string[] args) { //JSON file with one line per tweet. string rawPath = @"D:\Andrew Hardin\Desktop\coastal_users_better.txt"; //Load the users. User[] Users; using (StreamReader rdr = new StreamReader(rawPath)) { Users = rdr.ReadAllLines().Select(x => new User(x)).ToArray(); } //Only select the reliable users. User[] Reliable = Users.Where(x => x.Reliable).ToArray(); //Writeout diagnostics. string Base = Path.GetDirectoryName(rawPath); WriteDistanceList(Base + @"\TriangleDistances.csv", Reliable); WriteUserKML(Base + @"\diagnostic.kml", Reliable); WriteMultipoint(Base + @"\ImportToArcmap.csv", Reliable); }
static void Main(string[] args) { //the first argument is the words file, or the default words.txt file if no arguments are given var wordsFile = args.Length == 0 ? DEFAULT_WORDS_FILE : args[0]; //read in the words from file string[] words; using (TextReader reader = new StreamReader(wordsFile)) words = reader.ReadAllLines(); //frequency of each letter, called 'r' in the psuedo-code int[] freqs = new int[26]; //symmetric digraph frequencies, called 'd' in the psuedo-code int[,] sdFreqs = new int[26, 26]; //calculate frequencies foreach (var word in words) for (int i = 0; i < word.Length; i++) { //skip words with hyphens -- just an issue with my default word dictionary if (word.Contains('-')) continue; //get the array index of this character int cur = word[i] - 'a'; //increment the overall frequency of this letter freqs[cur]++; //increment the frequency of the current character following the previous character if (i > 0) { int prev = word[i - 1] - 'a'; sdFreqs[cur, prev]++; //we're generating a symmetric matrix, so we need to increment the other //side unless we're on the diagnol if (cur != prev) sdFreqs[prev, cur]++; } } //calculate the letter with maximum frequency, called 'r.m' in the psuedo-code int maxFreq = 0; for (int i = 0; i < freqs.Length; i++) if (freqs[maxFreq] < freqs[i]) maxFreq = i; //The stack of vowels to find Stack<int> v = new Stack<int>(); //calculate the vowels while (freqs[maxFreq] > 0) { //the highest frequency letter is a vowel v.Push(maxFreq); //the next maximum frequency to find, called 'j' in the psuedo-code int nextMaxFreq = 0; //remove all occurences of the current vowel for (int i = 0; i < freqs.Length; i++) { if (i != maxFreq) freqs[i] -= 2 * sdFreqs[i, maxFreq]; else freqs[i] = 0; if (freqs[nextMaxFreq] < freqs[i]) nextMaxFreq = i; } maxFreq = nextMaxFreq; } //print out the results Console.WriteLine("Vowels found are:"); foreach (var i in v) Console.WriteLine((char)('a' + i)); }
/// <summary> /// Randomly selects words between <see cref="MinWordLength" /> characters and <see cref="MaxWordLength" /> characters /// in length, inclusive, /// from the word list. /// </summary> /// <param name="reader">A <see cref="StreamReader" /> for the word list.</param> /// <returns>A number of random words meeting the word length limitations specified by the configuration.</returns> private IEnumerable<string> GetRandomWords(StreamReader reader) { #if DEBUG Debug.WriteLine(string.Format("Processing wordlist to get words between {0} and {1} chars", this.MinWordLength, this.MaxWordLength)); Stopwatch sw = Stopwatch.StartNew(); #endif //DEBUG IEnumerable<string> suitableWords = reader.ReadAllLines() .Where(w => (w.Length >= this.MinWordLength) && (w.Length <= this.MaxWordLength)) .ToList(); #if DEBUG sw.Stop(); Debug.WriteLine(string.Format("Done in {0}", sw.Elapsed)); #endif //DEBUG for (int i = 0; i < this.WordCount; i++) { yield return suitableWords.ElementAt(this.RandomSource.Next(0, suitableWords.Count())); } }