class Bayes::TokenList

Attributes

charset[R]

Public Class Methods

new(charset=nil) click to toggle source
# File lib/bayes.rb, line 47
def initialize(charset=nil)
        unless charset
                charset =
                        case $KCODE
                        when /^e/i
                                CHARSET::EUC
                        else
                                CHARSET::UTF8
                        end
        end
        @charset = charset
end

Public Instance Methods

_concat(array, prefix=nil)
Alias for: concat
_push(item, prefix=nil)
Alias for: push
add_host(host, prefix=nil) click to toggle source
# File lib/bayes.rb, line 78
def add_host(host, prefix=nil)
        if /^(?:\d{1,3}\.){3}\d{1,3}$/ =~ host
                while host.size>0
                        push(host, prefix)
                        host = host[/^(.*?)\.?\d+$/, 1]
                end
        else
                push(host, prefix)

                h = host
                while /^(.*?)[-_.](.*)$/=~h
                        h = $2
                        push($1, prefix)
                        push(h, prefix)
                end
        end
        self
end
add_mail_addr(addr, prefix=nil) click to toggle source
# File lib/bayes.rb, line 123
def add_mail_addr(addr, prefix=nil)
        push(addr, prefix)

        name, host = addr.split(/@/)
        return self if (name||"").empty?
        host ||= ""
        push(name, prefix)
        add_host(host, prefix)
        self
end
add_message(message, prefix=nil) click to toggle source
# File lib/bayes.rb, line 118
def add_message(message, prefix=nil)
        concat(message.scan(@charset::RE_MESSAGE_TOKEN), prefix)
        self
end
add_url(url, prefix=nil) click to toggle source
# File lib/bayes.rb, line 97
def add_url(url, prefix=nil)
        if %r[^(?:https?|ftp)://(.*?)(?::\d+)?/(.*?)\/?(\?.*)?$] =~ url
                host, path = $1, $2

                add_host(host, prefix)

                if path.size>0
                        push(path, prefix)

                        p = path
                        re = %r[^(.*)[-_./](.*?)$]
                        while re=~p
                                p = $1
                                push($2, prefix)
                                push(p, prefix)
                        end
                end
        end
        self
end
concat(array, prefix=nil) click to toggle source
# File lib/bayes.rb, line 61
def concat(array, prefix=nil)
        if prefix
                _concat(array.map{|i| "#{prefix} #{i.to_s}"})
        else
                _concat(array)
        end
end
Also aliased as: _concat
push(item, prefix=nil) click to toggle source
# File lib/bayes.rb, line 70
def push(item, prefix=nil)
        if prefix
                _push("#{prefix} #{item.to_s}")
        else
                _push(item)
        end
end
Also aliased as: _push