Lingua::EN::Semtags::LangUnit - a DTO used by C<Lingua::EN::Semtags::Sentence>


Lingua-EN-Semtags-Engine documentation Contained in the Lingua-EN-Semtags-Engine distribution.

Index


Code Index:

NAME

Top

Lingua::EN::Semtags::LangUnit - a DTO used by Lingua::EN::Semtags::Sentence

SYNOPSIS

Top

  use Lingua::EN::Semtags::LangUnit;

DESCRIPTION

Top

A DTO used by Lingua::EN::Semtags::Sentence and Lingua::EN::Semtags::LangUnit.

METHODS

add_isa($lunit)

Adds $isa to $self->{isas}.

is_phrase()

Returns true is this language unit is a phrase.

is_word()

Returns true if this language unit is a word.

isas()

Returns $self->{isas}.

pos()

Returns $self->{pos}(a Lingua::EN::Tagger part of speech tag).

poswn()

Returns $self->{pos} converted into the WordNet::QueryData style tag.

sense([$sense])

Returns/sets $self->{sense}.

token()

Returns $self->{token}.

SEE ALSO

Top

Lingua::EN::Semtags::Engine

AUTHOR

Top

Igor Myroshnichenko <igorm@cpan.org>

Copyright (c) 2008, All Rights Reserved.

This software is free software and may be redistributed and/or modified under the same terms as Perl itself.


Lingua-EN-Semtags-Engine documentation Contained in the Lingua-EN-Semtags-Engine distribution.

package Lingua::EN::Semtags::LangUnit;

use strict;
use warnings;
# POS - part of speech tag (Lingua::EN::Tagger style)
# POSWN - part of speech tag (WordNet style)
use constant POS2POSWN => {
	NN => 'n', # Noun
	VB => 'v', # Verb
	JJ => 'a', # Adjective
	RB => 'r'  # Adverb	
};
use constant TRUE  => 1;
use constant FALSE => 0;

our $VERSION = '0.01';

#============================================================	
sub new {
#============================================================
	my ($invocant, %args) = @_;
	my $self = bless ({}, ref $invocant || $invocant);
	$self->_init(%args);
	return $self;
}

#============================================================
sub _init {
#============================================================
	my ($self, %args) = @_;
	
	# Initialize attributes
	$self->{token} = undef;
	$self->{is_word} = FALSE;
	$self->{is_phrase} = FALSE;
	$self->{pos} = undef;
	$self->{sense} = undef;
	$self->{isas} = [];
	
	# Set the args that came from the constructor
	foreach my $arg (sort keys %args) {
		die "Unknown argument: $arg!" unless exists $self->{$arg};
		$self->{$arg} = $args{$arg};
	}
}

#============================================================
sub token { $_[0]->{token}; }
sub is_word { $_[0]->{is_word}; }
sub is_phrase { $_[0]->{is_phrase}; }
sub pos { $_[0]->{pos}; }
sub sense { defined $_[1] ? $_[0]->{sense} = $_[1] : $_[0]->{sense}; }
sub isas { @{$_[0]->{isas}}; }
sub add_isa { push @{$_[0]->{isas}}, $_[1]; }
sub poswn { $_[0]->pos =~ /^(\w\w)/ and exists POS2POSWN->{$1} ? POS2POSWN->{$1} : undef; }
#============================================================

TRUE;

__END__