From debbugs-submit-bounces@debbugs.gnu.org Wed Sep 18 11:58:31 2019 Received: (at submit) by debbugs.gnu.org; 18 Sep 2019 15:58:31 +0000 Received: from localhost ([127.0.0.1]:54734 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iAcLe-0007bP-ND for submit@debbugs.gnu.org; Wed, 18 Sep 2019 11:58:31 -0400 Received: from lists.gnu.org ([209.51.188.17]:33903) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iAcLb-0007bE-Uz for submit@debbugs.gnu.org; Wed, 18 Sep 2019 11:58:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54483) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iAcLa-0003J4-4K for guix-patches@gnu.org; Wed, 18 Sep 2019 11:58:27 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: *** X-Spam-Status: No, score=3.2 required=5.0 tests=BAYES_50,FREEMAIL_FROM, SPOOFED_FREEMAIL,URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iAcLY-0007kq-P2 for guix-patches@gnu.org; Wed, 18 Sep 2019 11:58:25 -0400 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35666) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iAcLY-0007jv-Io for guix-patches@gnu.org; Wed, 18 Sep 2019 11:58:24 -0400 Received: by mail-wm1-x344.google.com with SMTP id y21so682920wmi.0 for ; Wed, 18 Sep 2019 08:58:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ik/8VTq+SmL7Rw/0efRshmThF/HNJuUX9vBQIc+GLRk=; b=V0iAuDejuI9xUR6nJ04yr/KiR2632HivDz+XJQ2UqLk0jCwYR0VEBtlv5nALRbcQLb 3sJQ+yw/+TBoQaRdhzuNA4iED9okAFH1/jvKvShm/+f2mV12n/kVXrl9yxw/w5r9V+QK J65c7/A96SI+nmEWqBVsXhnJieuV1QWtKvs9IHhgZvytYoQgRouGwoLD9aDhT/ZBtOcs seNzOVVFfhU0wWiGHG6Vh7mHW4rBVOa5FWfuT9Z+r46aiWIQ/UfVeJJm2h8bJy7Btmnb bxJ2eu5EGrYQXJy5yXzEwpfE9kUAFc3oWD0XepLgWvs6q7CzNXo1oaf2+ccxgLJT3VHx TQeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ik/8VTq+SmL7Rw/0efRshmThF/HNJuUX9vBQIc+GLRk=; b=qpL5JfYhmLCttwh6Gg4VK4lT2xCGMsWDm9v/ZI7bLwcQsnzv6DFiKxRSZ1LtlnmHF7 ewnV91Pd2Txc/9pNv1/cpx3EWfvnsSXMSK7lEJvdxl3CCKqmhUeMgOEsBvY+IAfw0AMT GMRy3We2jKUn3Mk/cnteYb67vwTODy2SXnkoY12T4pasOn6g81SbHhzNkEiJysNGNqXB jOln/EHtlQZQX8PLn1vYs1kLRDA5F0ksKuNoQF9eJh6CFxOlwrT/5HYRLPXLgQU0/rat ZsmCKUOo5FKO+AgTHElcg/+vrtpdT8sM/wtU0DZ4LiwgbM2g9FJSUAIkkVqjOWupFHAb p50g== X-Gm-Message-State: APjAAAVl6fqwi9IczfOHciPGRFfijIo4NAQYNGuX2O3PZTg0GSzylI/4 OBR+YQY2fap2wK1qCjREVH12EwD/ X-Google-Smtp-Source: APXvYqxSBsDvl718W2qSllX3ia2okADUuGioDbsk1xOZtbxCybSNQ8EjIsmrWk5XkShFSf737uIhAw== X-Received: by 2002:a7b:c757:: with SMTP id w23mr3400486wmk.31.1568822302860; Wed, 18 Sep 2019 08:58:22 -0700 (PDT) Received: from pfiuh02.univ-paris-diderot.fr ([193.48.40.241]) by smtp.gmail.com with ESMTPSA id q22sm3351758wmj.31.2019.09.18.08.58.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Sep 2019 08:58:22 -0700 (PDT) From: zimoun To: guix-patches@gnu.org Subject: [PATCH] ui: 'relevance' connects regexps with a logical and. Date: Wed, 18 Sep 2019 17:57:57 +0200 Message-Id: <20190918155757.4198-1-zimon.toutoune@gmail.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 X-Spam-Score: 1.1 (+) X-Spam-Report: Spam detection software, running on the system "debbugs.gnu.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Fixes . Previously, the logical and connecting the regexps did not output the expected results (introduced in 8874faaaac665100a095ef25e39c9a389f5a397f). * guix/ui.scm (relevance) [score]: Change its arguments. [regexp->score]: New procedure. * tests/ui.scm ("package-relevance"): Add test. --- guix/ui.scm | 48 ++++++++++++++++++++++++ [...] Content analysis details: (1.1 points, 10.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: tobias.gr] 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (zimon.toutoune[at]gmail.com) 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [209.51.188.17 listed in list.dnswl.org] 2.4 SPOOFED_FREEMAIL No description available. X-Debbugs-Envelope-To: submit Cc: zimoun X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: 0.1 (/) Fixes . Previously, the logical and connecting the regexps did not output the expected results (introduced in 8874faaaac665100a095ef25e39c9a389f5a397f). * guix/ui.scm (relevance) [score]: Change its arguments. [regexp->score]: New procedure. * tests/ui.scm ("package-relevance"): Add test. --- guix/ui.scm | 48 ++++++++++++++++++++++++------------------------ tests/ui.scm | 5 ++++- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/guix/ui.scm b/guix/ui.scm index 7920335928..4be31db047 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -13,6 +13,7 @@ ;;; Copyright © 2018 Ricardo Wurmus ;;; Copyright © 2019 Chris Marusich ;;; Copyright © 2019 Tobias Geerinckx-Rice +;;; Copyright © 2019 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -1281,33 +1282,32 @@ weight of this field in the final score. A score of zero means that OBJ does not match any of REGEXPS. The higher the score, the more relevant OBJ is to REGEXPS." - (define (score str) - (define scores - (map (lambda (regexp) - (fold-matches regexp str 0 - (lambda (m score) - (+ score - (if (string=? (match:substring m) str) - 5 ;exact match - 1))))) - regexps)) - + (define (score regexp str) + (fold-matches regexp str 0 + (lambda (m score) + (+ score + (if (string=? (match:substring m) str) + 5 ;exact match + 1))))) + + (define (regexp->score regexp) + (let ((score-regexp (lambda (str) (score regexp str)))) + (fold (lambda (metric relevance) + (match metric + ((field . weight) + (match (field obj) + (#f relevance) + ((? string? str) + (+ relevance (* (score-regexp str) weight))) + ((lst ...) + (+ relevance (* weight (apply + (map score-regexp lst))))))))) + 0 metrics))) + + (let ((scores (map regexp->score regexps))) ;; Return zero if one of REGEXPS doesn't match. (if (any zero? scores) 0 - (reduce + 0 scores))) - - (fold (lambda (metric relevance) - (match metric - ((field . weight) - (match (field obj) - (#f relevance) - ((? string? str) - (+ relevance (* (score str) weight))) - ((lst ...) - (+ relevance (* weight (apply + (map score lst))))))))) - 0 - metrics)) + (reduce + 0 scores)))) (define %package-metrics ;; Metrics used to compute the "relevance score" of a package against a set diff --git a/tests/ui.scm b/tests/ui.scm index 2138e23369..d8573e88d8 100644 --- a/tests/ui.scm +++ b/tests/ui.scm @@ -267,6 +267,7 @@ Second line" 24)) (gcrypt (specification->package "guile-gcrypt")) (go (specification->package "go")) (gnugo (specification->package "gnugo")) + (libb2 (specification->package "libb2")) (rx (cut make-regexp <> regexp/icase)) (>0 (cut > <> 0)) (=0 zero?)) @@ -283,6 +284,8 @@ Second line" 24)) (=0 (package-relevance go (map rx '("go" "game")))) (>0 (package-relevance gnugo - (map rx '("go" "game"))))))) + (map rx '("go" "game")))) + (>0 (package-relevance libb2 + (map rx '("crypto" "library"))))))) (test-end "ui") -- 2.21.0