Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Xamarin.Forms;
  7. using NHyphenator;
  8.  
  9. namespace TestSillabe1
  10. {
  11.  
  12. public partial class MainPage : ContentPage
  13. {
  14. private Boolean StIgnore(char lettera)
  15. {
  16. char[] daIgnorare = { 'a', 'e', 'i', 'o', 'u', 's' };
  17. foreach (char c in daIgnorare)
  18. {
  19. if (lettera == c) { return false; }
  20. }
  21. return true;
  22. }
  23.  
  24. public MainPage()
  25. {
  26. InitializeComponent();
  27. }
  28.  
  29. private void Button_Clicked(object sender, EventArgs e)
  30. {
  31. Hyphenator hyphenator = new Hyphenator(HyphenatePatternsLanguage.Italian, "-", 1, 1, true);
  32. string result = hyphenator.HyphenateText(testo1.Text).ToLower();
  33. int cont = 0;
  34.  
  35. if (result.Length > 0) cont = cont + 1;
  36.  
  37. for (int i = 0; i < result.Length; i++)
  38. {
  39. ///se la stringa è solo una s va in errore, quindi uscire dal for
  40. if (result.Equals("s"))
  41. {
  42. break;
  43. }
  44. ///se la stringa è lunga due e il secondo carattere è una s va in errore, quindi uscire dal for
  45. else if ((result.Length == 2)&&(result[1]=='s'))
  46. {
  47. break;
  48. }
  49.  
  50. ///se troviamo la sequenza -s- allora non va considerata come consonante il contatore fa -1 mentre i andrà direttamente dopo -s-
  51. /*if (((result[i]).Equals('-') == true) && (result[i + 1].Equals('s') == true) && (result[i + 2].Equals('-') == true))
  52. { //esempio di parole "posto" che viene diviso come po-s-to
  53. cont = cont - 1;
  54. i = i + 2;
  55. }
  56. non serve è superfluo*/
  57.  
  58. ///se troviamo la sequenza s- allora non va considerata come consonante il contatore fa -1 mentre i andrà direttamente dopo s-
  59.  
  60.  
  61. if (result[i].Equals('s'))
  62. {
  63. if( i + 2 < result.Length)
  64. {
  65. if (result[i + 1].Equals('-') && StIgnore(result[i + 2]))
  66. {
  67. cont = cont - 1;
  68. i = i + 1;
  69. }
  70. }
  71.  
  72. //esempio di parole "stare" che viene diviso come s-ta-re
  73. }
  74. ///quando troviamo un '-' o uno ' ' allora il nostro contatore aumenta di uno
  75. if (result[i].Equals('-') == true || result[i].Equals(' '))
  76. {
  77. cont = cont + 1;
  78. }
  79.  
  80.  
  81. }
  82. ///stampa le sillabe
  83. testo2.Text = result + " \n" + cont;
  84.  
  85. }
  86.  
  87.  
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement