Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using BusinessLayer.Interfaces;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace BusinessLayer.Repository
- {
- class WordTranformation : IWordTransformation
- {
- HelpMehtods help = new HelpMehtods();
- public string MetaphoneTransformations(string word, int position)
- {
- string result = string.Empty;
- char character = word.ToArray()[position];
- switch (character)
- {
- case 'B':
- if (position == word.Length-1)
- {
- if (word.Last() - 1 == 'M')
- {
- result = "";
- }
- else
- {
- result = "B";
- }
- }
- break;
- case 'C':
- if (position != 0)
- {
- if (position + 1 <= word.Length)
- {
- var temp = word.Substring(position - 1, 1) + word.ToArray()[position] + word.Substring(position + 1, 1);
- if (temp == "SCH")
- {
- result = "K";
- }
- }
- }
- if (position + 1 <= word.Length)
- {
- var temp = word.Substring(word.ToArray()[position], 2);
- if (temp == "CH")
- {
- result = "X";
- break;
- }
- }
- if (position + 2 <= word.Length)
- {
- var temp = word.Substring(word.ToArray()[position], 3);
- if (temp == "CIA")
- {
- result = "X";
- break;
- }
- }
- if (position + 1 <= word.Length)
- {
- var temp = word.Substring(word.ToArray()[position], 2);
- if (temp == "CI" || temp == "CE" || temp == "CY")
- {
- result = "S";
- break;
- }
- }
- result = "K";
- break;
- case 'D':
- if (position + 2 <= word.Length)
- {
- var temp = word.Substring(word.ToArray()[position], 3);
- if (temp == "DGE" || temp == "DGY" || temp == "DGI")
- {
- result = "J";
- break;
- }
- else
- {
- result = "J";
- }
- }
- else
- {
- result = "T";
- }
- break;
- case 'F':
- result = "F";
- break;
- case 'G':
- //Läs på
- break;
- case 'H':
- if (position != 0)
- {
- if (position + 1 <= word.Length)
- {
- if (help.IsVowel(word.ToCharArray()[position-1]) && !help.IsVowel(word.ToCharArray()[position + 1]))
- {
- result = "";
- }
- }
- else
- {
- result = "H";
- }
- }
- else if (position == word.Length-1)
- {
- if (2 <= word.Length)
- {
- if (help.IsVowel(word.ToCharArray()[position - 1]))
- {
- result = "";
- }
- else
- {
- result = "H";
- }
- }
- else
- {
- result = "H";
- }
- }
- else
- {
- result = "H";
- }
- break;
- case 'J':
- result = "J";
- break;
- case 'K':
- if (position != 0)
- {
- if (word.Substring(position-1, 1) == "C")
- {
- result = "";
- }
- }
- else
- {
- result = "K";
- }
- break;
- case 'L':
- result = "L";
- break;
- case 'M':
- result = "M";
- break;
- case 'N':
- result = "N";
- break;
- case 'P':
- if (position + 1 <= word.Length)
- {
- var temp = word.Substring(position, 2);
- if (temp == "ph")
- {
- result = "F";
- }
- else
- {
- result = "P";
- }
- }
- else
- {
- result = "P";
- }
- break;
- case 'Q':
- result = "K";
- break;
- case 'R':
- result = "R";
- break;
- case 'S':
- if (position != 0)
- {
- if (word.Substring(position-1,1) == "H")
- {
- result = "X";
- }
- }
- if (position + 2 <= word.Length)
- {
- var temp = word.Substring(position,3);
- if (temp == "SIO" || temp == "SIA")
- {
- result = "X";
- }
- else
- {
- result = "S";
- }
- }
- else
- {
- result = "S";
- }
- break;
- case 'T':
- if (position != 0)
- {
- if (word.Substring(position - 1, 1) == "H")
- {
- result = "O";
- break;
- }
- }
- if (position + 2 <= word.Length)
- {
- var temp = word.Substring(position, 3);
- if (temp == "TIA" || temp == "TIO")
- {
- result = "X";
- }
- else if (temp == "TCH")
- {
- result = "";
- }
- }
- else
- {
- result = "T";
- }
- break;
- case 'V':
- result = "F";
- break;
- case 'W':
- if (position + 1 <= word.Length)
- {
- if (help.IsVowel(word.ToCharArray()[position+1]))
- {
- result = "W";
- break;
- }
- }
- break;
- case 'X':
- break;
- case 'Y':
- break;
- case 'Z':
- result = "S";
- break;
- default:
- break;
- }
- throw new NotImplementedException();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement