Skip to content

Commit 761d845

Browse files
committed
Add menu entry for word cloud files generation
1 parent babe6a1 commit 761d845

7 files changed

Lines changed: 64 additions & 34 deletions

File tree

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,17 @@ This also helps perform statistical computations using an in-memory XML document
3434
- Line chart, rather than bar chart, for metrics over Seasons.
3535
- More advanced charts (e.g., bubble charts) to show relationships between variables, such as poem length/metric, associated categories, or category/metric associations.
3636

37+
### Generation of word cloud text files
38+
39+
When a poem contains a month name in its tags, I generate a word cloud text file (archived in poetry site at `content\fr\other-perspectives\les-mois\[month name]`) then use it on the following website:
40+
https://nuagedemots.co/
41+
- Remove some irrelevant terms
42+
- Use rectangular form
43+
- Use Roboto font
44+
- Use blue theme
45+
46+
Then I cut out the figure to have fewer space around content. And I save it as `featured.png` in `content\fr\other-perspectives\les-mois\[month name]`.
47+
3748
### Content quality check
3849

3950
Because CMS editor gives indications (fields descriptions) but a miss or typo can happen.

src/Tests/Generators/WordCloudGeneratorTest.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using Toolbox.Generators;
2+
using Xunit;
3+
4+
namespace Tests.Generators;
5+
6+
public class WordCloudTextGeneratorTest(WithRealDataFixture fixture): IClassFixture<WithRealDataFixture>
7+
{
8+
[Fact]
9+
[Trait("UnitTest", "FileGeneration")]
10+
public void ShouldGenerateWordCloudFiles()
11+
{
12+
new WordCloudTextGenerator(fixture.Configuration).GenerateWordCloudFiles(fixture.Data);
13+
}
14+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Toolbox.Domain;
3+
using Toolbox.Settings;
4+
5+
namespace Toolbox.Generators;
6+
7+
public class WordCloudTextGenerator(IConfiguration configuration)
8+
{
9+
private static List<string> _months =
10+
[
11+
"janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre",
12+
"décembre"
13+
];
14+
15+
public void GenerateWordCloudFiles(Root data)
16+
{
17+
foreach (var month in _months)
18+
{
19+
var rootDir = Path.Combine(configuration[Constants.CONTENT_ROOT_DIR]!, "..", "other-perspectives",
20+
"les-mois", month);
21+
var filePath = Path.Combine(rootDir, "wordcloud.txt");
22+
var poems = data.Seasons.SelectMany(x => x.Poems).Where(p => p.ExtraTags.Contains(month));
23+
File.WriteAllText(filePath, string.Empty);
24+
foreach (var poem in poems)
25+
{
26+
File.AppendAllText(filePath, poem.Description.ToLowerInvariant());
27+
File.AppendAllText(filePath, Environment.NewLine);
28+
}
29+
}
30+
}
31+
}

src/Toolbox/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ private static async Task<bool> PerformActionAsync(MenuItem menuChoice)
253253
Console.WriteLine(reusedTitle);
254254
}
255255

256+
break;
257+
case MainMenuSettings.MenuChoices.GenerateWordCloudTextFiles:
258+
new WordCloudTextGenerator(_configuration!).GenerateWordCloudFiles(_data);
256259
break;
257260
case MainMenuSettings.MenuChoices.ExitProgram:
258261
Console.WriteLine("Closing program...");

src/Toolbox/Settings/MainMenuSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public enum MenuChoices
3636
ImportEnPoems = 600,
3737
OutputSeasonsDuration = 700,
3838
OutputReusedTitles = 800,
39+
GenerateWordCloudTextFiles = 900,
3940
ExitProgram = 99
4041
}
4142

src/Toolbox/appsettings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@
145145
"Key": 800,
146146
"Label": "Output reused titles"
147147
},
148+
{
149+
"Key": 900,
150+
"Label": "Generate word cloud text files"
151+
},
148152
{
149153
"Key": 0,
150154
"Label": "Reload data file"

0 commit comments

Comments
 (0)