NAME
Lingua::Phonology::Segment - a module to represent a segment as a bundle of feature values.
SYNOPSIS
use Lingua::Phonology;
$phono = new Lingua::Phonology;
# Define a feature set
$features = $phono->features;
$features->loadfile;
# Make a segment
$segment = $phono->segment;
# Set some values
$segment->labial(1);
$segment->continuant(0);
$segment->voice(1); # Segment is now voiced labial stop, i.e. [b]
# Reset the segment
$segment->clear;
DESCRIPTION
A Lingua::Phonology::Segment object provides a programmatic representation of a linguistic segment. Such a segment is associated with a Lingua::Phonology::Features object that lists the available features and the relationships between them. The segment itself is a list of the values for those features. This module provides methods for returning and setting these feature values.
METHODS
new
Takes on argument, a Lingua::Phonology::Features object. The Features object provides the list of available features. If no such object is provided, this method will carp and return undefined.
featureset
Returns the Features object currently associated with the segment. May be called with one argument, a Features object, in which case the current feature set is set to the object provided.
value
Takes one or two arguments. The first argument must be the name of a feature. If only one argument is provided, this method simply returns the value that the segment currently has for that feature. If there is a second argument, the value for the feature is set to that argument.
If you are attempting to set a value, the value will first be passed through Lingua::Phonology::Features::number_form(), and stored in its numeric form. See "number_form" in features for an explanation of how this conversion works. Conversely, values returned from this function have already been passed through number_form() and may differ significantly (though predictably) from the values originally passed in.
You may also pass a scalar reference to value(), in which case the value for the segment is set to the value that the reference points to. This has other side effects, though. See the description of "value_ref" for an explanation of why and how this works.
Values for nodes (features which are parents of other features) are different from the values for terminal features. A node has no value of its own; rather, its value is the aggregate of the values of its children. Therefore, the value returned from a node is a hash reference, the keys of which are features for children that have a defined value. The values of the hash ref are the values associated with those features (which may in turn be hash references, etc.). A node that has no defined children returns undef.
Conversely, the second argument to value() must be a hash reference if the feature you are assigning to is a node.
As a final note, in a hash reference returned from value(), the values for terminal features are actually scalar references pointing to the real values. See "value_ref" for details on why.
value_text
This method is equivalent to value(), and takes the same arguments. However, the return from value() is first passed through the text_form() function of Lingua::Phonology::Features and then returned. For details on this conversion see "number_form" in features.
value_ref
This method is identical in arguments to value(), taking a feature name as the first argument and a value as the optional second argument. However, it returns a scalar reference rather than a real value.
Internally, all of the values for a Segment object are stored as scalar references rather than direct values. When you call value(), all of the referencing and dereferencing is done for you, so you never have to think about this. However, at times it may be useful to cause two or more Segments to have references to the same value, in which case you may use the value_ref() method to return the reference from one of the objects. If the value that you give to value(), value_text(), or value_ref() is a scalar reference, then rather than setting the value via the current reference, the current reference will be replaced by the reference you provided. This can cause two segments to "share" a feature, so that changes made to one segment automatically appear on the other. This example should make things clearer:
# Assume you have a Lingua::Phonology::Features object called $features with the default feature set
$seg1 = Lingua::Phonology::Segment->new($features);
$seg2 = Lingua::Phonology::Segment->new($features);
# If we assign direct values, the segments can vary independently
$seg1->value('voice', 1);
$seg2->value('voice', $seg1->value('voice')); # $seg2->value('voice') also returns 1
$seg1->value('voice', 0); # now $seg1 return 0 for voice, but $seg2 returns 1
# If we assign references, then the segments are linked to each other for that value
$seg1->value('voice', 1');
$seg2->value('voice', $seg1->value_ref('voice')); # $seg2 now returns 1 for voice
$seg1->value('voice', 0); # now both $seg1 and $seg2 return 0 for voice
# To break the connection between segments, pass one of them a reference to a literal value
$seg1->value('voice', \1); # Now $seg1 returns 1, and $seg2 returns 0
As this example illustrates, any of the value_*() functions can be passed any kind of argument (numeric, textual, or reference). The functions only differ in what their return value is.
Calling feature names as methods
You can also return and set values to a segment by using the name of a feature as a method. This is usually easier and more readable that using value(). The following are exactly synonymous:
$seg1->value('voice', 1);
$seg1->voice(1);
Calling a feature-name method like this is always equivalent to calling value(), and never equivalent to calling value_text() or value_ref().
delink
Takes one argument, the name of a feature, and removes the value for that feature from the segment. The value for that feature will subsequently be undefined. This method does not affect the value that the internal reference points to, so other segments that may be pointing to the same value are unaffected. For example:
$seg1->voice('1);
$seg2->voice($seg1->value_ref('voice')); # $seg1 and $seg2 refer to the same value
$seg2->voice(undef); # now both $seg1 and $seg2 will return 'undef' for voice
$seg1->voice(1); # both will now return 1
$seg2->delink('voice'); # now $seg2 returns 'undef', but $seg1 returns 1
As an additional effect, the hash returned from "all_values"() will include a key-value pair like voice => undef if you assign an undef to a value, as in line 4 above, while if you use delink(), no key for the deleted feature will appear at all.
all_values
Takes no arguments. Returns a hash with feature names as its keys and feature values as its values. The feature names present in the hash will be those that have defined values for the segment, or those features that were explicitly set to be undef (as opposed to being "delink"ed).
clear
Takes no arguments. Clears all values from the segment. Calling "all_values"() after calling clear() will return an empty hash.
BUGS
The current method for handling suprasegmental features is ugly and hackish. Something new should be come up with.
SEE ALSO
Lingua::Phonology::Features, Lingua::Phonology::Symbols
AUTHOR
Jesse S. Bangs <jaspax@u.washington.edu>.
LICENSE
This module is free software. You can distribute and/or modify it under the same terms as Perl itself.