summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2020-01-26 12:23:21 +0000
committerdakkar <dakkar@thenautilus.net>2020-01-26 12:23:21 +0000
commitab6012faa67a80c3cf6a604c52580972c120fd89 (patch)
tree4188b227b861127e5348c3b1fd70bb057291033d
parenttimeout when parsing a socket (diff)
downloadMaildirIndexer-ab6012faa67a80c3cf6a604c52580972c120fd89.tar.gz
MaildirIndexer-ab6012faa67a80c3cf6a604c52580972c120fd89.tar.bz2
MaildirIndexer-ab6012faa67a80c3cf6a604c52580972c120fd89.zip
nicer types
-rw-r--r--lib/MaildirIndexer/Index/ByAddresses.rakumod18
1 files changed, 8 insertions, 10 deletions
diff --git a/lib/MaildirIndexer/Index/ByAddresses.rakumod b/lib/MaildirIndexer/Index/ByAddresses.rakumod
index d420c3e..5836cb8 100644
--- a/lib/MaildirIndexer/Index/ByAddresses.rakumod
+++ b/lib/MaildirIndexer/Index/ByAddresses.rakumod
@@ -9,15 +9,13 @@ use MaildirIndexer::Email;
# Algorithm::NaiveBayes::Classifier::Bernoulli class
has Array[Str] %!addresses-for-file;
-# I'd like to type-constrain these BagHash-es, but the compiler
-# currently dies if I try
has BagHash $!count-by-address-and-mailbox .= new;
has BagHash $!known-addresses .= new;
has BagHash $!count-by-mailbox .= new;
-has Hash $!p-address-given-mailbox .= new;
+has Numeric %!p-address-given-mailbox;
has Int $!total-count;
-has Hash $!cached-p-given-mailbox .= new;
+has Numeric %!cached-p-given-mailbox;
has Instant $!last-cached-at .= from-posix(0);
constant $NOT-ZERO = 1e-15;
@@ -37,10 +35,10 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
if ($count) {
my Numeric $a = $NOT-ZERO + $count;
my Numeric $b = 1 + $!count-by-mailbox{$mailbox};
- $!p-address-given-mailbox{$pair} = $a / $b;
+ %!p-address-given-mailbox{$pair} = $a / $b;
}
else {
- $!p-address-given-mailbox{$pair} :delete;
+ %!p-address-given-mailbox{$pair} :delete;
}
}
@@ -50,11 +48,11 @@ submethod account-for(Str @addresses,Str $mailbox,Int $step) {
my Numeric $p = $!count-by-mailbox{$mailbox} / $!total-count;
for $!known-addresses.keys -> Str $addr {
- my $addr-p = $!p-address-given-mailbox{$addr => $mailbox} // $NOT-ZERO;
+ my $addr-p = %!p-address-given-mailbox{$addr => $mailbox} // $NOT-ZERO;
$p *= 1 - $addr-p;
}
- $!cached-p-given-mailbox{$mailbox} = $p;
+ %!cached-p-given-mailbox{$mailbox} = $p;
}
$!last-cached-at = now;
}
@@ -93,10 +91,10 @@ submethod predict-mailbox-given-addresses(@addresses) {
my Numeric %prediction;
for $!count-by-mailbox.keys -> Str $mailbox {
- my Numeric $p = $!cached-p-given-mailbox{$mailbox} // $NOT-ZERO;
+ my Numeric $p = %!cached-p-given-mailbox{$mailbox} // $NOT-ZERO;
for @addresses -> Str $addr {
- my $addr-p = $!p-address-given-mailbox{$addr => $mailbox} // $NOT-ZERO;
+ my $addr-p = %!p-address-given-mailbox{$addr => $mailbox} // $NOT-ZERO;
$p *= $addr-p / ( 1- $addr-p );
}