11 @class_set = ClassSet.new()
12 @fast_set = FastSet.new()
15 def construct_url(params)
17 cmd = 'http://classify.oclc.org/classify2/Classify'
19 params += [ ['summary', 'false' ] ]
21 params.each do |tuple|
30 cmd += ERB::Util.url_encode(value)
37 return /[[:upper:]]/.match(c)
40 def lookup(author_grouping, title)
42 ['author', massage_author(author_grouping)],
43 ['title', massage_title(title)]
46 cmd = construct_url(params)
47 res = submit_request(cmd)
49 doc = Nokogiri::XML(res.body)
51 if "4" == response_code(doc)
52 # Multiple matches; pick the first one and re-query
53 owi = doc.css("works work")[0]["owi"]
58 cmd = construct_url(params)
59 res = submit_request(cmd)
63 doc = Nokogiri::XML(res.body)
66 if "2" != response_code(doc)
71 title = doc.css("classify editions edition")[0]["title"]
73 info = BookClass.new(author_grouping, title)
75 author = doc.css("classify editions edition")[0]["author"]
78 nodes = doc.css("classify recommendations ddc mostPopular")
79 if nil != nodes && nodes.length > 0
84 nodes = doc.css("classify recommendations lcc mostPopular")
85 if nil != nodes && nodes.length > 0
90 headings = doc.css("classify recommendations fast headings heading")
91 headings.each do |heading|
95 descr = heading.content
96 #puts 'DESCR: ' + descr
98 @fast_set.add(id, descr)
101 info.filename = title
103 @class_set.ensure_contains!(info)
108 def massage_author(input)
114 input.each_char do |c|
115 if isUpper?(c) and (reading_order.length > 0)
124 def massage_title(pathname)
125 basename = File.basename(pathname, '.*')
128 basename.each_char do |c|
141 def response_code(doc)
142 return doc.css("classify response")[0]["code"]
146 @class_set.save_state()
147 @fast_set.save_state()
150 def submit_request(cmd)
154 req = Net::HTTP::Get.new(url.to_s)
155 res = Net::HTTP.start(url.host, url.port) {|http|