DTA-CAB

 view release on metacpan or  search on metacpan

CAB/Analyzer/Moot.pm  view on Meta::CPAN

  ##-- restore local options
  $moot->{notag}     = $notag;
  $moot->{use_dmoot} = $use_dmoot;

  ##-- DEBUG
  #print STDERR "find_cycle()\n";
  #find_cycle([$moot,$doc,$acode_sub]);
  ##--/DEBUG

  return $doc;
}

##------------------------------------------------------------------------
## Methods: Analysis: Closure Utilities

## $asub_code = $moot->analysisCode()
##  + analysis closure for passing to Analyzer::accessClosure()
##  + default just returns $moot->{analyzeCode} || $DEFAULT_ANALYZE_CODE
sub analysisCode {
  my $moot = shift;
  return
    #analysisCodeDEBUG($moot) ||
    $moot->{analyzeCode} || $DEFAULT_ANALYZE_CODE;
}

##------------------------------------------------------------------------
## Methods: Analysis: DEBUG

## analysisCodeDEBUG() : from $DEFAULT_ANALYZE_CODE
sub analysisCodeDEBUG {
  my $anl = shift;

  ## copy+paste from debugger "print $DEFAULT_ANALYZE_CODE" after breaking first e.g. in analysisCode() above
  package DTA::CAB::Analyzer::Moot;
  my $moot=$anl;
  my $lab =$moot->{label};
  my $hmm =$moot->{hmm};
  my $tagx=$moot->{tagx};
  my $utf8=$moot->{hmmUtf8};
  my $prune=$moot->{prune};
  my $lctext=$moot->{lctext};
  my $notag=$moot->{notag};
  my $use_dmoot=$moot->{use_dmoot};
  my $moot_lang=$moot->{lang};
  my $xpne=$moot->{xpne};
  my $xpfm=$moot->{xpfm};
  my $fmtag=$moot->{fmtag};
  my ($s,$msent,$w,$mw,$t,$at,$lang,$val);
  sub {
    $s     = $_;
    $msent = [map {
      $w  = $_;
      $mw = $w->{$lab} = $w->{$lab} ? {%{$w->{$lab}}} : ($w->{$lab}={}); ##-- copy $w->{moot} if present
      $mw->{text} = (defined($mw->{word}) ? $mw->{word} : (($use_dmoot ? $_->{dmoot} : undef) ? ($use_dmoot ? $_->{dmoot} : undef)->{tag} : ($_->{xlit} ? $_->{xlit}{latin1Text} : $_->{text}) ##== _am_xlit
							  ) ##== _am_tag
		    ) if (!defined($mw->{text}));
      $mw->{text} = lc($mw->{text}) if ($lctext);
      $mw->{analyses} = [{tag=>"NE",details=>"NE.xp",prob=>0}] if ($xpne && ($w->{xp}//"") =~ /\b((?:pers)Name)\b/i); #place
      $mw->{analyses} = [{tag=>$fmtag,details=>"$fmtag.xp",prob=>0}] if ($xpfm && ($w->{xp}//"") =~ /\bforeign\b/i);
      $val = undef;	      ##-- temporary for _am_tagh_moota_uniq()
      $mw->{analyses} = [(map {$val && $val->{details} eq $_->{details} ? qw() : ($val=$_)} sort {($a->{details}//"") cmp ($b->{details}//"") || ($a->{prob}//0) <=> ($b->{prob}//0)} (map {{details=>$_->{hi}, prob=>($_->{w}||0), tag=>($_->{hi} =~ /\[\...
																							  } map {ref($_) ? $_ : {hi=>$_}} map {$_ ? @$_ : qw()}
																						       @$w{qw(mlatin tokpp toka)},
																						       ($use_dmoot && $w->{xlit} && !$w->{xlit}{isLatinExt} ? [$fmtag, "XY"] : qw()),
																						       ($use_dmoot && $w->{dmoot} ? $w->{dmoot}{morph}
																							: ($w->{morph}, ($w->{rw} ? (map {$_->{morph}} @{$w->{rw}}) : qw())))) ##-- _am_tagh_list2moota
			 )	##== _am_tagh_moota_uniq

			] if (!defined($mw->{analyses}));
      foreach (@{$mw->{analyses}}) {
	##-- tag-translation hack: apply BEFORE sending to moot!
	$_->{tag}=$t if (defined($t=$tagx->{$_->{tag}}));
      }
      $mw
    } @{$s->{tokens}}];
    return if (!@$msent);	##-- ignore empty sentences

    $hmm->tag_sentence($msent, $utf8) if (!$notag);

    ##-- language-guesser hack
    if ($moot_lang && ($lang=$s->{lang}) && $lang ne $moot_lang) {
      $_->{tag} = "$fmtag.$lang" foreach (grep {$_->{tag} !~ /^\$/} @$msent);
    }

    foreach (@$msent) {
      $_->{word}=$_->{text};
      delete($_->{text});
      #$_->{tag}=$t if (defined($t=$tagx->{$_->{tag}//""})); ##-- do NOT translate output tags (breaks en-wsj, 2016-06-09)
      $_->{tag}="NE"   if ($xpne && $_->{analyses} && $_->{analyses}[0] && $_->{analyses}[0]{details} eq "NE.xp");
      $_->{tag}=$fmtag if ($xpfm && $_->{analyses} && $_->{analyses}[0] && $_->{analyses}[0]{details} eq "FM.xp");
      if ($prune) {
	$t = $_->{tag}//"";
	@{$_->{analyses}} = grep {$_->{tag} eq $t} @{$_->{analyses}};
      }
    }
  }
}

1; ##-- be happy

__END__
##========================================================================
## POD DOCUMENTATION, auto-generated by podextract.perl, edited

##========================================================================
## NAME
=pod

=head1 NAME

DTA::CAB::Analyzer::Moot - generic Moot HMM tagger/disambiguator analysis API

=cut

##========================================================================
## SYNOPSIS
=pod

=head1 SYNOPSIS

 ##========================================================================



( run in 3.457 seconds using v1.01-cache-2.11-cpan-14f38c9f855 )