Lingua-GA-Gramadoir

 view release on metacpan or  search on metacpan

lib/Lingua/GA/Gramadoir.pm  view on Meta::CPAN

	else {
		$lh = Lingua::GA::Gramadoir::Languages->get_handle();
	}
	croak 'Could not set interface language' unless $lh;

	( my $datapath ) = __FILE__ =~ /(.*)\.pm/;
	my $ref;
	my $errormsg = gettext('%s: problem reading the database\n',
				gettext('An Gramadoir'));
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'eile.hash'))};
	croak $errormsg if ($@ or !$ref);
	%EILE = %$ref;
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'earraidi.hash'))};
	croak $errormsg if ($@ or !$ref);
	%EARRAIDI = %$ref;
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'nocombo.hash'))};
	croak $errormsg if ($@ or !$ref);
	%NOCOMBO = %$ref;
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'pos.hash'))};
	croak $errormsg if ($@ or !$ref);
	%POS = %$ref;
	%SOP = reverse %POS;
	eval {$ref = retrieve(File::Spec->catfile($datapath, '3grams.hash'))};
	croak $errormsg if ($@ or !$ref);
	%GRAMS = %$ref;
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'messages.hash'))};
	croak $errormsg if ($@ or !$ref);
	%MESSAGES = %$ref;
	for my $i (0 .. 6) {
		eval {$ref = retrieve(File::Spec->catfile($datapath, "focail$i.hash" ) )};
		croak $errormsg if ($@ or !$ref);
		push @FOCAIL, $ref;
	}
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'token.hash'))};
	croak $errormsg if ($@ or !$ref);
	@TOKEN = @$ref;
	foreach my $rule (@TOKEN) {
		my $patt = $rule->{'patt'};
		$rule->{'compiled'} = qr/$patt/;
		$rule->{'tail'} = substr($rule->{'tag'},1,1);
	}
	eval {$ref = retrieve(File::Spec->catfile($datapath, 'morph.hash'))};
	croak $errormsg if ($@ or !$ref);
	@MORPH = @$ref;
	foreach my $rule (@MORPH) {
		my $patt = $rule->{'patt'};
		$rule->{'compiled'} = qr/$patt/;
		$patt = $rule->{'rootpos'};
		if ($patt =~ m/^<\.([+*])?>$/) {
			$rule->{'poscompiled'} = '';   # for speed
		}
		else {
			$patt =~ s/\./[^>]/g;
			$patt =~ s/>$/\/?>/;
			$rule->{'poscompiled'} = qr/$patt/;
		}
		push @PUREMORPH, $rule if ($rule->{'level'} == -1);
	}

	if ($self->{'use_ignore_file'}) {
		my $homedir = $ENV{HOME} || $ENV{LOGDIR}; # || (getpwuid($>))[7];
		if (open (DATAFILE, File::Spec->catfile( $homedir, '.neamhshuim' ))) {
			while (<DATAFILE>) {
				chomp;
				carp gettext('%s: `%s\' corrupted at %s\n', 
					gettext('An Gramadoir'), ".neamhshuim", $.) if /^$/;
				$IGNORE{$_}++;
			}
		}
	}

	return bless $self, $class;
}

sub gettext
{
	my ( $string, @rest ) = @_;

	$string =~ s/\[/~[/g;
	$string =~ s/\]/~]/g;
	$string =~ s/\%s/[_1]/;
	$string =~ s/\%s/[_2]/;
	$string =~ s/\%s/[_3]/;
	$string =~ s/\\n$/\n/;
	$string =~ s#\\/\\([1-9])\\/#/[_$1]/#;
	$string =~ s#\\/([^_\\]+)\\/#/$1/#;

	return $lh->maketext($string, @rest);
}

##############################################################################

=head1 METHODS

=over

=item get_sentences TEXT

Splits the input TEXT up into sentences and returns a reference to an
array containing the sentences.

=cut

##############################################################################

# approximates "abairti" from bash version
# General philosophy is that it is *not* the job of the grammar checker
# to filter incoming texts (of, say, TeX or SGML markup).  On the other hand,
# SGML-like markup *must* be stripped so it doesn't interfere with
# the real work of the grammar checker.
sub get_sentences
{
	my ( $self, $text ) = @_;
	return undef unless defined $text;
	eval {from_to($text,$self->{'input_encoding'},'ISO-8859-1') };
# TRANSLATORS: "conversion" here means conversion between character encodings
	croak gettext('conversion from %s is not supported', 
			$self->{'input_encoding'}) if $@;
	my $answer = get_sentences_real($text);
	map{$_ = decode('ISO-8859-1', $_)} @$answer;
#	foreach my $s (@$answer) {



( run in 0.673 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )