crd.rb
#!/usr/local/bin/ruby
# -*- coding: utf-8 -*-
# $Id$
require_relative "fuwatto.rb"
module Fuwatto
class CRDApp < BaseApp
TERMS = 5
TITLE = "ふわっと レファ協 関連検索"
HELP_TEXT = <<EOF
<p>
入力したテキストまたはウェブページに関連したレファレンスを<a href="http://ci.nii.ac.jp">レファレンス協同データベース</a>で検索します。
長いテキストやURLで指定したページからでも関連キーワードを自動的に抜き出してレファレンス質問を検索できるのが特徴です。
</p>
EOF
def execute( method = :crd_search, terms = TERMS, opts = {} )
super( method, terms, opts )
end
end
end
if $0 == __FILE__
# 検索に使用する最大キーワード数
@cgi = CGI.new
begin
app = Fuwatto::CRDApp.new( @cgi )
data = {}
begin
opts = {}
if not @cgi[ "combination" ].empty?
opts[ :combination ] = true
opts[ :reranking ] = true
end
data = app.execute( :crd_search, Fuwatto::CRDApp::TERMS, opts )
rescue Fuwatto::NoHitError => e
data[ :error ] = e.class
end
app.output( "crd", data )
rescue Exception
if @cgi then
print @cgi.header( 'status' => CGI::HTTP_STATUS['SERVER_ERROR'], 'type' => 'text/html' )
else
print "Status: 500 Internal Server Error\n"
print "Content-Type: text/html\n\n"
end
puts "<h1>500 Internal Server Error</h1>"
puts "<pre>"
puts CGI::escapeHTML( "#{$!} (#{$!.class})" )
puts ""
puts CGI::escapeHTML( $@.join( "\n" ) )
puts "</pre>"
puts "<div>#{' ' * 500}</div>"
end
end