Advertisement
Guest User

Untitled

a guest
May 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.92 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.     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.                     break;
  32.                 case 'C':
  33.                     if (position != 0)
  34.                     {
  35.                         if (position + 1 <= word.Length)
  36.                         {
  37.                             var temp = word.Substring(position - 1, 1) + word.ToArray()[position] + word.Substring(position + 1, 1);
  38.                             if (temp == "SCH")
  39.                             {
  40.                                 result = "K";
  41.                             }
  42.                         }
  43.                     }
  44.                     if (position + 1 <= word.Length)
  45.                     {
  46.                         var temp = word.Substring(word.ToArray()[position], 2);
  47.                         if (temp == "CH")
  48.                         {
  49.                             result = "X";
  50.                             break;
  51.                         }
  52.                     }
  53.                     if (position + 2 <= word.Length)
  54.                     {
  55.                         var temp = word.Substring(word.ToArray()[position], 3);
  56.                         if (temp == "CIA")
  57.                         {
  58.                             result = "X";
  59.                             break;
  60.                         }                        
  61.                     }
  62.                     if (position + 1 <= word.Length)
  63.                     {
  64.                         var temp = word.Substring(word.ToArray()[position], 2);
  65.                         if (temp == "CI" || temp == "CE" || temp == "CY")
  66.                         {
  67.                             result = "S";
  68.                             break;
  69.                         }                        
  70.                     }
  71.                     result = "K";
  72.                     break;
  73.                 case 'D':
  74.                     if (position + 2 <= word.Length)
  75.                     {
  76.                         var temp = word.Substring(word.ToArray()[position], 3);
  77.                         if (temp == "DGE" || temp == "DGY" || temp == "DGI")
  78.                         {
  79.                             result = "J";
  80.                             break;
  81.                         }
  82.                         else
  83.                         {
  84.                             result = "J";
  85.                         }
  86.                     }
  87.                     else
  88.                     {
  89.                         result = "T";
  90.                     }
  91.                     break;
  92.                 case 'F':
  93.                     result = "F";
  94.                     break;
  95.                 case 'G':
  96.                     //Läs på
  97.                     break;
  98.                 case 'H':
  99.                     if (position != 0)
  100.                     {
  101.                         if (position + 1 <= word.Length)
  102.                         {
  103.                             if (help.IsVowel(word.ToCharArray()[position-1]) && !help.IsVowel(word.ToCharArray()[position + 1]))
  104.                             {
  105.                                 result = "";                                
  106.                             }
  107.                         }                  
  108.                         else
  109.                         {
  110.                             result = "H";
  111.                         }
  112.                     }
  113.                     else if (position == word.Length-1)
  114.                     {
  115.                         if (2 <= word.Length)
  116.                         {
  117.                             if (help.IsVowel(word.ToCharArray()[position - 1]))
  118.                             {
  119.                                 result = "";
  120.                             }
  121.                             else
  122.                             {
  123.                                 result = "H";
  124.                             }
  125.                         }
  126.                         else
  127.                         {
  128.                             result = "H";
  129.                         }
  130.                     }
  131.                     else
  132.                     {
  133.                         result = "H";
  134.                     }
  135.                     break;
  136.                 case 'J':
  137.                     result = "J";
  138.                     break;
  139.                 case 'K':
  140.                     if (position != 0)
  141.                     {
  142.                         if (word.Substring(position-1, 1) == "C")
  143.                         {
  144.                             result = "";
  145.                         }
  146.                     }
  147.                     else
  148.                     {
  149.                         result = "K";
  150.                     }
  151.                     break;
  152.                 case 'L':
  153.                     result = "L";
  154.                     break;
  155.                 case 'M':
  156.                     result = "M";
  157.                     break;
  158.                 case 'N':
  159.                     result = "N";
  160.                     break;
  161.                 case 'P':
  162.                     if (position + 1 <= word.Length)
  163.                     {
  164.                         var temp = word.Substring(position, 2);
  165.                         if (temp == "ph")
  166.                         {
  167.                             result = "F";
  168.                         }
  169.                         else
  170.                         {
  171.                             result = "P";
  172.                         }
  173.                     }
  174.                     else
  175.                     {
  176.                         result = "P";
  177.                     }
  178.                     break;
  179.                 case 'Q':
  180.                     result = "K";
  181.                     break;
  182.                 case 'R':
  183.                     result = "R";
  184.                     break;
  185.                 case 'S':
  186.                     if (position != 0)
  187.                     {
  188.                         if (word.Substring(position-1,1) == "H")
  189.                         {
  190.                             result = "X";
  191.                         }
  192.                     }
  193.                     if (position + 2 <= word.Length)
  194.                     {
  195.                         var temp = word.Substring(position,3);
  196.                         if (temp == "SIO" || temp == "SIA")
  197.                         {
  198.                             result = "X";
  199.                         }
  200.                         else
  201.                         {
  202.                             result = "S";
  203.                         }
  204.                     }
  205.                     else
  206.                     {
  207.                         result = "S";
  208.                     }
  209.                     break;
  210.                 case 'T':
  211.                     if (position != 0)
  212.                     {
  213.                         if (word.Substring(position - 1, 1) == "H")
  214.                         {
  215.                             result = "O";
  216.                             break;
  217.                         }
  218.                     }
  219.                     if (position + 2 <= word.Length)
  220.                     {
  221.                         var temp = word.Substring(position, 3);
  222.                         if (temp == "TIA" || temp == "TIO")
  223.                         {
  224.                             result = "X";
  225.                         }
  226.                         else if (temp == "TCH")
  227.                         {
  228.                             result = "";
  229.                         }
  230.                     }
  231.  
  232.                     else
  233.                     {
  234.                         result = "T";
  235.                     }
  236.                     break;
  237.                 case 'V':
  238.                     result = "F";
  239.                     break;
  240.                 case 'W':
  241.                     if (position + 1 <= word.Length)
  242.                     {
  243.                         if (help.IsVowel(word.ToCharArray()[position+1]))
  244.                         {
  245.                             result = "W";
  246.                             break;
  247.                         }
  248.                     }
  249.  
  250.                     break;
  251.                 case 'X':
  252.                     break;
  253.                 case 'Y':
  254.                     break;
  255.                 case 'Z':
  256.                     result = "S";
  257.                     break;
  258.                 default:
  259.                     break;
  260.             }
  261.             throw new NotImplementedException();
  262.         }
  263.     }
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement