-
Notifications
You must be signed in to change notification settings - Fork 31
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
Зиновьева Милана #13
Open
crycrash
wants to merge
12
commits into
kontur-courses:master
Choose a base branch
from
crycrash: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
Зиновьева Милана #13
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
30e4e30
added the project framework and word file processing
crycrash 14620e5
added a cloud rendering algorithm and an example
crycrash 301b059
added work with di containers. added a basic command line client
crycrash 360b777
small fixes. I'm sorry for the large number of modified files, I'm ti…
crycrash d08b4ac
added center, size, and color configurations. added a readme with exa…
crycrash 825ab62
added a second location algorithm
crycrash 5a4160d
fixed issues
crycrash 28ca5d5
added part of speech selection
crycrash 18b0f48
added coloring mode
crycrash 08a02a8
Fixed the logic for excluding words.
crycrash 586002f
fixed tests
crycrash 90e440c
the mystem file has been changed for different platforms
crycrash 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 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 |
---|---|---|
|
@@ -41,3 +41,4 @@ bld/ | |
msbuild.log | ||
msbuild.err | ||
msbuild.wrn | ||
FractalPainter/ |
This file contains 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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Autofac" Version="8.2.0" /> | ||
<PackageReference Include="CommandLineParser" Version="2.5.0" /> | ||
<PackageReference Include="System.ComponentModel.Composition" Version="4.0.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="../DrawingTagsCloudVisualization/DrawingTagsCloudVisualization.csproj" /> | ||
<ProjectReference Include="../TagsCloudVisualization/TagsCloudVisualization.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains 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,72 @@ | ||
using System.Drawing; | ||
using System.Runtime.InteropServices; | ||
using Autofac; | ||
using DrawingTagsCloudVisualization; | ||
using TagsCloudVisualization; | ||
using TagsCloudVisualization.FilesProcessing; | ||
using TagsCloudVisualization.ManagingRendering; | ||
|
||
namespace ConsoleClient; | ||
|
||
public static class DependencyInjectionConfig | ||
{ | ||
public static IContainer BuildContainer(Options options) | ||
{ | ||
var builder = new ContainerBuilder(); | ||
var pathToMystem = ""; | ||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) | ||
pathToMystem = "mystem.exe"; | ||
else | ||
pathToMystem = "mystem"; | ||
builder.RegisterInstance(new MyStemWrapper.MyStem | ||
{ | ||
PathToMyStem = pathToMystem, | ||
Parameters = "-ni" | ||
}).As<MyStemWrapper.MyStem>().SingleInstance(); | ||
|
||
builder.RegisterType<MorphologicalProcessing>() | ||
.As<IMorphologicalAnalyzer>() | ||
.InstancePerDependency(); | ||
|
||
builder.RegisterType<TxtFileProcessor>() | ||
.As<IFileProcessor>() | ||
.InstancePerDependency(); | ||
|
||
builder.Register<ISpiral>(c => | ||
{ | ||
var centerPoint = new Point(options.CenterX, options.CenterY); | ||
return options.AlgorithmForming switch | ||
{ | ||
"Circle" => new ArchimedeanSpiral(centerPoint, 1), | ||
_ => new FermatSpiral(centerPoint, 20), | ||
}; | ||
}).As<ISpiral>().InstancePerDependency(); | ||
|
||
builder.RegisterType<WordHandler>() | ||
.As<IWordHandler>() | ||
.InstancePerDependency(); | ||
builder.RegisterType<RectangleGenerator>() | ||
.As<IRectangleGenerator>() | ||
.InstancePerDependency(); | ||
builder.RegisterType<TagsCloudDrawingFacade>() | ||
.As<ITagsCloudDrawingFacade>() | ||
.InstancePerDependency(); | ||
|
||
switch (options.AlgorithmDrawing) | ||
{ | ||
case "Altering": | ||
builder.RegisterType<AlternatingColorsTagsCloudDrawer>().As<ITagsCloudDrawer>() | ||
.InstancePerDependency(); | ||
break; | ||
default: | ||
builder.RegisterType<StandartTagsCloudDrawer>().As<ITagsCloudDrawer>() | ||
.InstancePerDependency(); | ||
break; | ||
} | ||
builder.RegisterType<ImageSaver>() | ||
.As<IImageSaver>() | ||
.InstancePerDependency(); | ||
|
||
return builder.Build(); | ||
} | ||
} |
This file contains 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,39 @@ | ||
# 1 example: | ||
|
||
Agrs: dotnet run | ||
 | ||
|
||
# 2 example: | ||
|
||
Args: dotnet run -- -o Examples/example1.png -l 500 -w 500 | ||
 | ||
|
||
# 3 example: | ||
|
||
Args: dotnet run -- -o Examples/example2.png -x 150 -y 300 | ||
 | ||
|
||
# 4 example: | ||
|
||
Args: dotnet run -- -c pink -o Examples/example3.png | ||
 | ||
|
||
# 5 example: | ||
|
||
Args: dotnet run -- -a Fermat -o Examples/example4.png | ||
 | ||
|
||
# 6 example: | ||
|
||
Args: dotnet run -- -p S -o Examples/example5.png | ||
 | ||
|
||
# 7 example: | ||
|
||
Args: dotnet run -- -d Altering -o Examples/example7.png | ||
 | ||
|
||
# 8 example: | ||
|
||
Args: dotnet run -- -p A,V -o Examples/example8.png -i Examples/example1.txt | ||
 |
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 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,27 @@ | ||
да | ||
о | ||
кошка | ||
кошка | ||
большой | ||
большой | ||
большой | ||
дом | ||
дом | ||
красиво | ||
красиво | ||
красиво | ||
красиво | ||
и | ||
книга | ||
книга | ||
азбука | ||
азбука | ||
кружка | ||
кружка | ||
кружка | ||
алгебра | ||
алгебра | ||
алгебра | ||
носок | ||
носок | ||
не |
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 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,49 @@ | ||
да | ||
о | ||
кошка | ||
кошка | ||
большой | ||
большой | ||
большой | ||
дом | ||
дом | ||
дом | ||
красиво | ||
красиво | ||
красиво | ||
красиво | ||
и | ||
книга | ||
книга | ||
азбука | ||
азбука | ||
кружка | ||
кружка | ||
кружка | ||
алгебра | ||
алгебра | ||
алгебра | ||
носок | ||
носок | ||
носок | ||
не | ||
говно | ||
говно | ||
говно | ||
хуй | ||
хуй | ||
хуй | ||
залупа | ||
залупа | ||
мошонник | ||
мошонник | ||
мошонник | ||
мошонник | ||
говнохуй | ||
говнохуй | ||
говнохуй | ||
говнохуй | ||
влиять | ||
влиять | ||
бегать | ||
бегать |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 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 @@ | ||
namespace ConsoleClient; | ||
public interface ITagsCloudDrawingFacade | ||
{ | ||
void DrawRectangle(Options options); | ||
} |
This file contains 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,35 @@ | ||
using CommandLine; | ||
namespace ConsoleClient; | ||
|
||
public class Options | ||
{ | ||
[Option('i', "input", Default = "Examples/example.txt", HelpText = "Путь к входному текстовому файлу.")] | ||
public required string InputFilePath { get; set; } | ||
|
||
[Option('o', "output", Default = "Examples/example.png", HelpText = "Путь к выходному изображению.")] | ||
public required string OutputFilePath { get; set; } | ||
|
||
[Option('x', "centerX", Default = 200, HelpText = "Координата X центра.")] | ||
public int CenterX { get; set; } | ||
|
||
[Option('y', "centerY", Default = 200, HelpText = "Координата Y центра.")] | ||
public int CenterY { get; set; } | ||
|
||
[Option('l', "length", Default = 400, HelpText = "Длина изображения")] | ||
public int Length { get; set; } | ||
|
||
[Option('w', "width", Default = 400, HelpText = "Ширина изображения")] | ||
public int Width{ get; set; } | ||
|
||
[Option('c', "color", Default = "black", HelpText = "Цвет текста")] | ||
public string Color{ get; set; } | ||
|
||
[Option('a', "algorithmf", Default = "Circle", HelpText = "Алгоритм формирования(квадрат, круг)")] | ||
public string AlgorithmForming{ get; set; } | ||
|
||
[Option('p', "excludedpartofspeech", Required = false, HelpText = "Исключить часть речи S V A ADV NUM SPRO ANUM ADVPRO")] | ||
public string ExcludedPartOfSpeech{ get; set; } | ||
|
||
[Option('d', "algorithmd", Default = "Standart", HelpText = "Алгоритм рисования(Standart, Altering)")] | ||
public string AlgorithmDrawing{ get; set; } | ||
} |
This file contains 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,81 @@ | ||
using Autofac; | ||
using CommandLine; | ||
|
||
namespace ConsoleClient; | ||
|
||
|
||
public class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Parser.Default.ParseArguments<Options>(args) | ||
.WithParsed(RunApplication) | ||
.WithNotParsed(HandleErrors); | ||
} | ||
readonly static private HashSet<string> validPartsOfSpeech = | ||
[ | ||
"S", "V", "A", "ADV", "NUM", "SPRO", "ADVPRO", "ANUM" | ||
]; | ||
|
||
private static void RunApplication(Options options) | ||
{ | ||
if (options.AlgorithmForming != "Circle" && options.AlgorithmForming != "Fermat") | ||
{ | ||
Console.WriteLine($"Ошибка: Неизвестный алгоритм '{options.AlgorithmForming}'. Допустимые значения: 'Circle', 'Fermat'."); | ||
return; | ||
} | ||
if (!string.IsNullOrEmpty(options.ExcludedPartOfSpeech)) | ||
{ | ||
var excludedParts = options.ExcludedPartOfSpeech.Split(',', StringSplitOptions.RemoveEmptyEntries) | ||
.Select(part => part.Trim().ToUpper()); | ||
|
||
var invalidParts = excludedParts.Where(part => !validPartsOfSpeech.Contains(part)).ToList(); | ||
|
||
if (invalidParts.Count != 0) | ||
{ | ||
Console.WriteLine($"Ошибка: Неизвестные части речи '{string.Join(", ", invalidParts)}'"); | ||
return; | ||
} | ||
} | ||
if (options.AlgorithmDrawing != "Standart" && options.AlgorithmDrawing != "Altering") | ||
{ | ||
Console.WriteLine($"Ошибка: Неизвестный алгоритм рассказки '{options.AlgorithmDrawing}'"); | ||
return; | ||
} | ||
var container = DependencyInjectionConfig.BuildContainer(options); | ||
|
||
using var scope = container.BeginLifetimeScope(); | ||
try | ||
{ | ||
scope.Resolve<ITagsCloudDrawingFacade>().DrawRectangle(options); | ||
Console.WriteLine($"Облако тегов успешно сохранено в файл: {options.OutputFilePath}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine($"Произошла ошибка: {ex.Message}"); | ||
} | ||
} | ||
|
||
private static void HandleErrors(IEnumerable<Error> errors) | ||
{ | ||
Console.WriteLine("Ошибка при обработке аргументов командной строки."); | ||
foreach (var error in errors) | ||
{ | ||
switch (error) | ||
{ | ||
case UnknownOptionError unknownOptionError: | ||
Console.WriteLine($"- Неизвестный параметр: {unknownOptionError.Token}"); | ||
break; | ||
case SetValueExceptionError setValueExceptionError: | ||
Console.WriteLine($"- Ошибка установки значения: {setValueExceptionError.Exception.Message}"); | ||
break; | ||
case MissingValueOptionError missingValueOptionError: | ||
Console.WriteLine($"- Отсутствует значение: {missingValueOptionError.NameInfo}"); | ||
break; | ||
default: | ||
Console.WriteLine($"- Неизвестная ошибка: {error.GetType().Name}"); | ||
break; | ||
} | ||
} | ||
} | ||
} |
This file contains 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,20 @@ | ||
using System.Drawing; | ||
using DrawingTagsCloudVisualization; | ||
using TagsCloudVisualization; | ||
namespace ConsoleClient; | ||
|
||
public class TagsCloudDrawingFacade( | ||
IWordHandler wordHandler, | ||
IRectangleGenerator rectangleGenerator, IImageSaver imageSaver) : ITagsCloudDrawingFacade | ||
{ | ||
private readonly IWordHandler _wordHandler = wordHandler; | ||
private readonly IRectangleGenerator _rectangleGenerator = rectangleGenerator; | ||
private readonly IImageSaver _imageSaver = imageSaver; | ||
|
||
public void DrawRectangle(Options options) | ||
{ | ||
var frequencyRectangles = _wordHandler.ProcessFile(options.InputFilePath, options.ExcludedPartOfSpeech); | ||
var arrRect = _rectangleGenerator.ExecuteRectangles(frequencyRectangles, new Point(options.CenterX, options.CenterY)); | ||
_imageSaver.SaveToFile(options.OutputFilePath, options.Length, options.Width, options.Color, arrRect); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вот тут бы обработать коллекцию ошибок, чтобы пользователя не оставить в недоумении