-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ndvan
committed
Jul 25, 2019
1 parent
9c160f0
commit a069924
Showing
9 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
class TextEntriesController < ApplicationController | ||
def new | ||
@text_entry = TextEntry.new | ||
end | ||
|
||
def create | ||
@text_entry = current_or_guest_user.text_entries.build(text_entry_params) | ||
if @text_entry.save | ||
name = params[:name].empty? ? "Text entry" : params[:name] | ||
|
||
@list = @text_entry.create_list(name: name, description: params[:description]) | ||
flash[:success] = @list.name + " list is created!" | ||
|
||
entry = text_entry_params["corpus"].gsub("\n", " ") | ||
extracted_response = Req.get( Rails.configuration.x.sv_GNRD_wrapper_text + entry ) | ||
|
||
if extracted_response.empty? | ||
extracted_response = Req.get(Rails.configuration.x.sv_TaxonFinder_wrapper_text + entry) | ||
end | ||
|
||
@list.update_attributes(extracted: extracted_response.to_json) | ||
|
||
resolved_response = Req.post( Rails.configuration.x.sv_OToL_TNRS_wrapper, | ||
extracted_response.to_json, | ||
:content_type => :json ) | ||
|
||
if resolved_response.empty? | ||
extracted_for_gnr = extracted_response | ||
extracted_for_gnr["fuzzy_match"] = true | ||
extracted_for_gnr["multiple_match"] = false | ||
resolved_response = Req.post( Rails.configuration.x.sv_GNR_TNRS_wrapper, | ||
extracted_for_gnr.to_json, | ||
:content_type => :json ) | ||
end | ||
|
||
if resolved_response.empty? | ||
error = Req.post( Rails.configuration.x.sv_OToL_TNRS_wrapper, | ||
extracted_response.to_json, | ||
{:content_type => :json}, | ||
true ) | ||
fail_record = Failure.last.id | ||
end | ||
|
||
@list.update_attributes(resolved: resolved_response.to_json, | ||
resolving_error: error, | ||
possible_failure_record: fail_record) | ||
|
||
redirect_to list_path(@list) | ||
else | ||
render action: "new" | ||
end | ||
end | ||
|
||
private | ||
|
||
def text_entry_params | ||
params.require(:text_entry).permit(:corpus) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class TextEntry < ApplicationRecord | ||
has_one :list, as: :resource, dependent: :destroy | ||
belongs_to :user | ||
|
||
default_scope -> { order(created_at: :desc) } | ||
|
||
validates :user_id, presence: true | ||
validates :corpus, presence: true | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<% provide(:title, "Create trees from text entry") %> | ||
|
||
<div class="container"> | ||
<h1>Extract species names from text entry</h1> | ||
<%= form_for @text_entry, html: {class: "form-horizontal"} do |f| %> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6 col-sm-offset-3"> | ||
<%= render 'shared/error_messages', object: f.object %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= f.label :corpus, for: "corpus", class: "col-sm-3 control-label" do %> | ||
<span data-toggle="tooltip" title="Required field"><%= fa_icon "asterisk", text: "Input text" %></span> | ||
<% end %> | ||
<div class="col-sm-7"> | ||
<%= f.text_area :corpus, placeholder: "For better accuracy, use colon or space for seperator. E.g. Canis lupus pallipes, Panthera pardus, Melursus ursinus, Macaca mulatta", class: "form-control", rows: 8 %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= label_tag :name, for: "name", class: "col-sm-3 control-label" do %> | ||
Name for list | ||
<% end %> | ||
<div class="col-sm-4"> | ||
<%= text_field_tag :name, nil, placeholder: "Name", class: "form-control" %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<%= label_tag :description, "Description", for: "description_", class: "col-sm-3 control-label" %> | ||
<div class="col-sm-7"> | ||
<%= text_area :description, "", placeholder: "Description", class: "form-control", rows: 5 %> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<div class="col-sm-offset-3 col-sm-9"> | ||
<%= f.submit "Submit", class: "btn btn-default btn-lg btn-primary" %> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class CreateTextEntries < ActiveRecord::Migration[5.1] | ||
def change | ||
create_table :text_entries do |t| | ||
t.text :corpus | ||
t.references :user, foreign_key: true | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html | ||
|
||
one: | ||
corpus: MyText | ||
user: one | ||
|
||
two: | ||
corpus: MyText | ||
user: two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class TextEntryTest < ActiveSupport::TestCase | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |