Corpus Scripting Sample

Summary: Demonstrates how to control SpamSieve’s corpus using AppleScript.
Requires: SpamSieve
Install Location: ~/Library/Scripts/SpamSieve Scripts/
Last Modified: 2013-10-23

Description

This script demonstrates how to control SpamSieve’s corpus using AppleScript.

The order of the words in the corpus is undefined, so to save a particular word you should remember its string, not its index.

Using get every word (and other operations on very large numbers of words) will not work, because AppleScript runs out of memory. (There are typically 100,000 words in SpamSieve’s corpus.)

Installation Instructions · Download in Compiled Format · Download in Text Format

Script

tell application "SpamSieve"
    
tell current corpus
        
        
-- log the basic properties
        
log {"Corpus File:", file as string}
        
log {"Spam Messages:", spam message count as integer}
        
log {"Good Messages:", good message count as integer}
        
        
-- log all the words
        
set n to count words
        
repeat with i from 1 to n
            
log word i as string
        
end repeat
        
        
-- If you know a word, you can view or edit its information
        
-- by looking up the token info with its name. For instance:
        
set t to token info "foo"
        
        
-- double the spam count
        
set spam count of t to (2 * (t's spam count))
        
        
-- remove it from the corpus
        
set spam count of t to 0
        
set good count of t to 0
        
        
-- add a new word
        
set good count of token info "hammy" to 1
    
end tell
end tell