Repository: lucy Updated Branches: refs/heads/master 5f15a92bd -> 040bb290f
Improve Analyzer documentation Document that Analyzer subclasses must override the Equals method. Add synopsis with example classes to Perl POD. Project: http://git-wip-us.apache.org/repos/asf/lucy/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/040bb290 Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/040bb290 Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/040bb290 Branch: refs/heads/master Commit: 040bb290f12f8df015b1d9ae99758f1600a52f18 Parents: 5f15a92 Author: Nick Wellnhofer <[email protected]> Authored: Thu Feb 23 16:46:24 2017 +0100 Committer: Nick Wellnhofer <[email protected]> Committed: Thu Feb 23 17:15:36 2017 +0100 ---------------------------------------------------------------------- core/Lucy/Analysis/Analyzer.cfh | 2 + perl/buildlib/Lucy/Build/Binding/Analysis.pm | 59 ++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy/blob/040bb290/core/Lucy/Analysis/Analyzer.cfh ---------------------------------------------------------------------- diff --git a/core/Lucy/Analysis/Analyzer.cfh b/core/Lucy/Analysis/Analyzer.cfh index 8021529..b04a0c4 100644 --- a/core/Lucy/Analysis/Analyzer.cfh +++ b/core/Lucy/Analysis/Analyzer.cfh @@ -23,6 +23,8 @@ parcel Lucy; * smaller pieces ([](cfish:RegexTokenizer)), or it * might perform case folding to facilitate case-insensitive search * ([](cfish:Normalizer)). + * + * Subclasses of Analyzer must override the [](.Equals) method. */ public abstract class Lucy::Analysis::Analyzer inherits Clownfish::Obj { http://git-wip-us.apache.org/repos/asf/lucy/blob/040bb290/perl/buildlib/Lucy/Build/Binding/Analysis.pm ---------------------------------------------------------------------- diff --git a/perl/buildlib/Lucy/Build/Binding/Analysis.pm b/perl/buildlib/Lucy/Build/Binding/Analysis.pm index 367088f..e76b844 100644 --- a/perl/buildlib/Lucy/Build/Binding/Analysis.pm +++ b/perl/buildlib/Lucy/Build/Binding/Analysis.pm @@ -36,6 +36,63 @@ sub bind_all { sub bind_analyzer { my $pod_spec = Clownfish::CFC::Binding::Perl::Pod->new; + my $synopsis = <<'END_SYNOPSIS'; + my $strings = $analyzer->split($text); + + package SimpleAnalyzer; + use base qw( Lucy::Analysis::Analyzer ); + sub new { + return shift->SUPER::new; + } + sub equals { + my ( $self, $other ) = @_; + return $other->isa(__PACKAGE__); + } + sub transform { + my ( $self, $inversion ) = @_; + while ( my $token = $inversion->next ) { + my $text = $token->get_text; + # Transform text... + $token->set_text($text); + } + $inversion->reset; + return $inversion; + } + + package AnalyzerWithMemberVars; + use base qw( Lucy::Analysis::Analyzer ); + our %foo; + sub new { + my $self = shift->SUPER::new; + return $self->init( { @_ } ); + } + sub init { + my ( $self, $args ) = @_; + $foo{$$self} = $args->{foo}; + return $self; + } + sub DESTROY { + my $self = shift; + delete $foo{$$self}; + $self->SUPER::DESTROY; + } + sub equals { + my ( $self, $other ) = @_; + return $other->isa(__PACKAGE__) + && $foo{$$self} eq $foo{$$other}; + } + sub dump { + my $self = shift; + my $dump = $self->SUPER::dump; + $dump->{foo} = $foo{$$self}; + return $dump; + } + sub load { + my ( $self, $dump ) = @_; + my $loaded = $self->SUPER::load($dump); + return $loaded->init($dump); + } +END_SYNOPSIS my $constructor = <<'END_CONSTRUCTOR'; =head2 new @@ -51,7 +108,7 @@ sub bind_analyzer { Abstract constructor. Takes no arguments. END_CONSTRUCTOR - $pod_spec->set_synopsis(" # Abstract base class.\n"); + $pod_spec->set_synopsis($synopsis); $pod_spec->add_constructor( pod => $constructor ); my $binding = Clownfish::CFC::Binding::Perl::Class->new(
