Thread View: news.software.readers
15 messages
15 total messages
Started by Sylvain Robitaille
Mon, 06 Oct 1997 00:00
Re: [slrn] Variables in scorefile?
Author: Sylvain Robitaille
Date: Mon, 06 Oct 1997 00:00
Date: Mon, 06 Oct 1997 00:00
44 lines
2440 bytes
2440 bytes
On 6 Oct 1997 03:18:52 GMT, J.B. Nicholson-Owens <jbn@pop-a-wheelie.midwest.net> wrote: > I'm curious what others think of this idea: Allowing variables in score > files. The big problem I forsee is distinguishing them from literal text. If an approach similar to that in shell scripts is taken, with variables being used with the '$' character to identify them as such, I'm sure it could work. > I'd like the ability to define variables (like 'local-newsgroups' which > contains a comma-separated list of wildmats that match local newsgroups) > for use in my scorefile. I want it primarily because I'm getting lazier > and I don't want to have to type (or maintain) the same list of groups > repeatedly. I'm not sure I really understand what you're trying to do. Why don't you have a section in your scorefile for local groups, with the comma separated wildmat list in the [newsgroups] identifier? For example, in my scorefile, there is a section [concordia.*]. There's no reason why I can't have it be [concordia.*,news.software.readers,comp.os.*], and so on. > In order to get certain scores I want, I have to do that now. I could > score in a hook, but I'd prefer to keep all my scoring in one place. > Most of my scores don't require anything more elaborate than what the > slrn score syntax provides and I like to use the automated score entry > facility slrn provides. Is it a safe bet that this is where the problem occurs, (using the auto- mated score entry)? -- ---------------------------------------------------------------------- Sylvain Robitaille sp_robi@alcor.concordia.ca http://alcor.concordia.ca/~sp_robi Do not believe in miracles -- rely on them. ----------------------------------------------------------------------
Re: [slrn] Variables in scorefile?
Author: Sylvain Robitaille
Date: Fri, 10 Oct 1997 00:00
Date: Fri, 10 Oct 1997 00:00
51 lines
2247 bytes
2247 bytes
On 6 Oct 1997 06:42:31 GMT, J.B. Nicholson-Owens
<jbn@pop-a-wheelie.midwest.net> wrote:
> I already do. The problem is I have multiple instances where I name the
> same series of groups and I want to centralize this duplication by using an
> S-Lang variable. Scorefile variables would let me have one place to change
> this. But think beyond this use. Think of how much more one could do with
> scorefile entries that can be controlled programmatically.
How about something like this?
[local.*,news.group.one,news.group.other]
Score:: 100
From: jbn@pop\-a\-wheelie\.midwest\.net
From: sp_robi@alcor\.concordia\.ca
From: syl@alcor\.concordia\.ca
Score: 150
From: davis@space\.mit\.edu
Score:: -9999
Subject: \cWin.*NT
Subject: win.*95
Subject: microsoft
[some.other.news.group]
Score:: ....
Subject: ....
Subject: ....
Score: ....
From: ....
Subject: ....
I'm sure you get the idea by now. There's no reason to re-list the
newsgroups for each entry. Just order your entries under the appropriate
newsgroup "section", and unless I misunderstand, you'll get what you're
after (though still no defineable variables).
--
----------------------------------------------------------------------
Sylvain Robitaille
sp_robi@alcor.concordia.ca http://alcor.concordia.ca/~sp_robi
Art is anything you can get away with.
-- Marshall McLuhan.
----------------------------------------------------------------------
Re: [slrn] Variables in scorefile?
Author: Hubert Canon
Date: Fri, 10 Oct 1997 00:00
Date: Fri, 10 Oct 1997 00:00
30 lines
1980 bytes
1980 bytes
Dans news.software.readers, J.B. Nicholson-Owens �crivait : > I am fully aware how scorefiles can be created to do what you describe, I > already use that in my scorefile. However, that does not address the > situation where I must have lines like the above 3 that share a lot of > newsgroups. When I need to edit the groups common to all the lines above, I > have to make changes to multiple lines. That is silly and prone to making > mistakes[1]. Variables would fix this: > > [%moderated_groups ()] > [%moderated_groups (), supernews.*] > [~ %moderated_groups (), supernews.*, midwest.*, > news.admin.technical, ...] > > is far more clear and maintainable. What about using a preprocessor like m4 or cpp ? You may have your source in News/Score.m4 which you pass through m4 with a command like "m4 News/Score.m4 > News/Score" and your News/Score.m4 looks like : define(moderated_groups, `clari.*, *.moderated, whatever.*') [moderated_groups] [moderated_groups, supernews.*] [~ moderated_groups, supernews.*, midwest.*, news.admin.technical, ...] -- Hubert Canon
Re: [slrn] Variables in scorefile?
Author: Lloyd Zusman
Date: Sun, 12 Oct 1997 00:00
Date: Sun, 12 Oct 1997 00:00
77 lines
4322 bytes
4322 bytes
On 12 Oct 1997 19:38:48 GMT, J.B. Nicholson-Owens <jbn@pop-a-wheelie.midwest.net> wrote:
> Hubert Canon <Hubert.Canon@irisa.fr> wrote:
> > What about using a preprocessor like m4 or cpp ?
>
> I thought about doing this, but it doesn't reflect the dynamic nature of
> variables as well as real variables (or functions) do. I would like to
> change certain newsgroup variable definitions on the fly in S-Lang code. If
> I use pre-processing, I'm left with a static scorefile with the same limits
> of what I've got now. Also, I don't think I want to have to raise the
> resource requirements by a preprocessor (m4, cpp or something else) to do
> what can be done cleanly entirely with S-Lang.
I agree that m4 and the like are not quite sufficient for this
purpose. After reading your initial query, I started to write a
preprocessor in Perl that would serve as a front end to the editor
specified for manipulating the score file ... it would read a skeleton
score file containing variables which you'd edit, and then it would
create from this the real score file with the variables substituted
which slrn would read.
The problem with this (which I didn't figure out until I just about
finished it) is that slrn itself modifies the score file when you try
to edit it via slrn's user interface. Therefore, this entire skeleton-
scorefile-and-preprocessor method falls apart.
I could have hacked around this by saving a "before" and "after"
version of the score file, taking diffs, and then automatically
applying these diffs to the skeleton score file before editing it, but
I decided that this is way too much trouble to go through just to
provide some functionality that slrn could provide itself in a much
more straightforward manner, and in a way that integrates much more
tightly with the slang functionality that's already an integral part
of slrn.
> It's a fine idea for an interim solution, but ultimately I would like real
> S-Lang variables or functions in the scorefile. If there were a way to make
> slrn rescan the scorefile, preprocessing+rescan would be either exactly the
> same or almost the same as variables and functions in the scorefile
> (depending on the where the variables and functions may appear in the
> scorefile and how many times the scorefile would be rescanned to resolve
> functions or variables).
Perhaps a way to do this would be to provide a functional interface to
scoring. In other words, one could replace this ...
[my.newsgroup.1,my.newsgroup.2]
Subject: Make money fast!
score: -9999
... with something like this in a slang script ...
variable field = "Subject";
variable pattern = "Make money fast!";
variable score = -9999;
scoreNewsgroup("my.newsgroup.1", field, pattern, score);
scoreNewsgroup("my.newsgroup.2", field, pattern, score);
A variable in .slrnrc could control whether scores are managed
via the .scores file that is in use today, or via this newer
mechanism involving a slang script. All the features of slang
would be available in this scoring script, and this would
provide even more flexibility and functionality than
what we'd get from scanning and re-scanning the score file
for variable substitutions.
Perhaps most of the infrastructure for something like this is already
in place in slrn ... ???
> [ ... ]
--
Lloyd Zusman
ljz@asfast.com
Re: [slrn] Variables in scorefile?
Author: Lloyd Zusman
Date: Mon, 13 Oct 1997 00:00
Date: Mon, 13 Oct 1997 00:00
103 lines
5009 bytes
5009 bytes
On 13 Oct 1997 03:15:32 GMT, J.B. Nicholson-Owens <jbn@pop-a-wheelie.midwest.net> wrote:
> Lloyd Zusman <ljz@asfast.com> wrote:
> > Perhaps most of the infrastructure for something like this is already
> > in place in slrn ... ???
>
> [ ... ]
>
> But getting back to the functional solution you've suggested, if we assume
> that the functions are evaluated in the order they were set, converting
> one's flatfile to a functional equivalent is a considerable job for people
> with large scorefiles. [ ... ]
A script to convert a conventional scorefile to a slang script containing
its functional equivalant would be very easy to write, and this script
could be supplied with the distribution of slrn.
> [ ... ] Also, it's not clear how this would handle complex
> logical statements any differently than the current scorefile -- I think one
> might want a language with S-Lang's capabilities to handle complex
> arrangements of tests to determine a score. [ ... ]
Something like this would do that just fine:
variable score = 1000;
if (header("Subject") == "Free Money!" ||
header("Subject") == "Ponzi scheme!") {
score = -9999;
}
else if (lines() < 50000) {
score = 100;
}
else if (matches(newsgroup(), "alt.spam.*")) {
score = -100;
}
if (matches(newsgroup(), "alt.sex.*") {
score = get_score("alt.animals.hippopotamuses");
score -= 2000;
}
set_score(score);
... where header(), lines(), newsgroup(), matches(), get_score(), and
set_score() are new functions that would be supplied with slrn. I'm
sure that there would be a number of other new functions, as well.
> [ ... ] But most importantly, such
> functions add static data, not references to things that can change easily
> between entering groups.
The functions that I specified above would not add static data. They
would invoked automatically and dynamically for each newsgroup, and
the resulting score would be applied to each of these newsgroups.
> [ ... ] Even if API were added to remove or replace some
> scores with other scores, I think defining a variable to a certain string is
> easier to process and easier for the user to use than writing loops to find
> the score to replace and replacing it.
It would not be necessary (or even meaningful) to write a loop given
the constructs I outlined above.
> Flatfiles also have the advantage of being easy to read and edit. Depending
> on a memory-bound system precludes using other external tools like
> preparsers (perl, m4, cpp, etc). Finally, I don't think we'd want users to
> have to switch from one system to another entirely different looking system
> just to get a few more features.
It's true that this new system would have to be used if any new
features are desired. However, I find this preferable to adding a few
features to the current method for handling scorefiles. Once a few
features are added, someone would want another feature, and another,
etc. If this was script-able, then each person who wants new features
would be able to mix and match and pick and choose the features he or
she wants to use.
> With preprocessing built into slrn (or enhancing the current scorefile
> parser, whichever way you want to look at it), expanding S-Lang constructs
> just before processing by the current score processor still strikes me as
> the right balance of keeping what we've got now and adding a few more
> features.
I understand your point. Exactly which features are you looking for,
again? Only variable substitution? Anything else? If the majority
of users who want new scorefile functionality agree with your
preferred set of features, then I would concur with you. However, if
there is significant disagreement about the feature set among those
who want extra scorefile functions, I would then vote for slang
scripting capability in this area.
--
Lloyd Zusman
ljz@asfast.com
Re: [slrn] Variables in scorefile?
Author: Jan Hlavacek
Date: Mon, 13 Oct 1997 00:00
Date: Mon, 13 Oct 1997 00:00
80 lines
3751 bytes
3751 bytes
On 13 Oct 1997 05:34:39 GMT, Lloyd Zusman <ljz@asfast.com> wrote:
> On 13 Oct 1997 03:15:32 GMT, J.B. Nicholson-Owens <jbn@pop-a-wheelie.midwest.net> wrote:
> > Lloyd Zusman <ljz@asfast.com> wrote:
> > > Perhaps most of the infrastructure for something like this is already
> > > in place in slrn ... ???
> >
> > [ ... ]
> >
> > But getting back to the functional solution you've suggested, if we assume
> > that the functions are evaluated in the order they were set, converting
> > one's flatfile to a functional equivalent is a considerable job for people
> > with large scorefiles. [ ... ]
>
> A script to convert a conventional scorefile to a slang script containing
> its functional equivalant would be very easy to write, and this script
> could be supplied with the distribution of slrn.
>
>
> > [ ... ] Also, it's not clear how this would handle complex
> > logical statements any differently than the current scorefile -- I think one
> > might want a language with S-Lang's capabilities to handle complex
> > arrangements of tests to determine a score. [ ... ]
>
> Something like this would do that just fine:
>
> variable score = 1000;
>
> if (header("Subject") == "Free Money!" ||
> header("Subject") == "Ponzi scheme!") {
> score = -9999;
> }
> else if (lines() < 50000) {
> score = 100;
> }
> else if (matches(newsgroup(), "alt.spam.*")) {
> score = -100;
> }
>
> if (matches(newsgroup(), "alt.sex.*") {
> score = get_score("alt.animals.hippopotamuses");
> score -= 2000;
> }
>
> set_score(score);
>
> ... where header(), lines(), newsgroup(), matches(), get_score(), and
> set_score() are new functions that would be supplied with slrn. I'm
> sure that there would be a number of other new functions, as well.
>
You mean like current_newsgroup(), extract_article_header(),
get_header_score(), set_header_score()?
How about something like
define article_mode_hook ()
{
call ("bob");
while (header_down (1))
{
if (is_element (get_current_newsgroup (), GroupList1)
{
if (is_substr (extract_article_header ("Subject"), "blabla"))
{
score = get_header_score ();
score -= 1000;
set_header_score (score);
}
and so on?
lahvak
--
Jan Hlav\'{a}\v{c}ek <lahvak+n@math.ohio-state.edu> (BCC's will bounce)
home page: http://www.math.ohio-state.edu/~lahvak/
slrn page: http://www.math.ohio-state.edu/~lahvak/software/slrn.html
slrn documentation: http://www.math.ohio-state.edu/~lahvak/software/slrn/
Re: [slrn] Variables in scorefile?
Author: Lloyd Zusman
Date: Mon, 13 Oct 1997 00:00
Date: Mon, 13 Oct 1997 00:00
51 lines
2533 bytes
2533 bytes
On 13 Oct 1997 05:58:35 GMT, Jan Hlavacek <lahvak+n@math.ohio-state.edu> wrote:
> On 13 Oct 1997 05:34:39 GMT, Lloyd Zusman <ljz@asfast.com> wrote:
> >
> > [ ... ]
> >
> > Something like this would do that just fine:
> >
> > [ ... example deleted to save space ... ]
> >
> > ... where header(), lines(), newsgroup(), matches(), get_score(), and
> > set_score() are new functions that would be supplied with slrn. I'm
> > sure that there would be a number of other new functions, as well.
> >
>
> You mean like current_newsgroup(), extract_article_header(),
> get_header_score(), set_header_score()?
Yes ... I wasn't sure if all these existed already.
> How about something like
>
> define article_mode_hook ()
> {
> call ("bob");
> while (header_down (1))
> {
> if (is_element (get_current_newsgroup (), GroupList1)
> {
> if (is_substr (extract_article_header ("Subject"), "blabla"))
> {
> score = get_header_score ();
> score -= 1000;
> set_header_score (score);
> }
>
> and so on?
Yes. Exactly.
Over the next few days, I'll write something in Perl which reads a
score file and produces something like this as output. Since I don't
use article scoring, could someone email me a fairly extensive (and
correct!) score file that I could use as input during testing?
--
Lloyd Zusman
ljz@asfast.com
Re: [slrn] Variables in scorefile?
Author: Lloyd Zusman
Date: Tue, 14 Oct 1997 00:00
Date: Tue, 14 Oct 1997 00:00
77 lines
4899 bytes
4899 bytes
On 13 Oct 1997 17:05:36 GMT, J.B. Nicholson-Owens <jbn@pop-a-wheelie.midwest.net> wrote: > Jan Hlavacek <lahvak+n@math.ohio-state.edu> wrote: > > [ ... ] > > Are we settling for using the S-Lang slrn API as shipped with slrn (looping > over the articles, calculating and applying scores manually)? If so, I > think my earlier point about raising the resource requirements resurfaces; > perl is huge compared to S-Lang and slrn and seems to me like a LOT to ask > of someone to get the increase in functionality that would come with > scorefile variables or scorefile functions. First of all, the Perl thing I'm working on should only have to be run once by each user who wants to convert an existing score file into a group of slang functions. After that, he or she would work within the slang functions and forget about the score file. And furthermore, I presume that this would only be done by people who want the added functionality that the slang functions would provide. If someone only wanted the original score file functionality, there would be no advantage to converting to the slang-function method, and the repeated conversion costs would ensure that this approach would be a detriment for such users. I agree that scorefile variables alone would be a suitable, lightweight mechanism to enhance scorefile functionality. However, I'm not so sure that adding scorefile functions would be much different than using the slang-function approach in terms of overhead and complexity, and it would add a second scripting language when slang is already quite nicely usable and powerful. > I'm not altogether clear on exactly how this scoring API would look like. > I've seen two approaches, one that abstracts the current slrn S-Lang API > slightly and one that does not. Which way was this going? The one I'm working on implements the method which uses the current S-Lang API. In addition, I'll be writing slang convenience functions which would be used to make the logic more simple and readable. If this method catches on, these convenience functions could later be implemented in C in the slrn engine to further speed up this scoring process. You'll see my preliminary results by next weekend, I hope. > Also, by using such an approach some of the current scoring niceties go > away: progress meter (telling you how far scoring has proceeded), working on > the internal representation of articles instead of going through the UI (I > wonder if this will be significantly slower), losing the elegance of the > slrn scorefile (and gaining functionality� so far nobody has asked for). Is > there any hope of getting such a thing shipped with slrn or made a part of > the official slrn (as opposed to an elaborate macro)? Yes. It's true that most of these features would indeed go away. However, if the convenience functions I write ever end up being implemented in C, most of these scoring niceties could return. > I appreciate the effort being put into this project, but I wonder if it's > wise (and I wouldn't mind seeing an API before coding). Most of the > problems I mentioned can be coded into a macro, but is it worth reinventing > the wheel to get this functional enhancement? What I will initially deliver will be a usable API and a Perl script to convert existing score files into the appropriate slang code. This will be a good starting point for discussion. I'm not sure if what I'm doing is really worthwhile or not. If it turns out to be undesirable, then I'll still have a lot of fun, and all I'll lose is a little time. I'm mostly doing this to provide something that would stimulate discussion, debate, and perhaps some new ideas. -- Lloyd Zusman ljz@asfast.com
Re: [slrn] Variables in scorefile?
Author: Christopher B. Browne
Date: Tue, 14 Oct 1997 00:00
Date: Tue, 14 Oct 1997 00:00
57 lines
3755 bytes
3755 bytes
On 14 Oct 1997 03:24:41 GMT, Lloyd Zusman <ljz@asfast.com> posted: >First of all, the Perl thing I'm working on should only have to be run >once by each user who wants to convert an existing score file into a >group of slang functions. After that, he or she would work within the >slang functions and forget about the score file. And furthermore, I >presume that this would only be done by people who want the added >functionality that the slang functions would provide. If someone only >wanted the original score file functionality, there would be no >advantage to converting to the slang-function method, and the repeated >conversion costs would ensure that this approach would be a detriment >for such users. Dumb comment; is it known how the change will affect memory consumption? For a while, I was running SLRN with some "hacks" that made it emit new score rules for every article, based on whether I: a) Read the message, or b) Replied to/Followed up the message, or c) Deleted without reading, with rules giving small positive scores, large positive scores, and small negative scores, respectively. It was all well and good at improving the "score classifications," as boring authors and subjects would get marked down, and the interesting ones would get improved scores. The *problem* with it was twofold: a) The huge lists of rules that resulted chewed up a lot of RAM, and b) The rules got loaded/unloaded upon changing groups, which meant that a lot of work was done loading 'em. The memory footprint of a 1MB score file seemed to be on the order of 8-10MB, which is *not* a good thing. I would guess that if the "rules" are treated as SLANG functions, they'll get loaded in once when slrn is invoked, which lets you avoid "situation b)." But if the rules expand in memory consumption in "function" form from what's consumed by score rules presently, some definite breakage results... I would argue that an improved interface to scoring would involve creating a program outside and separate from SLRN that simply manages score rules. Most logically, it would implement the "SNSP" (Simple News Scoring Protocol) and run as a daemon. By so doing, there's the potential of allowing this to work with other news readers. "Multiple adoption" would be a good thing... -- Christopher B. Browne, cbbrowne@hex.net, chris_browne@sdt.com PGP Fingerprint: 10 5A 20 3C 39 5A D3 12 D9 54 26 22 FF 1F E9 16 URL: <http://www.hex.net/~cbbrowne/> Bill Gates to his broker: "You idiot, I said $150 million on **SNAPPLE**!!!"
Re: [slrn] Variables in scorefile?
Author: Christopher B. Browne
Date: Wed, 15 Oct 1997 00:00
Date: Wed, 15 Oct 1997 00:00
26 lines
2329 bytes
2329 bytes
On 15 Oct 1997 03:59:34 GMT, Lloyd Zusman <ljz@asfast.com> posted: >On 14 Oct 1997 13:12:06 GMT, Christopher B. Browne <cbbrowne@news.brownes.org> wrote: >> I would argue that an improved interface to scoring would involve creating >> a program outside and separate from SLRN that simply manages score rules. >> Most logically, it would implement the "SNSP" (Simple News Scoring >> Protocol) and run as a daemon. By so doing, there's the potential of >> allowing this to work with other news readers. "Multiple adoption" >> would be a good thing... >Yes, this is indeed another good potential solution. Is there any >documentation on SNSP? No. :-) I'm speaking of a protocol and "wishing it exists." The nearest thing that exists is Tim Pierce's "Modular Scoring" system. Which it appears you're aware of. -- Christopher B. Browne, cbbrowne@hex.net, chris_browne@sdt.com PGP Fingerprint: 10 5A 20 3C 39 5A D3 12 D9 54 26 22 FF 1F E9 16 URL: <http://www.hex.net/~cbbrowne/> Bill Gates to his broker: "You idiot, I said $150 million on **SNAPPLE**!!!"
Re: [slrn] Variables in scorefile?
Author: Lloyd Zusman
Date: Wed, 15 Oct 1997 00:00
Date: Wed, 15 Oct 1997 00:00
38 lines
2750 bytes
2750 bytes
On 14 Oct 1997 13:12:06 GMT, Christopher B. Browne <cbbrowne@news.brownes.org> wrote: > On 14 Oct 1997 03:24:41 GMT, Lloyd Zusman <ljz@asfast.com> posted: > >First of all, the Perl thing I'm working on should only have to be run > >once by each user who wants to convert an existing score file into a > >group of slang functions. After that, he or she would work within the > >slang functions and forget about the score file. And furthermore, I > >presume that this would only be done by people who want the added > >functionality that the slang functions would provide. If someone only > >wanted the original score file functionality, there would be no > >advantage to converting to the slang-function method, and the repeated > >conversion costs would ensure that this approach would be a detriment > >for such users. > > Dumb comment; is it known how the change will affect memory > consumption? Not yet. I'm hoping that once I have this thing working, I and others can benchmark it. > [ ... ] > > I would argue that an improved interface to scoring would involve creating > a program outside and separate from SLRN that simply manages score rules. > Most logically, it would implement the "SNSP" (Simple News Scoring > Protocol) and run as a daemon. By so doing, there's the potential of > allowing this to work with other news readers. "Multiple adoption" > would be a good thing... Yes, this is indeed another good potential solution. Is there any documentation on SNSP? -- Lloyd Zusman ljz@asfast.com
[slrn] Generator for an S-Lang-based scoring mechanism (2 of 2)
Author: l... Lloyd Zusman
Date: Fri, 17 Oct 1997 00:00
Date: Fri, 17 Oct 1997 00:00
31 lines
2203 bytes
2203 bytes
[ Posted to news.software.readers and alt.lang.s-lang, but followups set to news.software.readers. ] Well, I finished my first cut at 'scoregen', a Perl script which generates an S-Lang-based scoring routine which can be used as a replacement for the standard Slrn score file. I did some preliminary testing of this, and it seems to work fine. I'm posting it here for discussion and feedback, as well as to make it available to all of you who might find it useful or interesting. I enclosed the first section of the scoregen README file at the end of the previous message. In this message, I've enclosed the uuencoded, gzipped tar file of the package. Before running scoregen, you should read the complete README file and carefully study the sample input and output that I enclosed. I'm looking forward to your feedback. -- Lloyd Zusman l...@asfast.com ==================== uuencoded, gzipped tar file ==================== begin 664 scoregen.tar.gz <encoded_portion_removed> end
[slrn] Generator for an S-Lang-based scoring mechanism (1 of 2)
Author: l... Lloyd Zusman
Date: Fri, 17 Oct 1997 00:00
Date: Fri, 17 Oct 1997 00:00
128 lines
6843 bytes
6843 bytes
[ Posted to news.software.readers and alt.lang.s-lang, but
followups set to news.software.readers. ]
Well, I finished my first cut at 'scoregen', a Perl script which
generates an S-Lang-based scoring routine which can be used as a
replacement for the standard Slrn score file. I did some preliminary
testing of this, and it seems to work fine.
I'm posting it here for discussion and feedback, as well as to make it
available to all of you who might find it useful or interesting.
I'm enclosing the first section of the scoregen README file at the end
of this message. I'm posting a second message containing the
uuencoded, gzipped tar file of the package. Before running scoregen,
you should read the complete README file and carefully study the
sample input and output that I enclosed.
I'm looking forward to your feedback.
--
Lloyd Zusman
l...@asfast.com
====================== first part of README file ======================
scoregen -- Generate S-Lang scoring routines from an Slrn score file
--------------------------------------------------------------------
Version 0.01
Lloyd Zusman <l...@asfast.com>
1997/10/17
IMPORTANT NOTE: PLEASE READ ALL OF THIS BEFORE USING THIS SOFTWARE
BACKGROUND
----------
This is scoregen, a Perl script that reads an Slrn score file as input
and uses it to produce a group of S-Lang routines which perform the
same scoring functions.
The idea for scoregen came to me during a recent discussion in
news.software.readers among some of us Slrn aficionados. One of us,
J.B. Nicholson-Owens <j...@pop-a-wheelie.midwest.net>, was suggesting
that Slrn's score-file processing be enhanced with variable expansion
and perhaps some simple functional processing.
During the ensuing debate, it occurred to some of us that this
functionality and a lot more could be had simply by doing the scoring
from within S-Lang instead of via the standard score file.
Some objections to this idea were raised, and most of them hinged
around the fact that it would be complicated and time-consuming to
manually construct the S-Lang from an existing score file, especially
one which is large. It was then that I conceived of the current form
of scoregen.
Scoregen answers these objections because it automatically generates
the appropriate S-Lang code by reading a standard score file. Once
this code is generated, the resulting S-Lang scoring routine can then
be easily modified by hand whenever new scoring logic is desired.
The following point is important, and so I'm putting it in caps:
SCOREGEN IS ONLY INTENDED TO BE USED ONCE PER SCORE FILE
In other words, the recommended use of scoregen is for you to feed
your score file through it once and only once, and then to stop using
your score file. From then on, you should use the resulting S-Lang
routines to do your article scoring, and you should modify the
S-Lang code directly if you want to make any changes.
The reason that I recommend this is that the resulting S-Lang-based
scoring routines will by necessity run a bit slower than the
optimized, compiled C routines that currently do scoring. The only
advantage in using the resulting S-Lang-based routines is so that you
can easily add variable substitution and functional processing during
scoring. If you don't want these added features, stick to your
standard score file and forget about scoregen.
Of course, if S-Lang-based scoring catches on, it can be speeded up
quite a bit if some new Slrn intrinsics would be defined. I discuss
this topic in more detail below.
Scoregen generates the following routines:
score_article() This routine scores each article. It's
what gets generated from your score file,
and its structure is pretty much parallel
to that of your score file.
do_scoring() This routine loops through all the articles
in a newsgroup, calling score_article()
on each one. It's designed to be invoked
from within article_mode_hook. Alternatively,
the name of this routine can be changed to
"article_mode_hook", and it'll work just
fine in this capacity.
convenience routines The above two routines make use of a few
convenience routines that I wrote to
simplify the S-Lang-based scoring
procedure. These convenience routines are
also generated by scoregen.
Some of the convenience routines I wrote are direct recodings of C
routines that exist in the S-Lang source code. These routines are
good candidates for intrinsics. The other convenience functions can
also be made into intrinsics if this is deemed useful. The
S-Lang-based scoring would probably be speeded noticeably if these
routines were to be made into intrinsics (at least for large score
files). After some discussion, feedback, and inevitable retooling,
I'm quite willing to do the work to create these intrinsics for a
future version of S-Lang.
Note that one major purpose of scoregen is to stimulate discussion and
debate about S-Lang-based scoring. Although I spent some time trying
to optimize scoregen and make it useful, I do not consider it the
"be-all and the end-all". I'm hoping that through our discussion, we
Slrn lovers can come up with the best and most useful approaches to
scoring.
Re: [slrn] Generator for an S-Lang-based scoring mechanism (2 of 2)
Author: l... Lloyd Zusman
Date: Sat, 18 Oct 1997 00:00
Date: Sat, 18 Oct 1997 00:00
728 lines
19105 bytes
19105 bytes
[ Posted to news.software.readers and alt.lang.s-lang, but
followups set to news.software.readers. ]
My thanks to Hubert Canon <Huber...@irisa.fr> for pointing
out a parsing bug in my initial relase of scoregen. Enclosed
is a newer version of this program with this bug fixed.
There will be another release with some newer functionality coming
in a day or so.
--
Lloyd Zusman
l...@asfast.com
============================ scoregen-0.02 ============================
#!/usr/bin/perl
# This routine generates some S-Lang routines which do the same thing
# as specified in an Slrn score file.
#
# This routine must be run under Perl version 5.000 or later.
#
# Here's how to invoke it:
#
# scoregen [ Slrn-score-file [ S-Lang-output-file ] ]
#
# If S-Lang-output-file is missing, output goes to STDOUT.
# If Slrn-score-file is missing, input comes from STDIN.
#
#
# Version 0.02 -- Fixed bug in keyword matching.
# Treats initial missing newsgroups as all newsgroups.
# Put andelse/orelse processing in newsgroup matches.
#
# October 17, 1997
# Lloyd Zusman <l...@asfast.com>
#
#
# Version 0.01 -- Initial version
#
# October 17, 1997
# Lloyd Zusman <l...@asfast.com>
# This sets '$program' to the base name of argv0.
($program = $0) =~ s|^.*/||;
# Get the command-line arguments and process them.
$infile = shift(@ARGV);
$outfile = shift(@ARGV);
unless (defined($infile)) {
$inName = 'STDIN';
$outName = '';
$originalScoreFile = "that was piped in via $inName";
open(IN, "<&STDIN");
open(OUT, ">&STDOUT");
}
else {
unless (open(IN, "<$infile")) {
die "$program: unable to open input file: $infile\n";
}
$inName = $infile;
$originalScoreFile = "'$inName'";
if (defined($outfile)) {
unless (open(OUT, ">$outfile")) {
close(IN);
die "$program: unable to open output file: $outfile\n";
}
$outName = $outfile;
}
else {
open(OUT, ">&STDOUT");
undef($finalMessage);
$outName = '';
}
}
# Read all the input into the @inputLines array.
@inputLines = <IN>;
close(IN);
# Initialize some variables.
undef($currentGroups);
undef(@currentGroupList);
undef($inScore);
undef($inGroup);
undef($currentScore);
undef($currentExpires);
undef($out);
undef($orType);
undef(@headerInfo);
undef(%headerVar);
# Process the input.
$allGroupsFlag = ']['; # special code for all groups
$currentGroups = $allGroupsFlag;
@currentGroupList = ( $currentGroups );
foreach $inLine (@inputLines) {
chomp($line = $inLine);
# Skip comment lines as per the same rule in score.c
if ($line =~ m|^\s*[%#\000-\037]|) {
next;
}
# A newsgroup line?
if ($line =~ m|^\s*\[(\s*~)?\s*([^\[\]]*)\]\s*$|) {
# We found a [ group ... ] line.
$negation = $1;
$groups = $2;
scoreProcessing();
($currentGroups = $groups) =~ s|\s||g;
@currentGroupList = split(/,/, $currentGroups);
# Start processing this new set of group information.
undef($inScore);
undef($currentScore);
undef($currentExpires);
undef($orType);
undef(@headerInfo);
}
else {
# We found a potential score set.
if ($line =~ m|^(.+?):(:)?([^:].*)$|) {
$item = $1;
$extraColon = $2;
$value = $3;
$item =~ s|\s||g;
$value =~ s|^\s*(.*$)\s*$|$1|;
if ($item =~ m|^score$|i) {
# This is a Score: or a Score:: line
scoreProcessing();
undef($currentExpires);
undef(@headerInfo);
$orType = ($extraColon eq ':');
$currentScore = $value;
$inScore = 1;
}
elsif ($item =~ m|^expires$|i) {
# This is an Expires: line
$currentExpires = $value;
}
else {
# This is a header matching line.
if ($item =~ m|^(~)(.*)$|) {
$separator = $1;
$itemToken = $2;
}
else {
$separator = ':'; # use ':' as a flag when no negation
$itemToken = $item;
}
# Store the header info.
my $itemToken = ucfirst(lc($itemToken));
push(@headerInfo, "$itemToken$separator$value");
$headerVar{$itemToken} = $itemToken;
}
}
}
}
# We've processed all the lines from the original score file. Now,
# process the final score set and finish processing the final group
# information.
scoreProcessing();
if ($inGroup) {
endGroupProcessing();
}
# The '$out' variable now contains the generated S-Lang logic. Write
# it out after some initialization stuff, and then finish off with
# some termination code.
print OUT initialization();
print OUT $out;
print OUT termination();
close(OUT);
# OK. We're done.
if ($outName ne '') {
print "Success: $inName -> $outName\n";
}
exit(0);
# This routine outputs the stuff that goes at the head of the set
# of generated S-Lang routines.
sub initialization {
my $key = '';
my $result = '';
my $first = "\n";
my $now = dateTime();
$result .= <<EOD;
% -*- mode: slang; mode: fold -*-
%
% Automatically generated on $now.
%
% This file consists of S-Lang code that was generated from
% the Slrn score file $originalScoreFile.
%
% The original score file contents now appear at the bottom
% of this generated file, commented out.
%
% Routines: convenience functions -- See below.
% score_article() -- Scores each individual article.
% Called repeatedly by do_scoring().
% do_scoring() -- Scores all your articles.
EOD
# This retrieves the convenience functions which are defined after
# the __END__ line, below.
$result .= join('', <DATA>);
$result .= <<EOD;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This routine was generated from the original score file. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This routine is meant to be called once for each article, and
% it does the actual scoring. This is the routine that was
% generated from your original score file, and it's what you
% should be modifying if you want to alter your scoring algorithm.
define score_article ( newsgroup, today )
{
% Note that this routine makes use of 'andelse', 'orelse',
% and other constructs that might be confusing if you aren't
% familiar with S-Lang. I did this for two reasons: (1) to
% ensure that this routine runs as efficiently as possible,
% and (2) to make it comparatively easy for me to write the
% program which automatically generates this code.
%
% Feel free to replace these constructs with those of your
% choosing when you begin to manually alter the scoring
% algorithms in this routine.
variable score = get_header_score();
variable originalScore = score;
EOD
foreach $key (sort keys %headerVar) {
my $firstPart = sprintf("$first variable header%-10s", $key);
if ($key =~ m|^lines$|i) {
$result .= "$firstPart = " .
"integer( extract_article_header( \"$key\" ) );\n";
}
else {
$result .= "$firstPart = " .
"extract_article_header( \"$key\" );\n";
}
$first = '';
}
return ($result);
}
# This routine outputs the stuff that needs to be written after
# all the S-Lang code has been generated.
sub termination {
my $result = '';
$result .= " if ( score != originalScore )\n";
$result .= " {\n";
$result .= " set_header_score( score );\n";
$result .= " }\n";
$result .= "}\n";
$result .= <<EOD;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of generated routine. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Routine for invoking score_article(). %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Either invoke this routine from within article_mode_hook, or
% else insert this routine's logic into article_mode_hook, or
% else rename this routine as 'article_mode_hook'.
% define article_mode_hook ()
define do_scoring ()
{
call( "header_bob" );
uncollapse_threads();
% Initialize these here and repeatedly pass them into
% score_article() so that current_newsgroup() and get_today()
% only need to be called once.
variable newsgroup = current_newsgroup();
variable today = get_today();
do
{
score_article( newsgroup, today );
} while ( header_down( 1 ) );
collapse_threads();
call( "header_bob" );
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of routine for invoking score_article(). %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Original contents of score file begin here. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
EOD
foreach $line (@inputLines) {
$result .= "%% $line";
}
$result .= <<EOD;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of original contents of score file. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
EOD
return ($result);
}
# This routine begins the processing of a new group line.
sub startGroupProcessing {
if ($inGroup) {
endGroupProcessing();
}
if ($currentGroups =~ m|^\s*$|) {
return;
}
my $negation = shift;
my $group;
my $operator;
my $separator;
my $comment = '';
$out .= "\n ";
if ($negation) {
$out .= '!';
}
$out .= "if ( ";
if ($currentGroups eq $allGroupsFlag) {
$out .= '1';
$comment = ' % special case for all newsgroups';
}
else {
$out .= "orelse";
foreach $group (@currentGroupList) {
$out .= "\n { pattern_match( newsgroup, \"$group\" ) }";
}
}
$out .= " )$comment\n";
$out .= " {\n";
$out .= " % The following 'loop' construct makes it easier to\n";
$out .= " % automatically generate the code for managing the\n";
$out .= " % \"Expires:\" tag and for handling the case for\n";
$out .= " % score = 9999 and -9999. Feel free to modify this\n";
$out .= " % somewhat awkward syntax.\n\n";
$out .= " loop ( 1 )\n";
$out .= " {";
$inGroup = 1;
undef($currentGroups);
undef(@currentGroupList);
}
# This routine ends the processing of group information.
sub endGroupProcessing {
$out .= " }\n";
$out .= " }\n\n";
undef($inGroup);
}
# This routine generates all the scoring logic.
sub scoreProcessing {
unless ($currentGroups =~ m|^\s*$|) {
startGroupProcessing();
}
my ($key, $thing, $value, $sep, $op, $neg, $boolean);
unless ($currentExpires =~ m|^\s*$|) {
$out .= "\n if ( today >= date_value( \"$currentExpires\" ) )\n";
$out .= " {\n";
$out .= " break;\n";
$out .= " }\n";
}
if ($currentScore =~ m|^\s*$|) {
return;
}
if (scalar(@headerInfo) < 1) {
$sep = "\n";
}
else {
$sep = ' ';
if ($orType) {
$boolean = 'orelse';
}
else {
$boolean = 'andelse';
}
$out .= "\n if ( $boolean";
foreach $thing (@headerInfo) {
unless ($thing =~ m|^(.*?)([~:])(.*)$|) {
next;
}
$key = $1;
$neg = $2;
$value = $3;
if ($neg eq '~') {
$op = '>=';
$neg = ' not (';
$end = ') ';
}
else {
$op = '<';
$neg = '';
$end = '';
}
$out .= "\n {";
if ($key =~ m|^lines$|i) {
$out .= " ( header$key $op $value ) }";
}
else {
$out .= "$neg string_match( header$key, \"$value\", 1 ) $end}";
}
}
$out .= " )\n {\n";
}
$currentScore =~ m|^\s*(=)?\s*(\S.*)\s*?$|;
my $operator = $1;
my $score = $2;
$score =~ s|[\+\s]||g;
if ($score <= -9999 || $score >= 9999) {
$out .= "$sep score = $score;\n";
$out .= "$sep break;\n";
}
else {
if ($operator eq '') {
if ($score < 0) {
$score = -$score;
$operator = '-=';
}
else {
$operator = '+=';
}
}
$out .= "$sep score $operator $score;\n";
}
unless ($sep =~ m|^\n|) {
$out .= " }\n";
}
undef($inScore);
}
sub dateTime {
my ($now) = shift;
$now += 0;
if ($now < 1) {
$now = time();
}
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
return (sprintf("%04d/%02d/%02d at %02d:%02d:%02d",
$year + 1900, $mon + 1, $mday, $hour, $min, $sec));
}
# In Perl, everything after an __END__ line is ignored by the
# interpreter, and it's readable as data via the DATA file handle.
# I make use of this to store the S-Lang code for the convenience
# functions that I'm including with the code that gets generated.
# Look in the 'initialization' routine, above, to see how I access
# this information.
__END__
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% These are the convenience functions that are used below. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function converts a newsgroup pattern into a proper regexp.
% It does this in the same manner as the slrn_fix_regexp()
% function in util.c. Therefore, this routine is a good candidate
% for replacement by a new intrinsic.
define fix_regexp ( pattern )
{
variable len = strlen( pattern );
variable regexp = "^";
variable i;
for ( i = 0; i < len; i++ )
{
if ( pattern[i] == '.' )
{
regexp = strcat( regexp, "\\" );
}
else if ( pattern[i] == '*' )
{
regexp = strcat(regexp, ".");
}
regexp = strcat( regexp, substr( pattern, i + 1, 1 ) );
}
regexp = strcat( regexp, "$" );
return ( regexp );
}
% Return today's date in a form usable in date comparisons. The
% value returned is in the same form as that which is returned by
% the get_today() function in score.c, and therefore, this routine
% is another good candidate for replacement by a new intrinsic.
define get_today ()
{
variable now = time();
variable month = extract_element( now, 1, " " );
variable day = extract_element( now, 2, " " );
variable year = extract_element( now, 4, " " );
if ( orelse
{ strlen( month ) < 1 }
{ strlen( day ) < 1 }
{ strlen( year ) < 1 } )
{
% Error!
return ( -1 );
}
variable match =
string_match( "JanFebMarAprMayJunJulAugSepOctNovDec", month, 1 );
if ( match < 1 )
{
% Error!
return (-1);
}
year = integer( year );
month = ( match - 1 ) / 3;
day = integer( day );
return ( ( year * 10000 ) + ( month * 100 ) + day );
}
% Convert a date into an integer form useful for comparisons
% (but not useful for date arithmetic). The value returned
% is in the same form as that which is used by the get_today()
% and has_score_expired() functions in score.c.
define date_value ( date )
{
variable month = extract_element( date, 0, "/" );
variable day = extract_element( date, 1, "/" );
variable year = extract_element( date, 2, "/" );
if ( orelse
{ strlen( month ) < 1 }
{ strlen( day ) < 1 }
{ strlen( year ) < 1 } )
{
month = extract_element( date, 0, "-" );
day = extract_element( date, 1, "-" );
year = extract_element( date, 2, "-" );
if ( orelse
{ strlen( month ) < 1 }
{ strlen( day ) < 1 }
{ strlen( year ) < 1 } )
{
% Error!
return ( -1 );
}
}
year = integer( year );
month = integer( month );
day = integer( day );
if ( orelse
{ year < 1900 }
{ month < 1 }
{ month > 12 }
{ day < 1 }
{ day > 31 } )
{
% Error!
return ( -1 );
}
return ( ( year * 10000 ) + ( ( month - 1 ) * 100 ) + day );
}
% This is a case-insensitive version of the string_match()
% function. It's used below in the pattern_match() routine,
% and it also can be used within score_article(), below,
% if case-insensitive scoring pattern matching is desired.
define string_match_nocase ( string, pattern, pos )
{
return ( string_match( strlow( string ), strlow( pattern ), pos ) );
}
% This routine does a newsgroup pattern match. It's used
% below in score_article() to match newsgroups. It also
% could be used there to do this same kind of pattern matching
% on the "Newsgroups:" line during scoring.
define pattern_match ( group, pattern )
{
return ( string_match_nocase( group, fix_regexp( pattern ), 1 ) );
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of convenience functions. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[slrn] A 'scoregen' enhancement.
Author: l... Lloyd Zusman
Date: Sun, 19 Oct 1997 00:00
Date: Sun, 19 Oct 1997 00:00
799 lines
21129 bytes
21129 bytes
[ Posted to news.software.readers and alt.lang.s-lang, but
followups set to news.software.readers. ]
Again, I give my thanks to Hubert Canon <Huber...@irisa.fr> for
suggesting a useful feature for 'scoregen': he asked that I enhance
this program so that comments that appear in the original score file
get propagated into the generated S-Lang code.
Enclosed is the latest version of scoregen (version 0.03) which
now propagates comments as requested.
Thanks in advance for any feedback you might have about this software.
--
Lloyd Zusman
l...@asfast.com
----------------------------- scoregen-0.03 -----------------------------
#!/usr/bin/perl
# This routine generates some S-Lang routines which do the same thing
# as specified in an Slrn score file.
#
# This routine must be run under Perl version 5.000 or later.
#
# Here's how to invoke it:
#
# scoregen [ Slrn-score-file [ S-Lang-output-file ] ]
#
# If S-Lang-output-file is missing, output goes to STDOUT.
# If Slrn-score-file is missing, input comes from STDIN.
#
#
# Version 0.03 -- October 19, 1997, Lloyd Zusman <l...@asfast.com>
# Changed format of these revision comments.
# Got rid of string_match_nocase(); now using \\C in pattern_match().
# Added call to do_scoring() governed by doScoring variable.
# Propagate comments from score file into generated code.
#
# Version 0.02 -- October 17, 1997, Lloyd Zusman <l...@asfast.com>
# Fixed bug in keyword matching.
# Treats initial missing newsgroups as all newsgroups.
# Put andelse/orelse processing in newsgroup matches.
#
# Version 0.01 -- October 17, 1997, Lloyd Zusman <l...@asfast.com>
# Initial version.
# This sets '$program' to the base name of argv0.
($program = $0) =~ s|^.*/||;
# Get the command-line arguments and process them.
$infile = shift(@ARGV);
$outfile = shift(@ARGV);
unless (defined($infile)) {
$inName = 'STDIN';
$outName = '';
$originalScoreFile = "that was piped in via $inName";
open(IN, "<&STDIN");
open(OUT, ">&STDOUT");
}
else {
unless (open(IN, "<$infile")) {
die "$program: unable to open input file: $infile\n";
}
$inName = $infile;
$originalScoreFile = "'$inName'";
if (defined($outfile)) {
unless (open(OUT, ">$outfile")) {
close(IN);
die "$program: unable to open output file: $outfile\n";
}
$outName = $outfile;
}
else {
open(OUT, ">&STDOUT");
undef($finalMessage);
$outName = '';
}
}
# Read all the input into the @inputLines array.
@inputLines = <IN>;
close(IN);
# Initialize some variables.
undef($currentGroups);
undef(@currentGroupList);
undef($inGroup);
undef($currentScore);
undef($currentExpires);
undef(@currentComments);
undef(@groupComments);
undef(@expiresComments);
undef(@scoreComments);
undef($out);
undef($orType);
undef(@headerInfo);
undef(%headerVar);
undef($groupFound);
# Process the input.
$allGroupsFlag = ']['; # special code for all groups
$currentGroups = $allGroupsFlag;
@currentGroupList = ( $currentGroups );
foreach $inLine (@inputLines) {
chomp($line = $inLine);
# Skip comment lines as per the same rule in score.c
if ($line =~ m|^\s*[%#\000-\037]|) {
push(@currentComments, $line);
next;
}
# A newsgroup line?
if ($line =~ m|^\s*\[(\s*~)?\s*([^\[\]]*)\]\s*$|) {
# We found a [ group ... ] line.
$negation = $1;
$groups = $2;
$groupFound = 1;
@groupComments = @currentComments;
undef(@currentComments);
scoreProcessing();
($currentGroups = $groups) =~ s|\s||g;
@currentGroupList = split(/,/, $currentGroups);
# Start processing this new set of group information.
undef($currentScore);
undef($currentExpires);
undef($orType);
undef(@headerInfo);
}
else {
# We found a potential score set.
if ($line =~ m|^(.+?):(:)?([^:].*)$|) {
$item = $1;
$extraColon = $2;
$value = $3;
$item =~ s|\s||g;
$value =~ s|^\s*(.*$)\s*$|$1|;
if ($item =~ m|^score$|i) {
# This is a Score: or a Score:: line
scoreProcessing();
undef($currentExpires);
undef(@headerInfo);
$orType = ($extraColon eq ':');
$currentScore = $value;
@scoreComments = @currentComments;
undef(@currentComments);
}
elsif ($item =~ m|^expires$|i) {
# This is an Expires: line
$currentExpires = $value;
@expiresComments = @currentComments;
undef(@currentComments);
}
else {
# This is a header matching line.
if ($item =~ m|^(~)(.*)$|) {
$separator = $1;
$itemToken = $2;
}
else {
$separator = ':'; # use ':' as a flag when no negation
$itemToken = $item;
}
# Store the header info.
my $itemToken = ucfirst(lc($itemToken));
my $commentString = join("\n", @currentComments);
undef(@currentComments);
my $headerStuff =
"\001$commentString\001$itemToken$separator$value";
push(@headerInfo, $headerStuff);
$headerVar{$itemToken} = $itemToken;
}
}
}
}
# We've processed all the lines from the original score file. Now,
# process the final score set and finish processing the final group
# information.
scoreProcessing();
if ($inGroup) {
endGroupProcessing();
}
# The '$out' variable now contains the generated S-Lang logic. Write
# it out after some initialization stuff, and then finish off with
# some termination code.
print OUT initialization();
print OUT $out;
print OUT termination();
close(OUT);
# OK. We're done.
if ($outName ne '') {
print "Success: $inName -> $outName\n";
}
exit(0);
# This routine outputs the stuff that goes at the head of the set
# of generated S-Lang routines.
sub initialization {
my $key = '';
my $result = '';
my $first = "\n";
my $now = dateTime();
$result .= <<EOD;
% -*- mode: slang; mode: fold -*-
%
% Automatically generated on $now.
%
% This file consists of S-Lang code that was generated from
% the Slrn score file $originalScoreFile.
%
% The original score file contents now appear at the bottom
% of this generated file, commented out.
%
% Routines: convenience functions -- See below.
% score_article() -- Scores each individual article.
% Called repeatedly by do_scoring().
% do_scoring() -- Scores all your articles.
EOD
# This retrieves the convenience functions which are defined after
# the __END__ line, below.
$result .= join('', <DATA>);
$result .= <<EOD;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This routine was generated from the original score file. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This routine is meant to be called once for each article, and
% it does the actual scoring. This is the routine that was
% generated from your original score file, and it's what you
% should be modifying if you want to alter your scoring algorithm.
define score_article ( newsgroup, today )
{
% Note that this routine makes use of 'andelse', 'orelse',
% and other constructs that might be confusing if you aren't
% familiar with S-Lang. I did this for two reasons: (1) to
% ensure that this routine runs as efficiently as possible,
% and (2) to make it comparatively easy for me to write the
% program which automatically generates this code.
%
% Feel free to replace these constructs with those of your
% choosing when you begin to manually alter the scoring
% algorithms in this routine.
variable score = get_header_score();
variable originalScore = score;
EOD
foreach $key (sort keys %headerVar) {
my $firstPart = sprintf("$first variable header%-10s", $key);
if ($key =~ m|^lines$|i) {
$result .= "$firstPart = " .
"integer( extract_article_header( \"$key\" ) );\n";
}
else {
$result .= "$firstPart = " .
"extract_article_header( \"$key\" );\n";
}
$first = '';
}
return ($result);
}
# This routine outputs the stuff that needs to be written after
# all the S-Lang code has been generated.
sub termination {
my $result = '';
my $comment;
if (scalar(@currentComments) > 0) {
foreach $comment (@currentComments) {
$comment =~ s|^[^%#\000-\037]+||;
$result .= " $comment\n";
}
$result .= "\n";
undef(@currentComments);
}
$result .= " if ( score != originalScore )\n";
$result .= " {\n";
$result .= " set_header_score( score );\n";
$result .= " }\n";
$result .= "}\n";
$result .= <<EOD;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of generated routine. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Routine for invoking score_article(). %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Either invoke this routine from within article_mode_hook, or
% else insert this routine's logic into article_mode_hook, or
% else rename this routine as 'article_mode_hook'.
% define article_mode_hook ()
define do_scoring ()
{
call( "header_bob" );
uncollapse_threads();
% Initialize these here and repeatedly pass them into
% score_article() so that current_newsgroup() and get_today()
% only need to be called once.
variable newsgroup = current_newsgroup();
variable today = get_today();
do
{
score_article( newsgroup, today );
} while ( header_down( 1 ) );
collapse_threads();
call( "header_bob" );
}
% If 'doScoring' is set as a global variable, automatically invoke
% the do_scoring() routine. This allows you to conditionally use
% evalfile() on this generated score file to do your scoring.
if (doScoring) {
do_scoring();
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of routine for invoking score_article(). %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Original contents of score file begin here. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%
EOD
foreach $line (@inputLines) {
$result .= "%% $line";
}
$result .= <<EOD;
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of original contents of score file. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
EOD
return ($result);
}
# This routine begins the processing of a new group line.
sub startGroupProcessing {
if ($inGroup) {
endGroupProcessing();
}
if ($currentGroups =~ m|^\s*$|) {
return;
}
my $negation = shift;
my $if = 'if';
my $group;
my $operator;
my $separator;
my $comment;
if (scalar(@groupComments) > 0) {
foreach $comment (@groupComments) {
$comment =~ s|^[^%#\000-\037]+||;
$out .= " $comment\n";
}
undef(@groupComments);
}
$out .= "\n ";
if ($negation) {
$out .= '!';
}
$out .= 'if ( ';
if ($currentGroups eq $allGroupsFlag) {
$out .= "1";
$comment = ' % special case for all newsgroups';
}
else {
$out .= "orelse";
foreach $group (@currentGroupList) {
$out .= "\n { pattern_match( newsgroup, \"$group\" ) }";
}
$comment = '';
}
$out .= " )$comment\n";
$out .= " {\n";
$out .= " % The following 'loop' construct makes it easier to\n";
$out .= " % automatically generate the code for managing the\n";
$out .= " % \"Expires:\" tag and for handling the case for\n";
$out .= " % score = 9999 and -9999. Feel free to modify this\n";
$out .= " % somewhat awkward syntax.\n\n";
$out .= " loop ( 1 )\n";
$out .= " {";
$inGroup = 1;
undef($currentGroups);
undef(@currentGroupList);
}
# This routine ends the processing of group information.
sub endGroupProcessing {
$out .= " }\n";
$out .= " }\n\n";
undef($inGroup);
}
# This routine generates all the scoring logic.
sub scoreProcessing {
unless ($currentGroups =~ m|^\s*$|) {
startGroupProcessing();
}
my ($first, $key, $thing, $value, $sep, $op, $neg, $boolean, $comment);
$first = "\n";
unless ($currentExpires =~ m|^\s*$|) {
if (scalar(@expiresComments) > 0) {
my $comment;
foreach $comment (@expiresComments) {
$comment =~ s|^[^%#\000-\037]+||;
$out .= "$first $comment\n";
$first = '';
}
undef(@expiresComments);
}
$out .= "$first if ( today >= date_value( \"$currentExpires\" ) )\n";
$out .= " {\n";
$out .= " break;\n";
$out .= " }\n";
}
if ($currentScore =~ m|^\s*$|) {
return;
}
if (scalar(@scoreComments) > 0) {
foreach $comment (@scoreComments) {
$comment =~ s|^[^%#\000-\037]+||;
$out .= "\n $comment";
}
undef(@scoreComments);
}
if (scalar(@headerInfo) < 1) {
$sep = "\n";
}
else {
$sep = ' ';
if ($orType) {
$boolean = 'orelse';
}
else {
$boolean = 'andelse';
}
$out .= "\n if ( $boolean";
foreach $thing (@headerInfo) {
unless ($thing =~ m#^\001(.*?)\001(.*?)([~:])(.*)$#s) {
next;
}
$comment = $1;
$key = $2;
$neg = $3;
$value = $4;
unless ($comment =~ m|^\s*$|) {
my $c;
foreach $c (split(/\n/, $comment)) {
$c =~ s|^[^%#\000-\037]+||;
$out .= "\n $c";
}
}
if ($neg eq '~') {
$op = '>=';
$neg = ' not (';
$end = ') ';
}
else {
$op = '<';
$neg = '';
$end = '';
}
$out .= "\n {";
if ($key =~ m|^lines$|i) {
$out .= " ( header$key $op $value ) }";
}
else {
$value =~ s|\\|\\\\|g;
$out .= "$neg string_match( header$key, \"$value\", 1 ) $end}";
}
}
$out .= " )\n {\n";
}
$currentScore =~ m|^\s*(=)?\s*(\S.*)\s*?$|;
my $operator = $1;
my $score = $2;
$score =~ s|[\+\s]||g;
if ($score <= -9999 || $score >= 9999) {
$out .= "$sep score = $score;\n";
$out .= "$sep break;\n";
}
else {
if ($operator eq '') {
if ($score < 0) {
$score = -$score;
$operator = '-=';
}
else {
$operator = '+=';
}
}
$out .= "$sep score $operator $score;\n";
}
unless ($sep =~ m|^\n|) {
$out .= " }\n";
}
}
sub dateTime {
my ($now) = shift;
$now += 0;
if ($now < 1) {
$now = time();
}
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now);
return (sprintf("%04d/%02d/%02d at %02d:%02d:%02d",
$year + 1900, $mon + 1, $mday, $hour, $min, $sec));
}
# In Perl, everything after an __END__ line is ignored by the
# interpreter, and it's readable as data via the DATA file handle.
# I make use of this to store the S-Lang code for the convenience
# functions that I'm including with the code that gets generated.
# Look in the 'initialization' routine, above, to see how I access
# this information.
__END__
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% These are the convenience functions that are used below. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This function converts a newsgroup pattern into a proper regexp.
% It does this in the same manner as the slrn_fix_regexp()
% function in util.c. Therefore, this routine is a good candidate
% for replacement by a new intrinsic.
define fix_regexp ( pattern )
{
variable len = strlen( pattern );
variable regexp = "^";
variable i;
for ( i = 0; i < len; i++ )
{
if ( pattern[i] == '.' )
{
regexp = strcat( regexp, "\\" );
}
else if ( pattern[i] == '*' )
{
regexp = strcat(regexp, ".");
}
regexp = strcat( regexp, substr( pattern, i + 1, 1 ) );
}
regexp = strcat( regexp, "$" );
return ( regexp );
}
% Return today's date in a form usable in date comparisons. The
% value returned is in the same form as that which is returned by
% the get_today() function in score.c, and therefore, this routine
% is another good candidate for replacement by a new intrinsic.
define get_today ()
{
variable now = time();
variable month = extract_element( now, 1, " " );
variable day = extract_element( now, 2, " " );
variable year = extract_element( now, 4, " " );
if ( orelse
{ strlen( month ) < 1 }
{ strlen( day ) < 1 }
{ strlen( year ) < 1 } )
{
% Error!
return ( -1 );
}
variable match =
string_match( "JanFebMarAprMayJunJulAugSepOctNovDec", month, 1 );
if ( match < 1 )
{
% Error!
return (-1);
}
year = integer( year );
month = ( match - 1 ) / 3;
day = integer( day );
return ( ( year * 10000 ) + ( month * 100 ) + day );
}
% Convert a date into an integer form useful for comparisons
% (but not useful for date arithmetic). The value returned
% is in the same form as that which is used by the get_today()
% and has_score_expired() functions in score.c.
define date_value ( date )
{
variable month = extract_element( date, 0, "/" );
variable day = extract_element( date, 1, "/" );
variable year = extract_element( date, 2, "/" );
if ( orelse
{ strlen( month ) < 1 }
{ strlen( day ) < 1 }
{ strlen( year ) < 1 } )
{
month = extract_element( date, 0, "-" );
day = extract_element( date, 1, "-" );
year = extract_element( date, 2, "-" );
if ( orelse
{ strlen( month ) < 1 }
{ strlen( day ) < 1 }
{ strlen( year ) < 1 } )
{
% Error!
return ( -1 );
}
}
year = integer( year );
month = integer( month );
day = integer( day );
if ( orelse
{ year < 1900 }
{ month < 1 }
{ month > 12 }
{ day < 1 }
{ day > 31 } )
{
% Error!
return ( -1 );
}
return ( ( year * 10000 ) + ( ( month - 1 ) * 100 ) + day );
}
% This routine does a newsgroup pattern match. It's used
% below in score_article() to match newsgroups. It also
% could be used there to do this same kind of pattern matching
% on the "Newsgroups:" line during scoring.
define pattern_match ( group, pattern )
{
return ( string_match( group, fix_regexp( strcat( "\\C", pattern ) ), 1 ) );
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% End of convenience functions. %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads