Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp1
- {
- class Program
- {
- static char[] VOWELS = { 'а', 'е', 'и', 'о', 'у', 'ы', 'э', 'ю', 'я' };
- static string[] PERFECTIVE_GERUND_1 = { "в", "вши", "вшись" };
- static string[] PERFECTIVE_GERUND_2 = { "ив", "ивши", "ившись", "ыв", "ывши", "ывшись" };
- static string[] ADJEDCTIVE = { "ее", "ие", "ые", "ое", "ими", "ыми", "ей", "ий", "ый", "ой", "ем", "им", "ым", "ом", "его", "ого", "ему", "ому", "их", "ых", "ую", "юю", "ая", "яя", "ою", "ею" };
- static string[] PARTICIPLE_1 = { "ем", "нн", "вш", "ющ", "щ" };
- static string[] PARTICIPLE_2 = { "ивш", "ывш", "ующ" };
- static string[] REFLEXIVE = { "ся", "сь" };
- static string[] VERB_1 = { "ла", "на", "ете", "йте", "ли", "й", "л", "ем", "н", "ло", "но", "ет", "ют", "ны", "ть", "ешь", "нно" };
- static string[] VERB_2 = { "ила", "ыла", "ена", "ейте", "уйте", "ите", "или", "ыли", "ей", "уй", "ил", "ыл", "им", "ым", "ен", "ило", "ыло", "ено", "ят", "ует", "уют", "ит", "ыт", "ены", "ить", "ыть", "ишь", "ую", "ю" };
- static string[] NOUN = { "а", "ев", "ов", "ие", "ье", "е", "иями", "ями", "ами", "еи", "ии", "и", "ией", "ей", "ой", "ий", "й", "иям", "ям", "ием", "ем", "ам", "ом", "о", "у", "ах", "иях", "ях", "ы", "ь", "ию", "ью", "ю", "ия", "ья", "я" };
- static string[] SUPERLATIVE = { "ейш", "ейше" };
- static string[] DERIVATIONAL = { "ост", "ость" };
- static string RV, R1, R2, word;
- static string ValidateString(string a)
- {
- string result = a.ToLower();
- result = result.Replace('ё', 'е');
- foreach (char c in result)
- {
- if (c < 'а' || c > 'я')
- return null;
- }
- return result;
- }
- static int IndexOfVowel(string a)
- {
- foreach (char c in a)
- {
- foreach (char t in VOWELS)
- {
- if (c == t)
- {
- return a.IndexOf(c);
- }
- }
- }
- return -1;
- }
- static int IndexOfConsonant(string a)
- {
- bool yeah = false;
- foreach (char c in a)
- {
- yeah = false;
- foreach (char t in VOWELS)
- {
- if (c == t)
- {
- yeah = true;
- break;
- }
- }
- if (!yeah)
- return a.IndexOf(c);
- }
- return -1;
- }
- static string SetWord(string a)
- {
- return a.Replace(RV, "");
- }
- static bool IsEnding(string a, string ending)
- {
- int index = a.LastIndexOf(ending);
- if (index > 0 && a.Length - index == ending.Length)
- return true;
- else
- return false;
- }
- static void UpdateRS(string word)
- {
- RV = FindRV(word);
- R1 = FindR1(word);
- R2 = FindR2(word);
- return;
- }
- static string FindRV(string a)
- {
- string result = "";
- int pos = -1;
- bool exit = false;
- foreach (char c in a)
- {
- foreach (char t in VOWELS)
- {
- if (c == t)
- {
- pos = a.IndexOf(c);
- exit = true;
- break;
- }
- }
- if (exit)
- break;
- }
- result = a.Substring(++pos);
- return result;
- }
- static string FindR1(string a)
- {
- string result = "";
- int v, c;
- v = IndexOfVowel(a);
- c = IndexOfConsonant(a);
- if (v < 0 || c < 0)
- return result;
- while (a.Length > 0)
- {
- v = IndexOfVowel(a);
- c = IndexOfConsonant(a);
- if (c - v != 1)
- a = a.Substring(1);
- else
- {
- return a.Substring(++c);
- }
- }
- return result;
- }
- static string FindR2(string a)
- {
- a = FindR1(a);
- string result = "";
- int v, c;
- v = IndexOfVowel(a);
- c = IndexOfConsonant(a);
- if (v < 0 || c < 0)
- return result;
- while (a.Length > 0)
- {
- v = IndexOfVowel(a);
- c = IndexOfConsonant(a);
- if (c - v != 1)
- a = a.Substring(1);
- else
- {
- return a.Substring(++c);
- }
- }
- return result;
- }
- static bool DeleteGerund(string a, out string r)
- {
- string result = "";
- bool found = false;
- int index = -1;
- List<string> rs = new List<string>();
- foreach (string gerund in PERFECTIVE_GERUND_1)
- {
- index = a.LastIndexOf(gerund);
- if (index > 0 && (a[index - 1] == 'а' || a[index - 1] == 'я'))
- {
- if (IsEnding(a, gerund))
- {
- found = true;
- rs.Add(gerund);
- }
- }
- }
- foreach (string gerund in PERFECTIVE_GERUND_2)
- {
- index = a.LastIndexOf(gerund);
- if (index != -1)
- {
- if (IsEnding(a, gerund))
- {
- found = true;
- rs.Add(gerund);
- }
- }
- }
- if (found)
- {
- var sorted = from s in rs orderby s.Length descending select s;
- foreach (string gerund in sorted)
- {
- //result = a.Replace(gerund, "");
- Console.WriteLine("gerund " + gerund);
- //break;
- }
- }
- r = result;
- return found;
- }
- static bool DeleteReflexive(string a, out string r)
- {
- string result = "";
- bool found = false;
- foreach (string reflexive in REFLEXIVE)
- {
- if (a.LastIndexOf(reflexive) > -1)
- {
- if (IsEnding(a, reflexive))
- {
- result = a.Remove(a.LastIndexOf(reflexive), reflexive.Length);
- found = true;
- break;
- }
- }
- }
- r = result;
- return found;
- }
- static bool DeleteAdjectival(string a, out string r)
- {
- string result = "";
- bool found = false;
- List<string> rs = new List<string>();
- int index = -1;
- foreach (string adjective in ADJEDCTIVE)
- {
- if (a.LastIndexOf(adjective) > -1)
- {
- if (IsEnding(a, adjective))
- {
- found = true;
- rs.Add(adjective);
- }
- }
- foreach (string participle in PARTICIPLE_1)
- {
- index = a.LastIndexOf(participle);
- if (index > 0 && (a[index - 1] == 'а' || a[index - 1] == 'я'))
- {
- if (a.LastIndexOf(participle + adjective) > -1)
- {
- if (IsEnding(a, participle + adjective))
- {
- found = true;
- rs.Add(participle + adjective);
- }
- }
- }
- }
- foreach (string participle in PARTICIPLE_2)
- {
- if (a.LastIndexOf(participle + adjective) > -1)
- {
- if (IsEnding(a, participle + adjective))
- {
- found = true;
- rs.Add(participle + adjective);
- }
- }
- }
- }
- if (found)
- {
- var sorted = from s in rs orderby s.Length descending select s;
- foreach (string adjectival in sorted)
- {
- result = a.Replace(adjectival, "");
- //Console.WriteLine("adjectivalsss: " + adjectival);
- break;
- }
- }
- r = result;
- return found;
- }
- static bool DeleteVerb(string a, out string r)
- {
- string result = "";
- bool found = false;
- int index = -1;
- List<string> rs = new List<string>();
- foreach (string verb in VERB_1)
- {
- index = a.LastIndexOf(verb);
- if (index > 0 && (a[index - 1] == 'а' || a[index - 1] == 'я'))
- {
- if (IsEnding(a, verb))
- {
- found = true;
- rs.Add(verb);
- }
- }
- }
- foreach (string verb in VERB_2)
- {
- index = a.LastIndexOf(verb);
- if (index > -1)
- {
- if (IsEnding(a, verb))
- {
- found = true;
- rs.Add(verb);
- }
- }
- }
- if (found)
- {
- var sorted = from s in rs orderby s.Length descending select s;
- foreach (string verb in sorted)
- {
- result = a.Replace(verb, "");
- break;
- }
- }
- r = result;
- return found;
- }
- static bool DeleteNoun(string a, out string r)
- {
- string result = "";
- bool found = false;
- List<string> rs = new List<string>();
- foreach (string noun in NOUN)
- {
- if (a.LastIndexOf(noun) > -1)
- {
- if (IsEnding(a, noun))
- {
- result = a.Remove(a.LastIndexOf(noun), noun.Length);
- found = true;
- rs.Add(noun);
- }
- }
- }
- if (found)
- {
- var sorted = from s in rs orderby s.Length descending select s;
- foreach (string noun in sorted)
- {
- result = a.Replace(noun, "");
- break;
- }
- }
- r = result;
- return found;
- }
- static bool DeleteDerivational(string a, out string r)
- {
- string result = "";
- bool found = false;
- List<string> rs = new List<string>();
- foreach (string derivational in DERIVATIONAL)
- {
- if (a.LastIndexOf(derivational) > -1)
- {
- if (IsEnding(a, derivational))
- {
- result = a.Remove(a.LastIndexOf(derivational), derivational.Length);
- found = true;
- rs.Add(derivational);
- }
- }
- }
- if (found)
- {
- var sorted = from s in rs orderby s.Length descending select s;
- foreach (string derivational in sorted)
- {
- result = a.Replace(derivational, "");
- break;
- }
- }
- r = result;
- return found;
- }
- static bool DeleteSuperlative(string a, out string r)
- {
- string result = "";
- bool found = false;
- List<string> rs = new List<string>();
- foreach (string superlative in SUPERLATIVE)
- {
- if (a.LastIndexOf(superlative) > -1)
- {
- if (IsEnding(a, superlative))
- {
- result = a.Remove(a.LastIndexOf(superlative), superlative.Length);
- found = true;
- rs.Add(superlative);
- }
- }
- }
- if (found)
- {
- var sorted = from s in rs orderby s.Length descending select s;
- foreach (string superlative in sorted)
- {
- result = a.Replace(superlative, "");
- break;
- }
- }
- r = result;
- return found;
- }
- static void Main(string[] args)
- {
- Console.Write("Введите слово: ");
- word = ValidateString(Console.ReadLine());
- if (word == null)
- {
- Console.WriteLine("Слово было введено с символами кроме кириллицы или не было введено вообще!\n");
- Console.ReadKey();
- return;
- }
- UpdateRS(word);
- Console.WriteLine("RV (область слова после первой гласной): " + RV);
- Console.WriteLine("R1 (область слова после первого сочетания “гласная-согласная”): " + R1);
- Console.WriteLine("R2 (область R1 после первого сочетания “гласная-согласная”): " + R2);
- bool was = false;
- //word = RV;
- word = SetWord(word);
- // step 1
- //Console.WriteLine("gay".IndexOf("ass").ToString());
- Console.Write("\nШаг 1\n");
- string word_1;
- if (DeleteGerund(RV, out word_1))
- {
- RV = word_1;
- was = true;
- Console.WriteLine("Удалён PERFECTIVE_GERUND: " + word + word_1);
- }
- else
- {
- if (DeleteReflexive(RV, out word_1))
- {
- RV = word_1;
- was = true;
- Console.WriteLine("Удалён REFLEXIVE: " + word + word_1);
- }
- if (DeleteAdjectival(RV, out word_1))
- {
- RV = word_1;
- was = true;
- Console.WriteLine("Удалён ADJECTIVAL: " + word + word_1);
- }
- else if (DeleteVerb(RV, out word_1))
- {
- RV = word_1;
- was = true;
- Console.WriteLine("Удалён VERB: " + word + word_1);
- }
- else if (DeleteNoun(RV, out word_1))
- {
- RV = word_1;
- was = true;
- Console.WriteLine("Удалён NOUN: " + word + word_1);
- }
- }
- if (!was)
- Console.WriteLine("Произошло ничего");
- // step 2
- was = false;
- Console.Write("\nШаг 2:\n");
- if (IsEnding(word + RV, "и"))
- {
- RV = RV.Substring(0, RV.Length - 1);
- was = true;
- Console.WriteLine("Слово заканчивалось на \'и\', удалили: " + word + RV);
- }
- if (!was)
- Console.WriteLine("Произошло ничего");
- // step 3
- was = false;
- Console.Write("\nШаг 3:\n");
- UpdateRS(word + RV); // word before RV
- if (DeleteDerivational(R2, out word_1))
- {
- DeleteDerivational(RV, out word_1);
- RV = word_1;
- was = true;
- Console.WriteLine("Удалён DERIVATIONAL: " + word + RV);
- }
- if(!was)
- Console.WriteLine("Произошло ничего");
- // step 4
- was = false;
- Console.Write("\nШаг 4:\n");
- if (IsEnding(RV, "нн"))
- {
- RV = RV.Remove(RV.Length - 1);
- Console.WriteLine("Слово заканчивалось на \'нн\', удалили одну: " + word + RV);
- was = true;
- }
- else if(DeleteSuperlative(RV, out word_1))
- {
- RV = word_1;
- Console.WriteLine("Удалён SUPERLATIVE: " + word + RV);
- if (IsEnding(RV, "нн"))
- {
- RV = RV.Remove(RV.Length - 1);
- Console.WriteLine("Также слово заканчивалось на \'нн\', удалили одну: " + word + RV);
- }
- was = true;
- }
- else if (IsEnding(RV, "ь"))
- {
- RV = RV.Remove(RV.Length - 1);
- Console.WriteLine("Слово заканчивалось на \'ь\', удалили: " + word + RV);
- was = true;
- }
- if (!was)
- Console.WriteLine("Произошло ничего");
- Console.WriteLine("\n---------------------------------------\nИтак, основа слова: " + word + RV);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment