Skip to content

Commit

Permalink
feat: add urianger translator
Browse files Browse the repository at this point in the history
  • Loading branch information
kalilistic committed May 29, 2021
1 parent 4f52431 commit cf9a8e4
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/SillyChat.Test/Translator/PirateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SillyChat.Test
{
/// <summary>
/// Advanced Leet Test.
/// Pirate Test.
/// </summary>
public class PirateTest
{
Expand Down
2 changes: 1 addition & 1 deletion src/SillyChat.Test/Translator/TurkeyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace SillyChat.Test
{
/// <summary>
/// Advanced Leet Test.
/// Turkey Test.
/// </summary>
public class TurkeyTest
{
Expand Down
26 changes: 26 additions & 0 deletions src/SillyChat.Test/Translator/UriangerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Xunit;

namespace SillyChat.Test
{
/// <summary>
/// Urianger Test.
/// </summary>
public class UriangerTest
{
/// <summary>
/// Test translation.
/// </summary>
/// <param name="input"></param>
/// <param name="translation"></param>
[Theory]
[InlineData("cat", "Cat.")]
[InlineData("Hi, how are you?", @"Hail, how art thou?")]
public void StringsAreTranslatedToUrianger(string input, string translation)
{
var plugin = new SillyChatPluginMock();
var translator = new UriangerTranslator(plugin);
Assert.Equal(translation, translator.Translate(input));
}

}
}
13 changes: 12 additions & 1 deletion src/SillyChat.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=atcay/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=bluderbuss/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=callin/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cameth/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cap_0027n/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dalamud/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Ellohay/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=fleebag/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=goest/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=ihay/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=lmfao/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=mayhap/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=possesseth/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=probaby/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=requireth/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=riseth/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sillychat/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sillychatconfig/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=gurl/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -33,9 +41,12 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=sillyhistory/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=smat/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=swoggler/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Twould/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=tyfp/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=t_0027gether/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Uaeio/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Urianger/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=we_0027s/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=yarr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=yass/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/UserDictionary/Words/=yass/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=yester/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
2 changes: 1 addition & 1 deletion src/SillyChat/SillyChat.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="DalamudPluginCommon" Version="0.0.0-alpha.0.56" />
<PackageReference Include="DalamudPluginCommon" Version="0.0.0-alpha.0.57" />
<!--
<Reference Include="DalamudPluginCommon, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\DalamudPluginCommon\src\DalamudPluginCommon\bin\Debug\net48\DalamudPluginCommon.dll</HintPath>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ private static List<TranslationMode> GetModes(ISillyChatPlugin plugin)
new (3, "Pig Latin", new PigLatinTranslator(plugin)),
new (4, "Pirate", new PirateTranslator(plugin)),
new (5, "Turkey", new TurkeyTranslator(plugin)),
new (6, "Urianger", new UriangerTranslator(plugin)),
};
return translationModes.OrderBy(x => x.Name).ToList();
}
Expand Down
207 changes: 207 additions & 0 deletions src/SillyChat/SillyChat/Translator/UriangerTranslator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;

using DalamudPluginCommon;

// ReSharper disable ForeachCanBePartlyConvertedToQueryUsingAnotherGetEnumerator
// ReSharper disable ForeachCanBeConvertedToQueryUsingAnotherGetEnumerator
namespace SillyChat
{
/// <summary>
/// Translate to Urianger.
/// </summary>
public class UriangerTranslator : BaseTranslator
{
private readonly Dictionary<string, string> mappedWords = new ();
private readonly Dictionary<string, string> mappedPartialPhrases = new ();
private readonly Dictionary<string, string> mappedFullPhrases = new ();

/// <summary>
/// Initializes a new instance of the <see cref="UriangerTranslator"/> class.
/// </summary>
/// <param name="plugin">SillyChat plugin.</param>
public UriangerTranslator(ISillyChatPlugin plugin)
: base(plugin)
{
this.SetWordMapping();
this.SetFullPhraseMapping();
this.SetPartialPhraseMapping();
}

/// <inheritdoc />
public override string Translate(string input)
{
// full phrases
foreach (var phrase in this.mappedFullPhrases)
{
if (Regex.IsMatch(input, phrase.Key))
{
return phrase.Value;
}
}

// partial phrases
var outputText = input.ToLower();
foreach (var phrase in this.mappedPartialPhrases)
{
outputText = outputText.Replace(phrase.Key, phrase.Value);
}

var words = outputText.Split(' ');
var outputList = new List<string>();

// words
foreach (var word in words)
{
string currentWord = char.IsPunctuation(word.Last()) ? string.Concat(word.Take(word.Length - 1)) : word;

if (this.mappedWords.ContainsKey(currentWord))
{
currentWord = this.mappedWords[currentWord];
if (char.IsUpper(word.First()))
{
currentWord = new CultureInfo("en-US").TextInfo.ToTitleCase(currentWord);
}

if (char.IsPunctuation(word.Last()))
{
currentWord += word.Last();
}

outputList.Add(currentWord);
}
else
{
outputList.Add(word);
}
}

// merge & post fixes
outputText = string.Join(" ", outputList);
outputText = RunPostFixes(outputText);

return outputText;
}

private static string RunPostFixes(string str)
{
str = str.EnsureEndsWithDot();
str = str.CapitalizeFirst();
str = str.Replace(" ", " ");
str = str.Replace(" .", ".");
str = str.Replace(" i ", " I ");
str = str.Replace(" i' ", " I' ");
str = str.Replace("?.", "?");
return str;
}

private void SetFullPhraseMapping()
{
this.mappedFullPhrases.Add("^focus$", "We must needs remain vigilant.");
this.mappedFullPhrases.Add("^how are you\\?$", "How fares the realm?");
this.mappedFullPhrases.Add("^i'?ll come$", "I shall accompany thee on thy mission.");
this.mappedFullPhrases.Add("^ready\\?$", "Thou art prepared, I presume?");
this.mappedFullPhrases.Add("^ready[^?]*$", "'Twould seem so.");
this.mappedFullPhrases.Add("^(you|u) (ok|okay)\\??$", "Art thou unwell?");
}

private void SetPartialPhraseMapping()
{
this.mappedPartialPhrases.Add("how are you", "how art thou?");
this.mappedPartialPhrases.Add("hows it going", "how art thou?");
this.mappedPartialPhrases.Add("how's it going", "how art thou?");
this.mappedPartialPhrases.Add("take care", "May we all meet again ere long");
this.mappedPartialPhrases.Add("good luck", "I wish you every success");
this.mappedPartialPhrases.Add("i don't know", "I know not");
this.mappedPartialPhrases.Add("i dont know", "I know not");
this.mappedPartialPhrases.Add("whats up", "how art thou?");
this.mappedPartialPhrases.Add("what's up", "how art thou?");
}

private void SetWordMapping()
{
this.mappedWords.Add("again", "once more");
this.mappedWords.Add("are", "art");
this.mappedWords.Add("back", "returned");
this.mappedWords.Add("bad", "dire");
this.mappedWords.Add("between", "'twixt");
this.mappedWords.Add("come", "cameth");
this.mappedWords.Add("crazy", "chaos");
this.mappedWords.Add("cool", "excellent");
this.mappedWords.Add("dearest", "dearest");
this.mappedWords.Add("defeat", "vanquish");
this.mappedWords.Add("did", "didst");
this.mappedWords.Add("do", "doth");
this.mappedWords.Add("does", "doth");
this.mappedWords.Add("fast", "fleeting");
this.mappedWords.Add("go", "goest");
this.mappedWords.Add("have", "hath");
this.mappedWords.Add("hello", "hail");
this.mappedWords.Add("help", "serve");
this.mappedWords.Add("here", "hither");
this.mappedWords.Add("hey", "hail");
this.mappedWords.Add("hi", "hail");
this.mappedWords.Add("it is", "'tis");
this.mappedWords.Add("its", "'tis");
this.mappedWords.Add("killed", "slain");
this.mappedWords.Add("many", "numerous");
this.mappedWords.Add("need", "requireth");
this.mappedWords.Add("newbie", "neophyte");
this.mappedWords.Add("no", "nay");
this.mappedWords.Add("nah", "nay");
this.mappedWords.Add("only", "merely");
this.mappedWords.Add("perhaps", "mayhap");
this.mappedWords.Add("please", "pray");
this.mappedWords.Add("plz", "pray");
this.mappedWords.Add("pls", "pray");
this.mappedWords.Add("probaby", "perhaps");
this.mappedWords.Add("require", "requireth");
this.mappedWords.Add("rises", "riseth");
this.mappedWords.Add("sometimes", "On occasion");
this.mappedWords.Add("there", "yon");
this.mappedWords.Add("to", "unto");
this.mappedWords.Add("tomorrow", "morrow");
this.mappedWords.Add("want", "desire");
this.mappedWords.Add("weird", "strange");
this.mappedWords.Add("will", "shall");
this.mappedWords.Add("win", "prevail");
this.mappedWords.Add("written", "writ");
this.mappedWords.Add("yes", "aye");
this.mappedWords.Add("yep", "aye");
this.mappedWords.Add("yea", "aye");
this.mappedWords.Add("yesterday", "yester");
this.mappedWords.Add("you", "thou");
this.mappedWords.Add("u", "thou");
this.mappedWords.Add("lmfao", "... hah!");
this.mappedWords.Add("lmao", "... hah!");
this.mappedWords.Add("lol", "... hah!");
this.mappedWords.Add("rofl", "... hah!");
this.mappedWords.Add("haha", "... hah!");
this.mappedWords.Add("irl", "on the source");
this.mappedWords.Add("whats", "what 'tis");
this.mappedWords.Add("im", "I am");
this.mappedWords.Add("?", "What will you ask?");
this.mappedWords.Add("o/", "Greetings.");
this.mappedWords.Add("afk", "A moment to collect my thoughts, I prithee...");
this.mappedWords.Add("brb", "I shall be but a few moments.");
this.mappedWords.Add("lfg", "Might I impose on thee to allow entrance to thine party?");
this.mappedWords.Add("lf", "I pray thou wilt join our group");
this.mappedWords.Add("inv", "I pray thou wilt submit an invitation");
this.mappedWords.Add("bye", "farewell");
this.mappedWords.Add("god", "the Twelve");
this.mappedWords.Add("<3", "I have more than words for you, my friend.");
this.mappedWords.Add(":d", "Words cannot well express my joy");
this.mappedWords.Add("implying", "stating");
this.mappedWords.Add("tyfp", "You have my thanks");
this.mappedWords.Add("before", "ere");
this.mappedWords.Add("sorry", "Pray accept mine apologies");
this.mappedWords.Add("oops", "Pray accept mine apologies");
this.mappedWords.Add("whoops", "Pray accept mine apologies");
this.mappedWords.Add("sup", "How fares the realm?");
this.mappedWords.Add("possess", "possesseth");
this.mappedWords.Add("idk", "I know not");
}
}
}

0 comments on commit cf9a8e4

Please sign in to comment.