I need more speed
authorCameron Ball <cameron@moodle.com>
Wed, 8 May 2019 05:51:39 +0000 (13:51 +0800)
committerCameron Ball <cameron@moodle.com>
Wed, 8 May 2019 06:05:00 +0000 (14:05 +0800)
src/gnb.php

index 18c2590..e585c2b 100644 (file)
@@ -119,11 +119,15 @@ getTelegram()->addCommand(
                 return;
             }
 
-            $songs = map(function ($song) use ($arguments) {
+            $songs = filter(notEmpty)(map(function ($song) use ($arguments) {
                 $justTitle = explode('/', $song)[1];
-                similar_text(strtolower($arguments), strtolower($song), $perc);
-                return ['title' => $song, 'similarity' => $perc];
-            })(unserialize(file_get_contents(__DIR__ . '/hashmap.txt')));
+                similar_text(strtolower($arguments), strtolower($justTitle), $perc);
+
+                if (!empty(array_intersect(explode(' ', $arguments), explode(' ', $justTitle)))) {
+                    $perc += 50;
+                }
+                return $perc > 50 ? ['title' => $song, 'similarity' => $perc ] : [];
+            })(unserialize(file_get_contents(__DIR__ . '/hashmap.txt'))));
             $top5 = ∘(unlines, aaray_column('title'), aaray_slice(0)(5), 'array_reverse', 'array_values', ssort(∘(∘f(field('similarity')), ⬄, field('similarity'))));
 
             $this->replyWithMessage(
@@ -157,11 +161,15 @@ getTelegram()->addCommand(
             $faveMap = ∘(map(∘(flip(concat)("'s Faves"), 'ucwords', field(0), delemit('.'), 'basename')), foldMap(☐(field(1))(field(0))), foldMap(id))(zzipWith(∘(map, aaray_merge))($names)($hashes));
             $newFaves = zzipWith(∘(concat, flip(concat)(" in "), field(1), delemit('/'),  flip(field)($songHashMap)))(array_keys($faveMap))(array_values($faveMap));
 
-            $thing = map(function ($fave) use ($arguments) {
+            $thing = filter(notEmpty)(map(function ($fave) use ($arguments) {
                 $justTitle = join(' ', array_slice(explode(' ', $fave), 0 , -2));
                 similar_text(strtolower($arguments), strtolower($justTitle), $perc);
+
+                if (!empty(array_intersect(explode(' ', $arguments), explode(' ', $justTitle)))) {
+                    $perc += 50;
+                }
                 return ['title' => $fave, 'similarity' => $perc];
-            })($newFaves);
+            })($newFaves));
             $top5 = ∘(unlines, aaray_column('title'), aaray_slice(0)(5), 'array_reverse', 'array_values', ssort(∘(∘f(field('similarity')), ⬄, field('similarity'))));
 
             $this->replyWithMessage(