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. A segment may also be associated with a Lingua::Phonology::Symbols object, which allows the segment to return the symbol that it best matches.

METHODS

new

Takes one 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.

symbolset

Returns a Symbols object currently associated with the segment. You may call this method with one argument, in which case the symbol set is set to that argument.

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. When you assign a hash reference to a node in this way, keys not present in the hash are not affected. Therefore, assigning an empty hash to a node does NOT cause the node to be deleted, as might be expected, but rather has not affect at all. For example:

# Both sonorant and vocoid are children of ROOT

$segment->value('sonorant', 1);   
# Now the value for ROOT is { sonorant => 1 }

$segment->value('ROOT', { vocoid => 1 });
# Now the value for ROOT is { sonorant => 1, vocoid => 1 }

$segment->value('ROOT', {});
# The value for ROOT is still { sonorant => 1, vocoid => 1 }

To delete a node, use the method "delink" instead.

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().

WARNING: If you use a feature name that is the same as a reserved word (function or operator) in Perl, you can cause a non-terminating loop, due to the implementation of autoloaded functions. Use the longer form with value() instead.

Takes a list of arguments, which are names of feature, and removes the values for those features from the segment. The values for those features 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.

Calling delink() on a node causes all children of the node to be delinked recursively. This is the only way to clear a node in one step.

In scalar context, this method returns the number of items that were delinked. In list context, it returns a list of the former values of the features that were delinked. If you are delinking a node you will get a list of the values of the children of that node, in a consistent but not predictable order.

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).

spell

Takes no arguments. Returns a text string indicating the symbol that the current segment best matches if a Lingua::Phonology::Symbols object has been defined via symbolset(). Otherwise returns an error.

duplicate

Takes no arguments. Returns a new Lingua::Phonology::Segment object that is an identical copy of the current object.

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.