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

GregG #15

Open
wants to merge 5 commits 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
14 changes: 14 additions & 0 deletions ContentConsole.Test.Unit/ContentConsole.Test.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll</HintPath>
</Reference>
<Reference Include="Moq">
<HintPath>..\packages\Moq.4.2.1409.1722\lib\net40\Moq.dll</HintPath>
</Reference>
Expand All @@ -47,11 +51,21 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContentManagementTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ContentConsole\ContentConsole.csproj">
<Project>{70da2b36-ebf3-4438-9f95-ecc828a64527}</Project>
<Name>ContentConsole</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
Binary file added ContentConsole.Test.Unit/ContentManagementTest.cs
Binary file not shown.
4 changes: 2 additions & 2 deletions ContentConsole.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ContentConsole", "ContentConsole\ContentConsole.csproj", "{70DA2B36-EBF3-4438-9F95-ECC828A64527}"
EndProject
Expand Down
7 changes: 7 additions & 0 deletions ContentConsole/ContentConsole.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,16 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ContentManagement.cs" />
<Compile Include="Models\BannedWord.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="TestData\BannedWord.txt" />
<Content Include="TestData\NewBannedWords.txt" />
<Content Include="TestData\Text.txt" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
119 changes: 119 additions & 0 deletions ContentConsole/ContentManagement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace ContentConsole
{

public interface IContentManagement
{
List<BannedWord> BannedWordCounter(string text, string[] arrBannedWord);
List<BannedWord> BannedWordCounter(string text, string bannedWord);
string BannedWordReplacer(string text, string[] bannedWord);
}

//May be will need this interface without 'BannedWordReplacer' in future
public interface IContentManagementNoReplacer
{
List<BannedWord> BannedWordCounter(string text, string[] arrBannedWord);
List<BannedWord> BannedWordCounter(string text, string bannedWord);
}

public class ContentManagement : IContentManagement, IContentManagementNoReplacer
{
//Working with string ARRAY
public List<BannedWord> BannedWordCounter(string text, string[] arrBannedWords)
{
return FillBannedWord(text, TrimArray(arrBannedWords));
}
//Working with regular string
public List<BannedWord> BannedWordCounter(string text, string bannedWords)
{
return FillBannedWord(text, TrimArray(bannedWords));
}
private List<BannedWord> FillBannedWord(string text, string[] arrBannedWords)
{
var _bannedWord = new List<BannedWord>();

foreach (string word in arrBannedWords)
{
if (word.Trim() != "")
{
var cleanedtext = text.ToUpper().Replace(word.ToUpper(), "");
var cnt = (text.Length - cleanedtext.Length) / word.Length;
if (cnt > 0)
{
_bannedWord.Add(new BannedWord()
{
Word = word,
Count = cnt
});
}
}
}

return _bannedWord;
}

public string BannedWordReplacer(string text, string[] bannedWord)
{
bannedWord = TrimArray(bannedWord);
foreach (string word in bannedWord)
{
if (word.Trim() != "")
{
var temp = HashedString(word);
text = Regex.Replace(text, word, @temp, RegexOptions.IgnoreCase);
}
}

return text;
}
private string HashedString(string str)
{
var hash = "";
var first = "";

for (int i = 0; i < str.Length - 2; i++)
{
if (i == 0)
first = str.Substring(i, 1);
else if (first.Trim() == "")
{
first = " " + str.Substring(i, 1);
i ++;
}


hash += "#";
}

return first + hash + str.Substring(str.Length - 1, 1);
}

private string[] TrimArray(string str)
{
string[] arrTemp = str.Split(',');
return TrimArray(arrTemp);
}
private string[] TrimArray(string[] arr)
{
List<string> listTemp = new List<string>();
foreach (string s in arr)
{
var temp = s.Trim().ToLower();
if (temp != "")
listTemp.Add(temp);
}
listTemp.Sort();
//Remove duplicate (is exist)
listTemp = listTemp.Distinct().ToList();

return listTemp.ToArray();
}

}
}
14 changes: 14 additions & 0 deletions ContentConsole/Models/BannedWord.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ContentConsole
{
public class BannedWord
{
public string Word { get; set; }
public int Count { get; set; }
}
}
98 changes: 80 additions & 18 deletions ContentConsole/Program.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,105 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Drawing;

namespace ContentConsole
{
public static class Program
public class Program
{
public static void Main(string[] args)
{
string bannedWord1 = "swine";
string bannedWord2 = "bad";
string bannedWord3 = "nasty";
string bannedWord4 = "horrible";
List<BannedWord> bannedWord = null;
IContentManagement contentManagement = new ContentManagement();
string content = "";
string response = "";
string pathDataStorage = Environment.CurrentDirectory.ToString() + "/../../TestData/";
string[] arrBannedWords = File.ReadAllLines(pathDataStorage + "BannedWord.txt");

string content =
"The weather in Manchester in winter is bad. It rains all the time - it must be horrible for people visiting.";
Console.WriteLine("Content Management Console");
Console.WriteLine("");

int badWords = 0;
if (content.Contains(bannedWord1))
//Text proposal
Console.WriteLine("Please enter YES if you want to scan default text, otherwise press any key.");
response = Console.ReadLine();
if (response.ToLower() == "y" || response.ToLower() == "yes")
{
badWords = badWords + 1;
content = File.ReadAllText(pathDataStorage + "Text.txt");
}
if (content.Contains(bannedWord2))
else
{
badWords = badWords + 1;
Console.Write("Please enter the suggested text: ");
content = Console.ReadLine();
}
if (content.Contains(bannedWord3))

//Story selections
Console.WriteLine("");
Console.WriteLine("Please select Story you want to test (enter number of story):\n\n 1. User story \n 2. Administrator story \n 3. Reader story \n 4. Content curator story \n");
response = Console.ReadLine();
if (response == "1")
{
bannedWord = contentManagement.BannedWordCounter(content, arrBannedWords);
}
else if (response == "2")
{
//Bad words proposal
Console.WriteLine("Please enter new banned words separated by comma and press ENTER.");
response = Console.ReadLine();

//Storing this set of new banned words in the data storage (text file)
var path = pathDataStorage + "NewBannedWords.txt";
File.WriteAllText(path, response);

//Get stored banned word from data storage
response = File.ReadAllText(path);

bannedWord = contentManagement.BannedWordCounter(content, response);
}
else if (response == "3")
{
badWords = badWords + 1;
content = contentManagement.BannedWordReplacer(content, arrBannedWords);
}
if (content.Contains(bannedWord4))
else if (response == "4")
{
badWords = badWords + 1;
//Display original content with negative words count (similar to story 1, not totally understand the task for this story, need clarifications)
bannedWord = contentManagement.BannedWordCounter(content, arrBannedWords);
}
else
{
Console.WriteLine("Invalid request.");
Console.ReadKey();
return;
}

Console.WriteLine("");
Console.WriteLine("Scanned the text:");
Console.WriteLine(content);
Console.WriteLine("Total Number of negative words: " + badWords);

Console.WriteLine("Press ANY key to exit.");
if (bannedWord != null)
{
int badWordsTotal = 0;
foreach (BannedWord word in bannedWord)
{
Console.WriteLine("");
Console.Write("Number of '{0}' : ", word.Word);
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0}", word.Count);
Console.ForegroundColor = ConsoleColor.Gray;

badWordsTotal += word.Count;
}

Console.WriteLine("\n");
Console.Write("Total Number of negative words : ");
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("{0}", badWordsTotal);
Console.ForegroundColor = ConsoleColor.Gray;
}

Console.WriteLine("\n");
Console.WriteLine("Press any key for EXIT");
Console.ReadKey();

}
}

Expand Down
3 changes: 3 additions & 0 deletions ContentConsole/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,6 @@
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: InternalsVisibleTo("ContentConsole.Tests")]
[assembly: InternalsVisibleTo("ContentConsole.Explorables")]

5 changes: 5 additions & 0 deletions ContentConsole/TestData/BannedWord.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
swine
bad
nasty
horrible
Bad
1 change: 1 addition & 0 deletions ContentConsole/TestData/NewBannedWords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bad
1 change: 1 addition & 0 deletions ContentConsole/TestData/Text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I won't eat swine again but Daniel.. eating fats are good but there are horrible different types of fats.. some do attribute to bad health issues. Your on a computer so instead of assuming just do your own research. Or better yet hit the "South Beach Diet" they divide the good fats vs the bad fats.. even carbs have good vs bad. By the way to the other gentleman.. plants or dare I say vegetables and fruits don't carry any fats but a potato does contain starch. But nasty pork, never again!
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ This assignment is to analyse text, detecting and filtering negative words.
- Reformat, refactor and rework the provided code in any way you see fit.
- Code must be supported by tests to be "done-done".

## Advice to candidates

- You should approach this task in the same way that you would a real, production assignment. Do not 'code to the test'.
- It is more important that you show the right approach than that you complete all the stories. If you run low on time, apply an MVP to the stories.
- We will assume that the code you produce for this exercise reflects the kind of code you would write in a real-world situation, and assess accordingly.

## Task Stories

Please complete each story in order.
Expand Down Expand Up @@ -75,4 +81,6 @@ So that **I can see the original content**.

---

Note: Please submit your changes as a new pull request on *this* repo, and not on the original repo from which this is forked. If you can't submit a pull request then zip up your code and email it to us, but PRs are *strongly* preferred.

Thanks for your time, we look forward to hearing from you!