Changeset 5703 for platform/tdiary/lib

Show
Ignore:
Timestamp:
01/28/08 20:10:16 (10 months ago)
Author:
drry
Message:

platform/tdiary/lib/bayes.rb: use URI.regexp() for URL detection. fixed some regexps.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • platform/tdiary/lib/bayes.rb

    r5509 r5703  
    33 
    44require "pstore" 
     5require "uri" 
    56 
    67module Bayes 
     
    8485 
    8586                                h = host 
    86                                 while /^(.*?)[\.\-_](.*)$/=~h 
     87                                while /^(.*?)[._-](.*)$/=~h 
    8788                                        h = $2 
    8889                                        push($1, prefix) 
     
    9495 
    9596                def add_url(url, prefix=nil) 
    96                         if %r[^(?:https?|ftp)://(.*?)(?::\d+)?/(.*?)\/?(\?.*)?$] =~ url 
    97                                 host = $1 
    98                                 path = $2 
     97                        if URI.regexp(%w[http https ftp]) === url 
     98                                url  = URI.parse url 
     99                                host = url.host                       # $4 
     100                                path = url.path.gsub(%r{^/+|/+$}, '') # $7 
    99101 
    100102                                add_host(host, prefix) 
     
    104106 
    105107                                        p = path 
    106                                         re = %r[^(.*)[/\-\._](.*?)$] 
     108                                        re = %r[^(.*)[/._-](.*?)$] 
    107109                                        while re=~p 
    108110                                                p = $1