<commit_before>#!/usr/bin/env perl

use warnings;
use strict;
use Unison::WWW;
use Unison::WWW::Page;
use Unison::WWW::Table;

my $p = new Unison::WWW::Page;
my $u = $p->{unison};
my $v = $p->Vars();

print $p->render("Sequence lookup by alias"
				    . (defined $v->{seq} ? ": $v->{seq}" : ''),

				 $p->tip("use % for wildcard (but it's slower)"),
				 $p->start_form(-method => 'GET',
								-action => $p->make_url()),
				 "alias: ",
				 $p->textfield(-name=>'alias',
                               -default=>$v->{alias},
                               -size=>50,
                               -maxlength=>50),
				 $p->submit(-value=>'vroom!'),
				 $p->end_form(), "\n",

				 (defined $v->{alias} ? do_search($v->{alias}) : '')
				);


sub do_search {
  my $q = shift;
  my $results;
  my $sql = 'select pseq_id,canonical_oad_fmt(origin,alias,descr) as oad from v_palias';
  if ($q =~ m/%/) {
	$sql .= " where alias ilike ?";
  } else {
	$sql .= " where alias = ?";
  }
  $sql .= ' limit 1001';

  my @fields = ( 'pseq_id', 'origin:alias (description)' );
  my $ar = $u->selectall_arrayref($sql,undef,$q);

  if ($#$ar > 1000) {
	return "<b>Too many results returned ($#$ar); please narrow your query</b>";
  }

  for(my $i=0; $i<=$#$ar; $i++) {
	$ar->[$i][0] = sprintf('<a href="pseq_summary.pl?pseq_id=%d">%d</a>',
						   $ar->[$i][0],$ar->[$i][0]);
  }

  $results = $p->group(sprintf("%d results for %s",$#$ar+1,$q),
					   Unison::WWW::Table::render(\@fields,$ar));
  $results .= $p->sql($sql);
  return $results;
}<commit_msg>* now uses Unison:: palias code to do alias lookups<commit_after>#!/usr/bin/env perl

use warnings;
use strict;
use Unison::WWW;
use Unison::WWW::Page;
use Unison::WWW::Table;

my $p = new Unison::WWW::Page();
my $u = $p->{unison};
my $v = $p->Vars();

print $p->render("Sequence lookup by alias"
				 . (defined $v->{alias} ? ": $v->{alias}" : ''),

				 $p->tip("use % for wildcard (but it's slower)"),
				 $p->start_form(-method => 'GET',
								-action => $p->make_url()),
				 "alias: ",
				 $p->textfield(-name=>'alias',
                               -default=>$v->{alias},
                               -size=>50,
                               -maxlength=>50),
				 $p->submit(-value=>'vroom!'),
				 $p->end_form(), "\n",

				 (defined $v->{alias} ? do_search($v->{alias}) : '')
				);


sub do_search {
  my $q = shift;
  my @pids = $u->get_pseq_id_from_alias( $q );

  if ($#pids == -1) {
	return( '<b>No results returned</b>'
			. '<br>NOTE: Short regexp queries are silently ignored.');
  }

  if ($#pids >= 100) {
	return('<b>Too many results returned (' .($#pids+1) 
		   .'); please narrow your query (max is 100)</b>');
  }

  my $sth = $u->prepare('select best_oad(?)');
  my @ar = map { [$_, $u->selectrow_array($sth,undef,$_) ] } @pids;
  my @fields = ( 'pseq_id', 'origin:alias (description)' );
  my $ar = \@ar;
  for(my $i=0; $i<=$#$ar; $i++) {
	$ar->[$i][0] = sprintf('<a href="pseq_summary.pl?pseq_id=%d">%d</a>',
						   $ar->[$i][0],$ar->[$i][0]);
  }

  return $p->group(sprintf("%d results for %s",$#$ar+1,$q),
				   Unison::WWW::Table::render(\@fields,$ar));
}
{'fraction_non_alphanumeric': 0.24912615189068954, 'fraction_numerical': 0.010803940260565617, 'mean_word_length': 2.7298578199052135, 'pattern_counts': {'":': 2, '<': 16, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2064706', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1210, 'n_words': 248}