Minor change to oclc lookup heuristic.
[quanlib.git] / classify / lookup.rb
index 1fa5faaa9dc6f948610960644f194af496b4fc0c..889db51f48783dce8ca4ce469bb5f0bbee68d6b3 100644 (file)
@@ -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)