| 1 | =pod | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Lingua::Phonology::FileFormatPOD - Documentation for the xml file format | ||
| 6 | written and read by Lingua::Phonology | ||
| 7 | |||
| 8 | =head1 SYNOPSIS | ||
| 9 | |||
| 10 | <?xml version="1.0" standalone="yes" ?> | ||
| 11 | <phonology> | ||
| 12 | |||
| 13 | <!-- Feature definitions are contained within the <feature> tag --> | ||
| 14 | <features> | ||
| 15 | <feature name="TOP" type="privative"> | ||
| 16 | <!-- Children may be named with the <child> tag --> | ||
| 17 | <child name="Middle" /> | ||
| 18 | </feature> | ||
| 19 | <feature name="Middle" type="privative" /> | ||
| 20 | <feature name="bottom" type="privative" > | ||
| 21 | <!-- Parents may be named with the <parent> tag --> | ||
| 22 | <parent name="Middle" /> | ||
| 23 | </feature> | ||
| 24 | </features> | ||
| 25 | |||
| 26 | <!-- Symbol definitions are contained in the <symbol> tag --> | ||
| 27 | <symbols> | ||
| 28 | <symbol label="A" > | ||
| 29 | <feature name="bottom" value="1" /> | ||
| 30 | </symbol> | ||
| 31 | </symbols> | ||
| 32 | |||
| 33 | <!-- Syllabification settings are within the <syllable> tag --> | ||
| 34 | <syllable> | ||
| 35 | <set_complex_onset /> | ||
| 36 | <no_coda /> | ||
| 37 | <min_son_dist value="2" /> | ||
| 38 | </syllable> | ||
| 39 | |||
| 40 | <!-- Rules are defined in the <rules> tag --> | ||
| 41 | <rules> | ||
| 42 | <!-- By default, you are allowed to use n:method shortcuts --> | ||
| 43 | <rule name="Default" > | ||
| 44 | <!-- Equivalent to '$_[1]->bottom' --> | ||
| 45 | <where> 1:bottom </where> | ||
| 46 | |||
| 47 | <!-- Equivalent to "$_[0]->delink('Middle')" --> | ||
| 48 | <do> 0:delink('Middle') </do> | ||
| 49 | </rule> | ||
| 50 | |||
| 51 | <!-- If you don't want shortcuts, you can specify "plain" code --> | ||
| 52 | <rule name="Plain" > | ||
| 53 | <where type="plain" >$_[-1]->bottom</where> | ||
| 54 | <do type="plain" >$_[1]->delink('bottom')</do> | ||
| 55 | </rule> | ||
| 56 | |||
| 57 | <!-- You can also use more powerful linguistic-style rules --> | ||
| 58 | <rule name="Linguistic" > | ||
| 59 | [bottom] => 0 / _$ | ||
| 60 | </rule> | ||
| 61 | </rules> | ||
| 62 | |||
| 63 | </phonology> | ||
| 64 | |||
| 65 | =head1 DESCRIPTION | ||
| 66 | |||
| 67 | As of v0.3, Lingua::Phonology is able to read and write an XML file that | ||
| 68 | defines a complete Lingua::Phonology object. This file is meant to be | ||
| 69 | human-editable, so you can write a phonology definition in a text file and then | ||
| 70 | load it using Lingua::Phonology. Your perl script itself can be quite minimal, | ||
| 71 | as most of the work of creating your phonology is done in the file. | ||
| 72 | |||
| 73 | For example, the following script reads the phonology defined in | ||
| 74 | C<my_phono.xml>, then reads a list of underlying forms from STDIN, applies the | ||
| 75 | rules to them, and writes the surface forms to C<phono.out>. | ||
| 76 | |||
| 77 | use Lingua::Phonology; | ||
| 78 | |||
| 79 | my $phono = new Lingua::Phonology; | ||
| 80 | |||
| 81 | $phono->loadfile('my_phono.xml'); | ||
| 82 | |||
| 83 | open OUT, '>phono.out' or die $!; | ||
| 84 | |||
| 85 | while (<>) { | ||
| 86 | chomp $_; | ||
| 87 | |||
| 88 | # The following assumes one word per line. It also assumes that all of | ||
| 89 | # our symbols are one character and that there are no diacritics. | ||
| 90 | # Implementing this script if any of the preceding are false is left as | ||
| 91 | # an exercise to the reader. | ||
| 92 | @word = $phono->symbols->segment(split //, $_); | ||
| 93 | |||
| 94 | $phono->rules->apply_all(\@word); | ||
| 95 | |||
| 96 | print OUT $phono->symbols->spell(@word), "\n"; | ||
| 97 | } | ||
| 98 | |||
| 99 | Of course, having this be successful depends on C<my_phono.xml> working | ||
| 100 | properly. The rest of this document describes how to do that. | ||
| 101 | |||
| 102 | =head1 GETTING STARTED | ||
| 103 | |||
| 104 | The root element of your phonology should be <phonology></phonology>. | ||
| 105 | Within those tags are four major sub-sections: | ||
| 106 | |||
| 107 | =over 4 | ||
| 108 | |||
| 109 | =item * FEATURES | ||
| 110 | |||
| 111 | Defines the features your phonology uses. Enclosed in <features></features> tags, | ||
| 112 | described in the L<"FEATURES"> section. | ||
| 113 | |||
| 114 | =item * SYMBOLS | ||
| 115 | |||
| 116 | Defines the phonetic symbols your phonology uses. | ||
| 117 | Enclosed in <symbols></symbols> tags, described in the L<"SYMBOLS"> section. | ||
| 118 | |||
| 119 | =item * SYLLABLE | ||
| 120 | |||
| 121 | Defines syllabification rules for your phonology. Enclosed in <syllable></syllable> tags, described in the L<"SYLLABLE"> section. | ||
| 122 | |||
| 123 | =item * RULES | ||
| 124 | |||
| 125 | Defines rules that apply to words in your phonology and the order in which they | ||
| 126 | apply. Enclosed in <rules></rules> tags, described in the L<"RULES"> section. | ||
| 127 | Linguistic style rules are also included in the rules section, and are | ||
| 128 | described in L<"LINGUISTIC-STYLE RULES">. | ||
| 129 | |||
| 130 | =back | ||
| 131 | |||
| 132 | ALL phonology files must have EACH of these sections. Trying to read a | ||
| 133 | phonology which is missing some section will usually result in errors. | ||
| 134 | (Exception: If you use the C<loadfile()> method of one of the sub-objects, then | ||
| 135 | the file given only needs to have the section corresponding to the object used. | ||
| 136 | For example, if you call $phono->features->loadfile('phono.xml'), | ||
| 137 | 'phono.xml' only needs to have a <features></features> section.) | ||
| 138 | |||
| 139 | However, if a certain section is unneeded or unnecessary for your phonology, | ||
| 140 | nothing keeps you from using an tags with no content. | ||
| 141 | |||
| 142 | =head1 FEATURES | ||
| 143 | |||
| 144 | Your feature definitions should be enclosed in <features></features> | ||
| 145 | tags. This section defines the feature set that your phonology uses and the | ||
| 146 | heirarchy between them, which in turn controls the way you define your symbols | ||
| 147 | and rules. For a discussion of the general principles behind making a feature | ||
| 148 | set, see C<Lingua::Phonology::Features>. | ||
| 149 | |||
| 150 | Within the <features></features> tags, you use the <feature></feature> tag to | ||
| 151 | define a single feature. (That's singular: don't confuse the outer | ||
| 152 | <featureB<s>> tag with the inner <feature> tag.) The <feature> tag must contain | ||
| 153 | at least two attributes: a name, given by the B<name> attribute, and a type, | ||
| 154 | given by the B<type> attribute. The name may be any string, but the type must | ||
| 155 | be one of 'privative', 'binary', or 'scalar'. For the meanings of these | ||
| 156 | settings, see L<Lingua::Phonology::Features>. | ||
| 157 | |||
| 158 | If you don't need to specify parents or children for a feature, this is all you | ||
| 159 | need. You can use unary tag for such simple features, like this: | ||
| 160 | |||
| 161 | <feature name="foo" type="binary" /> | ||
| 162 | |||
| 163 | If a feature has children , you may list them inside <child /> tags inside the | ||
| 164 | <feature></feature> tags. The name of the child feature is given in the B<name> | ||
| 165 | attribute of the <child /> tag. For example: | ||
| 166 | |||
| 167 | <feature name="Parent" type="privative" > | ||
| 168 | <child name="Child 1" /> | ||
| 169 | <child name="Child 2" /> | ||
| 170 | </feature> | ||
| 171 | |||
| 172 | Alternately, you may use the <parent /> tag to name the parents of a feature, | ||
| 173 | like so: | ||
| 174 | |||
| 175 | <feature name="child" type="scalar" > | ||
| 176 | <parent name="Parent 1" /> | ||
| 177 | <parent name="Parent 2" /> | ||
| 178 | </feature> | ||
| 179 | |||
| 180 | Remember that the features you name inside <parent> or <child> tags must ALSO | ||
| 181 | be defined elsewhere with a <feature /> tag. Trying to include a child/parent | ||
| 182 | that is not defined on its own will generate a warning. | ||
| 183 | |||
| 184 | Also, the parent/child relationship is symmetrical. A feature is the child of | ||
| 185 | all of its parents and the parent of all of its children. You do NOT need to | ||
| 186 | include both <child> and <parent> tags for a child-parent pair, one or the | ||
| 187 | other will suffice. It's up to you whether you prefer to do this with <child> | ||
| 188 | tags or with <parent> tags. | ||
| 189 | |||
| 190 | To see a full example of a feature definition, see | ||
| 191 | L<Lingua::Phonology::Features/"THE DEFAULT FEATURE SET"> and look at the | ||
| 192 | DEFAULT FEATURE SET section. That section describes the default feature set | ||
| 193 | and shows the XML structure used to generate that feature set. | ||
| 194 | |||
| 195 | =head1 SYMBOLS | ||
| 196 | |||
| 197 | Your symbol definitions must be enclosed within the <symbols></symbols> tag. | ||
| 198 | You define your symbols based on features in your feature set, and associate | ||
| 199 | each of them with a label. For a discussion of the general ideas behind making | ||
| 200 | a symbol set, see L<Lingua::Phonology::Symbols>. | ||
| 201 | |||
| 202 | With the <symbols></symbols> tag are a series of <symbol> tags. (Once again, | ||
| 203 | the interior <symbol> tag is singular, while the outer <symbolB<s>> tag is | ||
| 204 | plural.) The <symbol> tag must have a B<label> attribute, the value for which | ||
| 205 | is the symbol string. Thus, the opening tag looks something like this: | ||
| 206 | |||
| 207 | <symbol label="k" > | ||
| 208 | |||
| 209 | Inside the <symbol></symbol> tags are a series of unary <feature> tags. Each of | ||
| 210 | these <feature> tags takes two attributes: a B<name> attribute that gives a | ||
| 211 | feature name from the current feature set, and a B<value> attribute that gives | ||
| 212 | the value of the symbol prototype for that feature. The C<value> attribute can | ||
| 213 | be either a number or a text value. Whatever it is, it will be converted | ||
| 214 | according to the C<number_form> and C<text_form> conversions described in | ||
| 215 | L<Lingua::Phonology::Features>. Some examples: | ||
| 216 | |||
| 217 | <feature name="privative_feature" value="*" /> | ||
| 218 | <feature name="binary_feature" value="+" /> | ||
| 219 | <feature name="scalar_feature" value="2" /> | ||
| 220 | |||
| 221 | A whole symbol definition looks like this: | ||
| 222 | |||
| 223 | <symbol label="k" > | ||
| 224 | <feature name="dorsal" value="1" /> | ||
| 225 | <feature name="voice" value="*" /> | ||
| 226 | </symbol> | ||
| 227 | |||
| 228 | You can define as many symbols as you want in your file. For an example of a | ||
| 229 | complete symbol set definition, see L<Lingua::Phonology::Symbols/"THE DEFAULT | ||
| 230 | SYMBOL SET">. That section describes the default symbols and shows the XML | ||
| 231 | structure used to generate those symbols. | ||
| 232 | |||
| 233 | =head1 SYLLABLE | ||
| 234 | |||
| 235 | Your syllable section is enclosed with the <syllable></syllable> tag. | ||
| 236 | The syllable section of your file defines the syllabification parameters used | ||
| 237 | in your phonology. Unlike the other sections, this section does not consist of | ||
| 238 | an unlimited number of definitions but of settings to a given number of | ||
| 239 | parameters. Each of the parameters is represented by its own tag. | ||
| 240 | |||
| 241 | Parameters for the syllable section fall into several categories. | ||
| 242 | |||
| 243 | =over 4 | ||
| 244 | |||
| 245 | =item * Boolean | ||
| 246 | |||
| 247 | Boolean parameters are either true or false. To set a boolean parameter to | ||
| 248 | true, include a unary tag with 'set_' prefixed to the name of the parameters. | ||
| 249 | You can turn on codas, for example, by including a <set_coda /> tag. | ||
| 250 | Conversely, you can set a boolean parameter to false by including a tag and | ||
| 251 | prefixing 'no_' to its name. You can turn codas off with a <no_coda /> | ||
| 252 | tag. | ||
| 253 | |||
| 254 | Including a tag that has the name of the parameter without any prefix turns | ||
| 255 | that parameter on. Thus, including a <coda /> tag turns codas on in | ||
| 256 | exactly the same way that <set_coda /> does. | ||
| 257 | |||
| 258 | Boolean parameters are C<onset, complex_onset, coda, complex_coda>. | ||
| 259 | |||
| 260 | =item * Integer | ||
| 261 | |||
| 262 | Integer parameters may have any whole number as their value. They may be set by | ||
| 263 | including the name of the parameter as a tag with a single B<value> parameter. | ||
| 264 | E.g. <min_son_dist value="2" />. | ||
| 265 | |||
| 266 | Integer parameters are C<min_son_dist, onset_son_dist, coda_son_dist, | ||
| 267 | min_nucl_son, min_coda_son, max_edge_son>. | ||
| 268 | |||
| 269 | =item * Code | ||
| 270 | |||
| 271 | Code parameters must have perl code as their value. The perl code is contained | ||
| 272 | between opening and closing tags of the name of the parameter. For example, you | ||
| 273 | might set 'clear_seg' with <clear_seg> not $_[0]->SYLL </clear_seg>. | ||
| 274 | |||
| 275 | The perl code is subject to shortcut expansion. See L<"Notes on writing perl | ||
| 276 | code"> below. | ||
| 277 | |||
| 278 | Code parameters are C<clear_seg, begin_adjoin, end_adjoin>. | ||
| 279 | |||
| 280 | =back | ||
| 281 | |||
| 282 | There are two additional parameters which don't fit into any of the above | ||
| 283 | types. These are C<direction> and C<sonorous>. | ||
| 284 | |||
| 285 | The C<direction> parameter is set with a unary tag that has a B<value> | ||
| 286 | attribute, rather like the integer tags. Like so: <direction value="leftward" | ||
| 287 | />. However, the only valid values it may have are "leftward" and "rightward." | ||
| 288 | |||
| 289 | The C<sonorous> parameter is set with a paired <sonorous></sonorous> | ||
| 290 | tag, within which are one or more <feature /> tags. Each <feature /> tag has a | ||
| 291 | B<name> attribute that defines the feature, and a B<score> attribute that gives | ||
| 292 | the number of sonority points that feature is worth. As an example, the | ||
| 293 | following defines the default sonority values: | ||
| 294 | |||
| 295 | <sonorous> | ||
| 296 | <feature name="sonorant" score="1" /> | ||
| 297 | <feature name="approximant" score="1" /> | ||
| 298 | <feature name="vocoid" score="1" /> | ||
| 299 | <feature name="aperture" score="1" /> | ||
| 300 | </sonorous> | ||
| 301 | |||
| 302 | The meaning and application of these parameters is described in more detail in | ||
| 303 | L<Lingua::Phonology::Syllable>. As a more complete example, the following | ||
| 304 | defines the default settings for Lingua::Phonology::Syllable: | ||
| 305 | |||
| 306 | <syllable> | ||
| 307 | <set_onset /> | ||
| 308 | <no_complex_onset /> | ||
| 309 | <no_coda /> | ||
| 310 | <no_complex_coda /> | ||
| 311 | <min_son_dist value="3" /> | ||
| 312 | <min_coda_son value="0" /> | ||
| 313 | <max_edge_son value="100" /> | ||
| 314 | <min_nucl_son value="3" /> | ||
| 315 | <direction value="rightward" /> | ||
| 316 | <sonorous> | ||
| 317 | <feature name="sonorant" score="1" /> | ||
| 318 | <feature name="approximant" score="1" /> | ||
| 319 | <feature name="vocoid" score="1" /> | ||
| 320 | <feature name="aperture" score="1" /> | ||
| 321 | </sonorous> | ||
| 322 | <clear_seg> return 1; </clear_seg> | ||
| 323 | <begin_adjoin> return 0; </begin_adjoin> | ||
| 324 | <end_adjoin> return 0; </end_adjoin> | ||
| 325 | </syllable> | ||
| 326 | |||
| 327 | =head1 RULES | ||
| 328 | |||
| 329 | Your rules section is enclosed in <rules></rules> tags. This section defines | ||
| 330 | the rules which act in your phonology. Rule definitions are enclosed in | ||
| 331 | <rule></rule> tags, rule order is written with <order></order> tags, and | ||
| 332 | persistent rules are written with <persist></persist> tags. Each of these is | ||
| 333 | discussed below. For a complete discussion of how to write rules and the | ||
| 334 | meanings of these parameters, see L<Lingua::Phonology::Rules>. | ||
| 335 | |||
| 336 | |||
| 337 | =head2 Rule declarations | ||
| 338 | |||
| 339 | You may make as many rules as you would like. Each rule is enclosed in | ||
| 340 | <rule></rule> tags. The opening <rule> tag must contain a B<name> attribute, | ||
| 341 | which gives the name of the rule to be added. E.g. C<< <rule name="Metathesis" > >> | ||
| 342 | |||
| 343 | Within the <rule></rule> tags you may include a tag for each of the properties | ||
| 344 | that a rule normally has. These properties include C<direction, domain, tier, | ||
| 345 | filter, where, do, result>. | ||
| 346 | |||
| 347 | The first three properties (C<direction, domain, tier>), take a simple text | ||
| 348 | string as their value. They are represented by a unary tag with a single | ||
| 349 | B<value> attribute. E.g.: | ||
| 350 | |||
| 351 | <direction value="rightward" /> | ||
| 352 | <domain value="SYLL" /> | ||
| 353 | <tier value="vocoid" /> | ||
| 354 | |||
| 355 | The other four properties (C<filter, where, do, result>) take perl code as | ||
| 356 | their value. They are represented as a pair of tags with perl as their | ||
| 357 | contents. E.g.: | ||
| 358 | |||
| 359 | <where> | ||
| 360 | $_[0]->vocoid and $_[1]->nasal | ||
| 361 | </where> | ||
| 362 | <do> | ||
| 363 | $_[0]->nasal($_[1]->value_ref('nasal')) | ||
| 364 | </do> | ||
| 365 | <!-- Likewise for other code properties --> | ||
| 366 | |||
| 367 | Considerations for writing code inside the XML structure and some shortcuts are | ||
| 368 | described below in L<"Notes on writing perl code">. A complete discussion of | ||
| 369 | rules and what they do is in L<Lingua::Phonology::Rules/"WRITING RULES">. | ||
| 370 | |||
| 371 | You may also use linguistic-style rules as the content of a rule declaration. | ||
| 372 | This is discussed in L<"LINGUISTIC-STYLE RULES"> | ||
| 373 | |||
| 374 | =head2 Rule order and persistent rules | ||
| 375 | |||
| 376 | To give the order in which your rules apply, use the <order></order> tags. | ||
| 377 | Within the <order> tag you include one or more <block></block> tags, which in | ||
| 378 | turn contain unary <rule> tags. Each <rule> tag has one B<name> attribute, | ||
| 379 | which gives the name of the rule to be applied. For example: | ||
| 380 | |||
| 381 | <order> | ||
| 382 | <block> | ||
| 383 | <rule name="A1" /> | ||
| 384 | <rule name="A2" /> | ||
| 385 | </block> | ||
| 386 | <block> | ||
| 387 | <rule name="B" /> | ||
| 388 | </block> | ||
| 389 | <block> | ||
| 390 | <rule name="C1" /> | ||
| 391 | <rule name="C2" /> | ||
| 392 | <rule name="C3" /> | ||
| 393 | </block> | ||
| 394 | </order> | ||
| 395 | |||
| 396 | Persistent rules are given within <persist></persist> tags. Between these tags | ||
| 397 | you may have any number of unary <rule> tags with a B<name> attribute, just as | ||
| 398 | above. Example: | ||
| 399 | |||
| 400 | <persist> | ||
| 401 | <rule name="P1" /> | ||
| 402 | <rule name="P2" /> | ||
| 403 | </persist> | ||
| 404 | |||
| 405 | Rule order and persistent rules are described in more detail in | ||
| 406 | L<Lingua::Phonology::Features/"apply_all"> and following sections. | ||
| 407 | |||
| 408 | =head2 Notes on writing perl code | ||
| 409 | |||
| 410 | When you write perl code as the content of a <where></where> tag or any other | ||
| 411 | similar tag, your code is evaluated in the package C<main>. Thus, if you | ||
| 412 | reference C<$foo> or any other variable other than C<@_>, you're getting | ||
| 413 | C<$main::foo>. If you want your code to be evaluated in some other package, be | ||
| 414 | sure to include the appropriate C<package> declaration. | ||
| 415 | |||
| 416 | The code for rule properties usually works on the contents of C<@_>, and we | ||
| 417 | write things like C<< $_[1]->feature_name >> constantly. It becomes tiresome to | ||
| 418 | repeatedly type this whole string, and when such strings are printed back out | ||
| 419 | they are escaped into the near-unreadable C<< $_[1]->feature_name >>. To | ||
| 420 | solve both problems, this module provides a shortcut method. Anything like C<< | ||
| 421 | $_[n]->method >> can be rewritten as C<n:method>, where C<n> is an integer and | ||
| 422 | C<method> is a method name. The module will expand such shortcuts appropriately | ||
| 423 | before evaluating them. Thus, all of the following are equivalent: | ||
| 424 | |||
| 425 | 1:nasal $_[1]->nasal | ||
| 426 | 0:delink('vocoid') $_[0]->delink('vocoid') | ||
| 427 | -1:BOUNDARY $_[-1]->BOUNDARY | ||
| 428 | 0:voice(1:value_ref('voice')) $_[0]->voice($_[1]->value_ref('voice')) | ||
| 429 | |||
| 430 | In order for this to work, there must be NO WHITESPACE between the number, the | ||
| 431 | colon, and the following method name. (This is to avoid most conflicts with the | ||
| 432 | ternary C<?:> operator.) Also, the number must be an integer matching the | ||
| 433 | regular expression C</-?\d+/>, and the method following must be a valid perl | ||
| 434 | method call. Thus, all of the following are B<incorrect>: | ||
| 435 | |||
| 436 | 1: labial | ||
| 437 | 1.2:nasal | ||
| 438 | 0:'long feature name' | ||
| 439 | $n:dorsal | ||
| 440 | |||
| 441 | By default, all perl code found in your XML file is expanded this way. If you | ||
| 442 | need to keep this from happening, then you can add a C<type="plain"> attribute | ||
| 443 | to the opening tag. The following two are identical: | ||
| 444 | |||
| 445 | <where> 1:nasal </where> | ||
| 446 | <where type="plain" > $_[1]->nasal </where> | ||
| 447 | |||
| 448 | Though as a matter of fact, there's nothing wrong with just doing this: | ||
| 449 | |||
| 450 | <where> $_[1]->nasal </where> | ||
| 451 | |||
| 452 | The only time you really B<have> to use the type attribute is if you insist on | ||
| 453 | doing something like this: | ||
| 454 | |||
| 455 | <where type="plain"> | ||
| 456 | $_[0]->aperture > 1 ? 1:0 | ||
| 457 | </where> | ||
| 458 | |||
| 459 | If you didn't use the C<type="plain"> attribute, this would come out to: | ||
| 460 | |||
| 461 | $_[1]->aperture > 1 ? $_[1]->0 | ||
| 462 | |||
| 463 | Which is a syntax error, of course. But if your use of whitespace is sane, you | ||
| 464 | should rarely, if ever, run into conflicts. | ||
| 465 | |||
| 466 | =head1 LINGUISTIC-STYLE RULES | ||
| 467 | |||
| 468 | Generative phonologists have developed a more-or-less standard notation for | ||
| 469 | writing their rules, and Lingua::Phonology can now parse such rules. To include | ||
| 470 | a linguistic-style rule in your rule set, simply write the rule as the content | ||
| 471 | of a <rule></rule> tag (i.e. not inside any other tag). For example: | ||
| 472 | |||
| 473 | <rule name="Vowel Nasalization" > | ||
| 474 | [vocoid] => [nasal] / _[nasal] | ||
| 475 | </rule> | ||
| 476 | |||
| 477 | If you are familiar with generative phonology literature, you will probably | ||
| 478 | find such rules easier to write and understand than the pure perl rules | ||
| 479 | discussed above. This section will discuss exactly how you can write such rules | ||
| 480 | and how the Lingua::Phonology module will turn them into perl code. | ||
| 481 | |||
| 482 | =head2 Input segments and output segments | ||
| 483 | |||
| 484 | The simplest form of linguistic rule is an unconditional change, in which some | ||
| 485 | segment or feature is changed regardless of what other segments are present. | ||
| 486 | Such rules follow this format: | ||
| 487 | |||
| 488 | input_segments => output_segments | ||
| 489 | |||
| 490 | You write the input segments on the left side, and what they become on the | ||
| 491 | right side. In the middle you write C<< => >>. Actually, because people have | ||
| 492 | their own styles, you can write any of C<< => >>, C<< -> >>, or C<< > >>. In | ||
| 493 | this document we'll always use C<< => >>. | ||
| 494 | |||
| 495 | To write this kind of rule, you simply need to know how to describe input | ||
| 496 | segments and output segments. In linguistic literature, this is generally done | ||
| 497 | by writing feature descriptions. A feature description consists of a set of | ||
| 498 | feature values enclosed in square brackets '[]', like this: | ||
| 499 | |||
| 500 | [-anterior voice] | ||
| 501 | |||
| 502 | The features inside the square brackets may be specified in three different | ||
| 503 | ways: | ||
| 504 | |||
| 505 | =over 4 | ||
| 506 | |||
| 507 | =item * privative style | ||
| 508 | |||
| 509 | In this style, you simply list the name of the feature to test or set any true | ||
| 510 | value: C<[nasal]>. To test for or set a false value, you precede the name of | ||
| 511 | the feature with an asterisk: C<[*nasal]>. This is most appropriate for | ||
| 512 | privative features which are either true (present) or false (absent). | ||
| 513 | |||
| 514 | =item * binary style | ||
| 515 | |||
| 516 | In this style, you put a '+' before the name of the feature to test or set the | ||
| 517 | value 1: C<[+anterior]>. You put a '-' before the name of the feature to test | ||
| 518 | or set the value 0: C<[-anterior]>. You may also put an '*' before the name of | ||
| 519 | the feature to set its value to undefined: C<[*anterior]>. This is most | ||
| 520 | appropriate for binary features which are either positive, negative, or | ||
| 521 | undefined. | ||
| 522 | |||
| 523 | =item * scalar style | ||
| 524 | |||
| 525 | In this style, you put the name of the feature first, followed by an '=', then | ||
| 526 | any value. If the value you give is a numeral or a word with no non | ||
| 527 | alphanumeric characters, you do not need to include the value in quotes: | ||
| 528 | C<[aperture=2], [scalar=word]>. If the value you wish to assign includes | ||
| 529 | non-alphanumeric characters, you need to put the value in double quotes: | ||
| 530 | C<[scalar="long, strange value"]>. This is best for scalar features which can | ||
| 531 | have a range of values. | ||
| 532 | |||
| 533 | =back | ||
| 534 | |||
| 535 | Strictly speaking, any type of feature can be tested or set with any of the | ||
| 536 | styles above, but it's recommended that you use each style with the appropriate | ||
| 537 | type of feature. | ||
| 538 | |||
| 539 | Example: | ||
| 540 | |||
| 541 | [dorsal -anterior] => [nasal] | ||
| 542 | |||
| 543 | Read: "Any segment that is dorsal and -anterior (i.e. a palatal) becomes nasal." | ||
| 544 | |||
| 545 | In formal linguistic literature you must always define your segments with | ||
| 546 | feature bundles like above. However, Lingua::Phonology also allows you to | ||
| 547 | define a segment with a symbol from the current symbol set. This is done by | ||
| 548 | writing the symbol between /slashes/, like so: C</s/>. This makes many rules | ||
| 549 | clearer. Example: | ||
| 550 | |||
| 551 | /z/ => /s/ | ||
| 552 | |||
| 553 | Read: "All /z/'s become /s/'s." | ||
| 554 | |||
| 555 | You can, of course, mix the two styles | ||
| 556 | |||
| 557 | [Coronal] => /s/ | ||
| 558 | |||
| 559 | Read: "All coronals (dentals, alveolars, etc.) become /s/." | ||
| 560 | |||
| 561 | Remember that whatever comes between the slashes is the symbol. If you write | ||
| 562 | C</sk/>, Lingua::Phonology will look for a single segment whose symbol is 'sk'. | ||
| 563 | If you want an /s/ followed by a /k/, write C</s//k/>. | ||
| 564 | |||
| 565 | Another extension of strict linguistic form is the fact that you can include | ||
| 566 | more than one segment in your input and output segments. Your linguistics | ||
| 567 | professor might not like the following rule, but Lingua::Phonology has no | ||
| 568 | problem with it: | ||
| 569 | |||
| 570 | /s/[nasal] => /z/[*nasal voice] | ||
| 571 | |||
| 572 | Read: "/s/ followed by a nasal is replaced with /z/ followed by a voiced stop." | ||
| 573 | |||
| 574 | The only stipulation here is that your statement must be B<balanced>: there | ||
| 575 | must be the same number of segments on both sides of the arrow. | ||
| 576 | |||
| 577 | One final trick is to use an empty set of braces, C<[]>, which will match | ||
| 578 | anything at all on the left side of an arrow, and leave a segment unchanged on | ||
| 579 | the right side. For example: | ||
| 580 | |||
| 581 | /s/[]/r/ => /S/[]/l/ | ||
| 582 | |||
| 583 | Read: "/s/ followed by anything, followed by an /r/, becomes /S/, followed by | ||
| 584 | the same thing, followed by an /l/." | ||
| 585 | |||
| 586 | The only thing that C<[]> does not match is nothing at all--it implies that | ||
| 587 | some segment exists there, but you don't care what it is. (To match nothing at | ||
| 588 | all you can use C<0>, but see below at L<"Inserting and deleting">. | ||
| 589 | |||
| 590 | See L<"Details of parsing"> for some warnings and more detail about how | ||
| 591 | segments are parsed. | ||
| 592 | |||
| 593 | =head2 Conditions | ||
| 594 | |||
| 595 | The rules we have written so far have been unconditioned rules, which don't | ||
| 596 | depend on segments other than the ones being changed. However most linguistic | ||
| 597 | rules are not unconditional, and so we need to add the condition clause. The | ||
| 598 | general format for rules with conditions is this: | ||
| 599 | |||
| 600 | input_segments => output_segments / conditions | ||
| 601 | |||
| 602 | A slash normally separates the condition from the rest of the rule. However, | ||
| 603 | this can sometimes get lost amid the slashes used around symbols, so you can | ||
| 604 | also write it with a colon: | ||
| 605 | |||
| 606 | input_segments => output_segments : conditions | ||
| 607 | |||
| 608 | The condition itself is written just like the input and output segments, with | ||
| 609 | bracketed feature bundles or symbols. However, you put an underscore '_' where | ||
| 610 | the input/output segment(s) go. No matter how many segments you use, you only | ||
| 611 | put a SINGLE underscore there to represent them. For example: | ||
| 612 | |||
| 613 | /s/ => /S/ : _/i/ | ||
| 614 | |||
| 615 | Read: "Replace /s/ with /S/ when the next segment is /i/". | ||
| 616 | |||
| 617 | You can put segments before and after the underscore: | ||
| 618 | |||
| 619 | [vocoid] => [nasal] / [voice]_[nasal] | ||
| 620 | |||
| 621 | Read: "Vocoids become nasalized when the next segment is nasal and the | ||
| 622 | preceding segment is voiced". | ||
| 623 | |||
| 624 | You often want to do something at the end of a word or at the beginning of a | ||
| 625 | word. For this, the special symbol C<$> is used. If you use a '$', it must be | ||
| 626 | either the very first symbol or the very last symbol in the condition (or you | ||
| 627 | can put one at both ends, but this implies that you know the whole word you're | ||
| 628 | looking for). Example: | ||
| 629 | |||
| 630 | [Coronal] => /s/ : _$ | ||
| 631 | |||
| 632 | Read: "Coronals become /s/ at the end of a word." | ||
| 633 | |||
| 634 | =head2 Sets of segments and conditions | ||
| 635 | |||
| 636 | Sometimes you want to do something when this OR that is true, and nothing can | ||
| 637 | be found in common between this and that. (Linguists hate such rules, but they | ||
| 638 | do exist, unfortunately.) To accomplish this, you need a set, which lists a | ||
| 639 | group of segments or conditions. In either case, a set consists of two | ||
| 640 | parenthesis '()' enclosing the options, which are themselves separated by pipes | ||
| 641 | '|'. | ||
| 642 | |||
| 643 | Here's an example segment set: | ||
| 644 | |||
| 645 | /s/ => /x/ : _(/r/ | /k/ | /u/ | /i/) | ||
| 646 | |||
| 647 | Read: "/s/ becomes /x/ when the next segment is any of /r/, /k/, /u/, or /i/". | ||
| 648 | This rule, by the way, actually exists in Old Church Slavic. I didn't make it | ||
| 649 | up, unlike most of the other example rules. | ||
| 650 | |||
| 651 | You can mix different kinds of feature definitions in a set, of course: | ||
| 652 | |||
| 653 | (/d/ | /g/ | [labial]) => [*Place] / _$ | ||
| 654 | |||
| 655 | Read: "/d/, /g/, or any labial delink their Place node (and become glottals) at | ||
| 656 | the end of a word." | ||
| 657 | |||
| 658 | You can also make a set of conditions. Example: | ||
| 659 | |||
| 660 | [labial] => /m/ : ( _/m/ | [nasal]_ ) | ||
| 661 | |||
| 662 | Read: "Any labial becomes /m/, either when the next segment is /m/ or when the | ||
| 663 | preceding segment is a nasal." | ||
| 664 | |||
| 665 | When you make a set of conditions, the set must be the B<entire> condition part | ||
| 666 | of the rule. For example, the following variation of the preceding rule is | ||
| 667 | wrong, and won't parse: | ||
| 668 | |||
| 669 | # WRONG | ||
| 670 | [labial] => /m/ : ( _/m/ | [nasal]_ )$ | ||
| 671 | |||
| 672 | Intention: "Any labial becomes /m/, either when it precedes an /m/ which is the | ||
| 673 | last segment in the word, or when it follows a nasal and is the last segment in | ||
| 674 | the word." As nice as this sounds, it doesn't work. Sorry. | ||
| 675 | |||
| 676 | =head2 Inserting and deleting | ||
| 677 | |||
| 678 | Insertion and deletion are both accomplished with the special symbol '0'. You | ||
| 679 | can use a '0' on either the left-hand or right-hand side of the arrow in a | ||
| 680 | linguistic rule, but it has a slightly different meaning on each side. You | ||
| 681 | CANNOT use a C<0> in the condition part of the rule, nor inside a segment set. | ||
| 682 | Both of the following are wrong: | ||
| 683 | |||
| 684 | (/k/ | [voice] | 0) => [nasal] #WRONG, will not parse | ||
| 685 | /s/ => /z/ : _0/d/ # WRONG, will not parse | ||
| 686 | |||
| 687 | On the left-hand side of an arrow, the C<0> means "Don't look for a segment | ||
| 688 | here, but insert a segment in this spot." The segment to be inserted is | ||
| 689 | whatever is in the corresponding spot on the right side of the arrow. Example: | ||
| 690 | |||
| 691 | /s/0[Coronal] => []/i/[] : _[*vocoid] | ||
| 692 | |||
| 693 | Read: "Insert an /i/ between /s/ and another coronal when the following segment | ||
| 694 | is not a vocoid". Remember that [] can be used on the left-hand side of a rule | ||
| 695 | to mean "match anything" and on the right-hand side of an arrow to mean "don't | ||
| 696 | change anything". This rule is exactly equivalent to the following rule: | ||
| 697 | |||
| 698 | 0 => /i/ : /s/_[Coronal][*vocoid] | ||
| 699 | |||
| 700 | The second form here is more formally correct, but the first illustrates how | ||
| 701 | you can include a C<0> anywhere in a rule to insert a segment at that point. | ||
| 702 | |||
| 703 | On the right-hand side of an arrow, the C<0> means "Delete whichever segment is | ||
| 704 | in this spot." The segment to be deleted is whichever segment occupies the same | ||
| 705 | spot on the right-hand side of the arrow. Example: | ||
| 706 | |||
| 707 | /s//k/ => /S/0 : _$ | ||
| 708 | |||
| 709 | Read: "An /s/ followed by a /k/ becomes /S/ followed by nothing at the end of a | ||
| 710 | word." | ||
| 711 | |||
| 712 | Here's a similar example: | ||
| 713 | |||
| 714 | [vocoid][nasal coda] => [nasal]0 | ||
| 715 | |||
| 716 | Read: "A vowel folllowed by a coda nasal is nasalized, and the nasal is | ||
| 717 | deleted." | ||
| 718 | |||
| 719 | =head2 Using linguistic rules with other rule parameters | ||
| 720 | |||
| 721 | You can use a linguistic rule together with other tags or parameters that are | ||
| 722 | normally part of a rule. In fact, it is often necessary to do so to create a | ||
| 723 | rule. For example, suppose you wish to have a front vowel harmony rule. You | ||
| 724 | could try to write something like this | ||
| 725 | |||
| 726 | [vocoid] => [-anterior] / _[][-anterior vocoid] | ||
| 727 | |||
| 728 | Read: "A vocoid becomes [-anterior] (front) when the segment after the next one | ||
| 729 | is also a front vocoid". Here we assume that the C<[]> represents the | ||
| 730 | intervening consonant, which we don't care about. However, this rule will break | ||
| 731 | if there is not exactly one consonant between the vowels. To remedy this, you | ||
| 732 | should specify a tier of C<vocoid>, which will cause the rule to ignore all | ||
| 733 | non-vocoids. The whole rule declaration would then look like this: | ||
| 734 | |||
| 735 | <rule name="Vowel Harmony" > | ||
| 736 | <tier value="vocoid" /> | ||
| 737 | [] => [-anterior] / _[-anterior] | ||
| 738 | </rule> | ||
| 739 | |||
| 740 | Note that we've removed the C<vocoid> statements from the feature bundles. | ||
| 741 | That's because they are now redundant--we know that only vocoids are included | ||
| 742 | in this rule. We also removed the C<[]> from the condition, because any | ||
| 743 | intervening consonant will not appear at all in our word. This rule will work | ||
| 744 | no matter how many consonants appear between the vowels. | ||
| 745 | |||
| 746 | The parameters that you can specify this way are C<direction, tier, filter, | ||
| 747 | domain, result>. You should not try to specify a C<where> or C<do> property | ||
| 748 | together with a linguistic rule, because the linguistic rule I<is> the C<where> | ||
| 749 | and C<do> properties. Any C<where> or C<do> that you specify will be ignored. | ||
| 750 | |||
| 751 | =head2 Limitations | ||
| 752 | |||
| 753 | There is one important aspect of linguistic rules which is missing in the | ||
| 754 | current implementation. That is the ability to include I<variables>, usually | ||
| 755 | denoted by Greek letters in generative rules. Variables let you assign the | ||
| 756 | value of one segment to be the same as the value of any other segment. The | ||
| 757 | current linguistic rule parser has no mechanism for variables, although this | ||
| 758 | will be implemented at a future date. | ||
| 759 | |||
| 760 | =head2 Details of parsing | ||
| 761 | |||
| 762 | Internally, Lingua::Phonology uses the strings C<'__TRUE', '__FALSE', | ||
| 763 | '__BOUNDARY', '__NULL'> as markers. DO NOT attempt to use symbols with these | ||
| 764 | names or assign these as values to a scalar reference. | ||
| 765 | |||
| 766 | For the curious, here is the perl code that Lingua::Phonology generates from | ||
| 767 | the feature declaration formats. These are all illustrated with C<$_[0]>, | ||
| 768 | although the actual element of C<@_> acted upon varies and should be | ||
| 769 | irrelevant: | ||
| 770 | |||
| 771 | Linguistic form When testing When assigning | ||
| 772 | =========================================================================== | ||
| 773 | [feature] ($_[0]->feature) $_[0]->feature(1); | ||
| 774 | [*feature] (not $_[0]->feature) $_[0]->delink('feature'); | ||
| 775 | [-feature] ($_[0]->feature == 0) $_[0]->feature(0); | ||
| 776 | [+feature] ($_[0]->feature == 1) $_[0]->feature(1); | ||
| 777 | [feature=val] ($_[0]->feature eq 'val') $_[0]->feature('val'); | ||
| 778 | /sym/ ($_[0]->spell eq 'sym') Lingua::Phonology::Functions::change($_[0], 'sym'); | ||
| 779 | |||
| 780 | The parser for linguistic rules was written with Parse::RecDescent. What | ||
| 781 | follows is the Parse::RecDescent grammar, minus some irrelevant detail. | ||
| 782 | |||
| 783 | |||
| 784 | Rule: From Arrow To When(?) | ||
| 785 | |||
| 786 | From: (Segment | SegmentSet | Null)(s) | ||
| 787 | |||
| 788 | Arrow: '>' | '->' | '=>' | ||
| 789 | |||
| 790 | To: (Segment | Null)(s) | ||
| 791 | |||
| 792 | When: ('/'|':') (Condition | ConditionSet) | ||
| 793 | |||
| 794 | ConditionSet: '(' <leftop: Condition '|' Condition> ')' | ||
| 795 | |||
| 796 | Condition: Boundary(?) (Segment | SegmentSet)(s?) '_' (Segment | SegmentSet)(s?) Boundary(?) | ||
| 797 | |||
| 798 | SegmentSet: '(' <leftop: Segment '|' Segment> ')' | ||
| 799 | |||
| 800 | Segment: ( '[' Feature(s?) ']' | '/' Text '/') | ||
| 801 | |||
| 802 | Feature: Text '=' Text | /[\+\-\*]/ Text | Text | ||
| 803 | |||
| 804 | Text: /\w+/ | <perl_quotelike> | ||
| 805 | |||
| 806 | Boundary: '$' | ||
| 807 | |||
| 808 | Null: '0' | ||
| 809 | |||
| 810 | =head1 SAVING A PHONOLOGY | ||
| 811 | |||
| 812 | Lingua::Phonology objects can save their state to a file with the C<savefile()> | ||
| 813 | method. This method accepts a filename as its argument, and is documented in | ||
| 814 | C<Lingua::Phonology/"savefile">. When you use this method, the XML document | ||
| 815 | generated has a couple of idiosyncrasies: | ||
| 816 | |||
| 817 | =over 4 | ||
| 818 | |||
| 819 | =item * | ||
| 820 | |||
| 821 | The order of elements will not be preserved from the file you loaded (if you | ||
| 822 | loaded a file), except for those handful of elements for which ordering is | ||
| 823 | crucial. | ||
| 824 | |||
| 825 | =item * | ||
| 826 | |||
| 827 | Formatting is made as human-readable as possible, but there may be some | ||
| 828 | problems. | ||
| 829 | |||
| 830 | =item * | ||
| 831 | |||
| 832 | Code references are deparsed using B::Deparse. B::Deparse is not always able to | ||
| 833 | deparse a code reference correctly, though I have never had problems with it. | ||
| 834 | |||
| 835 | =item * | ||
| 836 | |||
| 837 | Deparsed code is always written out with C<n:method> shortcuts. There is no | ||
| 838 | capability for remembering or re-creating linguistic style rules, and probably | ||
| 839 | never will be. As a corrolary, if you want to see how your linguistic rules are | ||
| 840 | parsed into perl, you can load your XML file and then save it to a different | ||
| 841 | file to see what comes out. | ||
| 842 | |||
| 843 | =back | ||
| 844 | |||
| 845 | =head1 BUGS | ||
| 846 | |||
| 847 | Lingua::Phonology has little or no resources for dealing with files that are | ||
| 848 | valid XML but don't follow the format given here. It is likely to die with | ||
| 849 | unhelpful error messages, instead. | ||
| 850 | |||
| 851 | =head1 SEE ALSO | ||
| 852 | |||
| 853 | L<Lingua::Phonology> | ||
| 854 | |||
| 855 | L<Lingua::Phonology::Features> | ||
| 856 | |||
| 857 | L<Lingua::Phonology::Symbols> | ||
| 858 | |||
| 859 | L<Lingua::Phonology::Segment> | ||
| 860 | |||
| 861 | L<Lingua::Phonology::Rules> | ||
| 862 | |||
| 863 | L<Lingua::Phonology::Syllable> | ||
| 864 | |||
| 865 | =head1 AUTHOR | ||
| 866 | |||
| 867 | Jesse S. Bangs <F<jaspax@cpan.org>>. | ||
| 868 | |||
| 869 | =head1 LICENSE | ||
| 870 | |||
| 871 | This module is free software. You can distribute and/or modify it under the | ||
| 872 | same terms as Perl itself. | ||
| 873 | |||
| 874 | =cut |