/// <summary> /// ищем гибриды по двум спискам слов /// </summary> /// <param name="OT">таб</param> /// <param name="w1">список1</param> /// <param name="w2">список2</param> /// <param name="i">номер первого слова</param> /// <param name="j">номер второго слова</param> /// <param name="min">минимальное пересечение, букв</param> /// <param name="prior">приоритет</param> /// <returns>строка ответов с разделителем \r\n</returns> private static string FindGybrids(OneTab OT, List <string> w1, List <string> w2, int i, int j, int min, int prior) { string r2 = ""; foreach (string s1 in w1) { foreach (string s2 in w2) { int mi = min; int ma = s1.Length - 1; if (s1.Length > s2.Length) { ma = s2.Length - 1; } if (ma < mi) { continue; } for (int k = mi; k <= ma; k++) { // s1 - первые символы (второе слово), s2 - последние символы (первое слово) if (s1.Substring(0, k) == s2.Substring(s2.Length - k, k)) { string ans = s2.Substring(0, s2.Length - k) + s1; Answer.Add(OT, prior, ans, i, j); r2 = r2 + ans + "\r\n"; } } } } return(r2); }
/// <summary> /// решение гапоифики /// </summary> /// <param name="T">таб</param> /// <returns>true</returns> public bool Process(OneTab T) { OT = T; task = OT.tbTextTask.Text; string[] ar1 = System.Text.RegularExpressions.Regex.Split(task, "\r\n"); string resout = ""; foreach (string s1 in ar1) { //resout = resout + s1 + ":\r\n"; string s = Books.ClearBookName(s1).ToLower(); if (s != "") { for (int i = 0; i < Books.WordsCount; i++) { if (s == Books.gapo[i].ToLower()) { Answer.Add(T, 3, Books.dict[i], -1); resout = resout + Books.dict[i] + "\r\n"; } } } resout = resout + "\r\n"; } T.tbSectors.Invoke(new Action(() => { T.btSolve.Enabled = true; })); T.tbTextHints.Invoke(new Action(() => { T.tbTextHints.Text = resout; })); T.tcTabText.Invoke(new Action(() => { T.tcTabText.SelectTab(1); })); return(true); }
// решает один сектор // вход - Уровень, структура стыковки private void SolveOne(Level lvl, OneOlimp oo) { List <string> wrd3 = new List <string>(); List <string> wrd2 = new List <string>(); List <string> wrd1 = new List <string>(); List <List <string> > wrds = new List <List <string> >(); foreach (int i in oo.nums) { wrds.Add(GetSec(lvl, i)); } if (oo.nums.Count == 4) { wrd3.AddRange(Get3(oo.num, wrds, oo.nums, 0, 1, 2)); wrd3.AddRange(Get3(oo.num, wrds, oo.nums, 0, 1, 3)); wrd3.AddRange(Get3(oo.num, wrds, oo.nums, 0, 2, 3)); wrd3.AddRange(Get3(oo.num, wrds, oo.nums, 1, 2, 3)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 0, 1)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 0, 2)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 0, 3)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 1, 2)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 1, 3)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 2, 3)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 0)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 1)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 2)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 3)); } if (oo.nums.Count == 3) { wrd3.AddRange(Get3(oo.num, wrds, oo.nums, 0, 1, 2)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 0, 1)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 0, 2)); wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 1, 2)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 0)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 1)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 2)); } if (oo.nums.Count == 2) { wrd2.AddRange(Get2(oo.num, wrds, oo.nums, 0, 1)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 0)); wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 1)); } if (oo.nums.Count == 1) { wrd1.AddRange(Get1(oo.num, wrds, oo.nums, 0)); } wrd1 = Words.KillDupesAndRange(wrd1); wrd2 = Words.KillDupesAndRange(wrd2); wrd3 = Words.KillDupesAndRange(wrd3); Answer.Add(OT, 3, wrd3, oo.num); Answer.Add(OT, 4, wrd2, oo.num); Answer.Add(OT, 5, Associations.GetFirstItems(wrd1, 7), oo.num); Answer.Add(OT, 6, wrd1, oo.num); }
} // струкрура данных для одной строчки расчлененок /// <summary> /// решает одну расчлененку, это уже отдельный поток /// </summary> /// <param name="s1">строка в формате "строитель(3)блеф(2)картон(2)</param> /// <param name="slov">количество слов</param> /// <returns></returns> private List <string> ProcessOne(string s1, int slov) { List <string> res = new List <string>(); if (s1.Trim().Length == 0) { return(res); } OneStr os = Prepare(s1); string[] wrds = Transposition(os); List <string> wrds2 = Spaces(wrds, slov); SpellChecker sc = new SpellChecker(); res = sc.Check(wrds2); Answer.Add(OT, 3, res, -1); return(res); }
private void Event_Click_btAnswer(object sender, EventArgs e) { if (tbAnswer.Text.Trim() != "") { Answer.Add(this, 1, tbAnswer.Text.Trim(), -1); tbAnswer.Text = ""; } if (tbAnswerMulti.Text.Trim() != "") { string[] ansm = System.Text.RegularExpressions.Regex.Split(tbAnswerMulti.Text, "\r\n"); foreach (string s1 in ansm) { if (s1.Trim() != "") { Answer.Add(this, 2, s1, -1); } } tbAnswerMulti.Text = ""; } }
/// <summary> /// распознание и вбивание картинок /// </summary> /// <param name="T">таб</param> /// <returns>true</returns> public bool Process(OneTab T) { string resout = ""; // создаем массив путей из больших картинок string[] SmallImagePath = Image.GetSmallImagePathes(T, T.level.urls, T.iRows, T.iCols); // отрисуем их в ГУИ string html = GetPicsHtml(SmallImagePath); T.wbPictures.Invoke(new Action(() => { T.wbPictures.DocumentText = html; })); T.wbPictures.Invoke(new Action(() => { T.tcTabWeb.SelectedIndex = 1; })); // из путей к картинкам делаем коллекции слов List <Words> TextsFromPics = Image.GetAllDescriptions(SmallImagePath); // пробуем вбить ответы (то есть передать их во вбиватор, включая указание приоритета) for (int i = 0; i < TextsFromPics.Count; i++) { Words W = TextsFromPics[i]; if (W != null) { List <string> ww5 = Words.KillDupesAndRange(W.all_base10, 5); List <string> ww100 = Words.KillDupesAndRange(W.all_base10, 100); Answer.Add(T, 4, ww5, i); foreach (string s1 in ww100) { resout = resout + s1 + " "; } } resout = resout + "\r\n"; //*** позже добавить более низкие приоритеты } T.tbSectors.Invoke(new Action(() => { T.btSolve.Enabled = true; })); T.tbTextHints.Invoke(new Action(() => { T.tbTextHints.Text = resout; })); T.tcTabText.Invoke(new Action(() => { T.tcTabText.SelectTab(1); })); return(true); }
/// <summary> /// решение гапоифики /// </summary> /// <param name="T">таб</param> /// <returns>true</returns> public bool Process(OneTab T) { OT = T; task = OT.tbTextTask.Text; string resout = ""; string[] ar1 = System.Text.RegularExpressions.Regex.Split(task, "\r\n"); foreach (string s1 in ar1) { if (s1 != "") { // получим возможные наименвоания фильмов List <string> names = Films.GetNameList(s1); // и маску в формате "га по и фи ка" string mask = Films.PrepareSearchString(s1); mask = mask.ToLower().Replace(" ", " ").Replace(" ", " ").Trim(); foreach (string name in names) { // уберем цифры в скобках string n = RemoveYearBrackets(name); n = RemoveYearBrackets(n); // уберем спецсимволы n = n.Replace("`", " ").Replace("~", " ").Replace("!", " ").Replace("@", " ").Replace("#", " ").Replace("№", " ").Replace("\"", " "); n = n.Replace(";", " ").Replace("$", " ").Replace("%", " ").Replace("^", " ").Replace(":", " ").Replace("&", " ").Replace("?", " "); n = n.Replace("*", " ").Replace("(", " ").Replace(")", " ").Replace("-", " ").Replace("_", " ").Replace("=", " ").Replace("+", " "); n = n.Replace("{", " ").Replace("}", " ").Replace("[", " ").Replace("]", " ").Replace("/", " ").Replace("|", " ").Replace("\\", " "); n = n.Replace(";", " ").Replace(":", " ").Replace("'", " ").Replace(",", " ").Replace(".", " ").Replace("<", " ").Replace(">", " "); n = n.Replace("«", " ").Replace("»", " "); n = n.Replace("…", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Replace(" ", " ").Trim(); // составим из очередного найденного названия маску в стиле "га по и фи ка" string[] ar2 = n.Split(' '); string nn = ""; foreach (string s in ar2) { if (s == "") { continue; } if (s.Length == 1) { nn = nn + s + " "; } else { nn = nn + s.Substring(0, 2) + " "; } } nn = nn.ToLower().Replace(" ", " ").Replace(" ", " ").Trim(); // проверяем, если соответствует - передаем во вбиватор if (nn == mask) { Answer.Add(T, 3, n, -1); resout = resout + n + "\r\n"; } } } resout = resout + "\r\n"; } T.tbSectors.Invoke(new Action(() => { T.btSolve.Enabled = true; })); T.tbTextHints.Invoke(new Action(() => { T.tbTextHints.Text = resout; })); T.tcTabText.Invoke(new Action(() => { T.tcTabText.SelectTab(1); })); return(true); }