127 lines
5.5 KiB
C#
127 lines
5.5 KiB
C#
namespace DramaLing.Api.Services;
|
|
|
|
public interface IWordVariationService
|
|
{
|
|
string[] GetCommonVariations(string word);
|
|
bool IsVariationOf(string baseWord, string variation);
|
|
}
|
|
|
|
public class WordVariationService : IWordVariationService
|
|
{
|
|
private readonly ILogger<WordVariationService> _logger;
|
|
|
|
public WordVariationService(ILogger<WordVariationService> logger)
|
|
{
|
|
_logger = logger;
|
|
}
|
|
|
|
private readonly Dictionary<string, string[]> CommonVariations = new()
|
|
{
|
|
["eat"] = ["eats", "ate", "eaten", "eating"],
|
|
["go"] = ["goes", "went", "gone", "going"],
|
|
["have"] = ["has", "had", "having"],
|
|
["be"] = ["am", "is", "are", "was", "were", "been", "being"],
|
|
["do"] = ["does", "did", "done", "doing"],
|
|
["take"] = ["takes", "took", "taken", "taking"],
|
|
["make"] = ["makes", "made", "making"],
|
|
["come"] = ["comes", "came", "coming"],
|
|
["see"] = ["sees", "saw", "seen", "seeing"],
|
|
["get"] = ["gets", "got", "gotten", "getting"],
|
|
["give"] = ["gives", "gave", "given", "giving"],
|
|
["know"] = ["knows", "knew", "known", "knowing"],
|
|
["think"] = ["thinks", "thought", "thinking"],
|
|
["say"] = ["says", "said", "saying"],
|
|
["tell"] = ["tells", "told", "telling"],
|
|
["find"] = ["finds", "found", "finding"],
|
|
["work"] = ["works", "worked", "working"],
|
|
["feel"] = ["feels", "felt", "feeling"],
|
|
["try"] = ["tries", "tried", "trying"],
|
|
["ask"] = ["asks", "asked", "asking"],
|
|
["need"] = ["needs", "needed", "needing"],
|
|
["seem"] = ["seems", "seemed", "seeming"],
|
|
["turn"] = ["turns", "turned", "turning"],
|
|
["start"] = ["starts", "started", "starting"],
|
|
["show"] = ["shows", "showed", "shown", "showing"],
|
|
["hear"] = ["hears", "heard", "hearing"],
|
|
["play"] = ["plays", "played", "playing"],
|
|
["run"] = ["runs", "ran", "running"],
|
|
["move"] = ["moves", "moved", "moving"],
|
|
["live"] = ["lives", "lived", "living"],
|
|
["believe"] = ["believes", "believed", "believing"],
|
|
["hold"] = ["holds", "held", "holding"],
|
|
["bring"] = ["brings", "brought", "bringing"],
|
|
["happen"] = ["happens", "happened", "happening"],
|
|
["write"] = ["writes", "wrote", "written", "writing"],
|
|
["sit"] = ["sits", "sat", "sitting"],
|
|
["stand"] = ["stands", "stood", "standing"],
|
|
["lose"] = ["loses", "lost", "losing"],
|
|
["pay"] = ["pays", "paid", "paying"],
|
|
["meet"] = ["meets", "met", "meeting"],
|
|
["include"] = ["includes", "included", "including"],
|
|
["continue"] = ["continues", "continued", "continuing"],
|
|
["set"] = ["sets", "setting"],
|
|
["learn"] = ["learns", "learned", "learnt", "learning"],
|
|
["change"] = ["changes", "changed", "changing"],
|
|
["lead"] = ["leads", "led", "leading"],
|
|
["understand"] = ["understands", "understood", "understanding"],
|
|
["watch"] = ["watches", "watched", "watching"],
|
|
["follow"] = ["follows", "followed", "following"],
|
|
["stop"] = ["stops", "stopped", "stopping"],
|
|
["create"] = ["creates", "created", "creating"],
|
|
["speak"] = ["speaks", "spoke", "spoken", "speaking"],
|
|
["read"] = ["reads", "reading"],
|
|
["spend"] = ["spends", "spent", "spending"],
|
|
["grow"] = ["grows", "grew", "grown", "growing"],
|
|
["open"] = ["opens", "opened", "opening"],
|
|
["walk"] = ["walks", "walked", "walking"],
|
|
["win"] = ["wins", "won", "winning"],
|
|
["offer"] = ["offers", "offered", "offering"],
|
|
["remember"] = ["remembers", "remembered", "remembering"],
|
|
["love"] = ["loves", "loved", "loving"],
|
|
["consider"] = ["considers", "considered", "considering"],
|
|
["appear"] = ["appears", "appeared", "appearing"],
|
|
["buy"] = ["buys", "bought", "buying"],
|
|
["wait"] = ["waits", "waited", "waiting"],
|
|
["serve"] = ["serves", "served", "serving"],
|
|
["die"] = ["dies", "died", "dying"],
|
|
["send"] = ["sends", "sent", "sending"],
|
|
["expect"] = ["expects", "expected", "expecting"],
|
|
["build"] = ["builds", "built", "building"],
|
|
["stay"] = ["stays", "stayed", "staying"],
|
|
["fall"] = ["falls", "fell", "fallen", "falling"],
|
|
["cut"] = ["cuts", "cutting"],
|
|
["reach"] = ["reaches", "reached", "reaching"],
|
|
["kill"] = ["kills", "killed", "killing"],
|
|
["remain"] = ["remains", "remained", "remaining"]
|
|
};
|
|
|
|
public string[] GetCommonVariations(string word)
|
|
{
|
|
if (string.IsNullOrEmpty(word))
|
|
return Array.Empty<string>();
|
|
|
|
var lowercaseWord = word.ToLower();
|
|
if (CommonVariations.TryGetValue(lowercaseWord, out var variations))
|
|
{
|
|
_logger.LogDebug("Found {Count} variations for word: {Word}", variations.Length, word);
|
|
return variations;
|
|
}
|
|
|
|
_logger.LogDebug("No variations found for word: {Word}", word);
|
|
return Array.Empty<string>();
|
|
}
|
|
|
|
public bool IsVariationOf(string baseWord, string variation)
|
|
{
|
|
if (string.IsNullOrEmpty(baseWord) || string.IsNullOrEmpty(variation))
|
|
return false;
|
|
|
|
var variations = GetCommonVariations(baseWord);
|
|
var result = variations.Contains(variation.ToLower());
|
|
|
|
_logger.LogDebug("Checking if {Variation} is variation of {BaseWord}: {Result}",
|
|
variation, baseWord, result);
|
|
|
|
return result;
|
|
}
|
|
} |