GNU bug report logs -
#37448
[PATCH] ui: 'relevance' connects regexps with a logical and.
Previous Next
Reported by: zimoun <zimon.toutoune <at> gmail.com>
Date: Wed, 18 Sep 2019 15:59:02 UTC
Severity: normal
Tags: fixed, patch
Done: Ludovic Courtès <ludo <at> gnu.org>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 37448 in the body.
You can then email your comments to 37448 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
guix-patches <at> gnu.org
:
bug#37448
; Package
guix-patches
.
(Wed, 18 Sep 2019 15:59:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
zimoun <zimon.toutoune <at> gmail.com>
:
New bug report received and forwarded. Copy sent to
guix-patches <at> gnu.org
.
(Wed, 18 Sep 2019 15:59:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Fixes <https://bugs.gnu.org/36763>.
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 <rekado <at> elephly.net>
;;; Copyright © 2019 Chris Marusich <cmmarusich <at> gmail.com>
;;; Copyright © 2019 Tobias Geerinckx-Rice <me <at> tobias.gr>
+;;; Copyright © 2019 Simon Tournier <zimon.toutoune <at> gmail.com>
;;;
;;; 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
Information forwarded
to
guix-patches <at> gnu.org
:
bug#37448
; Package
guix-patches
.
(Thu, 19 Sep 2019 19:55:01 GMT)
Full text and
rfc822 format available.
Message #8 received at 37448 <at> debbugs.gnu.org (full text, mbox):
Hey ho,
zimoun <zimon.toutoune <at> gmail.com> skribis:
> Fixes <https://bugs.gnu.org/36763>.
> 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.
Perfect, applied.
Thanks!
Ludo’.
Added tag(s) fixed.
Request was from
Ludovic Courtès <ludo <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Thu, 19 Sep 2019 19:55:02 GMT)
Full text and
rfc822 format available.
bug closed, send any further explanations to
37448 <at> debbugs.gnu.org and zimoun <zimon.toutoune <at> gmail.com>
Request was from
Ludovic Courtès <ludo <at> gnu.org>
to
control <at> debbugs.gnu.org
.
(Thu, 19 Sep 2019 19:55:02 GMT)
Full text and
rfc822 format available.
bug archived.
Request was from
Debbugs Internal Request <help-debbugs <at> gnu.org>
to
internal_control <at> debbugs.gnu.org
.
(Fri, 18 Oct 2019 11:24:08 GMT)
Full text and
rfc822 format available.
This bug report was last modified 4 years and 185 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.