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

Ватлин Алексей #193

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Alex-Vay
Copy link

No description provided.

var frequencyDict = text
.Then(w => w
.GroupBy(word => word)
.OrderByDescending(group => group.Count())

Choose a reason for hiding this comment

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

Имеет это смысл? Dictionary не гарантирует порядок

text = text.Then(processor.ProcessText);

var frequencyDict = text
.Then(w => w

Choose a reason for hiding this comment

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

Если все через Then делать, то становится менее читаемо. Почему бы тут сразу не посмотреть успешно текст сформирован или нет, и вернуть ошибку.

  • Не всегда сообщение в Result = сообщение, которое нужно написать пользователю.

Поэтому я бы предложил, чтобы тут был маппер из внутренних ошибок в ошибки человекочитаемые

foreach (var processor in processors)
text = text.Then(processor.ProcessText);

var frequencyDict = text

Choose a reason for hiding this comment

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

В методы исключения можно вынести

frequencyDict
.Then(dict =>
{
var maxFrequency = dict.Values.Max();

Choose a reason for hiding this comment

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

Чтобы не вычислять каждый раз максимальный элемент, можно воспользоваться PriorityQueue<>, SortedList и тд. На свой вкус.

var fontSize = (int)(MIN_FONTSIZE + (float)pair.Value / maxFreq * (MAX_FONTSIZE - MIN_FONTSIZE));
return new(pair.Key, fontSize);
}

Choose a reason for hiding this comment

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

Лишняя строка

".txt" => new TxtFileReader(txtSettings),
".csv" => new CsvFileReader(csvSettings),
".docx" => new WordFileReader(wordSettings),
_ => throw new InvalidOperationException($"Unsupported file extension: {extension}")

Choose a reason for hiding this comment

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

Исключение. Если введу файл с другим расширением, оно как раз вызовится


namespace TagsCloudVisualization.Visualizers.ImageColoring;

public class CustumSingleColoring(Color color) : IImageColoring

Choose a reason for hiding this comment

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

Custom

stem.StandardInput.Write($"{word}\n");
var wordInfo = stem.StandardOutput.ReadLine();
var infoStart = wordInfo.IndexOf("{");
if (wordInfo is not null && !IsBoring(wordInfo))

Choose a reason for hiding this comment

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

Проверка на null после того, как переменную уже вызывали

var wordInfo = stem.StandardOutput.ReadLine();
var infoStart = wordInfo.IndexOf("{");
if (wordInfo is not null && !IsBoring(wordInfo))
result.Add(wordInfo.Substring(0, infoStart));

Choose a reason for hiding this comment

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

А зачем нам Substring? Мы же не преобразуем никак слово-то. А оно у нас уже есть

Copy link
Author

Choose a reason for hiding this comment

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

У меня там не совсем слово. То есть мне stem возвращает что-то вроде "Всем{весь=APRO=дат..." и вот всю часть с информацией я отсекаю

[TestFixture]
public class BoringWordsFilterTests
{
private string path = "./../../../TestData/text.txt";

Choose a reason for hiding this comment

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

Выстави файл в CopyAlways и будет он у тебя всегда рядом со сборкой

var text = reader.ReadLines();
var filtered = text.Then(filter.ProcessText);

filtered.Then(r => r.Should().BeEquivalentTo("Привет", "файл", "должен", "обрабатываться", "корректно"));

Choose a reason for hiding this comment

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

А для чего мы дальше Result тянем сюда?
почему не просто
filtered.IsSuccess.Should().BeTrue();
filtered.GetValueOrThrow().Should().BeEquivalentTo("Привет", "файл", "должен", "обрабатываться", "корректно");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants