-
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
Сибогатов Ринат #204
Open
sibogatovr
wants to merge
13
commits into
kontur-courses:master
Choose a base branch
from
sibogatovr: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
Сибогатов Ринат #204
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d0feb67
init, hardcode, v1
sibogatovr 5cffcd9
Добавлены настройки Шрифта, Скучных слов, Цвета, Цвета популярных сл…
sibogatovr 0ce51a9
Добавлен commandLineParser
sibogatovr 4072767
fix
sibogatovr ac8b8ae
fix tests
sibogatovr d7d53fd
refactor: Разделение ответственности в классе DocReader, TagCloudApp
sibogatovr 4148cb1
feat: Добавлены тесты
sibogatovr 5e0054f
feat: add FontSizeCalculator
sibogatovr 3f50bf8
refactor: improve property names and perform minor code cleanup
sibogatovr 2320a14
refactor: Improve variable names, code readability
sibogatovr 21aa80d
feat: Add Readme.md file
sibogatovr 553a053
refactor: decomposition Run method, update the FileReader
sibogatovr ed0c9b1
fix: encoding issue in Readme.md
sibogatovr 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,14 @@ | ||
using System.ComponentModel; | ||
|
||
namespace TagsCloudContainer.Enums | ||
{ | ||
public enum FileType | ||
{ | ||
[Description(".doc")] | ||
Doc, | ||
[Description(".docx")] | ||
Docx, | ||
[Description(".txt")] | ||
Txt | ||
} | ||
} |
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,11 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface ICircularCloudLayouter | ||
{ | ||
public Point CloudCenter { get; init; } | ||
public IList<Rectangle> Rectangles { get; init; } | ||
Rectangle PutNextRectangle(string word, Font font); | ||
} | ||
} |
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,10 @@ | ||
| ||
using TagsCloudContainer.Utility; | ||
|
||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface IFileReader | ||
{ | ||
Result<IEnumerable<string>> ReadWords(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,16 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface IImageSettings | ||
{ | ||
Color BackgroundColor { get; init; } | ||
Color FontColor { get; init; } | ||
Font GetFont(); | ||
int Width { get; set; } | ||
int Height { get; set; } | ||
|
||
void UpdateSettings(int width, int 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,9 @@ | ||
using System.Drawing; | ||
|
||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface INextPointProvider | ||
{ | ||
Point GetNextPoint(); | ||
} | ||
} |
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,8 @@ | ||
| ||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface IPreprocessor | ||
{ | ||
IEnumerable<string> Process(IEnumerable<string> words, string boringWordsFilePath); | ||
} | ||
} |
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,8 @@ | ||
| ||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface ITagCloudClient | ||
{ | ||
void Run(); | ||
} | ||
} |
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 System.Drawing; | ||
|
||
namespace TagsCloudContainer.Interfaces | ||
{ | ||
public interface ITagCloudGenerator | ||
{ | ||
Bitmap GenerateTagCloud(IEnumerable<string> words, IImageSettings 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,23 @@ | ||
using CommandLine; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TagsCloudContainer.TagsCloud; | ||
using TagsCloudContainer.Utility; | ||
|
||
namespace TagsCloudContainer | ||
{ | ||
public class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
Parser.Default.ParseArguments<CommandLineOptions>(args) | ||
.WithParsed(options => | ||
{ | ||
using (var serviceProvider = Startup.ConfigureServices()) | ||
{ | ||
var tagCloudApp = serviceProvider.GetRequiredService<TagCloudApp>(); | ||
tagCloudApp.Run(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,30 @@ | ||
using Spire.Doc; | ||
using Spire.Doc.Documents; | ||
using TagsCloudContainer.Interfaces; | ||
using TagsCloudContainer.Utility; | ||
|
||
namespace TagsCloudContainer.Readers | ||
{ | ||
public class DocReader : IFileReader | ||
{ | ||
public Result<IEnumerable<string>> ReadWords(string filePath) | ||
{ | ||
try | ||
{ | ||
var document = new Document(); | ||
document.LoadFromFile(filePath); | ||
|
||
var words = document.Sections | ||
.Cast<Section>() | ||
.SelectMany(section => section.Paragraphs.Cast<Paragraph>()) | ||
.SelectMany(paragraph => paragraph.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries)); | ||
|
||
return Result<IEnumerable<string>>.Success(words); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Result<IEnumerable<string>>.Failure($"Error reading .doc file: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
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,31 @@ | ||
using NPOI.XWPF.UserModel; | ||
using TagsCloudContainer.Interfaces; | ||
using TagsCloudContainer.Utility; | ||
|
||
namespace TagsCloudContainer.Readers | ||
{ | ||
public class DocxReader : IFileReader | ||
{ | ||
public Result<IEnumerable<string>> ReadWords(string filePath) | ||
{ | ||
var words = new List<string>(); | ||
|
||
try | ||
{ | ||
using (var doc = new XWPFDocument(File.OpenRead(filePath))) | ||
{ | ||
foreach (var paragraph in doc.Paragraphs) | ||
{ | ||
words.AddRange(paragraph.Text.Split(' ', StringSplitOptions.RemoveEmptyEntries)); | ||
} | ||
} | ||
|
||
return Result<IEnumerable<string>>.Success(words); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Result<IEnumerable<string>>.Failure($"Error reading .docx file: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
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,76 @@ | ||
using System.ComponentModel; | ||
using TagsCloudContainer.Enums; | ||
using TagsCloudContainer.Interfaces; | ||
using TagsCloudContainer.Readers; | ||
using TagsCloudContainer.Utility; | ||
|
||
namespace TagsCloudContainer.TagsCloud | ||
{ | ||
public class FileReader | ||
{ | ||
public Result<IEnumerable<string>> ReadFile(string filePath) | ||
{ | ||
var fileReaderResult = GetFileReader(filePath); | ||
|
||
if (fileReaderResult.IsSuccess) | ||
{ | ||
var fileReader = fileReaderResult.Value; | ||
return fileReader.ReadWords(filePath); | ||
} | ||
else | ||
{ | ||
return Result<IEnumerable<string>>.Failure(fileReaderResult.ErrorMessage); | ||
} | ||
} | ||
|
||
private Result<IFileReader> GetFileReader(string filePath) | ||
{ | ||
try | ||
{ | ||
FileType fileType = GetFileType(filePath); | ||
|
||
switch (fileType) | ||
{ | ||
case FileType.Doc: | ||
return Result<IFileReader>.Success(new DocReader()); | ||
case FileType.Docx: | ||
return Result<IFileReader>.Success(new DocxReader()); | ||
case FileType.Txt: | ||
return Result<IFileReader>.Success(new TxtReader()); | ||
default: | ||
return Result<IFileReader>.Failure("Unsupported file extension"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Result<IFileReader>.Failure($"Error getting file reader: {ex.Message}"); | ||
} | ||
} | ||
|
||
static FileType GetFileType(string filePath) | ||
{ | ||
string fileExtension = Path.GetExtension(filePath)?.ToLower(); | ||
|
||
var fileTypes = Enum.GetValues(typeof(FileType)).Cast<FileType>(); | ||
|
||
foreach (var fileType in fileTypes) | ||
{ | ||
var descriptionAttribute = GetEnumDescription(fileType); | ||
if (descriptionAttribute != null && descriptionAttribute.Equals(fileExtension)) | ||
{ | ||
return fileType; | ||
} | ||
} | ||
|
||
throw new InvalidOperationException("Unsupported file extension"); | ||
} | ||
|
||
static string GetEnumDescription(Enum value) | ||
{ | ||
var field = value.GetType().GetField(value.ToString()); | ||
var attribute = (DescriptionAttribute)Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)); | ||
|
||
return attribute?.Description; | ||
} | ||
} | ||
} |
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,26 @@ | ||
using TagsCloudContainer.Interfaces; | ||
using TagsCloudContainer.Utility; | ||
|
||
namespace TagsCloudContainer.Readers | ||
{ | ||
public class TxtReader : IFileReader | ||
{ | ||
public Result<IEnumerable<string>> ReadWords(string filePath) | ||
{ | ||
try | ||
{ | ||
var lines = File.ReadAllLines(filePath); | ||
|
||
var words = lines.SelectMany(line => line.Split(' ')); | ||
|
||
var nonEmptyWords = words.Where(word => !string.IsNullOrEmpty(word)); | ||
|
||
return Result<IEnumerable<string>>.Success(nonEmptyWords); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Result<IEnumerable<string>>.Failure($"Error reading file: {ex.Message}"); | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
# TagsCloudContainer | ||
|
||
������ ������������ ����� ��������� ��� ��������� ������ ����� �� ����� � ������� ����. ��������� ������������ �������� ������� ����, �������� ������� ������ � ��������� �����, � ����� ���������� ���� ���� � ������� �������� ��� ����������. | ||
|
||
## ��������� ���������: | ||
|
||
- ��������� ���������������� �������� ������� ����. | ||
- ����������� ���������� ���� ���� � ������� ��������. | ||
- ����������� ��������� ����� ��� ����. | ||
- ����������� ����������� �������� �����, ����, ������. | ||
- �������� CLI. | ||
- ����������� ������: \*.doc, \*.docx, \*.txt. | ||
- ��������� ��������������� ����� ��� ����� ����������������. | ||
- ������� ������ ��������� � �����������. | ||
|
||
## ���������� ���� �� ������ | ||
|
||
- ������ ���� ������� ���� ���������, ��������� � ����� 'boring_words.txt' | ||
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,31 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using TagsCloudContainer.Interfaces; | ||
using TagsCloudContainer.Readers; | ||
using TagsCloudContainer.TagsCloud; | ||
|
||
namespace TagsCloudContainer | ||
{ | ||
public class Startup | ||
{ | ||
public static ServiceProvider ConfigureServices() | ||
{ | ||
return new ServiceCollection() | ||
.AddSingleton<IFileReader, TxtReader>() | ||
.AddSingleton<IPreprocessor, WordPreprocessor>() | ||
.AddSingleton<IImageSettings, ImageSettings>() | ||
.AddSingleton<FileReader>() | ||
.AddSingleton<ITagCloudGenerator, TagCloudGenerator>() | ||
.AddScoped(provider => | ||
{ | ||
var fileReader = provider.GetRequiredService<IFileReader>(); | ||
var preprocessor = provider.GetRequiredService<IPreprocessor>(); | ||
var tagCloudGenerator = provider.GetRequiredService<ITagCloudGenerator>(); | ||
var imageSettings = provider.GetRequiredService<IImageSettings>(); | ||
var fReader = provider.GetRequiredService<FileReader>(); | ||
|
||
return new TagCloudApp(preprocessor, imageSettings, fReader); | ||
}) | ||
.BuildServiceProvider(); | ||
} | ||
} | ||
} |
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.
Слетела кодировка