public static string BreakToSentencesWordnet(string explanation, WordEntryCollection EntireWordCollection) { string pattern = @"(v\.)|(n\.)|(adj\.)|(adv\.)"; string output = explanation; int position; int lengthIncreament = 0; foreach (Match mat in Regex.Matches(explanation, pattern)) { output = output.Insert(mat.Index + mat.Value.Length + lengthIncreament, Environment.NewLine); if (mat.Index > 0) { output = output.Insert(mat.Index + lengthIncreament, Environment.NewLine); lengthIncreament += 2; } lengthIncreament += 2; } pattern = @"[a-zA-Z]+"; lengthIncreament = 0; foreach (Match mat in Regex.Matches(output, pattern)) { // Check if the mat.value is a valid word if ((position = EntireWordCollection.FindSimilarity(mat.Value)) > 0) { //MessageBox.Show(mat.Value + " " + position); output = output.Insert(mat.Index + position + lengthIncreament, Environment.NewLine); lengthIncreament += 2; } } return(output); }
public static string BreakToSentencesConcise(string explanation, WordEntryCollection EntireCollection) { string BreakLine = @"(v\.)|(n\.)|(adj\.)|(adv\.)"; Match mat = Regex.Match(explanation, BreakLine); if (mat.Success) { explanation = explanation.Remove(0, mat.Index); } //mat = Regex.Match(explanation, BreakLine); //int Inc = 0; //foreach (Match m in Regex.Matches(explanation, BreakLine)) //{ // explanation = explanation.Insert(mat.Index + mat.Length + Inc, Environment.NewLine); // if (mat.Index != 0) // { // explanation = explanation.Insert(mat.Index + Inc, Environment.NewLine); // Inc += 2; // } // Inc += 2; //} string complex = @"((v\.)|(n\.)|(adj\.)|(adv\.))([^.]+)((v\.)|(n\.)|(adj\.)|(adv\.))"; string output = ""; string single; int Inc; int position; single = explanation; while (explanation != null || explanation == "") { Inc = 1; mat = Regex.Match(explanation, BreakLine); if (mat.Success) { output += mat.Value + Environment.NewLine; explanation = explanation.Replace(mat.Value, ""); } mat = Regex.Match(explanation, BreakLine); if (mat.Success) { single = explanation.Remove(mat.Index, explanation.Length - mat.Index); explanation = explanation.Remove(0, mat.Index); //MessageBox.Show(explanation); } else { single = explanation; explanation = null; } //while (mat.Success) //{ // single = single.Replace(mat.Value, ""); // mat = Regex.Match(single, BreakLine); //} string word = @"[a-zA-Z]+"; Inc = 0; int index = 1; single = index.ToString() + ". " + single; foreach (Match m1 in Regex.Matches(single, word)) { if ((position = EntireCollection.FindSimilarity(m1.Value)) > 0) { //MessageBox.Show(mat.Value + " " + position); ++index; single = single.Insert(m1.Index + position + Inc, Environment.NewLine + index.ToString() + ". "); Inc += 5; } } output += single + Environment.NewLine; } //output = BreakToSentencesWordnet(explanation, EntireCollection); return(output); }