private static TagGroups ReadTagGroups(string pathToTagGroups) { var path = Path.Combine(Directory.GetCurrentDirectory(), pathToTagGroups); var tagGroups = new TagGroups(); var groups = new StreamReader(path) .ReadToEnd() .Split(';') .Where(line => !string.IsNullOrEmpty(line)); foreach (var group in groups) { var items = group.Split(' '); var name = items[0]; var freq = items[1] .Replace('.', ',') .Split('-') .Select(double.Parse) .ToArray(); var size = items[2] .Split('x') .Select(int.Parse) .ToArray(); tagGroups.AddSizeGroup(name, new FrequencyGroup(freq[0], freq[1]), new Size(size[0], size[1])); } return(tagGroups); }
static void Main(string[] args) { if (!IsInputCorrect(args)) { return; } var pathToWords = args[0]; var pathToPicture = args[1]; var tagGroups = new TagGroups(); if (args.Length > 2) { tagGroups = ReadTagGroups(args[2]); } else { tagGroups.AddSizeGroup("Big", new FrequencyGroup(0.9, 1), new Size(80, 150)); tagGroups.AddSizeGroup("Average", new FrequencyGroup(0.6, 0.9), new Size(60, 100)); tagGroups.AddSizeGroup("Small", new FrequencyGroup(0, 0.6), new Size(30, 50)); } var settings = DrawSettings.WordsInRectangles; if (args.Length > 3) { settings = (DrawSettings)(int.Parse(args[3]) % 4); } var spiral = new Spiral(); var cloud = new CircularCloudLayouter(spiral); var visualizer = new CloudVisualizer.CloudVisualizer { Settings = settings }; var cloudItems = new TagReader(tagGroups) .GetTags(pathToWords) .Select(tag => new CloudItem(tag.Word, cloud.PutNextRectangle(tag.Size))) .ToArray(); var picture = visualizer.CreatePictureWithItems(cloudItems); picture.Save(Path.Combine(Directory.GetCurrentDirectory(), $"{pathToPicture}.png")); }