X-Git-Url: http://jaekl.net/gitweb/?p=quanlib.git;a=blobdiff_plain;f=classify%2Flookup.rb;h=889db51f48783dce8ca4ce469bb5f0bbee68d6b3;hp=1fa5faaa9dc6f948610960644f194af496b4fc0c;hb=952e15e8397db7ca1aad1f71e66f529b31cb75ce;hpb=2891b7126f522211f6d38f1ea3f684ffefb27b94 diff --git a/classify/lookup.rb b/classify/lookup.rb index 1fa5faa..889db51 100644 --- a/classify/lookup.rb +++ b/classify/lookup.rb @@ -37,10 +37,10 @@ class Lookup return /[[:upper:]]/.match(c) end - def lookup(author_grouping, title) + def lookup(author_grouping, pathname) params = [ ['author', massage_author(author_grouping)], - ['title', massage_title(title)] + ['title', massage_title(pathname)] ] cmd = construct_url(params) @@ -64,6 +64,9 @@ class Lookup end if "2" != response_code(doc) + # Lookup failed. Let's try shortening the title, if it's in multiple parts + + #TODO TODO puts "Lookup failed" return nil end @@ -124,18 +127,12 @@ class Lookup def massage_title(pathname) basename = File.basename(pathname, '.*') - result = "" - basename.each_char do |c| - if '_' == c - result += ' ' - elsif '-' == c - result += "'" - else - result += c - end - end + basename.gsub!('_', ' ') + basename.gsub!('--', ': ') + basename.gsub!('-s ', "'s ") + basename.gsub!('s- ', "s' ") - return result + return basename end def response_code(doc)