Skip to content
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

Галичев Артем #20

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions TagsCloudConsole/Extensions/ContainerBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public static class ContainerBuilderExtensions
{
public static ContainerBuilder RegisterWordAnalytics(this ContainerBuilder builder)
{
builder.RegisterType<Mystem.Net.Mystem>().AsSelf();
builder.RegisterInstance(WordList.CreateFromFiles("Dictionaries/ru/ru.dic"));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не обработал кейс, когда словарь не смогли подгрузить, надо пользователю сказать, что не так и что нужно сделать


return builder;
Expand Down Expand Up @@ -80,7 +79,7 @@ public static ContainerBuilder RegisterTagLayouter(this ContainerBuilder builder

public static ContainerBuilder RegisterTagVisualizer(this ContainerBuilder builder)
{
builder.RegisterType<TagVisualizer>().As<ITagVisualizer>();
builder.RegisterType<CartesianTagVisualizer>().As<ITagVisualizer>();

return builder;
}
Expand Down
6 changes: 2 additions & 4 deletions TagsCloudVisualization/ImageSavers/PngSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ namespace TagsCloudVisualization.ImageSavers;

public class PngSaver(string path) : IImageSaver
{
public void Save(Bitmap bitmap)
{
throw new NotImplementedException();
}
public void Save(Bitmap bitmap) =>
bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Png);
}
2 changes: 2 additions & 0 deletions TagsCloudVisualization/Layouters/TagLayouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public class TagLayouter : ITagLayouter

public TagLayouter(ICloudLayouter cloudLayouter, TagLayouterOptions options)
{
if (options.MinFontSize <= 0)
throw new ArgumentException($"{nameof(options.MinFontSize)} must be more than zero.");
if (options.MinFontSize > options.MaxFontSize)
throw new ArgumentException($"{nameof(options.MinFontSize)} must be less or equal {nameof(options.MaxFontSize)}");

Expand Down
6 changes: 5 additions & 1 deletion TagsCloudVisualization/TagsCloudVisualization.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mystem.Net" Version="1.0.0" />
<PackageReference Include="DeepMorphy" Version="2.0.3" />
<PackageReference Include="System.Drawing.Common" Version="8.0.10" />
<PackageReference Include="WeCantSpell.Hunspell" Version="5.2.1" />
</ItemGroup>

<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Runtime.Loader.UseRidGraph" Value="true" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions TagsCloudVisualization/TextReaders/TxtReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ namespace TagsCloudVisualization.TextReaders;

public class TxtReader : ITextReader
{
public bool IsCanRead(string filePath)
{
throw new NotImplementedException();
}
public bool IsCanRead(string filePath) =>
filePath.EndsWith(".txt");

public string ReadWords(string filePath)
{
throw new NotImplementedException();
using var reader = new StreamReader(filePath);

return reader.ReadToEnd();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно без стрима, просто File.ReadAllText(Async)

}
}
29 changes: 29 additions & 0 deletions TagsCloudVisualization/Visualizers/CartesianTagVisualizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Drawing;
using TagsCloudVisualization.ColorFactories;
using TagsCloudVisualization.Models;

namespace TagsCloudVisualization.Visualizers;

public class CartesianTagVisualizer(IColorFactory colorFactory, Size imageSize) : ITagVisualizer
{
private readonly Point _centerOffset = new Point(imageSize.Width / 2, imageSize.Height / 2);
private readonly Size _imageSize = imageSize;

public Bitmap Visualize(IEnumerable<Tag> tags)
{
var bitmap = new Bitmap(_imageSize.Width, _imageSize.Height);
using var graphics = Graphics.FromImage(bitmap);

foreach (var tag in tags)
{
var brush = new SolidBrush(colorFactory.GetColor());
var font = new Font(tag.FontFamily, tag.FontSize);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Эти штуки тоже IDisposable реализуют

var rectangle = tag.Rectangle;
rectangle.Offset(_centerOffset);

graphics.DrawString(tag.Content, font, brush, tag.Rectangle);
}

return bitmap;
}
}
13 changes: 0 additions & 13 deletions TagsCloudVisualization/Visualizers/TagVisualizer.cs

This file was deleted.

23 changes: 10 additions & 13 deletions TagsCloudVisualization/WordsHandlers/BoringWordsHandler.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
using DeepMorphy;

namespace TagsCloudVisualization.WordsHandlers;

public class BoringWordsHandler(Mystem.Net.Mystem mystem) : IWordHandler
public class BoringWordsHandler : IWordHandler
{
private static readonly MorphAnalyzer Analyzer = new();
private static readonly HashSet<string> CorrectSpeechParts = ["сущ", "инф_гл", "прил", "деепр"];

public IEnumerable<string> Handle(IEnumerable<string> words)
{
foreach (var word in words)
{
var lemma = mystem.Mystem.Analyze(word).Result![0];

var grammeme = lemma.AnalysisResults.First().Grammeme!;
var speechPart = grammeme[..grammeme.IndexOf(',')];

if (speechPart != "S" && speechPart != "V")
continue;

yield return word;
}
return Analyzer
.Parse(words)
.Where(x => CorrectSpeechParts.Contains(x["чр"].BestGramKey))
.Select(x => x.Text);
}
}
3 changes: 2 additions & 1 deletion di.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=archimedean/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=layouter/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=layouters/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=layouters/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=_0434_0435_0435_043F_0440/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>