Lingua-Boolean-Tiny

 view release on metacpan or  search on metacpan

lib/Lingua/Boolean/Tiny.pm  view on Meta::CPAN

		
		return 1 if fc $text eq fc $self->yes;
		return 0 if fc $text eq fc $self->no;
		return 1 if match($text, $self->yes_expr);
		return 0 if match($text, $self->no_expr);
		return 1 if $text eq 1;
		return 0 if $text eq 0;
		return undef;
	}
	
	sub yesno
	{
		$_[1] ? $_[0]->yes : $_[0]->no
	}
	
	sub make_classes
	{
		my $base = shift;
		no strict 'refs';
		for (@_)
		{
			my ($lang, $codes, $yes, $no, $yes_expr, $no_expr) = @$_;
			$yes_expr = $yes unless defined $yes_expr;
			$no_expr  = $no  unless defined $no_expr;
			my $class = "Lingua::Boolean::Tiny::$lang";
			${"$class\::AUTHORITY"} = $AUTHORITY;
			${"$class\::VERSION"}   = $VERSION;
			@{"$class\::ISA"}       = ($base);
			no warnings qw( closure );
			eval qq
			{
				package $class;
				sub new       { my \$k = shift; bless qr{$lang}, \$k };
				sub yes       { \$yes };
				sub no        { \$no };
				sub yes_expr  { \$yes_expr };
				sub no_expr   { \$no_expr };
				sub languages { \$lang };
				sub langs     { \@{ \$codes } };
			};
			for my $lang (@$codes)
			{
				$Lingua::Boolean::Tiny::LANG{$lang} = $class;
			}
			push @Lingua::Boolean::Tiny::LANG, $codes->[0];
		}
		
		return 1;
	}
}

{
	package Lingua::Boolean::Tiny::Union;
	
	our $AUTHORITY = 'cpan:TOBYINK';
	our $VERSION   = '0.008';
	
	sub new
	{
		my $class = shift;
		bless [ grep defined, map "Lingua::Boolean::Tiny"->new_strict($_), @_ ] => $class;
	}
	
	sub boolean
	{
		my $self = shift;
		for (@$self)
		{
			my $r = $_->boolean(@_);
			return $r if defined $r;
		}
		return undef;
	}
	
	sub langs
	{
		my $self = shift;
		map $_->langs, @$self;
	}
	
	sub languages
	{
		my $self = shift;
		map $_->languages, @$self;
	}
}

"Lingua::Boolean::Tiny::BASE"->make_classes(
	[
		Chinese => [qw( zh zho chi )],
		q/是/ => q/不是/,
		[qr{^[yY是]}, qw( 是 對 是 对 ), qr{^[ds]h[ìi]$}i],
		[qr{^[nN不否]}, qw( 不是 不對 不是 不对 ), qr{^b[úu]\s*[ds]h[ìi]$}i],
	],
	[
		English => [qw( en eng )],
		qw( yes no ),
		[qr{^y(?:es)?$}i, qr{^on$}i, qr{^ok$}i, qr{^true$}i],
		[qr{^no?$}i, qr{^off$}i, qr{not ?ok$}i, qr{^false$}i],
	],
	[
		Spanish => [qw( es spa )],
		qw( sí no ),
		qr{^[sSyY]},
		qr{^[nN]$},
	],
	[
		Hindi => [qw( hi hin )],
		q/हाँ/ => q/नहीं/,
		["हाँ", qr{^h[aā]̃$}i, "जी", qr{^j[īi]$}i, "जी हाँ", qr{^j[īi]\s*h[aā]̃$}i, qr{^ji\s*ha$}i, qr{^[yY]}],
		["नहीं", qr{^nahī̃$}i, "जी नहीं", qr{^jī nahī̃$}i, qr{^ji\s*nahi$}i, qr{^[nN]}],
	],
	[
		Russian => [qw( ru rus )],
		qw( да нет ),
		[qr{^[ДдYy]}, qr{^да$}i, qr{^da$}i],
		[qr{^[НнNn]}, qr{^нет$}i, qr{^n[iy]?et$}i],
	],
	[
		Arabic => [qw( ar ara )],
		q/نعم/ => q/ﻻ/,

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.037 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )