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)
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
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)
first = false
elsif row.length >= 2
author_grouping = row[0]
- title = row[1]
+ pathname = row[1]
- info = classset.get(author_grouping, title)
+ info = classset.get(author_grouping, pathname)
if nil == info
query_count += 1
- info = lookup.lookup(author_grouping, title)
+ info = lookup.lookup(author_grouping, pathname)
+
puts info.inspect()
puts 'Saving state...'
if nil != info
classset.ensure_contains!(info)
else
- puts 'WARNING: lookup of ' + author_grouping + ', "' + title + '" failed.'
+ puts 'WARNING: lookup of ' + author_grouping + ', "' + pathname + '" failed.'
File.open('failed.log', 'a:UTF-8') do |fd|
- fd.puts(author_grouping.to_s + ',' + title.to_s)
+ fd.puts(author_grouping.to_s + ',' + pathname.to_s)
end
end