-
Notifications
You must be signed in to change notification settings - Fork 303
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
Овечкин Илья #193
Open
magnat0
wants to merge
10
commits into
kontur-courses:master
Choose a base branch
from
magnat0: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
Овечкин Илья #193
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a03b6f7
add tests
magnat0 e5aa566
realization an application to create a tag cloud
magnat0 c9ca5fe
delete unused usings + change the modifier to private
magnat0 fc18be4
change the encoding + change client name
magnat0 476c62a
transfer code from tagCloudClient to Actions
magnat0 68f2a8f
small refactor
magnat0 51685ac
change class registration
magnat0 69b18b8
fix the namespace and refactor RectanglePlace
magnat0 c969104
edit class registration and delete the drawer constructor
magnat0 fa7e208
refactor tests
magnat0 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using TagsCloudContainer.Client; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
using TagsCloudContainer.Infrastucture.UiActions; | ||
|
||
namespace TagsCloudContainer.Actions | ||
{ | ||
public class AlgorithmSettingsAction : IUiAction | ||
{ | ||
private AlgorithmSettings algorithmSettings; | ||
private ITagCloudClient tagCloudClient; | ||
|
||
public AlgorithmSettingsAction(AlgorithmSettings settings, ITagCloudClient tagCloudClient) | ||
{ | ||
this.algorithmSettings = settings; | ||
this.tagCloudClient = tagCloudClient; | ||
} | ||
|
||
public string Category => "���������"; | ||
|
||
public string Name => "��������"; | ||
|
||
public string Description => "�������� ��������� ���������"; | ||
|
||
public void Perform() | ||
{ | ||
tagCloudClient.SetSettings(algorithmSettings); | ||
} | ||
} | ||
} |
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,32 @@ | ||
using TagsCloudContainer.Client; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
using TagsCloudContainer.Infrastucture.UiActions; | ||
|
||
namespace TagsCloudContainer.Actions | ||
{ | ||
public class DrawTagCloudAction : IUiAction | ||
{ | ||
private ImageSettings imageSettings; | ||
private FileSettings fileSettings; | ||
private ITagCloudClient tagCloudClient; | ||
|
||
public DrawTagCloudAction(ImageSettings imageSettings, FileSettings fileSettings, ITagCloudClient tagCloudClient) | ||
{ | ||
this.tagCloudClient = tagCloudClient; | ||
this.imageSettings = imageSettings; | ||
this.fileSettings = fileSettings; | ||
} | ||
|
||
public string Category => "�����������"; | ||
|
||
public string Name => "���������� �����������"; | ||
|
||
public string Description => "���������� ����������� ������ �����"; | ||
|
||
public void Perform() | ||
{ | ||
tagCloudClient.DrawImage(fileSettings.SourceFilePath, | ||
fileSettings.BoringFilePath, imageSettings.Width, imageSettings.Height); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using TagsCloudContainer.Client; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
using TagsCloudContainer.Infrastucture.UiActions; | ||
|
||
namespace TagsCloudContainer.Actions | ||
{ | ||
public class ImageSettingsAction : IUiAction | ||
{ | ||
private ImageSettings imageSettings; | ||
private ITagCloudClient tagCloudClient; | ||
|
||
public ImageSettingsAction(ImageSettings settings, ITagCloudClient tagCloudClient) | ||
{ | ||
this.imageSettings = settings; | ||
this.tagCloudClient = tagCloudClient; | ||
} | ||
|
||
public string Category => "���������"; | ||
|
||
public string Name => "�����������"; | ||
|
||
public string Description => "�������� ��������� �����������"; | ||
|
||
public void Perform() | ||
{ | ||
tagCloudClient.SetSettings(imageSettings); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using TagsCloudContainer.Client; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
using TagsCloudContainer.Infrastucture.UiActions; | ||
|
||
namespace TagsCloudContainer.Actions | ||
{ | ||
public class SaveImageAction : IUiAction | ||
{ | ||
private FileSettings fileSettings; | ||
private ITagCloudClient tagCloudClient; | ||
|
||
public SaveImageAction(FileSettings settings, ITagCloudClient tagCloudClient) | ||
{ | ||
this.fileSettings = settings; | ||
this.tagCloudClient = tagCloudClient; | ||
} | ||
|
||
public string Category => "�����������"; | ||
|
||
public string Name => "���������"; | ||
|
||
public string Description => "��������� �����������"; | ||
|
||
public void Perform() | ||
{ | ||
tagCloudClient.SaveImage(fileSettings.ImagePath); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using TagsCloudContainer.Client; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
using TagsCloudContainer.Infrastucture.UiActions; | ||
|
||
namespace TagsCloudContainer.Actions | ||
{ | ||
public class SelectBoringWordsFileAction : IUiAction | ||
{ | ||
private FileSettings fileSetting; | ||
private ITagCloudClient tagCloudClient; | ||
|
||
public SelectBoringWordsFileAction(FileSettings settings, ITagCloudClient tagCloudClient) | ||
{ | ||
this.fileSetting = settings; | ||
this.tagCloudClient = tagCloudClient; | ||
} | ||
|
||
public string Category => "�����"; | ||
|
||
public string Name => "���� �� �������� �������"; | ||
|
||
public string Description => "������� ���� �� ������� ������� ����"; | ||
|
||
public void Perform() | ||
{ | ||
fileSetting.BoringFilePath = tagCloudClient.SetBoringFilePath(fileSetting.BoringFilePath); | ||
} | ||
} | ||
} |
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,29 @@ | ||
using TagsCloudContainer.Client; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
using TagsCloudContainer.Infrastucture.UiActions; | ||
|
||
namespace TagsCloudContainer.Actions | ||
{ | ||
public class SelectSourceFileAction : IUiAction | ||
{ | ||
private FileSettings fileSettings; | ||
private ITagCloudClient tagCloudClient; | ||
|
||
public SelectSourceFileAction(FileSettings settings, ITagCloudClient tagCloudClient) | ||
{ | ||
this.fileSettings = settings; | ||
this.tagCloudClient = tagCloudClient; | ||
} | ||
|
||
public string Category => "�����"; | ||
|
||
public string Name => "���� c� �������"; | ||
|
||
public string Description => "������� ���� �� ������� ��� ������ �����"; | ||
|
||
public void Perform() | ||
{ | ||
fileSettings.SourceFilePath = tagCloudClient.SetSourceFilePath(fileSettings.SourceFilePath); | ||
} | ||
} | ||
} |
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,45 @@ | ||
using TagsCloudContainer.Infrastucture; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
|
||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public class CircularCloudLayouter : ICloudLayouter | ||
{ | ||
private readonly AlgorithmSettings algorithmSettings; | ||
private readonly ImageSettings imageSettings; | ||
|
||
|
||
public CircularCloudLayouter(AlgorithmSettings algorithmSettings, ImageSettings imageSettings) | ||
{ | ||
this.algorithmSettings = algorithmSettings; | ||
this.imageSettings = imageSettings; | ||
} | ||
|
||
public List<TextRectangle> GetRectangles(Dictionary<string, int> wordFrequencies) | ||
{ | ||
var rectanglePlacer = new RectanglePlacer( | ||
algorithmSettings, | ||
new Point(imageSettings.Width / 2, imageSettings.Height / 2)); | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
|
||
var rectangles = new List<TextRectangle>(); | ||
var bitmap = new Bitmap(imageSettings.Width, imageSettings.Height); | ||
var graphics = Graphics.FromImage(bitmap); | ||
|
||
foreach (var word in wordFrequencies.Keys) | ||
{ | ||
var fontSize = CalculateFontSize(wordFrequencies, word, imageSettings.Font.Size); | ||
var font = new Font(imageSettings.Font.FontFamily, fontSize, imageSettings.Font.Style, imageSettings.Font.Unit); | ||
var textSize = graphics.MeasureString(word, font); | ||
var rectangle = rectanglePlacer.GetPossibleNextRectangle(rectangles, textSize); | ||
rectangles.Add(new TextRectangle(rectangle, word, font)); | ||
} | ||
|
||
return rectangles; | ||
} | ||
|
||
private float CalculateFontSize(Dictionary<string, int> wordFrequencies, string word, float fontSize) | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
{ | ||
return fontSize + (wordFrequencies[word] - wordFrequencies.Values.Min()) * 20 / (wordFrequencies.Values.Max()); | ||
} | ||
} | ||
} |
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,24 @@ | ||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public class FileParser : IFileParser | ||
{ | ||
public List<string> ReadWordsInFile(string filePath) | ||
{ | ||
var words = new List<string>(); | ||
var lines = File.ReadAllLines(filePath); | ||
|
||
foreach (var line in lines) | ||
{ | ||
var lineWords = line.ToLower().Trim().Split(' '); | ||
if (lineWords.Length > 1) | ||
{ | ||
throw new Exception("There is more than one word in a line"); | ||
} | ||
words.Add(lineWords[0]); | ||
} | ||
|
||
return words; | ||
} | ||
|
||
} | ||
} |
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,9 @@ | ||
using TagsCloudContainer.Infrastucture; | ||
|
||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public interface ICloudLayouter | ||
{ | ||
List<TextRectangle> GetRectangles(Dictionary<string, int> wordFrequencies); | ||
} | ||
} |
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,7 @@ | ||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public interface IFileParser | ||
{ | ||
List<string> ReadWordsInFile(string filePath); | ||
} | ||
} |
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,9 @@ | ||
using TagsCloudContainer.Infrastucture; | ||
|
||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public interface IRectanglePlacer | ||
{ | ||
RectangleF GetPossibleNextRectangle(List<TextRectangle> cloudRectangles, SizeF rectangleSize); | ||
} | ||
} |
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,7 @@ | ||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public interface IWordProcessor | ||
{ | ||
Dictionary<string, int> CalculateFrequencyInterestingWords(string sourceFilePath, string boringFilePath); | ||
} | ||
} |
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,54 @@ | ||
using TagsCloudContainer.Infrastucture; | ||
using TagsCloudContainer.Infrastucture.Settings; | ||
|
||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public sealed class RectanglePlacer: IRectanglePlacer | ||
{ | ||
private Point center; | ||
private double radius; | ||
private double angle; | ||
private double deltaRadius; | ||
private double deltaAngle; | ||
|
||
public RectanglePlacer(AlgorithmSettings algorithmSettings, Point center) | ||
{ | ||
if (center.X < 0 || center.Y < 0) | ||
throw new ArgumentException("the coordinates of the center must be positive numbers"); | ||
this.center = center; | ||
this.deltaRadius = algorithmSettings.DeltaRadius; | ||
this.deltaAngle = algorithmSettings.DeltaAngle; | ||
this.radius = algorithmSettings.Radius; | ||
this.angle = algorithmSettings.Angle; | ||
} | ||
|
||
public RectangleF GetPossibleNextRectangle(List<TextRectangle> cloudRectangles, SizeF rectangleSize) | ||
{ | ||
if (rectangleSize.Width <= 0 || rectangleSize.Height <= 0) | ||
throw new ArgumentException("the width and height of the rectangle must be positive numbers"); | ||
|
||
return FindPossibleNextRectangle(cloudRectangles, rectangleSize); | ||
} | ||
|
||
private RectangleF FindPossibleNextRectangle(List<TextRectangle> cloudRectangles, SizeF rectangleSize) | ||
{ | ||
while (true) | ||
{ | ||
var point = new Point( | ||
(int)(center.X + radius * Math.Cos(angle)), | ||
(int)(center.Y + radius * Math.Sin(angle)) | ||
); | ||
var possibleRectangle = new RectangleF(point, rectangleSize); | ||
|
||
if (!cloudRectangles.Any(textRectangle => textRectangle.Rectangle.IntersectsWith(possibleRectangle))) | ||
{ | ||
return possibleRectangle; | ||
} | ||
|
||
angle += deltaAngle; | ||
radius += deltaRadius; | ||
} | ||
} | ||
|
||
} | ||
} |
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,41 @@ | ||
using StopWord; | ||
|
||
namespace TagsCloudContainer.Algorithm | ||
{ | ||
public class WordProcessor : IWordProcessor | ||
{ | ||
|
||
private readonly IFileParser parser; | ||
|
||
public WordProcessor(IFileParser parser) | ||
{ | ||
this.parser = parser; | ||
} | ||
|
||
public Dictionary<string, int> CalculateFrequencyInterestingWords(string sourceFilePath, string boringFilePath) | ||
{ | ||
var wordFrequencies = new Dictionary<string, int>(); | ||
var interestingWords = GetInterestingWords(sourceFilePath, boringFilePath); | ||
|
||
for (int i = 0; i < interestingWords.Count; i++) | ||
This comment was marked as resolved.
Sorry, something went wrong. |
||
{ | ||
if (!wordFrequencies.ContainsKey(interestingWords[i])) | ||
wordFrequencies.Add(interestingWords[i], 0); | ||
wordFrequencies[interestingWords[i]]++; | ||
} | ||
|
||
return wordFrequencies.OrderByDescending(x => x.Value).ToDictionary(); | ||
} | ||
|
||
public List<string> GetInterestingWords(string sourceFilePath, string boringFilePath) | ||
{ | ||
var boringWords = parser.ReadWordsInFile(boringFilePath); | ||
var sourceWords = parser.ReadWordsInFile(sourceFilePath); | ||
var stopWords = StopWords.GetStopWords("ru"); | ||
|
||
var interestingWords = sourceWords.Where(word => !boringWords.Contains(word) && !stopWords.Contains(word)).ToList(); | ||
|
||
return interestingWords; | ||
} | ||
} | ||
} |
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.
This comment was marked as resolved.
Sorry, something went wrong.