Skip to content

Commit

Permalink
Work on speeding up Marpa::R2::HTML
Browse files Browse the repository at this point in the history
  • Loading branch information
- committed Sep 26, 2012
1 parent 310828e commit d28d3ab
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
23 changes: 14 additions & 9 deletions r2/html/lib/Marpa/R2/HTML.pm
Expand Up @@ -524,8 +524,8 @@ sub handler_find {

say STDERR "handler_find(); action: $action";

if ( $action =~ / \A SPE_ /xms ) {
$handler = $self->{handler_by_species}->{$action};
if ( index($action, 'SPE_') == 0 ) {
$handler = $self->{handler_by_species}->{substr $action, 4};
last FIND_HANDLER;
}
$class //= q{*};
Expand Down Expand Up @@ -899,14 +899,10 @@ sub parse {
my $marpa_token = $marpa_tokens[$marpa_token_ix];
last RECCE_RESPONSE if not defined $marpa_token;

say STDERR "token = ", $marpa_token->[0];
my $marpa_symbol_id = $grammar->thin_symbol( $marpa_token->[0] );
my $read_result =
$recce->alternative( $marpa_symbol_id, PHYSICAL_TOKEN, 1 );
if ( $read_result != $UNEXPECTED_TOKEN_ID ) {
say "UNEXPECTED_TOKEN_ID = ", $UNEXPECTED_TOKEN_ID;
say STDERR "result = $read_result ",
$LIBMARPA_ERROR_NAMES[$read_result];
$marpa_token_ix++;
$recce->earleme_complete();
my $last_html_token_of_marpa_token //= $marpa_token->[1]->[0]->[2];
Expand Down Expand Up @@ -1281,10 +1277,19 @@ say STDERR "Start tag token candidate:\n", Data::Dumper::Dumper($start_tag_token
die "Unexpected step type: $type";
} ## end STEP: while (1)

my $value = $stack[0];
my $result = $stack[0];
Marpa::R2::exception('No parse: evaler returned undef')
if not defined $value;
return \$value;
if not defined $result;

if ( $result->[Marpa::R2::HTML::Internal::TDesc::TYPE] eq 'VALUED_SPAN' )
{
$result = $result->[Marpa::R2::HTML::Internal::TDesc::VALUE];
}
else {
die "Not yet implemented";
}

return $result;

} ## end sub parse

Expand Down
6 changes: 3 additions & 3 deletions r2/html/lib/Marpa/R2/HTML/Callback.pm
Expand Up @@ -190,8 +190,7 @@ sub Marpa::R2::HTML::descendants {
$is_valued
? $data->[Marpa::R2::HTML::Internal::TDesc::VALUE]
: undef;
push @per_descendant_results,
defined $value ? q{} . $value : undef;
push @per_descendant_results, $value;
next ARGSPEC;
} ## end if ( $argspec eq 'value' )
if ( $argspec eq 'original' ) {
Expand All @@ -204,7 +203,8 @@ sub Marpa::R2::HTML::descendants {
]
)
: ( $data, $data );
Marpa::R2::HTML::Internal::token_range_to_original(
push @per_descendant_results,
Marpa::R2::HTML::Internal::token_range_to_original(
$parse_instance, $start_ix, $end_ix );
next ARGSPEC;
} ## end if ( $argspec eq 'original' )
Expand Down
6 changes: 5 additions & 1 deletion r2/html/script/marpa_r2_html_score
Expand Up @@ -108,7 +108,11 @@ my $length_by_element = $instance->{length};
my $count_by_element = $instance->{count};
my $html_length = $length_by_element->{html};
my $total_lengths = List::Util::sum values %{ $length_by_element };
my $complexity = sprintf "%.3f", ($total_lengths / ($html_length * log ($html_length)));
my $complexity = 0;
if ( $html_length >= 1 ) {
$complexity = sprintf "%.3f",
( $total_lengths / ( $html_length * log($html_length) ) );
}
my $max_depths = $value->{depths};
my $max_element_depth = $max_depths->{ANY};
delete $max_depths->{ANY};
Expand Down

0 comments on commit d28d3ab

Please sign in to comment.