-
Notifications
You must be signed in to change notification settings - Fork 295
Яценко Ирина #194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lholypeachy
wants to merge
14
commits into
kontur-courses:master
Choose a base branch
from
lholypeachy:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Яценко Ирина #194
Changes from 3 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
39d3095
Начальное проектирование
lholypeachy 72dc4ee
Реализация сохранения облака тегов в png файл
lholypeachy b10e764
Добавлен декоратор для TextProcessor
lholypeachy 0d8598d
Дополнен класс Options
lholypeachy dc94da5
Реализация пунктов на перспективу
lholypeachy 72b4011
Реализована сборка зависимостей
lholypeachy 7503746
Реализовано исключение "скучных" слов
lholypeachy ef70034
Исправление ошибок
lholypeachy 64d8ba7
Добавлена возможность читать pdf файлы и новые тестовые случаи
lholypeachy 4d436c6
Исправление ошибок
lholypeachy d292a71
Корректировка ITextProcessor и изменение расчета коэффициента масштаб…
lholypeachy 480aa40
Преобразование TextProcessors в коллекцию
lholypeachy 30f1be0
Разбиение процессов обработки текста на соответствующие классы
lholypeachy eb2c1f6
Рефакторинг кода
lholypeachy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| namespace TagCloudGenerator | ||
| { | ||
| public interface ITextProcessor | ||
| { | ||
| string[] ProcessText(string[] file); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| using CommandLine; | ||
| using TagCloudGenerator; | ||
|
|
||
| public class Program | ||
| { | ||
| static TagCloudDrawer tagCloudDrawer = new TagCloudDrawer(); | ||
| public class Options | ||
| { | ||
| [Option('p', "path", Required = true, HelpText = "The path for the text file.")] | ||
| public string Path { get; set; } | ||
| } | ||
| public static void Main(string[] args) | ||
| { | ||
| Parser.Default.ParseArguments<Options>(args) | ||
| .WithParsed<Options>(o => tagCloudDrawer.DrawWordsCloud(o.Path)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
LevShisterov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "profiles": { | ||
| "TagCloudGenerator": { | ||
| "commandName": "Project", | ||
| "commandLineArgs": "-p \"C:\\Users\\lholy\\Documents\\GitHub\\di\\TagCloudGeneratorTest\\TestsData\\test3.txt\"" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| using System.Drawing; | ||
| using TagsCloudVisualization.PointDistributors; | ||
| using TagsCloudVisualization; | ||
| using System.Reflection; | ||
|
|
||
| namespace TagCloudGenerator | ||
| { | ||
| public class TagCloudDrawer | ||
| { | ||
| public VisualizingSettings settings; | ||
| public void DrawWordsCloud(string filePath) | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| var tagCloudDrawer = new TagCloudDrawer(); | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var words = ReadTextFromFile(filePath); | ||
| tagCloudDrawer.Draw(words); | ||
|
|
||
| Console.WriteLine($"The tag cloud is drawn, the path to the image: {Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)}"); | ||
| } | ||
|
|
||
| private string[] ReadTextFromFile(string filePath) | ||
| { | ||
| TextProcessor textProcessor = new TextProcessor(); | ||
|
|
||
| var text = File.ReadAllLines(filePath); | ||
| return textProcessor.ProcessText(text); | ||
| } | ||
|
|
||
| private void Draw(string[] text) | ||
| { | ||
| var center = new Point(500, 500); | ||
| var distributor = new Spiral(1,center, 0.1); | ||
| var layouter = new CircularCloudLayouter(center, distributor); | ||
| var brush = new SolidBrush(Color.Aqua); | ||
| var font = new Font("Arial", 24); | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var bitmap = new Bitmap(1000, 1000); | ||
| var graphics = Graphics.FromImage(bitmap); | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for (var i = 0; i < text.Length; i++) | ||
| { | ||
| SizeF size = graphics.MeasureString(text[i], font); | ||
| var rect = layouter.PutNextRectangle(size.ToSize()); | ||
|
|
||
| if (i == 0 ) | ||
| distributor.centerOnPoint = true; | ||
|
|
||
| graphics.DrawString(text[i], font, brush, rect.X, rect.Y); | ||
|
||
| } | ||
|
|
||
| bitmap.Save("Test33.png"); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net6.0-windows</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="CommandLineParser" Version="2.9.1" /> | ||
| <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" /> | ||
| <PackageReference Include="NuGet.CommandLine" Version="6.8.0"> | ||
| <PrivateAssets>all</PrivateAssets> | ||
| <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
| </PackageReference> | ||
| <PackageReference Include="WeCantSpell.Hunspell" Version="5.0.0" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\TagsCloudVisualization\TagsCloudVisualization.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace TagCloudGenerator | ||
| { | ||
| public class TextProcessor : ITextProcessor | ||
| { | ||
| public string[] ProcessText(string[] file) | ||
| { | ||
| for (var i = 0; i < file.Length; i++) | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| file[i] = file[i].ToLower(); | ||
| } | ||
|
|
||
| return file; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| namespace TagCloudGenerator | ||
| { | ||
| public abstract class TextProcessorWrapper : ITextProcessor | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| protected readonly ITextProcessor textProcessor; | ||
| public TextProcessorWrapper(ITextProcessor textProcessor) | ||
| { | ||
| this.textProcessor = textProcessor; | ||
| } | ||
|
|
||
| public virtual string[] ProcessText(string[] file) | ||
| { | ||
| return textProcessor.ProcessText(file); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| namespace TagCloudGenerator | ||
| { | ||
| public class WordCounter | ||
| { | ||
| public Dictionary<string, int> words; | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public Dictionary<string, int> CountWords(string text) | ||
| { | ||
| words = new Dictionary<string, int>(); | ||
|
|
||
| foreach (string word in text.Split(' ')) | ||
| { | ||
| if (words.ContainsKey(word)) | ||
| words[word]++; | ||
| else words[word] = 1; | ||
| } | ||
|
|
||
| return words; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net6.0-windows</TargetFramework> | ||
|
|
||
| <IsPackable>false</IsPackable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="FluentAssertions" Version="6.12.0" /> | ||
| <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" /> | ||
| <PackageReference Include="NUnit" Version="3.13.3" /> | ||
| <PackageReference Include="NUnit3TestAdapter" Version="4.3.0" /> | ||
| <PackageReference Include="NUnit.Analyzers" Version="3.5.0" /> | ||
| <PackageReference Include="coverlet.collector" Version="3.1.2" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Folder Include="TestsData\" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\TagCloudGenerator\TagCloudGenerator.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| using FluentAssertions; | ||
| using NUnit.Framework; | ||
| using TagCloudGenerator; | ||
| using System.IO; | ||
| using System; | ||
|
|
||
| namespace TagCloudGeneratorTest | ||
| { | ||
| public class Tests | ||
| { | ||
| private TextProcessor textProcessor; | ||
|
|
||
| [SetUp] | ||
| public void Setup() | ||
| { | ||
| var processor = new TextProcessor(); | ||
| textProcessor = processor; | ||
| } | ||
|
|
||
| [Test] | ||
| public void WhenPassWordsInUppercase_ShouldReturnWordsInLowerCase() | ||
| { | ||
| var filePath = @"C:\Users\lholy\Documents\GitHub\di\TagCloudGeneratorTest\TestsData\test1.txt"; | ||
| var file = File.ReadAllLines(filePath); | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var fileText = textProcessor.ProcessText(file); | ||
|
|
||
| var result = ""; | ||
| for(var i = 0; i < fileText.Length; i++) | ||
| { | ||
| if (i == fileText.Length - 1) | ||
| { | ||
| result += fileText[i]; | ||
| continue; | ||
| } | ||
| result += (fileText[i] + Environment.NewLine); | ||
| } | ||
|
|
||
| result.Should().Be("��������\r\n������\r\n�����\r\n��\r\n�����"); | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| Создание | ||
| Облака | ||
| Тегов | ||
| Из | ||
| Файла |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| из | ||
| оно | ||
| на |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| Sun | ||
| of | ||
| the | ||
| sleepless | ||
| Melancholy | ||
| star | ||
| Whose | ||
| tearful | ||
| beam | ||
| glows | ||
| tremulously | ||
| far | ||
| That | ||
| show’st | ||
| the | ||
| darkness | ||
| thou | ||
| canst | ||
| not | ||
| dispel | ||
| How | ||
| like | ||
| art | ||
| thou | ||
| to | ||
| joy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using System; | ||
| using System.Drawing; | ||
| using System.Linq; | ||
| using TagsCloudVisualization.PointDistributors; | ||
|
|
||
| namespace TagsCloudVisualization | ||
| { | ||
| public class CircularCloudLayouter : ICircularCloudLayouter | ||
| { | ||
| private readonly Cloud cloud; | ||
| private readonly IPointDistributor distributor; | ||
|
|
||
| public CircularCloudLayouter(Point center, IPointDistributor type) | ||
LevShisterov marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| cloud = new Cloud(center); | ||
| distributor = type; | ||
| } | ||
|
|
||
| public Rectangle PutNextRectangle(Size rectangleSize) | ||
| { | ||
| if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) | ||
| throw new ArgumentException(); | ||
|
|
||
| if (cloud.Rectangles.Count == 0) | ||
| return AddToCenterPosition(rectangleSize); | ||
|
|
||
| var rectangle = new Rectangle(distributor.GetPosition(), rectangleSize); | ||
|
|
||
| while (HaveIntersection(rectangle)) | ||
| { | ||
| rectangle.Location = distributor.GetPosition(); | ||
| } | ||
|
|
||
| cloud.Rectangles.Add(rectangle); | ||
|
|
||
| return rectangle; | ||
| } | ||
|
|
||
| private Rectangle AddToCenterPosition(Size rectangleSize) | ||
| { | ||
| var newRectangle = new Rectangle(new Point(cloud.Center.X - rectangleSize.Width / 2, | ||
| cloud.Center.Y - rectangleSize.Height / 2), rectangleSize); | ||
|
|
||
| cloud.Rectangles.Add(newRectangle); | ||
|
|
||
| return newRectangle; | ||
| } | ||
|
|
||
| private bool HaveIntersection(Rectangle newRectangle) => | ||
| cloud.Rectangles.Any(rectangle => rectangle.IntersectsWith(newRectangle)); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using System.Collections.Generic; | ||
| using System.Drawing; | ||
|
|
||
| namespace TagsCloudVisualization | ||
| { | ||
| public class Cloud | ||
| { | ||
| public Cloud(Point center) | ||
| { | ||
| Center = center; | ||
| } | ||
|
|
||
| public readonly Point Center; | ||
| public readonly List<Rectangle> Rectangles = new(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System.Drawing; | ||
|
|
||
| namespace TagsCloudVisualization | ||
| { | ||
| public interface ICircularCloudLayouter | ||
| { | ||
| Rectangle PutNextRectangle(Size rectangleSize); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
TagsCloudVisualization/PointDistributors/IPointDistributor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System.Drawing; | ||
|
|
||
| namespace TagsCloudVisualization.PointDistributors | ||
| { | ||
| public interface IPointDistributor | ||
| { | ||
| Point GetPosition(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.