Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add multi separator and more bad words #31

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions PersianSwear-CSharp/PersianSwear.Tests/FilterPersianWordsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void RemoveSensitivePhrases_WhenCalledWithInSensitiveSentence_ReturnsExac
{
var inSensitiveSentence = _helper.GenerateInSensitiveSentence();
var result = _sut.RemoveSensitivePhrases(inSensitiveSentence);
Assert.AreEqual(inSensitiveSentence, result);
}
Assert.AreEqual(inSensitiveSentence.RemoveLinesInSentence().RemoveSeperatiorsInSentence(), result);
}

[Test]
public void RemoveSensitivePhrases_WhenCalledWithSensitiveSentence_ReturnsFixedSentence()
Expand Down Expand Up @@ -119,15 +119,15 @@ public void GetSensitivePhrases_WhenCalledWithInSensitiveSentence_ReturnsEmptyLi
[Test]
public void GetSensitivePhrases_WhenCalledWithSensitiveSentence_ReturnsListOfSensitivePhrases()
{
var sensitiveSentence = _helper.GenerateSensitiveSentence();
var result = _sut.GetSensitivePhrases(sensitiveSentence);
var sensitivePhrases = result as string[] ?? result.ToArray();
Assert.IsNotEmpty(sensitivePhrases);
foreach (var sensitivePhrase in sensitivePhrases)
{
Assert.IsTrue(_helper.DoesPhraseExistInFile(sensitivePhrase));
}
}
var sensitiveSentence = _helper.GenerateSensitiveSentence();
var result = _sut.GetSensitivePhrases(sensitiveSentence);
var sensitivePhrases = result as string[] ?? result.ToArray();
Assert.IsNotEmpty(sensitivePhrases);
foreach (var sensitivePhrase in sensitivePhrases)
{
Assert.IsTrue(_helper.DoesPhraseExistInFile(sensitivePhrase));
}
}

[Test]
[TestCase(null)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ public void RemoveSensitivePhrases_WhenCalledWithInSensitiveSentence_ReturnsExac
{
var inSensitiveSentence = _helper.GenerateInSensitiveSentence();
var result = _sut.RemoveSensitivePhrases(inSensitiveSentence);
Assert.AreEqual(inSensitiveSentence, result);
}
Assert.AreEqual(inSensitiveSentence.RemoveLinesInSentence().RemoveSeperatiorsInSentence(), result);
}

[Test]
public void RemoveSensitivePhrases_WhenCalledWithSensitiveSentence_ReturnsFixedSentence()
Expand Down
49 changes: 33 additions & 16 deletions PersianSwear-CSharp/PersianSwear.Tests/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,44 @@ public string GenerateInSensitivePhrase()
return "سلام";
}

public string GenerateSensitiveSentence()
{
StringBuilder builder = new();
for (var i = 0; i < 10; i++)
{
builder.Append(GenerateSensitivePhrase() + " ");
builder.Append(GenerateInSensitivePhrase() + " ");
builder.AppendLine();
}
public string GenerateSensitiveSentence()
{
StringBuilder builder = new();
var separatorSelector = 0;
for (var i = 1; i < 10; i++)
{
var Separators = new string[] { " ", ".", "-", "_", ",", ";" };
var separator = Separators[separatorSelector];

return builder.ToString();
}
builder.Append(GenerateSensitivePhrase() + separator);
builder.Append(GenerateInSensitivePhrase() + separator);
builder.AppendLine();

public string GenerateInSensitiveSentence()
separatorSelector++;
if (separatorSelector == 5)
separatorSelector = 0;
}

return builder.ToString();
}

public string GenerateInSensitiveSentence()
{
StringBuilder builder = new();
for (var i = 0; i < 10; i++)
{
builder.Append(GenerateInSensitivePhrase() + " ");
var separatorSelector = 0;
for (var i = 0; i < 10; i++)
{
var Separators = new string[] { " ", ".", "-", "_", ",", ";" };
var separator = Separators[separatorSelector];

builder.Append(GenerateInSensitivePhrase() + separator);
builder.AppendLine();
}
builder.AppendLine();

separatorSelector++;
if (separatorSelector == 5)
separatorSelector = 0;
}

return builder.ToString();
}
Expand Down
18 changes: 14 additions & 4 deletions PersianSwear-CSharp/PersianSwear/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ namespace PersianSwear;

public static class Tools
{
private const char Separator = ' ';
private const string Pattern = "\r\n|\r|\n";
private static readonly char[] Separators = new char[] { ' ', '.', '-', '_', ',', ';' };
private const string Pattern = "\r\n|\r|\n";

public static IEnumerable<string> GetPhrasesInSentence(this string sentence)
{
return sentence.Split(Separator);
return sentence.Split(Separators);
}

public static string[] GetLinesInSentence(this string sentence)
{
return Regex.Split(sentence, Pattern);
}
}

public static string RemoveLinesInSentence(this string sentence)
{
return sentence.Replace("\r", "");
}

public static string RemoveSeperatiorsInSentence(this string sentence)
{
return sentence.Replace('.', ' ').Replace('-', ' ').Replace('_', ' ').Replace(',', ' ').Replace(';', ' ');
}
}
Loading