<% # ======================================================================= # 意味検索プログラム Web Interface # 1st.version : 2005/08/01 by Keichiro Katayama # current Version : 2005/08/01 # ======================================================================= # wssp.rhtml # Version 2.1alpha # 2007/05/16 # ===================== # Kanji Code # ===================== $KCODE = 'EUC' ERuby.charset = 'euc-jp' # ===================== # Load Library # ===================== # Main Class require 'lib/libwssp.rb' # CGI Support Library require 'cgi' # DNS Lookup require "../wjpp/lib/dnslookup.rb" # Initialize cgi = CGI::new wssp = Wssp::new( cgi ) wssp_log_name = '/www/world/toribank/wssp/wssp_query_log/wssp.log' # ===================== # Query Check # ===================== has_query = false query_by_sent = true # default ( 日本語文による検索をデフォルトとする? true / false ) preset_mode = false result = nil jp_num = ep_num = sp_num = record_set = nil error_msg = nil # lower limit (bytes) min_sent_length = 12 loop{ if cgi.has_key?('query_type') then case cgi.params['query_type'].first.strip when 'sent' has_query = true query_by_sent = true when 'param' has_query = true query_by_sent = false when 'preset' has_query = true query_by_sent = true preset_mode = true else break end end if has_query then # restore conditions... wssp.condition_names.each_index{ |i| key = "cond_#{i}" val = 'FF' if cgi.has_key?(key) then tmp = wssp.condition_set.assoc( cgi.params[key].first.strip ) if ! tmp.nil? then val = tmp.first end end wssp.conditions[i] = val } unless query_by_sent then # restore parameters... wssp.condition_names.each_index{ |i| key = "param_#{i}" if cgi.has_key?(key) then tmp = cgi.params[key].dup tmp.sort! tmp.uniq! j = 0 tmp.each{ |x| unless x.empty? then wssp.parameters[i][j] = x j += 1 end } end } end # Exec Query if query_by_sent then # by Japanese Sentence Mode if preset_mode then sent = cgi.params['preset_sentence'].first else sent = cgi.params['sentence'].first # Check Length (2008/03/29 add) current_min_sent_length = min_sent_length if sent =~ /[。.?]$/ then current_min_sent_length += 2 end unless sent.length >= current_min_sent_length then error_msg = "文が短すぎます(#{min_sent_length/2}文字以上)" end end if sent.nil? || sent.empty? then has_query = false break end wssp.sentence = sent.strip begin jp_num, ep_num, sp_num, record_set = wssp.search_by_sent rescue Wssp::SentenceTooLong error_msg = "文が長すぎます(#{Wssp::MAX_SENT_LENGTH/2}文字以下)" rescue Wssp::ConditionError, Wssp::ParameterError error_msg = "ArgumentError!" rescue error_msg = "Internal Error!" end else # by Parameter Mode begin jp_num, ep_num, sp_num, record_set = wssp.search_by_param rescue Wssp::SentenceTooLong error_msg = "Too Long Sentence!(max=#{Wssp::MAX_SENT_LENGTH})" rescue Wssp::ConditionError, Wssp::ParameterError error_msg = "ArgumentError!" rescue error_msg = "Internal Error!" end end # Log log_time = Time.now.strftime( "%Y/%m/%d %H:%M:%S" ) log_addr = cgi.remote_addr.dup log_host = lookup_with_gethostbyaddr( log_addr ) if log_addr == log_host then log_host = '' end log_data = [ log_time, log_addr, log_host, ( query_by_sent ? 'by Sent' : 'by Param' ), wssp.sentence, wssp.last_cond, wssp.last_param ] if error_msg.nil? then if record_set.nil? then log_data.push 'Success', 'Result: Not Found' else log_data.push 'Success', 'Result: %d(%d)' % [ record_set.length, sp_num ] end else log_data.push 'Error', error_msg end File.open( wssp_log_name, 'a' ){ |log| begin log.flock( File::LOCK_EX ) log.puts log_data.join( "\t" ) ensure log.flock( File::LOCK_UN ) end } # end of Log end # ---- break } # end of loop # end of setup # ======================================================================= %> wssp

パターン意味検索プログラム

<% if has_query then %> <% if ! error_msg.nil? then %>

<%= error_msg %>

<% elsif record_set.nil? || record_set.empty? then %>

Not found...

<% else %>

Results

<% begin %> <% unless wssp.last_cond.nil? then %>

Condition: <%= CGI.escapeHTML( wssp.last_cond ) %>

<% end %> <% unless wssp.last_param.nil? then %>

Parameter: <%= CGI.escapeHTML( wssp.last_param ) %>

<% end %> <% unless record_set.length == sp_num then %>

Too Much Result. (<%= record_set.length %> corpus only!)

<% end %>

Number of Matched Corpus: <%= sp_num %> (Japanese Pattern: <%= jp_num %>, English Pattern: <%= ep_num %>)

<% record_set.each{ |record| %>
<% if record.wj_pid.nil? || record.wj_pid.empty? then %> <% else %> <% end %> <% if record.pj_pid.nil? || record.pj_pid.empty? then %> <% else %> <% end %> <% if record.cj_pid.nil? || record.cj_pid.empty? then %> <% else %> <% end %>
<%= CGI.escapeHTML(record.sid) %>
単語レベルパターン <%= CGI.escapeHTML( record.wj_pid ) %>: <%= CGI.escapeHTML( record.wj_pattern ) %>
<%= CGI.escapeHTML( record.we_pid ) %>: <%= CGI.escapeHTML( record.we_pattern ) %>
句レベルパターン <%= CGI.escapeHTML( record.pj_pid ) %>: <%= CGI.escapeHTML( record.pj_pattern ) %>
<%= CGI.escapeHTML( record.pe_pid ) %>: <%= CGI.escapeHTML( record.pe_pattern ) %>
節レベルパターン <%= CGI.escapeHTML( record.cj_pid ) %>: <%= CGI.escapeHTML( record.cj_pattern ) %>
<%= CGI.escapeHTML( record.ce_pid ) %>: <%= CGI.escapeHTML( record.ce_pattern ) %>
文種別 <%= CGI.escapeHTML(record.bunshu) %> 
統語構造第1分類 <%= CGI.escapeHTML( record.tougo_1 ) %>  統語構造第2分類 <%= CGI.escapeHTML( record.tougo_2 ) %> 
第1従属節の意味分類 <%= CGI.escapeHTML( record.zyuusetsu_1.split(%r!/!).join(', ') ) %>  第2従属節の意味分類 <%= CGI.escapeHTML( record.zyuusetsu_2.split(%r!/!).join(', ') ) %> 
主節の意味分類 <%= CGI.escapeHTML( record.syusetsu.split(%r!/!).join(', ') ) %> 
第1節間の意味分類 <%= CGI.escapeHTML( record.cb_imi_1.split(%r!/!).join(', ') ) %>  第2節間の意味分類 <%= CGI.escapeHTML( record.cb_imi_2.split(%r!/!).join(', ') ) %> 
第1節間KW <%= CGI.escapeHTML( record.cb_kw_1 ) %>  第2節間KW <%= CGI.escapeHTML( record.cb_kw_2 ) %> 
<% } %> <% rescue %>

Internal Server Error!

<% end %>
<% end %> <% end %>