| 1 | package Lingua::FI::Hyphenate; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Lingua::FI::Hyphenate - Finnish hyphenation (suomen tavutus) | ||||||||||
| 6 | |||||||||||
| 7 | =head1 NIMI | ||||||||||
| 8 | |||||||||||
| 9 | Lingua::FI::Hyphenate - suomen tavutus | ||||||||||
| 10 | |||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||
| 12 | |||||||||||
| 13 | use Lingua::FI::Hyphenate qw(tavuta); | ||||||||||
| 14 | |||||||||||
| 15 | my @tavut = tavuta("kodeissansakaan"); | ||||||||||
| 16 | |||||||||||
| 17 | print "@tavut\n"; # will print "ko deis san sa kaan\n"; | ||||||||||
| 18 | |||||||||||
| 19 | =head1 KÄYTTÖ | ||||||||||
| 20 | |||||||||||
| 21 | use Lingua::FI::Hyphenate qw(tavuta); | ||||||||||
| 22 | |||||||||||
| 23 | my @tavut = tavuta("kodeissansakaan"); | ||||||||||
| 24 | |||||||||||
| 25 | print "@tavut\n"; # tulostaa "ko deis san sa kaan\n"; | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | tavuta() returns as a list the syllables of its Finnish input list. | ||||||||||
| 30 | |||||||||||
| 31 | The used character set is ISO 8859-1, of which the Finnish word | ||||||||||
| 32 | characters the vowels are | ||||||||||
| 33 | |||||||||||
| 34 | aeiouyäåö AEIOUYÅÄÖ | ||||||||||
| 35 | |||||||||||
| 36 | and the consonants are | ||||||||||
| 37 | |||||||||||
| 38 | bcdfghjklmnpqrstvwxz BCDFGHJKLMNPQRSTVWXZ | ||||||||||
| 39 | |||||||||||
| 40 | The rules for syllable divisions are: | ||||||||||
| 41 | |||||||||||
| 42 | =over 4 | ||||||||||
| 43 | |||||||||||
| 44 | =item * | ||||||||||
| 45 | |||||||||||
| 46 | B<Before> any consonant-vowel pair I<except> when the said consonant is | ||||||||||
| 47 | the latter consonant of a syllable-initial consonant-consonant pair. | ||||||||||
| 48 | |||||||||||
| 49 | =item * | ||||||||||
| 50 | |||||||||||
| 51 | B<Between> any vowel-vowel pair I<except> when the vowel pair is a | ||||||||||
| 52 | Finnish diphthong, that is any of the I<ai au ei eu ey ie iu iy oi ou | ||||||||||
| 53 | ui uo yi yö äi äy öi öy>. | ||||||||||
| 54 | |||||||||||
| 55 | =back | ||||||||||
| 56 | |||||||||||
| 57 | =head1 KUVAUS | ||||||||||
| 58 | |||||||||||
| 59 | tavuta() palauttaa listana suomenkielisen syötelistansa tavut. | ||||||||||
| 60 | |||||||||||
| 61 | Käytetty merkistö on ISO 8859-1, suomenkieliset vokaalit ovat | ||||||||||
| 62 | |||||||||||
| 63 | aeiouyäåö AEIOUYÅÄÖ | ||||||||||
| 64 | |||||||||||
| 65 | ja konsonantit ovat | ||||||||||
| 66 | |||||||||||
| 67 | bcdfghjklmnpqrstvwxz BCDFGHJKLMNPQRSTVWXZ | ||||||||||
| 68 | |||||||||||
| 69 | Tavujakosäännöt ovat: | ||||||||||
| 70 | |||||||||||
| 71 | =over 4 | ||||||||||
| 72 | |||||||||||
| 73 | =item * | ||||||||||
| 74 | |||||||||||
| 75 | B<Ennen> jokaista konsonantti-vokaali-paria I<paitsi> kun mainittu | ||||||||||
| 76 | konsonantti on tavunalkuisen konsonantti-konsonantti-parin jälkimmäinen. | ||||||||||
| 77 | |||||||||||
| 78 | =item * | ||||||||||
| 79 | |||||||||||
| 80 | Jokaisen vokaali-vokaali-parin B<välissä> I<paitsi> kun vokaalipari on | ||||||||||
| 81 | suomen diftongi, eli jokin seuraavista: I<ai au ei eu ey ie iu iy | ||||||||||
| 82 | oi ou ui uo yi yö äi äy öi öy>. | ||||||||||
| 83 | |||||||||||
| 84 | =head1 CAVEAT | ||||||||||
| 85 | |||||||||||
| 86 | tavuta() works only for single words. Compound words may get wrongly | ||||||||||
| 87 | hyphenated, especially when the first component ends in a consonant | ||||||||||
| 88 | and the second component begins with a vowel. For example, | ||||||||||
| 89 | "kaivosaukko" ('the opening of a mine', compound of "kaivos", 'mine', | ||||||||||
| 90 | and "aukko", 'opening') will be wrongly hyphenated as "kai-vo-sauk-ko" | ||||||||||
| 91 | ('well otter'). Caveat hyphenator. | ||||||||||
| 92 | |||||||||||
| 93 | You may hint the correct word/syllable division by inserting a "-" at | ||||||||||
| 94 | the right places. In fact, any non-Finnish word characters are | ||||||||||
| 95 | removed and replaced with syllable divisions. | ||||||||||
| 96 | |||||||||||
| 97 | =head1 VAROITUS | ||||||||||
| 98 | |||||||||||
| 99 | tavuta() toimii vain yksittäisille sanoille. Sanaliitot saattavat | ||||||||||
| 100 | tavuttua väärin, varsinkin jos ensimmäinen osa päättyy konsonanttiin | ||||||||||
| 101 | ja toinen osa alkaa vokaalilla. Esimerkiksi "kaivosaukko" tavuttuu | ||||||||||
| 102 | väärin: "kai-vo-sauk-ko". Tarkkavaisuutta tavutukseen. | ||||||||||
| 103 | |||||||||||
| 104 | Voit antaa tavutusvihjeitä käyttämällä "-"-merkkiä sopivissa kohdissa. | ||||||||||
| 105 | Itse asiassa kaikki paitsi kirjaimet poistetaan ja korvataan tavurajoilla. | ||||||||||
| 106 | |||||||||||
| 107 | =head1 AUTHOR | ||||||||||
| 108 | |||||||||||
| 109 | Jarkko Hietaniemi <jhi@iki.fi> | ||||||||||
| 110 | |||||||||||
| 111 | =head1 COPYRIGHT | ||||||||||
| 112 | |||||||||||
| 113 | Copyright 2001 Jarkko Hietaniemi | ||||||||||
| 114 | |||||||||||
| 115 | =head1 LICENSE | ||||||||||
| 116 | |||||||||||
| 117 | This library is free software; you can redistribute it and/or modify | ||||||||||
| 118 | it under the same terms as Perl itself. | ||||||||||
| 119 | |||||||||||
| 120 | =head1 TEKIJÄ | ||||||||||
| 121 | |||||||||||
| 122 | Jarkko Hietaniemi <jhi@iki.fi> | ||||||||||
| 123 | |||||||||||
| 124 | =head1 TEKIJÄNOIKEUS | ||||||||||
| 125 | |||||||||||
| 126 | Copyright 2001 Jarkko Hietaniemi | ||||||||||
| 127 | |||||||||||
| 128 | =head1 LISENSSI | ||||||||||
| 129 | |||||||||||
| 130 | Tämä kirjastomoduli on vapaa; voit jakaa ja/tai muuttaa sitä samojen | ||||||||||
| 131 | ehtojen mukaisesti kuin Perliä itseään. | ||||||||||
| 132 | |||||||||||
| 133 | =cut | ||||||||||
| 134 | |||||||||||
| 135 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 136 | |||||||||||
| 137 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT_OK); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 138 | |||||||||||
| 139 | 1 | $VERSION = '0.04'; | |||||||||
| 140 | |||||||||||
| 141 | 1 | require Exporter; | |||||||||
| 142 | 1 | @ISA = qw(Exporter); | |||||||||
| 143 | 1 | @EXPORT_OK = qw(tavuta); | |||||||||
| 144 | |||||||||||
| 145 | # Hardcode the character classes instead of depending on locales. | ||||||||||
| 146 | |||||||||||
| 147 | 1 | my $v = "aeiouyäåöAEIOUYÅÄÖ"; | |||||||||
| 148 | 1 | my $k = "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ"; | |||||||||
| 149 | 1 | my $V = "[$v]"; | |||||||||
| 150 | 1 | my $K = "[$k]"; | |||||||||
| 151 | |||||||||||
| 152 | 1 | my $VU = 0; | |||||||||
| 153 | |||||||||||
| 154 | 15 | ▶ | sub tavuta { | ||||||||
|
Subroutine
tavuta: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 155 | 15 | my (@sanat) = @_; | |||||||||
| 156 | |||||||||||
| 157 | 15 | my @tavut = @sanat; | |||||||||
| 158 | |||||||||||
| 159 | # Anything not a letter is a syllable division. | ||||||||||
| 160 | |||||||||||
| 161 | 15 | @tavut = map { split /[^$v$k]+/ } @tavut; | |||||||||
| 162 | |||||||||||
| 163 | # Syllable division before any KV. | ||||||||||
| 164 | # Exception: the rare loanword-based ^KK syllables. | ||||||||||
| 165 | |||||||||||
| 166 | 15 | @tavut = map { split /(?=(?<!^$K)$K$V)/ } @tavut; | |||||||||
| 167 | |||||||||||
| 168 | # Syllable division between any VV pair | ||||||||||
| 169 | # that is not a Finnish diphtong. | ||||||||||
| 170 | |||||||||||
| 171 | 15 | @tavut = map { split /(.*?[aA])(?=[eoEO])/ } @tavut; | |||||||||
| 172 | 15 | @tavut = map { split /(.*?[eiEI])(?=[aoäöAOÄÖ])/ } @tavut; | |||||||||
| 173 | 15 | @tavut = map { split /(.*?[ouOU])(?=[aeAE])/ } @tavut; | |||||||||
| 174 | 15 | @tavut = map { split /(.*?[yäYÄ])(?=[eäEÄ])/ } @tavut; | |||||||||
| 175 | 15 | @tavut = map { split /(.*?[öÖ])(?=[eE])/ } @tavut; | |||||||||
| 176 | |||||||||||
| 177 | 15 | ▶ | if ($VU) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 178 | # TO DO - TEKEMÄTTÄ. | ||||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | 15 | @tavut; | |||||||||
| 182 | } | ||||||||||
| 183 | |||||||||||
| 184 | 1 | 1; | |||||||||