+;;; gnus-gl.el --- an interface to GroupLens for Gnus
+;; Copyright (C) 1995,96 Free Software Foundation, Inc.
+
+;; Author: Brad Miller <bmiller@cs.umn.edu>
+;; Keywords: news, score
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING. If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;;; Commentary:
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; GroupLens software and documentation is copyright (c) 1995 by Paul
;; Resnick (Massachusetts Institute of Technology); Brad Miller, John
;; As of version 2.5, grouplens now works as a minor mode of
;; gnus-summary-mode. To get make that work you just need a couple of
;; hooks.
-;; In addition, there are a few gnus-*-hooks that need to be set:
-;; (add-hook 'gnus-startup-hook 'bbb-login)
-;; (add-hook 'gnus-summary-mode-hook 'gnus-grouplens-mode)
-;;
-;; If you want to see grouplens scores using our format you might want to
-;; add a %uG to the gnus-summary-line-format. For example, I use:
-;; (setq gnus-summary-line-format "%U%R%uG%I%(%[%4L: %-20,20uB%]%) %s\n")
-;; The above format also assumes that you are using gnus-bbdb You can
-;; just as easily ad %uG to whatever format string you use. Or add
-;; a %i to just see a simple numeric version of the predictions that
-;; uses less space on the summary line. If you use %uG you have several
-;; choices for how things look. See the doc string for the
-;; grouplens-prediction-display variable.
-;; (setq grouplens-prediction-display 'prediction-bar)
-;;
-;; If you use %uI on your group-line-format you will get (GroupLens Enhanced)
-;; after the names of newsgroups supported by GroupLens.
-;; (setq gnus-group-line-format "%M%S%p%5y: %(%g%) %uI\n")
+;; (setq gnus-use-grouplens t)
+;; (setq grouplens-pseudonym "")
+;; (setq grouplens-bbb-host "grouplens.cs.umn.edu")
;;
;; (setq gnus-summary-default-score 0)
;;
-;; In addition there are some GroupLens user variables to set
-;; (setq grouplens-pseudonym "foobar")
-;; If you are using a bbb other than twain.cs.umn.edu you will need to
-;; set the grouplens-bbb-host variable, and possibly the
-;; grouplens-bbb-port variable.
-;;
-;;(setq grouplens-newsgroups '("comp.lang.c++" "rec.humor" "rec.food.recipes"))
-;; This sets up the groups for which you will get predictions and ratings.
-;;
;; USING GROUPLENS
;; How do I Rate an article??
;; Before you type n to go to the next article, hit a number from 1-5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
+;;; Code:
+
(require 'gnus-score)
-(eval-and-compile (require 'cl))
+(require 'cl)
+(require 'gnus-load)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; User variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defvar gnus-summary-grouplens-line-format
- "%U%R%z%l%I%(%[%4L: %-20,20n%]%) %s\n"
+ "%U\%R\%z%l%I\%(%[%4L: %-20,20n%]%) %s\n"
"*The line format spec in summary GroupLens mode buffers.")
(defvar grouplens-pseudonym ""
- "User's pseudonym. This pseudonym is obtained during the registration
-process")
+ "User's pseudonym. This pseudonym is obtained during the registration process")
(defvar grouplens-bbb-host "grouplens.cs.umn.edu"
"Host where the bbbd is running" )
(defvar grouplens-score-offset 0
"Offset the prediction by this value.
-Setting this variable to -2 would have the following effect on grouplens
-scores:
+Setting this variable to -2 would have the following effect on
+GroupLens scores:
+
1 --> -2
2 --> -1
3 --> 0
4 --> 1
5 --> 2
-the reason a user might want to do this is to combine grouplens
-predictions with scores calculated by other score methods")
+The reason is that a user might want to do this is to combine
+GroupLens predictions with scores calculated by other score methods.")
(defvar grouplens-score-scale-factor 1
- "This variable allow sthe user to magify the effect of grouplens scores.
+ "This variable allows the user to magnify the effect of GroupLens scores.
The scale factor is applied after the offset.")
-(defvar gnus-grouplens-override-scoring t
- "Tell Grouplens to override the normal Gnus scoring mechanism. If
- this variable is non-nill than Grouplens will completely override
- the normal scoring mechanism of Gnus. When nil, Grouplens will not
- override the normal scoring mechanism so both can be used at once.")
-
+(defvar gnus-grouplens-override-scoring 'override
+ "Tell Grouplens to override the normal Gnus scoring mechanism.
+GroupLens scores can be combined with gnus scores in one of three ways.
+'override -- just use grouplens predictions for grouplens groups
+'combine -- combine grouplens scores with gnus scores
+'separate -- treat grouplens scores completely separate from gnus")
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; Program global variables
(defvar bbb-alist nil)
(defvar bbb-timeout-secs 10
- "Number of seconds to wait for some response from the BBB before
- we give up and assume that something has died..." )
+ "Number of seconds to wait for some response from the BBB.
+If this times out we give up and assume that something has died..." )
(defvar grouplens-previous-article nil
- "message-id of the last article read")
+ "Message-ID of the last article read.")
(defvar bbb-read-point)
(defvar bbb-response-point)
"Ask the bbb for predictions, and build up the score alist."
(if (or (null grouplens-bbb-token)
(equal grouplens-bbb-token "0"))
- (gnus-message 3 "Error: You are not logged in to a BBB")
+ (progn
+ (gnus-message 3 "Error: You are not logged in to a BBB")
+ nil)
(gnus-message 5 "Fetching Predictions...")
(let (predict-list
- (predict-command (build-predict-command midlist groupname
- grouplens-bbb-token))
+ (predict-command (bbb-build-predict-command midlist groupname
+ grouplens-bbb-token))
(bbb-process (bbb-connect-to-bbbd grouplens-bbb-host
grouplens-bbb-port)))
(if bbb-process
(setq bbb-mid-list (cons this bbb-mid-list))))
bbb-mid-list))
-(defun build-predict-command (mlist grpname token)
+(defun bbb-build-predict-command (mlist grpname token)
(let ((cmd (concat "getpredictions " token " " grpname "\r\n"))
art)
(while mlist
(goto-char bbb-read-point))
(setq match-end (point))
(goto-char (+ bbb-response-point 4)) ;; we ought to be right before OK
- (build-response-alist)))
+ (bbb-build-response-alist)))
;; build-response-alist assumes that the cursor has been positioned at
;; the first line of the list of mid/rating pairs. For now we will
;; use a prediction of 99 to signify no prediction. Ultimately, we
;; should just ignore messages with no predictions.
-(defun build-response-alist ()
+(defun bbb-build-response-alist ()
(let ((resp nil)
(match-end (point)))
(setq grouplens-current-hashtable (make-hash-table :test 'equal :size 100))
(buffer-substring (match-beginning 1) (match-end 1)))
(defun bbb-get-pred ()
- (let ((tpred (round (string-to-int (buffer-substring
+ (let ((tpred (string-to-number (buffer-substring
(match-beginning 2)
- (match-end 2))))))
+ (match-end 2)))))
(if (> tpred 0)
- (* grouplens-score-scale-factor (+ grouplens-score-offset tpred))
+ (round (* grouplens-score-scale-factor (+ grouplens-score-offset tpred)))
1)))
(defun bbb-get-confl ()
(defconst grplens-minrating 1)
(defconst grplens-predstringsize 12)
-(defalias 'bbb-grouplens-score 'gnus-user-format-function-G)
-
(defvar gnus-tmp-score)
-(defun gnus-user-format-function-G (header)
- (let* ((rate-string (make-string 12 ? ))
- (mid (aref header (nth 1 (assoc "message-id" gnus-header-index))))
- (hashent (gethash mid grouplens-current-hashtable))
- (iscore (if (string-match "September" gnus-version)
- gnus-tmp-score
- score))
- (low (car (cdr hashent)))
- (high (car (cdr (cdr hashent)))))
- (aset rate-string 0 ?|)
- (aset rate-string 11 ?|)
- (unless (member grouplens-current-group grouplens-newsgroups)
- (unless (equal grouplens-prediction-display 'prediction-num)
- (cond ((< iscore 0)
- (setq iscore 1))
- ((> iscore 5)
- (setq iscore 5))))
- (setq low 0)
- (setq high 0))
- (if (and (bbb-valid-score iscore)
- (not (null mid)))
- (cond
- ;; prediction-spot
- ((equal grouplens-prediction-display 'prediction-spot)
- (setq rate-string (bbb-fmt-prediction-spot rate-string iscore)))
- ;; confidence-interval
- ((equal grouplens-prediction-display 'confidence-interval)
- (setq rate-string (bbb-fmt-confidence-interval iscore low high)))
- ;; prediction-bar
- ((equal grouplens-prediction-display 'prediction-bar)
- (setq rate-string (bbb-fmt-prediction-bar rate-string iscore)))
- ;; confidence-bar
- ((equal grouplens-prediction-display 'confidence-bar)
- (setq rate-string (format "| %4.2f |" iscore)))
- ;; confidence-spot
- ((equal grouplens-prediction-display 'confidence-spot)
- (setq rate-string (format "| %4.2f |" iscore)))
- ;; prediction-num
- ((equal grouplens-prediction-display 'prediction-num)
- (setq rate-string (bbb-fmt-prediction-num iscore)))
- ;; confidence-plus-minus
- ((equal grouplens-prediction-display 'confidence-plus-minus)
- (setq rate-string (bbb-fmt-confidence-plus-minus iscore low high))
- )
- (t (gnus-message 3 "Invalid prediction display type")))
- (aset rate-string 5 ?N) (aset rate-string 6 ?A))
- rate-string))
+(defun bbb-grouplens-score (header)
+ (if (eq gnus-grouplens-override-scoring 'separate)
+ (bbb-grouplens-other-score header)
+ (let* ((rate-string (make-string 12 ? ))
+ (mid (aref header (nth 1 (assoc "message-id" gnus-header-index))))
+ (hashent (gethash mid grouplens-current-hashtable))
+ (iscore gnus-tmp-score)
+ (low (car (cdr hashent)))
+ (high (car (cdr (cdr hashent)))))
+ (aset rate-string 0 ?|)
+ (aset rate-string 11 ?|)
+ (unless (member grouplens-current-group grouplens-newsgroups)
+ (unless (equal grouplens-prediction-display 'prediction-num)
+ (cond ((< iscore 0)
+ (setq iscore 1))
+ ((> iscore 5)
+ (setq iscore 5))))
+ (setq low 0)
+ (setq high 0))
+ (if (and (bbb-valid-score iscore)
+ (not (null mid)))
+ (cond
+ ;; prediction-spot
+ ((equal grouplens-prediction-display 'prediction-spot)
+ (setq rate-string (bbb-fmt-prediction-spot rate-string iscore)))
+ ;; confidence-interval
+ ((equal grouplens-prediction-display 'confidence-interval)
+ (setq rate-string (bbb-fmt-confidence-interval iscore low high)))
+ ;; prediction-bar
+ ((equal grouplens-prediction-display 'prediction-bar)
+ (setq rate-string (bbb-fmt-prediction-bar rate-string iscore)))
+ ;; confidence-bar
+ ((equal grouplens-prediction-display 'confidence-bar)
+ (setq rate-string (format "| %4.2f |" iscore)))
+ ;; confidence-spot
+ ((equal grouplens-prediction-display 'confidence-spot)
+ (setq rate-string (format "| %4.2f |" iscore)))
+ ;; prediction-num
+ ((equal grouplens-prediction-display 'prediction-num)
+ (setq rate-string (bbb-fmt-prediction-num iscore)))
+ ;; confidence-plus-minus
+ ((equal grouplens-prediction-display 'confidence-plus-minus)
+ (setq rate-string (bbb-fmt-confidence-plus-minus iscore low high))
+ )
+ (t (gnus-message 3 "Invalid prediction display type")))
+ (aset rate-string 5 ?N) (aset rate-string 6 ?A))
+ rate-string)))
;;
;; Gnus user format function that doesn't depend on
;; bbb-build-mid-scores-alist being used as the score function, but is
;; instead called from gnus-select-group-hook. -- LAB
-(defun gnus-user-format-function-L (header)
+(defun bbb-grouplens-other-score (header)
(if (not (member grouplens-current-group grouplens-newsgroups))
;; Return an empty string
""
(let* ((rate-string (make-string 12 ? ))
(mid (aref header (nth 1 (assoc "message-id" gnus-header-index))))
(hashent (gethash mid grouplens-current-hashtable))
- (pred (nth 0 hashent))
+ (pred (or (nth 0 hashent) 0))
(low (nth 1 hashent))
(high (nth 2 hashent)))
- (gnus-message 5 (concat "mid = " mid))
;; Init rate-string
(aset rate-string 0 ?|)
(aset rate-string 11 ?|)
(member gnus-newsgroup-name grouplens-newsgroups))
(let ((bbb-process (bbb-connect-to-bbbd grouplens-bbb-host
grouplens-bbb-port))
- (rate-command (build-rate-command grouplens-rating-alist)))
+ (rate-command (bbb-build-rate-command grouplens-rating-alist)))
(if bbb-process
(save-excursion
(set-buffer (process-buffer bbb-process))
(gnus-message 3 "No BBB connection")))
(setq grouplens-rating-alist nil)))
-(defun build-rate-command (rate-alist)
+(defun bbb-build-rate-command (rate-alist)
(let (this
(cmd (concat "putratings " grouplens-bbb-token
" " grouplens-current-group " \r\n")))
(nth 1 (assoc "message-id" gnus-header-index)))
(gnus-message 3 "You must select an article before you rate it")))
-(defvar gnus-tmp-group)
-(defun gnus-user-format-function-I (header)
- (let ((gname (if (string-match "September" gnus-version)
- gnus-tmp-group
- group)))
- (if (member gname grouplens-newsgroups) " (GroupLens Enhanced)" "")))
-
(defun bbb-grouplens-group-p (group)
"Say whether GROUP is a GroupLens group."
(if (member group grouplens-newsgroups) " (GroupLens Enhanced)" ""))
;; BUG REPORTING
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-(defconst gnus-gl-version "gnus-gl.el 2.9")
+(defconst gnus-gl-version "gnus-gl.el 2.12")
(defconst gnus-gl-maintainer-address "grouplens-bug@cs.umn.edu")
(defun gnus-gl-submit-bug-report ()
"Submit via mail a bug report on gnus-gl"
(if (null arg) (not gnus-grouplens-mode)
(> (prefix-numeric-value arg) 0)))
(when gnus-grouplens-mode
- (if (not (fboundp 'make-local-hook))
- (add-hook 'gnus-select-article-hook 'grouplens-do-time)
- (make-local-hook 'gnus-select-article-hook)
- (add-hook 'gnus-select-article-hook 'grouplens-do-time nil 'local))
- (if (not (fboundp 'make-local-hook))
- (add-hook 'gnus-exit-group-hook 'bbb-put-ratings)
- (make-local-hook 'gnus-exit-group-hook)
- (add-hook 'gnus-exit-group-hook 'bbb-put-ratings nil 'local))
+ (gnus-make-local-hook 'gnus-select-article-hook)
+ (gnus-add-hook 'gnus-select-article-hook 'grouplens-do-time nil 'local)
+ (gnus-make-local-hook 'gnus-exit-group-hook)
+ (gnus-add-hook 'gnus-exit-group-hook 'bbb-put-ratings nil 'local)
(make-local-variable 'gnus-score-find-score-files-function)
- (if gnus-grouplens-override-scoring
- (setq gnus-score-find-score-files-function
- 'bbb-build-mid-scores-alist)
- (add-hook 'gnus-select-group-hook
- '(lambda()
- (bbb-build-mid-scores-alist gnus-newsgroup-name))))
+ (cond ((eq gnus-grouplens-override-scoring 'combine)
+ ;; either add bbb-buld-mid-scores-alist to a list
+ ;; or make a list
+ (if (listp gnus-score-find-score-files-function)
+ (setq gnus-score-find-score-files-function
+ (append 'bbb-build-mid-scores-alist
+ gnus-score-find-score-files-function ))
+ (setq gnus-score-find-score-files-function
+ (list gnus-score-find-score-files-function
+ 'bbb-build-mid-scores-alist))))
+ ;; leave the gnus-score-find-score-files variable alone
+ ((eq gnus-grouplens-override-scoring 'separate)
+ (add-hook 'gnus-select-group-hook
+ '(lambda()
+ (bbb-build-mid-scores-alist gnus-newsgroup-name))))
+ ;; default is to override
+ (t (setq gnus-score-find-score-files-function
+ 'bbb-build-mid-scores-alist)))
+
+ ;; Change how summary lines look
(make-local-variable 'gnus-summary-line-format)
- (setq gnus-summary-line-format gnus-summary-grouplens-line-format)
(make-local-variable 'gnus-summary-line-format-spec)
+ (setq gnus-summary-line-format gnus-summary-grouplens-line-format)
+ (setq gnus-summary-line-format-spec nil)
+ (gnus-update-format-specifications nil 'summary)
+ (gnus-update-summary-mark-positions)
;; Set up the menu.
(when (and menu-bar-mode
(provide 'gnus-gl)
-;;; end gnus-gl.el
-
+;;; gnus-gl.el ends here