Skip to content

Commit

Permalink
Translator: Improved proxy manipulation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltanar committed Feb 10, 2024
1 parent fe2fa85 commit 7732841
Show file tree
Hide file tree
Showing 9 changed files with 427 additions and 314 deletions.
1 change: 1 addition & 0 deletions Goals-Latest.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- see details should change to correct user game tab when multiple user games for one vn
- allow process monitor to keep running always/make process monitor only have one instance-
- Option to stop monitor
- When no user games have been added, tab should say 'Drag executable here to add it'
##### Entries
- Implement priority
- Change Series-specific to dropdown (none,title,series, producer?)
Expand Down
113 changes: 85 additions & 28 deletions Happy Reader Tests/ProxyModTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public class ProxyModTests
private const string Name3T = "Chris";
private const string Name4 = "ロボト";
private const string Name4T = "Robot";
private const string Suffix1 = "さん";
private const string Name5 = "お兄ちゃん";
private const string Name5T = "Onii-chan";
private const string Suffix1 = "さん";
private const string Suffix1T = "-san";
private const string Suffix2 = "たち";
private const string Suffix2T = "-tachi";
Expand All @@ -51,13 +53,16 @@ private static void PopulateEntries(HappyReaderDatabase testDatabase)
entry.InitGameId();
}
var entries = testDatabase.Entries.Where(e => e?.GameData?.Equals(Game) ?? false).ToList();
var newEntries = new List<Entry>();
newEntries.Add(GetNameEntry(Name1, Name1T));
newEntries.Add(GetNameEntry(Name2, Name2T));
newEntries.Add(GetNameEntry(Name3, Name3T));
newEntries.Add(GetNameEntry(Name4, Name4T));
newEntries.Add(GetNameEntry(NameF1, NameF1T, "m.f"));
newEntries = newEntries.Except(entries, Entry.ClashComparer).ToList();
var newEntries = new List<Entry>
{
GetNameEntry(Name1, Name1T),
GetNameEntry(Name2, Name2T),
GetNameEntry(Name3, Name3T),
GetNameEntry(Name4, Name4T),
GetNameEntry(Name5, Name5T),
GetNameEntry(NameF1, NameF1T, "m.f")
};
newEntries = newEntries.Except(entries, Entry.ClashComparer).ToList();
testDatabase.AddEntries(newEntries);
}

Expand All @@ -80,71 +85,71 @@ public void NameSuffix1()
{
TranslateAndAssert(
$"私は{Name1}{Suffix1}です。",
$"I am {Name1T}{Suffix1T}.");
$"I am {Name1T}{Suffix1T}.", 1);
}

[TestMethod]
public void Name1Suffix1_Name2Suffix2()
{
TranslateAndAssert(
$"私は{Name1}{Suffix1}ですそれともあなたは{Name2}{Suffix2}。",
$"I am {Name1T}{Suffix1T} and you are {Name2T}{Suffix2T}.");
$"I am {Name1T}{Suffix1T} and you are {Name2T}{Suffix2T}.", 2);
}

[TestMethod]
public void Name1Suffix1_Name1Suffix2()
{
TranslateAndAssert(
$"私は{Name1}{Suffix1}ですそれともあなたは{Name1}{Suffix2}。",
$"I am {Name1T}{Suffix1T} and you are {Name1T}{Suffix2T}.");
$"I am {Name1T}{Suffix1T} and you are {Name1T}{Suffix2T}.", 2);
}

[TestMethod]
public void Name1Suffix1_Name2Suffix1()
{
TranslateAndAssert(
$"私は{Name1}{Suffix1}ですそれともあなたは{Name2}{Suffix1}。",
$"I am {Name1T}{Suffix1T} and you are {Name2T}{Suffix1T}.");
$"I am {Name1T}{Suffix1T} and you are {Name2T}{Suffix1T}.", 2);
}

[TestMethod]
public void Name1Suffix1_Name1Suffix1()
{
TranslateAndAssert(
$"私は{Name1}{Suffix1}ですそれともあなたは{Name1}{Suffix1}。",
$"I am {Name1T}{Suffix1T} and you are {Name1T}{Suffix1T}.");
$"I am {Name1T}{Suffix1T} and you are {Name1T}{Suffix1T}.", 1);
}

[TestMethod]
public void Name1DotName2Suffix1()
{
TranslateAndAssert(
$"私は{Name1}{Name2}{Suffix1}です。",
$"I am {Name1T} {Name2T}{Suffix1T}.");
$"I am {Name1T} {Name2T}{Suffix1T}.", 1);
}

[TestMethod]
public void Name2DotName1Suffix1()
{
TranslateAndAssert(
$"私は{Name2}{Name1}{Suffix1}です。",
$"I am {Name2T} {Name1T}{Suffix1T}.");
$"I am {Name2T} {Name1T}{Suffix1T}.", 1);
}

[TestMethod]
public void Name1DotName2Suffix1_Name1Suffix1()
{
TranslateAndAssert(
$"私は{Name1}{Name2}{Suffix1}ですそれともあなたは{Name1}{Suffix1}。",
$"I am {Name1T} {Name2T}{Suffix1T} and you are {Name1T}{Suffix1T}.");
$"I am {Name1T} {Name2T}{Suffix1T} and you are {Name1T}{Suffix1T}.", 2);
}

[TestMethod]
public void Name1DotName2_Name1()
{
TranslateAndAssert(
$"私は{Name1}{Name2}ですそれともあなたは{Name1}。",
$"I am {Name1T} {Name2T} and you are {Name1T}.");
$"I am {Name1T} {Name2T} and you are {Name1T}.", 2);
}

[TestMethod]
Expand All @@ -153,15 +158,15 @@ public void Name1DotName2_Name1DotName2()
//todo: dot proxymod should group matches per contents and assign a proxy id like that.
TranslateAndAssert(
$"私は{Name1}{Name2}ですそれともあなたは{Name1}{Name2}。",
$"I am {Name1T} {Name2T} and you are {Name1T} {Name2T}.");
$"I am {Name1T} {Name2T} and you are {Name1T} {Name2T}.", 1);
}

[TestMethod]
public void Name1DotName2_Name1DotName3()
{
TranslateAndAssert(
$"私は{Name1}{Name2}ですそれともあなたは{Name1}{Name3}。",
$"I am {Name1T} {Name2T} and you are {Name1T} {Name3T}.");
$"I am {Name1T} {Name2T} and you are {Name1T} {Name3T}.", 2);
}


Expand All @@ -170,53 +175,105 @@ public void Name1DotName2_Name1DotName3_Name1DotName2()
{
TranslateAndAssert(
$"私は{Name1}{Name2}ですそれともあなたは{Name1}{Name3}、最初は彼は{Name4}。",
$"I am {Name1T} {Name2T} and you are {Name1T} {Name3T}, finally, he is {Name4T}.");
$"I am {Name1T} {Name2T} and you are {Name1T} {Name3T}, finally, he is {Name4T}.", 3);
}

[TestMethod]
public void Name1DotName2_Name3DotName4()
{
TranslateAndAssert(
$"私は{Name1}{Name2}ですそれともあなたは{Name3}{Name4}。",
$"I am {Name1T} {Name2T} and you are {Name3T} {Name4T}.");
$"I am {Name1T} {Name2T} and you are {Name3T} {Name4T}.", 2);
}

[TestMethod]
public void Name2DotName1Suffix1_Name1Suffix1()
{
TranslateAndAssert(
$"私は{Name2}{Name1}{Suffix1}ですそれともあなたは{Name1}{Suffix1}。",
$"I am {Name2T} {Name1T}{Suffix1T} and you are {Name1T}{Suffix1T}.");
$"I am {Name2T} {Name1T}{Suffix1T} and you are {Name1T}{Suffix1T}.", 2);
}

[TestMethod]
public void NameF1Suffix1_Name2()
{
TranslateAndAssert(
$"私は{NameF1}{Suffix1}ですそれともあなたは{Name2}。",
$"I am {NameF1T}{Suffix1T} and you are {Name2T}.");
$"I am {NameF1T}{Suffix1T} and you are {Name2T}.", 2);
}

[TestMethod]
public void MainRoleTest()
{
TranslateAndAssert(
$"{Name1}{Suffix1}できたそしてもお腹すいたみたい。",
$"{Name1T}{Suffix1T} came and he looked hungry.");
$"{Name1T}{Suffix1T} came and he looked hungry.", 1);
}

[TestMethod]
public void SubRoleTest()
{
TranslateAndAssert(
$"{NameF1}{Suffix1}できたそしてもお腹すいたみたい。",
$"{NameF1T}{Suffix1T} came and she looked hungry.");
$"{NameF1T}{Suffix1T} came and she looked hungry.", 1);
}

private void TranslateAndAssert(string input, string expectedOutput)
[TestMethod]
public void Name5Name5()
{
TranslateAndAssert(
$"{Name5}{Name5}",
$"{Name5T} {Name5T}", 1);
}

[TestMethod]
public void Name5Name5Name5()
{
TranslateAndAssert(
$"{Name5}{Name5}{Name5}",
$"{Name5T} {Name5T} {Name5T}", 1);
}

[TestMethod]
public void Name5Name5Name5_Name5Name5Name5()
{
TranslateAndAssert(
$"私は{Name5}{Name5}{Name5}ですそれともあなたは{Name5}{Name5}{Name5}。",
$"I am {Name5T} {Name5T} {Name5T} and you are {Name5T} {Name5T} {Name5T}.", 1);
}

[TestMethod]
public void Name5Name5Name5_Name4Name4Name4()
{
TranslateAndAssert(
$"私は{Name5}{Name5}{Name5}ですそれともあなたは{Name4}{Name4}{Name4}。",
$"I am {Name5T} {Name5T} {Name5T} and you are {Name4T} {Name4T} {Name4T}.", 2);
}

[TestMethod]
public void Name5Name4()
{
TranslateAndAssert(
$"{Name5}{Name4}",
$"{Name5T} {Name4T}",1);
}

[TestMethod]
public void Name5Suffix1()
{
TranslateAndAssert(
$"{Name5}{Suffix1}",
$"{Name5T}{Suffix1T}",1);
}

private void TranslateAndAssert(string input, string expectedOutput, int? expectedProxiesUsed = null)
{
var translation = Translator.Instance.Translate(User, Game, input, false, false);
var translation = Translator.Instance.Translate(User, Game, input, true, false);
Assert.AreEqual(expectedOutput, translation.Output);
}
if (!expectedProxiesUsed.HasValue) return;
var proxiesUsed = translation.GetProxiesUsed()?.ToList() ?? new List<ProxiesWithCount>();
var proxiesText = string.Join("; ", proxiesUsed);
Assert.AreEqual(expectedProxiesUsed, proxiesUsed.Sum(p=>p.Count), proxiesText);
}
}
}
5 changes: 3 additions & 2 deletions Happy Reader Tests/TestTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class TestTranslator : ITranslator
{"私は由紀子ですそれともあなたは本田。","I am Yukiko and you are Honda."},
{"私は武田ですそれともあなたは山澤、最初は彼は本田。", "I am Takeda and you are Yamazawa, finally, he is Honda."},
{"本田できたそしてもお腹すいたみたい。", "Honda came and he looked hungry."},
{"由紀子できたそしてもお腹すいたみたい。", "Yukiko came and she looked hungry."}
};
{"由紀子できたそしてもお腹すいたみたい。", "Yukiko came and she looked hungry."},
{"本田", "Honda"},
};

public void Initialise()
{
Expand Down
4 changes: 3 additions & 1 deletion Happy Reader/Model/RoleProxy.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Happy_Reader.Database;

namespace Happy_Reader
Expand All @@ -8,7 +9,8 @@ public class RoleProxy
public string Role { get; set; }
public string MainRole { get; set; }
public Entry Entry { get; set; }
public string FullRoleString => $"[[{MainRole}#{Id}]]";
public int RepeatCount { get; set; } = 1;
public string FullRoleString => string.Join("",Enumerable.Repeat($"[[{MainRole}#{Id}]]",RepeatCount));
public int Id { get; set; }
public List<Entry> ProxyMods { get; set; } = new List<Entry>();

Expand Down
17 changes: 11 additions & 6 deletions Happy Reader/Model/Translation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,17 @@ public Translation(Translation first, Translation second)
IsCharacterOnly = false;
}

public IEnumerable<Entry> GetEntriesUsed()
{
return _partResults.Where(pr => pr.EntriesUsed != null)
.SelectMany(pr => pr.EntriesUsed.SelectMany(eu => eu))
.Concat(_entriesUsedStageOne).Distinct();
}
public IEnumerable<Entry> GetEntriesUsed()
{
return _partResults.Where(pr => pr.EntriesUsed != null)
.SelectMany(pr => pr.EntriesUsed.SelectMany(eu => eu))
.Concat(_entriesUsedStageOne).Distinct();
}
public IEnumerable<ProxiesWithCount> GetProxiesUsed()
{
return _partResults
.SelectMany(pr => pr.ProxiesUsed);
}

public IEnumerable<CachedTranslation> GetMachineTranslationsUsed()
{
Expand Down
Loading

0 comments on commit 7732841

Please sign in to comment.