Advertisement
Guest User

Untitled

a guest
May 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 12.40 KB | None | 0 0
  1. using BusinessLayer.Interfaces;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace BusinessLayer.Repository
  9. {
  10.     public class WordTranformation : IWordTransformation
  11.     {
  12.         HelpMehtods help = new HelpMehtods();
  13.         public string MetaphoneTransformations(string word, int position)
  14.         {
  15.             string result = string.Empty;
  16.             char character = word.ToArray()[position];
  17.             switch (character)
  18.             {
  19.                 case 'B':
  20.                     if (position == word.Length-1)
  21.                     {
  22.                         if (word.Last() - 1 == 'M')
  23.                         {
  24.                             result = "";
  25.                         }
  26.                         else
  27.                         {
  28.                             result = "B";
  29.                         }
  30.                     }
  31.                     else
  32.                     {
  33.                         result = "B";
  34.                     }
  35.                     break;
  36.                 case 'C':
  37.                     if (position != 0)
  38.                     {
  39.                         if (position + 1 < word.Length)
  40.                         {
  41.                             var temp = word.Substring(position - 1, 1) + word.ToArray()[position] + word.Substring(position + 1, 1);
  42.                             if (temp == "SCH")
  43.                             {
  44.                                 result = "K";
  45.                             }
  46.                         }
  47.                     }
  48.                     if (position + 1 < word.Length)
  49.                     {
  50.                         var temp = word.Substring(position, 2);
  51.                         if (temp == "CH")
  52.                         {
  53.                             result = "X";
  54.                             break;
  55.                         }
  56.                     }
  57.                     if (position + 2 < word.Length)
  58.                     {
  59.                         var temp = word.Substring(position, 3);
  60.                         if (temp == "CIA")
  61.                         {
  62.                             result = "X";
  63.                             break;
  64.                         }                        
  65.                     }
  66.                     if (position + 1 < word.Length)
  67.                     {
  68.                         var temp = word.Substring(position, 2);
  69.                         if (temp == "CI" || temp == "CE" || temp == "CY")
  70.                         {
  71.                             result = "S";
  72.                             break;
  73.                         }                        
  74.                     }
  75.                     result = "K";
  76.                     break;
  77.                 case 'D':
  78.                     if (position + 2 < word.Length)
  79.                     {
  80.                         var temp = word.Substring(position, 3);
  81.                         if (temp == "DGE" || temp == "DGY" || temp == "DGI")
  82.                         {
  83.                             result = "J";
  84.                             break;
  85.                         }
  86.                         else
  87.                         {
  88.                             result = "T";
  89.                             break;
  90.                         }
  91.                     }
  92.                     else
  93.                     {
  94.                         result = "T";
  95.                     }
  96.                     break;
  97.                 case 'F':
  98.                     result = "F";
  99.                     break;
  100.                 case 'G':
  101.                     if (position + 1 < word.Length)
  102.                     {
  103.                         if (word.Substring(position+1, 1) == "H")
  104.                         {
  105.                             if (position != 0)
  106.                             {
  107.                                 if (position != word.Length && !help.IsVowel(word.ToCharArray()[position-1]))
  108.                                 {
  109.                                     result = "";
  110.                                     break;
  111.                                 }
  112.                             }
  113.                             else
  114.                             {
  115.                                 if (position != word.Length)
  116.                                 {
  117.                                     result = "";
  118.                                     break;
  119.                                 }
  120.                             }
  121.  
  122.                         }
  123.                     }
  124.                     if (position + 1 < word.Length)
  125.                     {
  126.                         if (word.Substring(position + 1, 1) == "N")
  127.                         {
  128.                             result = "";
  129.                             break;
  130.                         }
  131.                     }
  132.                     if (position + 3 <= word.Length)
  133.                     {
  134.                         if (word.Substring(position + 1, 1) == "NED")
  135.                         {
  136.                             result = "";
  137.                             break;
  138.                         }
  139.                     }
  140.                     if (position != 0)
  141.                     {
  142.                         var temp = word.Substring(position-1,1);
  143.                         if (temp == "I" || temp == "E" || temp == "Y")
  144.                         {
  145.                             if (position + 1 < word.Length)
  146.                             {
  147.                                 if (word.Substring(position+1, 1) != "G")
  148.                                 {
  149.                                     result = "J";
  150.                                 }
  151.                                 else
  152.                                 {
  153.                                     result = "K";
  154.                                 }
  155.                             }
  156.                             else
  157.                             {
  158.                                 result = "J";
  159.                             }
  160.                         }
  161.                     }
  162.                     else
  163.                     {
  164.                         result = "K";
  165.                     }
  166.                     break;
  167.                 case 'H':
  168.                     if (position != 0)
  169.                     {
  170.                         if (position + 1 < word.Length)
  171.                         {
  172.                             if (help.IsVowel(word.ToCharArray()[position-1]) && !help.IsVowel(word.ToCharArray()[position + 1]))
  173.                             {
  174.                                 result = "";                                
  175.                             }
  176.                         }                  
  177.                         else
  178.                         {
  179.                             result = "H";
  180.                         }
  181.                     }
  182.                     else if (position == word.Length-1)
  183.                     {
  184.                         if (2 <= word.Length)
  185.                         {
  186.                             if (help.IsVowel(word.ToCharArray()[position - 1]))
  187.                             {
  188.                                 result = "";
  189.                             }
  190.                             else
  191.                             {
  192.                                 result = "H";
  193.                             }
  194.                         }
  195.                         else
  196.                         {
  197.                             result = "H";
  198.                         }
  199.                     }
  200.                     else
  201.                     {
  202.                         result = "H";
  203.                     }
  204.                     break;
  205.                 case 'J':
  206.                     result = "J";
  207.                     break;
  208.                 case 'K':
  209.                     if (position != 0)
  210.                     {
  211.                         if (word.Substring(position-1, 1) == "C")
  212.                         {
  213.                             result = "";
  214.                         }
  215.                         else
  216.                         {
  217.                             result = "K";
  218.                             break;
  219.                         }
  220.                     }
  221.                     else
  222.                     {
  223.                         result = "K";
  224.                     }
  225.                     break;
  226.                 case 'L':
  227.                     result = "L";
  228.                     break;
  229.                 case 'M':
  230.                     result = "M";
  231.                     break;
  232.                 case 'N':
  233.                     result = "N";
  234.                     break;
  235.                 case 'P':
  236.                     if (position + 1 < word.Length)
  237.                     {
  238.                         var temp = word.Substring(position, 2);
  239.                         if (temp == "PH")
  240.                         {
  241.                             result = "F";
  242.                         }
  243.                         else
  244.                         {
  245.                             result = "P";
  246.                         }
  247.                     }
  248.                     else
  249.                     {
  250.                         result = "P";
  251.                     }
  252.                     break;
  253.                 case 'Q':
  254.                     result = "K";
  255.                     break;
  256.                 case 'R':
  257.                     result = "R";
  258.                     break;
  259.                 case 'S':
  260.                     if (position != 0)
  261.                     {
  262.                         if (word.Substring(position-1,1) == "H")
  263.                         {
  264.                             result = "X";
  265.                         }
  266.                     }
  267.                     if (position + 2 < word.Length)
  268.                     {
  269.                         var temp = word.Substring(position,3);
  270.                         if (temp == "SIO" || temp == "SIA")
  271.                         {
  272.                             result = "X";
  273.                         }
  274.                         else
  275.                         {
  276.                             result = "S";
  277.                         }
  278.                     }
  279.                     else
  280.                     {
  281.                         result = "S";
  282.                     }
  283.                     break;
  284.                 case 'T':
  285.                     if (position != 0)
  286.                     {
  287.                         if (word.Substring(position - 1, 1) == "H")
  288.                         {
  289.                             result = "O";
  290.                             break;
  291.                         }
  292.                     }
  293.                     if (position + 2 < word.Length)
  294.                     {
  295.                         var temp = word.Substring(position, 3);
  296.                         if (temp == "TIA" || temp == "TIO")
  297.                         {
  298.                             result = "X";
  299.                         }
  300.                         else if (temp == "TCH")
  301.                         {
  302.                             result = "";
  303.                         }
  304.                         else
  305.                         {
  306.                             result = "T";
  307.                         }
  308.                     }
  309.  
  310.                     else
  311.                     {
  312.                         result = "T";
  313.                     }
  314.                     break;
  315.                 case 'V':
  316.                     result = "F";
  317.                     break;
  318.                 case 'W':
  319.                     if (position + 1 < word.Length)
  320.                     {
  321.                         if (help.IsVowel(word.ToCharArray()[position+1]))
  322.                         {
  323.                             result = "W";
  324.                             break;
  325.                         }
  326.                         else
  327.                         {
  328.                             result = "";
  329.                         }
  330.                     }
  331.                     else
  332.                     {
  333.                         result = "";
  334.                     }
  335.                     break;
  336.                 case 'X':
  337.                     result = "KS";
  338.                     break;
  339.                 case 'Y':
  340.                     if (position + 1 < word.Length)
  341.                     {
  342.                         if (help.IsVowel(word.ToCharArray()[position + 1]))
  343.                         {
  344.                             result = "Y";
  345.                             break;
  346.                         }
  347.                         else
  348.                         {
  349.                             result = "";
  350.                         }
  351.                     }
  352.                     break;
  353.                 case 'Z':
  354.                     result = "S";
  355.                     break;
  356.                 default:
  357.                     break;
  358.             }
  359.             return result;
  360.         }
  361.     }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement