Permalink
Browse files

fixed several problems

  • Loading branch information...
1 parent 9314e0f commit c425aa70e3c79d479ee7b63ce8ba78ea97139375 @dimus dimus committed Mar 30, 2012
@@ -9,14 +9,17 @@ def index
def show
resolver = NameResolver.find_by_token(params[:id])
respond_to do |format|
- present_result(format, resolver)
+ present_result(format, resolver, true)
end
end
def create(from_get = false)
new_data = get_data
opts = get_opts
- token = Base64.urlsafe_encode64(UUID.create_v4.raw_bytes)[0..-3]
+ token = "_"
+ while token.match(/_/)
+ token = Base64.urlsafe_encode64(UUID.create_v4.raw_bytes)[0..-3]
+ end
status = ProgressStatus.working
message = "Submitted"
@@ -29,6 +32,7 @@ def create(from_get = false)
result = {
:id => token,
:url => "%s/name_resolvers/%s" % [Gni::Config.base_url, token],
+ :data_sources => data_sources,
}
resolver = NameResolver.create!(
@@ -55,15 +59,19 @@ def create(from_get = false)
private
- def present_result(format, resolver)
- res = resolver.result
- res[:url] += ".%s" % params[:format] if ['xml', 'json'].include?(params[:format])
- res[:status] = resolver.progress_status.name
- res[:message] = resolver.progress_message
- res[:parameters] = resolver.options
- format.html { redirect_to name_resolver_path(resolver) }
- format.json { render :json => json_callback(res.to_json, params[:callback]) }
- format.xml { render :xml => res.to_xml }
+ def present_result(format, resolver, is_show = false)
+ @res = resolver.result
+ @res[:url] += ".%s" % params[:format] if ['xml', 'json'].include?(params[:format])
+ @res[:status] = resolver.progress_status.name
+ @res[:message] = resolver.progress_message
+ @res[:parameters] = resolver.options
+ if is_show
+ format.html
+ else
+ format.html { redirect_to name_resolver_path(resolver.token) }
+ end
+ format.json { render :json => json_callback(@res.to_json, params[:callback]) }
+ format.xml { render :xml => @res.to_xml }
end
def get_data
@@ -8,6 +8,8 @@ class NameResolver < ActiveRecord::Base
serialize :options, Hash
serialize :result, Hash
+ before_create :add_default_options
+
CONTEXT_THRESHOLD = 0.9
EXACT_STRING = 1
EXACT_CANONICAL = 2
@@ -401,6 +403,10 @@ def get_score(result)
result[:prescore] = "%s|%s|%s" % [s,a,c]
result[:score] = Gni.num_to_score(prescore)
end
+
+ def add_default_options
+ self.options = {:with_context => false, :data_sources => []}.merge(self.options)
+ end
def format_result
r = result
@@ -34,4 +34,4 @@
</div>
<% end %>
</div>
-<% end %>
+<% end %>

0 comments on commit c425aa7

Please sign in to comment.