Bonjour,
Je voudrais savoir si quelqu'un a une fonction qui permette de compter les syllabes d'un mot?
Merci
David
Bonjour,
Je voudrais savoir si quelqu'un a une fonction qui permette de compter les syllabes d'un mot?
Merci
David
Ca marche plutot bien meme avec des mots francais
Il te faut adapter le code pour compter les syllabes
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86 procedure Syllabify(Syllables: TStringList; s: string); const Consonants = ['b','B','c','C','d','D','f','F','g','G', 'h','H','j','J','k','K','l','L','m','M','n','N', 'ñ','Ñ','p','P','q','Q','r','R','s','S','t','T', 'v','V','w','W','x','X','y','Y','z','Z']; StrongVowels = ['a','A','á','Á','e','E','é','É', 'í','Í','o','ó','O','Ó','ú','Ú']; WeakVowels = ['i','I','u','U','ü','Ü']; Vowels = StrongVowels + WeakVowels; Letters = Vowels + Consonants; var i, j, n, m, hyphen: integer; begin j := 2; s := #0 + s + #0; n := Length(s) - 1; i := 2; Syllables.Clear; while i <= n do begin hyphen := 0; // Do not hyphenate if s[i] in Consonants then begin if s[i+1] in Vowels then begin if s[i-1] in Vowels then hyphen := 1; end else if (s[i] in ['s', 'S']) and (s[i-1] in ['n', 'N']) and (s[i+1] in Consonants) then begin hyphen := 2; end else if (s[i+1] in Consonants) and (s[i-1] in Vowels) then begin if s[i+1] in ['r','R'] then begin if s[i] in ['b','B','c','C','d','D','f','F','g', 'G','k','K','p','P','r','R','t','T','v','V'] then hyphen := 1 else hyphen := 2; end else if s[i+1] in ['l','L'] then begin if s[i] in ['b','B','c','C','d','D','f','F','g', 'G','k','K','l','L','p','P','t','T','v','V'] then hyphen := 1 else hyphen := 2; end else if s[i+1] in ['h', 'H'] then begin if s[i] in ['c', 'C', 's', 'S', 'p', 'P'] then hyphen := 1 else hyphen := 2; end else hyphen := 2; end; end else if s[i] in StrongVowels then begin if (s[i-1] in StrongVowels) then hyphen := 1 end else if s[i] = '-' then begin Syllables.Add(Copy(s, j, i - j)); Syllables.Add('-'); inc(i); j := i; end; if hyphen = 1 then begin // Hyphenate here Syllables.Add(Copy(s, j, i - j)); j := i; end else if hyphen = 2 then begin // Hyphenate after inc(i); Syllables.Add(Copy(s, j, i - j)); j := i; end; inc(i); end; m := Syllables.Count - 1; if (j = n) and (m >= 0) and (s[n] in Consonants) then Syllables[m] := Syllables[m] + s[n] // Last letter else Syllables.Add(Copy(s, j, n - j + 1)); // Last syllable end; // To test the procedure yon can drop a Textbox and a Label on a form and //in the Change event of the Textbox write: procedure TForm1.Edit1Change(Sender: TObject); var Syllables: TStringList; begin Syllables := TStringList.Create; try Syllabify(Syllables, Edit1.Text); Label1.Caption := StringReplace(Trim(Syllables.Text), #13#10, '-', [rfReplaceAll]); finally Syllables.Free; end; end;
Delphi 2009 - ZeosLib - DevExpress - TMS - PgDAC
PostgreSQL 8.4 sous Debian
Sites : http://postgresql.developpez.com http://dgriessinger.developpez.com
Impec! Merci beaucoup hpalpha!
Génial ce code
Merci aussi, même si j'ai rien demandé.
Un version C#, pour ceux que ça intéresse
Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105 static class Phono { #region Constantes de lettres readonly static char[] consonants = new char[] { 'B','C','D','F','G', 'H','J','K','L','M','N', 'Ñ','P','Q','R','S', 'T','V','W','X','Y','Z'}; readonly static char[] strongVowels = new char[] { 'A','Á','E','É', 'Í','O','Ó','Ú'}; readonly static char[] weakVowels = new char[] { 'I', 'U', 'Ü' }; readonly static char[] vowels = new char[] { 'A','Á','E','É', 'Í','O','Ó','Ú', 'I','U','Ü'}; readonly static char[] letters = new char[] { 'A','Á','E','É', 'Í','O','Ó','Ú', 'I','U','Ü', 'B','C','D','F','G', 'H','J','K','L','M','N', 'Ñ','P','Q','R','S', 'T','V','W','X','Y','Z'}; #endregion public static List<string> Syllabiser(string s) { int i, j, n, m; s = s.ToUpper(); i = 1; j = 0; n = s.Length - 1; List<string> syllabes = new List<string>(); while (i < n) { int hyphen = 0; if (consonants.Contains(s[i])) { if (vowels.Contains(s[i + 1])) { if (vowels.Contains(s[i - 1])) hyphen = 1; } else if (s[i] == 'S' && s[i - 1] == 'N' && (consonants.Contains(s[i + 1]))) hyphen = 2; else if (consonants.Contains(s[i + 1]) && vowels.Contains(s[i - 1])) if (s[i + 1] == 'R') if (s[i] == 'B' || s[i] == 'C' || s[i] == 'D' || s[i] == 'F' || s[i] == 'G' || s[i] == 'K' || s[i] == 'P' || s[i] == 'R' || s[i] == 'T' || s[i] == 'V') hyphen = 1; else hyphen = 2; else if (s[i + 1] == 'L') if (s[i] == 'B' || s[i] == 'C' || s[i] == 'D' || s[i] == 'F' || s[i] == 'G' || s[i] == 'K' || s[i] == 'L' || s[i] == 'P' || s[i] == 'T' || s[i] == 'V') hyphen = 1; else hyphen = 2; else if (s[i + 1] == 'H') if (s[i] == 'C' || s[i] == 'S' || s[i] == 'P') hyphen = 1; else hyphen = 2; else hyphen = 2; } else if (strongVowels.Contains(s[i])) { if (strongVowels.Contains(s[i - 1])) hyphen = 1; } else if (s[i] == '-') { syllabes.Add(s.Substring(j, i - j)); syllabes.Add("-"); i++; j = i; } if (hyphen == 1) { // Hyphenate here syllabes.Add(s.Substring(j, i - j)); j = i; } else if (hyphen == 2) { // Hyphenate after i++; syllabes.Add(s.Substring(j, i - j)); j = i; } i++; } m = syllabes.Count - 1; if (j == n && m >= 0 && consonants.Contains(s[n])) syllabes[m] = syllabes[m] + s[n]; // Last letter else syllabes.Add(s.Substring(j, n - j + 1)); return syllabes; } }
Vous avez un bloqueur de publicités installé.
Le Club Developpez.com n'affiche que des publicités IT, discrètes et non intrusives.
Afin que nous puissions continuer à vous fournir gratuitement du contenu de qualité, merci de nous soutenir en désactivant votre bloqueur de publicités sur Developpez.com.
Partager