51 lines
1.4 KiB
C#
51 lines
1.4 KiB
C#
using System.Collections.Concurrent;
|
|
using System.Text;
|
|
|
|
namespace Tarpit;
|
|
|
|
public static class TagUtils
|
|
{
|
|
public static void CreateTags(ConcurrentQueue<string> tags, Dictionary<string, List<string>> words)
|
|
{
|
|
string[] startWords = ["Andersen", "Denmark", "The", "Earth", "Who", "His", "Her", "Following", "At", "A"];
|
|
List<string> tagsList = [];
|
|
StringBuilder sb = new();
|
|
|
|
while (true)
|
|
{
|
|
if (tags.Count >= 100)
|
|
{
|
|
Thread.Sleep(100);
|
|
continue;
|
|
}
|
|
|
|
tagsList.Add(startWords[Random.Shared.Next(startWords.Length - 1)]);
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
{
|
|
List<string> temp = WordUtils.PredictNextWords(tagsList[i], words);
|
|
|
|
if (temp.Count != 0)
|
|
{
|
|
tagsList.Add(temp[Random.Shared.Next(temp.Count - 1)]);
|
|
}
|
|
else
|
|
{
|
|
tagsList.Add(startWords[Random.Shared.Next(startWords.Length - 1)]);
|
|
}
|
|
}
|
|
|
|
for (int i = 0; i < tagsList.Count; i++)
|
|
{
|
|
sb.Append(tagsList[i]);
|
|
sb.Append(' ');
|
|
}
|
|
|
|
tags.Enqueue($"<p>{sb}</p>");
|
|
|
|
sb.Clear();
|
|
|
|
tagsList.Clear();
|
|
}
|
|
}
|
|
} |