Make interjections language based

This commit is contained in:
niksedk 2023-09-19 18:55:24 +02:00
parent dabf588d0a
commit 39d553de6d
10 changed files with 393 additions and 121 deletions

View File

@ -0,0 +1,37 @@
<interjections>
<word>Æh</word>
<word>Æhh</word>
<word>Æhhh</word>
<word>Ah</word>
<word>Ahem</word>
<word>Ahh</word>
<word>Ahhh</word>
<word>Ahhhh</word>
<word>Eh</word>
<word>Ehh</word>
<word>Ehhh</word>
<word>Erm</word>
<word>Gah</word>
<word>Hm</word>
<word>Hmm</word>
<word>Hmmm</word>
<word>Huh</word>
<word>Mm</word>
<word>Mmm</word>
<word>Mmmm</word>
<word>Oh</word>
<word>Øh</word>
<word>Ohh</word>
<word>Øhh</word>
<word>Ohhh</word>
<word>Øhhh</word>
<word>Ow</word>
<word>Oww</word>
<word>Owww</word>
<word>Ugh</word>
<word>Ughh</word>
<word>Uh</word>
<word>Uhh</word>
<word>Uhhh</word>
<word>Whew</word>
</interjections>

View File

@ -0,0 +1,32 @@
<interjections>
<word>Ah</word>
<word>Ahem</word>
<word>Ahh</word>
<word>Ahhh</word>
<word>Ahhhh</word>
<word>Eh</word>
<word>Ehh</word>
<word>Ehhh</word>
<word>Erm</word>
<word>Gah</word>
<word>Hm</word>
<word>Hmm</word>
<word>Hmmm</word>
<word>Huh</word>
<word>Mm</word>
<word>Mmm</word>
<word>Mmmm</word>
<word>Oh</word>
<word>Ohh</word>
<word>Ohhh</word>
<word>Ow</word>
<word>Oww</word>
<word>Owww</word>
<word>Phew</word>
<word>Ugh</word>
<word>Ughh</word>
<word>Uh</word>
<word>Uhh</word>
<word>Uhhh</word>
<word>Whew</word>
</interjections>

View File

@ -4,6 +4,9 @@ using Nikse.SubtitleEdit.Core.Enums;
using Nikse.SubtitleEdit.Core.Forms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Nikse.SubtitleEdit.Forms;
namespace Test.Logic.Forms
{
@ -20,18 +23,33 @@ namespace Test.Logic.Forms
/// </summary>
public TestContext TestContext { get; set; }
private static string _interjectionsFileName;
private static RemoveTextForHI GetRemoveTextForHiLib()
{
SetInterjections();
var hiSettings = new RemoveTextForHISettings(new Subtitle());
return new RemoveTextForHI(hiSettings);
}
private static void SetInterjections()
{
if (_interjectionsFileName == null)
{
_interjectionsFileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".xml");
File.WriteAllText(_interjectionsFileName, "<interjections> <word>Ah</word> <word>Ahem</word> <word>Ahh</word> <word>Ahhh</word> <word>Ahhhh</word> <word>Eh</word> <word>Ehh</word> <word>Ehhh</word> <word>Erm</word> <word>Gah</word> <word>Hm</word> <word>Hmm</word> <word>Hmmm</word> <word>Huh</word> <word>Mm</word> <word>Mmm</word> <word>Mmmm</word> <word>Oh</word> <word>Ohh</word> <word>Ohhh</word> <word>Ow</word> <word>Oww</word> <word>Owww</word> <word>Phew</word> <word>Ugh</word> <word>Ughh</word> <word>Uh</word> <word>Uhh</word> <word>Uhhh</word> <word>Whew</word></interjections>", Encoding.UTF8);
}
}
private static InterjectionRemoveContext GetRemoveInterjectionContext(string text, bool onlyInSeparatedLine)
{
SetInterjections();
return new InterjectionRemoveContext
{
OnlySeparatedLines = onlyInSeparatedLine,
Interjections = RemoveTextForHI.GetInterjectionList(),
Interjections = RemoveTextForHI.GetInterjectionList(_interjectionsFileName),
Text = text,
};
}
@ -244,7 +262,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
string text = "- He's got the clap." + Environment.NewLine + "- SAM: (gasps) What?";
string expected = "- He's got the clap." + Environment.NewLine + "- What?";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -281,7 +299,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
const string text = "- Aw, save it. Storm?\r\n- [Storm]\r\nWe're outta here.";
const string expected = "- Aw, save it. Storm?\r\n- We're outta here.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -299,7 +317,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
const string text = "[Chuckles,\r\nCoughing]\r\nBut we lived through it.";
const string expected = "But we lived through it.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -316,7 +334,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
const string text = "is the body of a mutant kid\r\non the 6:00 news.";
const string expected = "is the body of a mutant kid\r\non the 6:00 news.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -335,7 +353,7 @@ namespace Test.Logic.Forms
string text = "<i>NARRATOR:" + Environment.NewLine +
"Previously on NCIS</i>";
const string expected = "<i>Previously on NCIS</i>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -354,7 +372,7 @@ namespace Test.Logic.Forms
string text = "<b>NARRATOR:" + Environment.NewLine +
"Previously on NCIS</b>";
const string expected = "<b>Previously on NCIS</b>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -372,7 +390,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
string text = "- JOHN: Hey." + Environment.NewLine + "- ...hey.";
string expected = "- Hey." + Environment.NewLine + "- ...hey.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -396,7 +414,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
const string text = "[MAN]Where?![MAN]";
const string expected = "Where?!";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -412,7 +430,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
string text = "HECTOR: Hi." + Environment.NewLine + "-Oh, hey, Hector.";
string expected = "- Hi." + Environment.NewLine + "- Oh, hey, Hector.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -428,7 +446,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
const string text = "<b>HECTOR: Hi.</b>";
const string expected = "<b>Hi.</b>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -704,7 +722,7 @@ namespace Test.Logic.Forms
target.Settings.ColonSeparateLine = false;
const string text = "MICHAEL: How are you?";
const string expected = "How are you?";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -922,7 +940,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColon = true;
string text = "- I insist." + Environment.NewLine + "<i>- [ Woman Laughing]</i>";
const string expected = "I insist.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -949,7 +967,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColon = true;
string text = "WOMAN: A glass of champagne, please." + Environment.NewLine + "- (Laughter)";
const string expected = "A glass of champagne, please.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -968,7 +986,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenQuestionMarks = true;
string text = "? My Paul ?" + Environment.NewLine + "? I give you all ?";
string expected = string.Empty;
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1034,7 +1052,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
string text = "<i>- A man who wants to make his mark..." + Environment.NewLine + "- [ Coughing]</i>";
const string expected = "<i>A man who wants to make his mark...</i>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1045,7 +1063,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveIfAllUppercase = true;
string text = "- And you?" + Environment.NewLine + "- I—";
string expected = "- And you?" + Environment.NewLine + "- I—";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1055,7 +1073,7 @@ namespace Test.Logic.Forms
var target = GetRemoveTextForHiLib();
target.Settings.RemoveIfAllUppercase = true;
string text = string.Empty;
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(text, actual);
}
@ -1068,7 +1086,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveIfTextContains = null;
const string text = "<i>♪♪[Ambient Electronic]</i>";
const string expected = "<i>♪♪</i>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1082,7 +1100,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
const string text = "Oh — Oh, that's nice!";
const string expected = "That's nice!";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1094,7 +1112,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "- Uh—uh, my God!" + Environment.NewLine + "- Uh, my God.";
string expected = "- My God!" + Environment.NewLine + "- My God.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1106,7 +1124,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "- Uh — uh, my God!" + Environment.NewLine + "- Uh, my God.";
string expected = "- My God!" + Environment.NewLine + "- My God.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1118,7 +1136,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "- I just, uh —" + Environment.NewLine + "- What?";
string expected = "- I just —" + Environment.NewLine + "- What?";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1130,7 +1148,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenParentheses = true;
const string text = "I'm trying to! (MASTER): Faster now. evacuate.";
const string expected = "I'm trying to! Faster now. evacuate.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1142,7 +1160,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "- Mr. Harding?" + Environment.NewLine + "Uh--";
const string expected = "Mr. Harding?";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1154,7 +1172,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "- Mr. Harding?" + Environment.NewLine + "- Mm-hm. Oh.";
const string expected = "Mr. Harding?";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1166,7 +1184,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "-Sit down. Sit down." + Environment.NewLine + "-Oh! Oh!";
const string expected = "Sit down. Sit down.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1178,7 +1196,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "Oh." + Environment.NewLine + "-I'm awfully tired.";
const string expected = "I'm awfully tired.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1215,7 +1233,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
string text = "WOMAN: <i>Mr. Sportello?</i>" + Environment.NewLine + "- Mm-hm.";
string expected = "<i>- Mr. Sportello?</i>" + Environment.NewLine + "- Mm-hm.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1228,7 +1246,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "WOMAN: <i>Mr. Sportello?</i>" + Environment.NewLine + "- Mm-hm.";
string expected = "<i>Mr. Sportello?</i>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1241,7 +1259,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = true;
string text = "- \"My father doesn't want me to be him.\"" + Environment.NewLine + "EAMES: Exactly.";
string expected = "- \"My father doesn't want me to be him.\"" + Environment.NewLine + "- Exactly.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1262,7 +1280,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
string text = "-[gurgling]" + Environment.NewLine + "-Mom?";
const string expected = "Mom?";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1273,7 +1291,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
string text = "-[Ronnie laughs]" + Environment.NewLine + "-[sighs] Wow, Ronnie.";
const string expected = "Wow, Ronnie.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1284,7 +1302,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
const string text = "<font color=\"#808080\">[Whistling]</font> Hallo everybody!";
const string expected = "Hallo everybody!";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1295,7 +1313,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
const string text = "♪ <font color=\"#000000\">[LIGHT SWITCH CLICKS]</font>";
const string expected = "♪";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1306,7 +1324,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
const string text = "Foobar <font color=\"#808080\">[CHAINS RATTLING]</font> Foobar";
const string expected = "Foobar Foobar";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1332,7 +1350,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveWhereContains = false;
string text = "<i>- ♪♪[Continues ]</i>" + Environment.NewLine + "- It's pretty strong stuff.";
const string expected = "It's pretty strong stuff.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1347,7 +1365,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
string text = "♪ Trotting down the paddock" + Environment.NewLine + "on a bright, sunny day ♪♪";
string expected = string.Empty;
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1362,7 +1380,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
string text = "<i>♪ Trotting down the paddock" + Environment.NewLine + "on a bright, sunny day ♪♪</i>";
string expected = string.Empty;
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1377,7 +1395,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenBrackets = true;
string text = "- ♪ Honey, honey, yeah ♪" + Environment.NewLine + "- ♪ Heard it through|the grapevine ♪";
string expected = string.Empty;
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1395,7 +1413,7 @@ namespace Test.Logic.Forms
string expected = "- The meal is ready. Let's go!" + Environment.NewLine + "- J. T. Lancer!";
var sub = new Subtitle();
sub.Paragraphs.Add(new Paragraph(text, 0, 2000));
string actual = target.RemoveTextFromHearImpaired(text, sub, 0);
string actual = target.RemoveTextFromHearImpaired(text, sub, 0, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1453,7 +1471,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenCustomTags = true;
target.Settings.CustomStart = "♪";
target.Settings.CustomEnd = "♪";
string actual = target.RemoveTextFromHearImpaired("- ♪ To defeat ♪" + Environment.NewLine + "- Referee: Salute.");
string actual = target.RemoveTextFromHearImpaired("- ♪ To defeat ♪" + Environment.NewLine + "- Referee: Salute.", _interjectionsFileName);
Assert.AreEqual("Salute.", actual);
}
@ -1498,7 +1516,7 @@ namespace Test.Logic.Forms
string text = "Let's count!" + Environment.NewLine + "1.. 2... 3!";
string expected = "Let's count!" + Environment.NewLine + "1.. 2... 3!";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1515,7 +1533,7 @@ namespace Test.Logic.Forms
const string text = "ENGINE STARTING";
const string expected = "";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1533,7 +1551,7 @@ namespace Test.Logic.Forms
string text = "- NORA: <i>Sir?</i>" + Environment.NewLine + "- (CAR DOOR CLOSES)";
string expected = "<i>Sir?</i>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1551,7 +1569,7 @@ namespace Test.Logic.Forms
string text = "- Well, received, technically." + Environment.NewLine + "- KEVIN: <i>Mmm-hmm.</i>";
string expected = "- Well, received, technically." + Environment.NewLine + "<i>- Mmm-hmm.</i>";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1570,7 +1588,7 @@ namespace Test.Logic.Forms
string text = "- Well, received, technically." + Environment.NewLine + "- KEVIN: <i>Mmm-hmm.</i>";
string expected = "Well, received, technically.";
string actual = target.RemoveTextFromHearImpaired(text);
string actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1621,7 +1639,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenParentheses = true;
target.Settings.RemoveInterjections = true;
string expected = "- How many, sir?" + Environment.NewLine + "- 275.";
string actual = target.RemoveTextFromHearImpaired("- How many, sir?" + Environment.NewLine + "- Uh — (clears throat) 275.");
string actual = target.RemoveTextFromHearImpaired("- How many, sir?" + Environment.NewLine + "- Uh — (clears throat) 275.", _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -1632,7 +1650,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenParentheses = false;
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
string actual = target.RemoveTextFromHearImpaired("[scoffs]: Nice try.");
string actual = target.RemoveTextFromHearImpaired("[scoffs]: Nice try.", _interjectionsFileName);
Assert.AreEqual("Nice try.", actual);
}
@ -1645,7 +1663,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenCustomTags = true;
target.Settings.CustomStart = "♪";
target.Settings.CustomEnd = "♪";
string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- <i>♪ [Ominous tone plays] ♪</i>");
string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- <i>♪ [Ominous tone plays] ♪</i>", _interjectionsFileName);
Assert.AreEqual("Ferguson, Kaz...", actual);
}
@ -1656,7 +1674,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- <i>♪ [Ominous tone plays] ♪</i>");
string actual = target.RemoveTextFromHearImpaired("- Ferguson, Kaz..." + Environment.NewLine + "- <i>♪ [Ominous tone plays] ♪</i>", _interjectionsFileName);
Assert.AreEqual("Ferguson, Kaz...", actual);
}
@ -1668,7 +1686,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "<i>Captain's log, stardate 1514. 1:</i>");
string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "<i>Captain's log, stardate 1514. 1:</i>", _interjectionsFileName);
Assert.AreEqual("<i>Captain's log, stardate 1514. 1:</i>", actual);
}
@ -1679,7 +1697,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "Captain's log, stardate 1514. 1:");
string actual = target.RemoveTextFromHearImpaired("KIRK:" + Environment.NewLine + "Captain's log, stardate 1514. 1:", _interjectionsFileName);
Assert.AreEqual("Captain's log, stardate 1514. 1:", actual);
}
@ -1690,7 +1708,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "<i>--and trespassed into our star systems.</i>");
string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "<i>--and trespassed into our star systems.</i>", _interjectionsFileName);
Assert.AreEqual("<i>--and trespassed into our star systems.</i>", actual);
}
@ -1701,7 +1719,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "--and trespassed into our star systems.");
string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "--and trespassed into our star systems.", _interjectionsFileName);
Assert.AreEqual("--and trespassed into our star systems.", actual);
}
@ -1712,7 +1730,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenSquares = true;
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "<i>—and trespassed into our star systems.</i>");
string actual = target.RemoveTextFromHearImpaired("BALOK[OVER RADIO]:" + Environment.NewLine + "<i>—and trespassed into our star systems.</i>", _interjectionsFileName);
Assert.AreEqual("<i>—and trespassed into our star systems.</i>", actual);
}
@ -1724,7 +1742,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.RemoveTextBetweenCustomTags = false;
string actual = target.RemoveTextFromHearImpaired("<i> -JOHN: Hvordan går det?</i>" + Environment.NewLine + "<i>-Marry: Det går fint!</i>");
string actual = target.RemoveTextFromHearImpaired("<i> -JOHN: Hvordan går det?</i>" + Environment.NewLine + "<i>-Marry: Det går fint!</i>", _interjectionsFileName);
Assert.AreEqual("<i>- Hvordan går det?</i>" + Environment.NewLine + "<i>- Det går fint!</i>", actual);
}
@ -1788,7 +1806,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBetweenCustomTags = true;
target.Settings.CustomStart = "♪";
target.Settings.CustomEnd = "♪";
string actual = target.RemoveTextFromHearImpaired("♪ Give me hope and" + Environment.NewLine + "give me patience ♪");
string actual = target.RemoveTextFromHearImpaired("♪ Give me hope and" + Environment.NewLine + "give me patience ♪", _interjectionsFileName);
Assert.AreEqual(string.Empty, actual);
}
@ -1798,7 +1816,7 @@ namespace Test.Logic.Forms
var target = GetRemoveTextForHiLib();
target.Settings.RemoveTextBeforeColon = false;
target.Settings.RemoveTextBetweenParentheses = true;
string actual = target.RemoveTextFromHearImpaired("(Not, it's not (a secret).)");
string actual = target.RemoveTextFromHearImpaired("(Not, it's not (a secret).)", _interjectionsFileName);
Assert.AreEqual(string.Empty, actual);
}
@ -1808,7 +1826,7 @@ namespace Test.Logic.Forms
var target = GetRemoveTextForHiLib();
target.Settings.RemoveTextBeforeColon = false;
target.Settings.RemoveTextBetweenParentheses = true;
string actual = target.RemoveTextFromHearImpaired("(MAN) Not, it's... (WOMAN) not.");
string actual = target.RemoveTextFromHearImpaired("(MAN) Not, it's... (WOMAN) not.", _interjectionsFileName);
Assert.AreEqual("Not, it's... not.", actual);
}
@ -1884,7 +1902,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColon = true;
target.Settings.RemoveTextBeforeColonOnlyUppercase = true;
target.Settings.OnlyIfInSeparateLine = true;
string actual = target.RemoveTextFromHearImpaired("<i>-Era stato avveritito.</i>" + Environment.NewLine + "-(PARLA IN SPANOLO)");
string actual = target.RemoveTextFromHearImpaired("<i>-Era stato avveritito.</i>" + Environment.NewLine + "-(PARLA IN SPANOLO)", _interjectionsFileName);
Assert.AreEqual("<i>Era stato avveritito.</i>", actual);
}
@ -1895,7 +1913,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColon = true;
target.Settings.RemoveTextBeforeColonOnlyUppercase = true;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("Senti, [si schiarisce la voce]," + Environment.NewLine + "dille semplicemente che ti e mancata.");
string actual = target.RemoveTextFromHearImpaired("Senti, [si schiarisce la voce]," + Environment.NewLine + "dille semplicemente che ti e mancata.", _interjectionsFileName);
Assert.AreEqual("Senti," + Environment.NewLine + "dille semplicemente che ti e mancata.", actual);
}
@ -1912,7 +1930,7 @@ namespace Test.Logic.Forms
var target = GetRemoveTextForHiLib();
target.Settings.RemoveTextBeforeColon = false;
target.Settings.RemoveTextBetweenBrackets = true;
string actual = target.RemoveTextFromHearImpaired("Spoken text." + Environment.NewLine + "<i>- [hearing impaired text] Spoken text.</i>");
string actual = target.RemoveTextFromHearImpaired("Spoken text." + Environment.NewLine + "<i>- [hearing impaired text] Spoken text.</i>", _interjectionsFileName);
Assert.AreEqual("- Spoken text." + Environment.NewLine + "<i>- Spoken text.</i>", actual);
}
@ -1923,7 +1941,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColon = true;
target.Settings.RemoveTextBeforeColonOnlyUppercase = true;
target.Settings.RemoveInterjections = false;
string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!");
string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!", _interjectionsFileName);
Assert.AreEqual("Mr. Wylie!", actual);
}
@ -1934,7 +1952,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColon = true;
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
target.Settings.RemoveInterjections = false;
string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!");
string actual = target.RemoveTextFromHearImpaired("- [chuckles]" + Environment.NewLine + "- MRS. TRYON: Mr. Wylie!", _interjectionsFileName);
Assert.AreEqual("Mr. Wylie!", actual);
}
@ -1948,7 +1966,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = true;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?");
string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", _interjectionsFileName);
Assert.AreEqual("Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", actual);
}
@ -1961,7 +1979,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = true;
target.Settings.OnlyIfInSeparateLine = true;
string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?");
string actual = target.RemoveTextFromHearImpaired("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", _interjectionsFileName);
Assert.AreEqual("[man] Aren't you a little old" + Environment.NewLine + "to be playing with dolls, Michael?", actual);
}
@ -1974,7 +1992,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = true;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("- You're weird!" + Environment.NewLine + "- [sigh]");
string actual = target.RemoveTextFromHearImpaired("- You're weird!" + Environment.NewLine + "- [sigh]", _interjectionsFileName);
Assert.AreEqual("You're weird!", actual);
}
@ -1987,7 +2005,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = true;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("\u2010 You're weird!" + Environment.NewLine + "\u2010 [sigh]");
string actual = target.RemoveTextFromHearImpaired("\u2010 You're weird!" + Environment.NewLine + "\u2010 [sigh]", _interjectionsFileName);
Assert.AreEqual("You're weird!", actual);
}
@ -2039,7 +2057,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = false;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("- Oh. No." + Environment.NewLine + "-");
string actual = target.RemoveTextFromHearImpaired("- Oh. No." + Environment.NewLine + "-", _interjectionsFileName);
Assert.AreEqual("Oh. No.", actual);
}
@ -2052,7 +2070,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = false;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("-" + Environment.NewLine + "- Oh. No.");
string actual = target.RemoveTextFromHearImpaired("-" + Environment.NewLine + "- Oh. No.", _interjectionsFileName);
Assert.AreEqual("Oh. No.", actual);
}
@ -2065,7 +2083,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = false;
target.Settings.OnlyIfInSeparateLine = true;
var actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]");
var actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]", _interjectionsFileName);
Assert.AreEqual("What's going on...?! [gasps]", actual);
}
@ -2078,7 +2096,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveInterjections = false;
target.Settings.RemoveTextBetweenBrackets = false;
target.Settings.OnlyIfInSeparateLine = false;
string actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]");
string actual = target.RemoveTextFromHearImpaired("What's going on...?! [gasps]", _interjectionsFileName);
Assert.AreEqual("What's going on...?!", actual);
}
@ -2214,7 +2232,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
var text = "Oh, I was just in my office" + Environment.NewLine + "and-and it was... 10:00.";
var expected = "I was just in my office" + Environment.NewLine + "and-and it was... 10:00.";
var actual = target.RemoveTextFromHearImpaired(text);
var actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
@ -2231,7 +2249,7 @@ namespace Test.Logic.Forms
target.Settings.RemoveTextBeforeColonOnlyUppercase = false;
var text = "and that is gonna take..." + Environment.NewLine + "[STAMMERS] ... real deep pockets.";
var expected = "and that is gonna take..." + Environment.NewLine + "... real deep pockets.";
var actual = target.RemoveTextFromHearImpaired(text);
var actual = target.RemoveTextFromHearImpaired(text, _interjectionsFileName);
Assert.AreEqual(expected, actual);
}
}

View File

@ -144,7 +144,6 @@ namespace Nikse.SubtitleEdit.Core.Common
public bool OcrUseWordSplitList { get; set; }
public bool OcrUseWordSplitListAvoidPropercase { get; set; }
public string BDOpenIn { get; set; }
public string Interjections { get; set; }
public string MicrosoftBingApiId { get; set; }
public string MicrosoftTranslatorApiKey { get; set; }
public string MicrosoftTranslatorTokenEndpoint { get; set; }
@ -490,7 +489,6 @@ namespace Nikse.SubtitleEdit.Core.Common
OcrTrainMergedLetters = "ff ft fi fj fy fl rf rt rv rw ry rt rz ryt tt TV tw yt yw wy wf ryt xy";
OcrUseWordSplitList = true;
OcrUseWordSplitListAvoidPropercase = true;
Interjections = "Ah;Ahem;Ahh;Ahhh;Ahhhh;Eh;Ehh;Ehhh;Erm;Hm;Hmm;Hmmm;Huh;Mm;Mmm;Mmmm;Phew;Gah;Oh;Ohh;Ohhh;Ow;Oww;Owww;Ugh;Ughh;Uh;Uhh;Uhhh;Whew";
MicrosoftTranslatorTokenEndpoint = "https://api.cognitive.microsoft.com/sts/v1.0/issueToken";
GoogleTranslateNoKeyWarningShow = true;
GoogleApiV1ChunkSize = 1500;
@ -5001,12 +4999,6 @@ $HorzAlign = Center
settings.Tools.BDOpenIn = subNode.InnerText;
}
subNode = node.SelectSingleNode("Interjections");
if (subNode != null)
{
settings.Tools.Interjections = subNode.InnerText;
}
subNode = node.SelectSingleNode("MicrosoftBingApiId");
if (subNode != null)
{
@ -11293,7 +11285,6 @@ $HorzAlign = Center
textWriter.WriteElementString("OcrUseWordSplitList", settings.Tools.OcrUseWordSplitList.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("OcrUseWordSplitListAvoidPropercase", settings.Tools.OcrUseWordSplitListAvoidPropercase.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("BDOpenIn", settings.Tools.BDOpenIn);
textWriter.WriteElementString("Interjections", settings.Tools.Interjections);
textWriter.WriteElementString("MicrosoftBingApiId", settings.Tools.MicrosoftBingApiId);
textWriter.WriteElementString("MicrosoftTranslatorApiKey", settings.Tools.MicrosoftTranslatorApiKey);
textWriter.WriteElementString("MicrosoftTranslatorTokenEndpoint", settings.Tools.MicrosoftTranslatorTokenEndpoint);

View File

@ -2,7 +2,9 @@
using Nikse.SubtitleEdit.Core.Forms.FixCommonErrors;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
namespace Nikse.SubtitleEdit.Core.Forms
{
@ -847,12 +849,12 @@ namespace Nikse.SubtitleEdit.Core.Forms
private static readonly char[] TrimStartNoiseChar = { '-', ' ' };
public string RemoveTextFromHearImpaired(string input)
public string RemoveTextFromHearImpaired(string input, string interjectionsFileName)
{
return RemoveTextFromHearImpaired(input, null, -1);
return RemoveTextFromHearImpaired(input, null, -1, interjectionsFileName);
}
public string RemoveTextFromHearImpaired(string inputWithoutUnicodeReplace, Subtitle subtitle, int index)
public string RemoveTextFromHearImpaired(string inputWithoutUnicodeReplace, Subtitle subtitle, int index, string interjectionsFileName)
{
if (StartsAndEndsWithHearImpairedTags(HtmlUtil.RemoveHtmlTags(inputWithoutUnicodeReplace, true).TrimStart(TrimStartNoiseChar)))
{
@ -1021,7 +1023,7 @@ namespace Nikse.SubtitleEdit.Core.Forms
{
if (_interjections == null)
{
ReloadInterjection();
ReloadInterjection(interjectionsFileName);
}
// reusable context
@ -1557,10 +1559,51 @@ namespace Nikse.SubtitleEdit.Core.Forms
return sb.ToString().Trim();
}
public static IList<string> GetInterjectionList()
public static List<string> GetInterjections(string fileName)
{
var words = new List<string>();
if (File.Exists(fileName))
{
try
{
var xml = new XmlDocument();
xml.Load(fileName);
if (xml.DocumentElement != null)
{
var nodes = xml.DocumentElement.SelectNodes("word");
if (nodes != null)
{
foreach (XmlNode node in nodes)
{
var w = node.InnerText.Trim();
if (w.Length > 0)
{
words.Add(w);
}
}
}
return words;
}
}
catch
{
// ignore
}
}
return words;
}
public static string GetInterjectionsFileName(string twoLetterLanguage)
{
return Path.Combine(Configuration.DictionariesDirectory, twoLetterLanguage + "_interjections.xml");
}
public static IList<string> GetInterjectionList(string fileName)
{
var interjectionList = new HashSet<string>();
foreach (var s in Configuration.Settings.Tools.Interjections.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
foreach (var s in GetInterjections(fileName))
{
if (s.Length <= 0)
{
@ -1578,9 +1621,9 @@ namespace Nikse.SubtitleEdit.Core.Forms
return sortedList;
}
public void ReloadInterjection()
public void ReloadInterjection(string fileName)
{
_interjections = GetInterjectionList();
_interjections = GetInterjectionList(fileName);
}
}
}

View File

@ -2048,12 +2048,14 @@ namespace Nikse.SubtitleEdit.Forms
var prev = sub.GetParagraphOrDefault(0);
var first = true;
var lang = LanguageAutoDetect.AutoDetectGoogleLanguage(sub);
var interjectionsFileName = RemoveTextForHI.GetInterjectionsFileName(lang);
foreach (var p in sub.Paragraphs)
{
if (IsActionEnabled(CommandLineConverter.BatchAction.RemoveTextForHI))
{
_removeTextForHearingImpaired.Settings = _removeTextForHiSettings;
p.Text = _removeTextForHearingImpaired.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p));
p.Text = _removeTextForHearingImpaired.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p), interjectionsFileName);
}
if (IsActionEnabled(CommandLineConverter.BatchAction.RemoveFormatting))

View File

@ -18,16 +18,9 @@ namespace Nikse.SubtitleEdit.Forms
UiUtil.FixFonts(this);
}
public string GetInterjectionsSemiColonSeparatedString()
public List<string> GetInterjectionList()
{
var sb = new StringBuilder();
foreach (var s in _interjections)
{
sb.Append(';');
sb.Append(s.Trim());
}
return sb.ToString().Trim(';');
return _interjections;
}
private void Interjections_KeyDown(object sender, KeyEventArgs e)
@ -42,14 +35,10 @@ namespace Nikse.SubtitleEdit.Forms
}
}
public void Initialize(string semiColonSeparatedList)
public void Initialize(List<string> interjections)
{
_interjections = new List<string>();
var arr = semiColonSeparatedList.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
foreach (var s in arr)
{
_interjections.Add(s.Trim());
}
_interjections = interjections;
FillListBox();
Text = LanguageSettings.Current.Interjections.Title;

View File

@ -42,6 +42,8 @@
this.toolStripMenuItemInvertSel = new System.Windows.Forms.ToolStripMenuItem();
this.checkBoxRemoveTextBeforeColon = new System.Windows.Forms.CheckBox();
this.groupBoxRemoveTextConditions = new System.Windows.Forms.GroupBox();
this.comboBoxLanguage = new Nikse.SubtitleEdit.Controls.NikseComboBox();
this.labelLanguage = new System.Windows.Forms.Label();
this.checkBoxInterjectionOnlySeparateLine = new System.Windows.Forms.CheckBox();
this.checkBoxRemoveIfAllUppercase = new System.Windows.Forms.CheckBox();
this.checkBoxColonSeparateLine = new System.Windows.Forms.CheckBox();
@ -185,6 +187,8 @@
//
this.groupBoxRemoveTextConditions.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.groupBoxRemoveTextConditions.Controls.Add(this.comboBoxLanguage);
this.groupBoxRemoveTextConditions.Controls.Add(this.labelLanguage);
this.groupBoxRemoveTextConditions.Controls.Add(this.checkBoxInterjectionOnlySeparateLine);
this.groupBoxRemoveTextConditions.Controls.Add(this.checkBoxRemoveIfAllUppercase);
this.groupBoxRemoveTextConditions.Controls.Add(this.checkBoxColonSeparateLine);
@ -211,13 +215,47 @@
this.groupBoxRemoveTextConditions.TabStop = false;
this.groupBoxRemoveTextConditions.Text = "Remove text conditions";
//
// comboBoxLanguage
//
this.comboBoxLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.comboBoxLanguage.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxLanguage.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
this.comboBoxLanguage.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179)))));
this.comboBoxLanguage.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120)))));
this.comboBoxLanguage.ButtonForeColor = System.Drawing.SystemColors.ControlText;
this.comboBoxLanguage.ButtonForeColorDown = System.Drawing.Color.Orange;
this.comboBoxLanguage.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.comboBoxLanguage.DropDownHeight = 400;
this.comboBoxLanguage.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxLanguage.DropDownWidth = 196;
this.comboBoxLanguage.FormattingEnabled = true;
this.comboBoxLanguage.Location = new System.Drawing.Point(718, 18);
this.comboBoxLanguage.MaxLength = 32767;
this.comboBoxLanguage.Name = "comboBoxLanguage";
this.comboBoxLanguage.SelectedIndex = -1;
this.comboBoxLanguage.SelectedItem = null;
this.comboBoxLanguage.SelectedText = "";
this.comboBoxLanguage.Size = new System.Drawing.Size(196, 21);
this.comboBoxLanguage.TabIndex = 16;
this.comboBoxLanguage.UsePopupWindow = false;
//
// labelLanguage
//
this.labelLanguage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.labelLanguage.Location = new System.Drawing.Point(475, 21);
this.labelLanguage.Name = "labelLanguage";
this.labelLanguage.Size = new System.Drawing.Size(237, 25);
this.labelLanguage.TabIndex = 20;
this.labelLanguage.Text = "Language";
this.labelLanguage.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// checkBoxInterjectionOnlySeparateLine
//
this.checkBoxInterjectionOnlySeparateLine.AutoSize = true;
this.checkBoxInterjectionOnlySeparateLine.Location = new System.Drawing.Point(600, 53);
this.checkBoxInterjectionOnlySeparateLine.Location = new System.Drawing.Point(600, 76);
this.checkBoxInterjectionOnlySeparateLine.Name = "checkBoxInterjectionOnlySeparateLine";
this.checkBoxInterjectionOnlySeparateLine.Size = new System.Drawing.Size(137, 17);
this.checkBoxInterjectionOnlySeparateLine.TabIndex = 18;
this.checkBoxInterjectionOnlySeparateLine.TabIndex = 19;
this.checkBoxInterjectionOnlySeparateLine.Text = "Only if on separate line";
this.checkBoxInterjectionOnlySeparateLine.UseVisualStyleBackColor = true;
this.checkBoxInterjectionOnlySeparateLine.CheckedChanged += new System.EventHandler(this.checkBoxInterjectionOnlySeparateLine_CheckedChanged);
@ -248,10 +286,10 @@
//
// buttonEditInterjections
//
this.buttonEditInterjections.Location = new System.Drawing.Point(718, 26);
this.buttonEditInterjections.Location = new System.Drawing.Point(718, 49);
this.buttonEditInterjections.Name = "buttonEditInterjections";
this.buttonEditInterjections.Size = new System.Drawing.Size(103, 23);
this.buttonEditInterjections.TabIndex = 17;
this.buttonEditInterjections.TabIndex = 18;
this.buttonEditInterjections.Text = "Edit...";
this.buttonEditInterjections.UseVisualStyleBackColor = true;
this.buttonEditInterjections.Click += new System.EventHandler(this.buttonEditInterjections_Click);
@ -259,10 +297,10 @@
// checkBoxRemoveInterjections
//
this.checkBoxRemoveInterjections.AutoSize = true;
this.checkBoxRemoveInterjections.Location = new System.Drawing.Point(582, 30);
this.checkBoxRemoveInterjections.Location = new System.Drawing.Point(582, 53);
this.checkBoxRemoveInterjections.Name = "checkBoxRemoveInterjections";
this.checkBoxRemoveInterjections.Size = new System.Drawing.Size(130, 17);
this.checkBoxRemoveInterjections.TabIndex = 16;
this.checkBoxRemoveInterjections.TabIndex = 17;
this.checkBoxRemoveInterjections.Text = "Remove interjections ";
this.checkBoxRemoveInterjections.UseVisualStyleBackColor = true;
this.checkBoxRemoveInterjections.CheckedChanged += new System.EventHandler(this.checkBoxRemoveInterjections_CheckedChanged);
@ -278,6 +316,16 @@
//
// comboBoxRemoveIfTextContains
//
this.comboBoxRemoveIfTextContains.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxRemoveIfTextContains.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
this.comboBoxRemoveIfTextContains.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179)))));
this.comboBoxRemoveIfTextContains.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120)))));
this.comboBoxRemoveIfTextContains.ButtonForeColor = System.Drawing.SystemColors.ControlText;
this.comboBoxRemoveIfTextContains.ButtonForeColorDown = System.Drawing.Color.Orange;
this.comboBoxRemoveIfTextContains.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.comboBoxRemoveIfTextContains.DropDownHeight = 400;
this.comboBoxRemoveIfTextContains.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
this.comboBoxRemoveIfTextContains.DropDownWidth = 122;
this.comboBoxRemoveIfTextContains.FormattingEnabled = true;
this.comboBoxRemoveIfTextContains.Items.AddRange(new object[] {
"¶",
@ -287,9 +335,14 @@
this.comboBoxRemoveIfTextContains.Location = new System.Drawing.Point(427, 131);
this.comboBoxRemoveIfTextContains.MaxLength = 25;
this.comboBoxRemoveIfTextContains.Name = "comboBoxRemoveIfTextContains";
this.comboBoxRemoveIfTextContains.SelectedIndex = -1;
this.comboBoxRemoveIfTextContains.SelectedItem = null;
this.comboBoxRemoveIfTextContains.SelectedText = "¶";
this.comboBoxRemoveIfTextContains.Size = new System.Drawing.Size(122, 21);
this.comboBoxRemoveIfTextContains.TabIndex = 15;
this.comboBoxRemoveIfTextContains.TabStop = false;
this.comboBoxRemoveIfTextContains.Text = "¶";
this.comboBoxRemoveIfTextContains.UsePopupWindow = false;
this.comboBoxRemoveIfTextContains.TextChanged += new System.EventHandler(this.CheckBoxRemoveTextBetweenCheckedChanged);
//
// checkBoxRemoveWhereContains
@ -305,6 +358,16 @@
//
// comboBoxCustomEnd
//
this.comboBoxCustomEnd.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxCustomEnd.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
this.comboBoxCustomEnd.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179)))));
this.comboBoxCustomEnd.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120)))));
this.comboBoxCustomEnd.ButtonForeColor = System.Drawing.SystemColors.ControlText;
this.comboBoxCustomEnd.ButtonForeColorDown = System.Drawing.Color.Orange;
this.comboBoxCustomEnd.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.comboBoxCustomEnd.DropDownHeight = 400;
this.comboBoxCustomEnd.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
this.comboBoxCustomEnd.DropDownWidth = 38;
this.comboBoxCustomEnd.FormattingEnabled = true;
this.comboBoxCustomEnd.Items.AddRange(new object[] {
"¶",
@ -313,13 +376,28 @@
this.comboBoxCustomEnd.Location = new System.Drawing.Point(116, 135);
this.comboBoxCustomEnd.MaxLength = 2;
this.comboBoxCustomEnd.Name = "comboBoxCustomEnd";
this.comboBoxCustomEnd.SelectedIndex = -1;
this.comboBoxCustomEnd.SelectedItem = null;
this.comboBoxCustomEnd.SelectedText = "¶";
this.comboBoxCustomEnd.Size = new System.Drawing.Size(38, 21);
this.comboBoxCustomEnd.TabIndex = 8;
this.comboBoxCustomEnd.TabStop = false;
this.comboBoxCustomEnd.Text = "¶";
this.comboBoxCustomEnd.UsePopupWindow = false;
this.comboBoxCustomEnd.TextChanged += new System.EventHandler(this.CheckBoxRemoveTextBetweenCheckedChanged);
//
// comboBoxCustomStart
//
this.comboBoxCustomStart.BackColor = System.Drawing.SystemColors.Window;
this.comboBoxCustomStart.BackColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(240)))), ((int)(((byte)(240)))), ((int)(((byte)(240)))));
this.comboBoxCustomStart.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(171)))), ((int)(((byte)(173)))), ((int)(((byte)(179)))));
this.comboBoxCustomStart.BorderColorDisabled = System.Drawing.Color.FromArgb(((int)(((byte)(120)))), ((int)(((byte)(120)))), ((int)(((byte)(120)))));
this.comboBoxCustomStart.ButtonForeColor = System.Drawing.SystemColors.ControlText;
this.comboBoxCustomStart.ButtonForeColorDown = System.Drawing.Color.Orange;
this.comboBoxCustomStart.ButtonForeColorOver = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.comboBoxCustomStart.DropDownHeight = 400;
this.comboBoxCustomStart.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDown;
this.comboBoxCustomStart.DropDownWidth = 38;
this.comboBoxCustomStart.FormattingEnabled = true;
this.comboBoxCustomStart.Items.AddRange(new object[] {
"¶",
@ -328,9 +406,14 @@
this.comboBoxCustomStart.Location = new System.Drawing.Point(41, 135);
this.comboBoxCustomStart.MaxLength = 2;
this.comboBoxCustomStart.Name = "comboBoxCustomStart";
this.comboBoxCustomStart.SelectedIndex = -1;
this.comboBoxCustomStart.SelectedItem = null;
this.comboBoxCustomStart.SelectedText = "¶";
this.comboBoxCustomStart.Size = new System.Drawing.Size(38, 21);
this.comboBoxCustomStart.TabIndex = 6;
this.comboBoxCustomStart.TabStop = false;
this.comboBoxCustomStart.Text = "¶";
this.comboBoxCustomStart.UsePopupWindow = false;
this.comboBoxCustomStart.TextChanged += new System.EventHandler(this.CheckBoxRemoveTextBetweenCheckedChanged);
//
// checkBoxRemoveTextBeforeColonOnlyUppercase
@ -442,6 +525,7 @@
// textBoxAfterText
//
this.textBoxAfterText.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.textBoxAfterText.FocusedColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(120)))), ((int)(((byte)(215)))));
this.textBoxAfterText.Location = new System.Drawing.Point(12, 543);
this.textBoxAfterText.Multiline = true;
this.textBoxAfterText.Name = "textBoxAfterText";
@ -529,5 +613,7 @@
private System.Windows.Forms.CheckBox checkBoxInterjectionOnlySeparateLine;
private Nikse.SubtitleEdit.Controls.NikseTextBox textBoxAfterText;
private System.Windows.Forms.Label labelText;
private Controls.NikseComboBox comboBoxLanguage;
private System.Windows.Forms.Label labelLanguage;
}
}

View File

@ -7,21 +7,40 @@ using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using System.Xml;
namespace Nikse.SubtitleEdit.Forms
{
public sealed partial class FormRemoveTextForHearImpaired : PositionAndSizeForm
{
public class LanguageItem
{
public CultureInfo Code { get; }
public string Name { get; }
public LanguageItem(CultureInfo code, string name)
{
Code = code;
Name = name;
}
public override string ToString()
{
return Name;
}
}
public Subtitle Subtitle;
public int TotalFixes { get; private set; }
private readonly LanguageStructure.RemoveTextFromHearImpaired _language;
private readonly RemoveTextForHI _removeTextForHiLib;
private Dictionary<Paragraph, string> _fixes;
private readonly Main _mainForm;
private string _interjectionsLanguage;
private readonly List<Paragraph> _unchecked = new List<Paragraph>();
private readonly List<Paragraph> _edited = new List<Paragraph>();
private readonly List<Paragraph> _editedOld = new List<Paragraph>();
private static readonly Color ListBackMarkColor = Configuration.Settings.General.UseDarkTheme? Color.PaleVioletRed : Color.PeachPuff;
private static readonly Color ListBackMarkColor = Configuration.Settings.General.UseDarkTheme ? Color.PaleVioletRed : Color.PeachPuff;
public FormRemoveTextForHearImpaired(Main main, Subtitle subtitle)
{
@ -85,9 +104,33 @@ namespace Nikse.SubtitleEdit.Forms
{
comboBoxRemoveIfTextContains.Left = checkBoxRemoveWhereContains.Left + checkBoxRemoveWhereContains.Width;
Subtitle = new Subtitle(subtitle);
InitializeLanguageNames(subtitle);
GeneratePreview();
}
private void InitializeLanguageNames(Subtitle subtitle)
{
_interjectionsLanguage = LanguageAutoDetect.AutoDetectGoogleLanguage(subtitle);
comboBoxLanguage.BeginUpdate();
comboBoxLanguage.Items.Clear();
foreach (var ci in Utilities.GetSubtitleLanguageCultures())
{
comboBoxLanguage.Items.Add(new LanguageItem(ci, ci.EnglishName));
if (ci.TwoLetterISOLanguageName == _interjectionsLanguage)
{
comboBoxLanguage.SelectedIndex = comboBoxLanguage.Items.Count - 1;
}
}
comboBoxLanguage.Sorted = true;
comboBoxLanguage.EndUpdate();
if (comboBoxLanguage.SelectedIndex < 0)
{
comboBoxLanguage.SelectedIndex = 0;
}
}
public void InitializeSettingsOnly()
{
comboBoxRemoveIfTextContains.Left = checkBoxRemoveWhereContains.Left + checkBoxRemoveWhereContains.Width;
@ -124,7 +167,7 @@ namespace Nikse.SubtitleEdit.Forms
}
else
{
var newText = _removeTextForHiLib.RemoveTextFromHearImpaired(p.Text, Subtitle, index);
var newText = _removeTextForHiLib.RemoveTextFromHearImpaired(p.Text, Subtitle, index, GetInterjectionsFileName());
if (p.Text.RemoveChar(' ') != newText.RemoveChar(' '))
{
count++;
@ -256,11 +299,14 @@ namespace Nikse.SubtitleEdit.Forms
{
using (var editInterjections = new Interjections())
{
editInterjections.Initialize(Configuration.Settings.Tools.Interjections);
var fileName = GetInterjectionsFileName();
editInterjections.Initialize(RemoveTextForHI.GetInterjections(fileName));
if (editInterjections.ShowDialog(this) == DialogResult.OK)
{
Configuration.Settings.Tools.Interjections = editInterjections.GetInterjectionsSemiColonSeparatedString();
_removeTextForHiLib.ReloadInterjection();
//Configuration.Settings.Tools.Interjections = editInterjections.GetInterjectionsSemiColonSeparatedString();
SaveInterjections(editInterjections.GetInterjectionList());
_removeTextForHiLib.ReloadInterjection(fileName);
if (checkBoxRemoveInterjections.Checked)
{
GeneratePreview();
@ -269,6 +315,31 @@ namespace Nikse.SubtitleEdit.Forms
}
}
private void SaveInterjections(List<string> interjections)
{
var xml = new XmlDocument();
xml.LoadXml("<interjections/>");
foreach (var s in interjections)
{
XmlNode node = xml.CreateElement("word");
node.InnerText = s;
xml.DocumentElement.AppendChild(node);
}
xml.Save(GetInterjectionsFileName());
}
private string GetInterjectionsFileName()
{
var lang = "en";
if (comboBoxLanguage.SelectedIndex >= 0 && comboBoxLanguage.Items[comboBoxLanguage.SelectedIndex] is LanguageItem l)
{
lang = l.Code.TwoLetterISOLanguageName;
}
return RemoveTextForHI.GetInterjectionsFileName(lang);
}
private void FormRemoveTextForHearImpaired_Resize(object sender, EventArgs e)
{
var availableWidth = (listViewFixes.Width - (columnHeaderApply.Width + columnHeaderLine.Width + 20)) / 2;

View File

@ -19,6 +19,7 @@ using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Nikse.SubtitleEdit.Core.Forms;
namespace Nikse.SubtitleEdit.Logic.CommandLineConvert
{
@ -2195,9 +2196,11 @@ namespace Nikse.SubtitleEdit.Logic.CommandLineConvert
case BatchAction.RemoveTextForHI:
var hiSettings = new Core.Forms.RemoveTextForHISettings(sub);
var hiLib = new Core.Forms.RemoveTextForHI(hiSettings);
var lang = LanguageAutoDetect.AutoDetectGoogleLanguage(sub);
var interjectionsFileName = RemoveTextForHI.GetInterjectionsFileName(lang);
foreach (var p in sub.Paragraphs)
{
p.Text = hiLib.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p));
p.Text = hiLib.RemoveTextFromHearImpaired(p.Text, sub, sub.Paragraphs.IndexOf(p), interjectionsFileName);
}
break;