X Tutup
Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,15 @@ def loader
end

def entities
ids = Document.accessible(current_account, current_organization).where({:id => params[:ids]}).pluck('id')
json 'entities' => Entity.where({ :document_id => ids })
documents = Document.accessible(current_account, current_organization).where({:id => params[:ids]})
result = {}
documents.each do |doc|
if doc.processing_jobs.select{|x| x.action == "process_entities" && x.complete == false}.present?
error = "Entities are still being extracted. Please try again later."
end
result[doc.id.to_s] = {'entities' => Entity.where({ :document_id => doc.id }), "error" => error}
end
json result
end

def entity
Expand Down
1 change: 1 addition & 0 deletions lib/dc/import/entity_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def extract_entities(document, calais, chunk_number)
kind = Entity.normalize_kind(entity[:type])
value = entity[:name]
next unless kind && value
next if value.length >= 255 # If value is over 255, this is not a valid entity.
value = Entity.normalize_value(value)
next if kind == :phone && Validators::PHONE !~ value
next if kind == :email && Validators::EMAIL !~ value
Expand Down
8 changes: 4 additions & 4 deletions public/javascripts/model/entities.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,12 @@ dc.model.EntitySet = Backbone.Collection.extend({
var missing = _.select(docs, function(doc){ return !doc.entities.loaded; });
if (!missing.length) return callback();
dc.ui.spinner.show();
$.get('/documents/entities.json', {'ids[]' : _.pluck(missing, 'id')}, function(resp) {
var entities = _.groupBy(resp.entities, 'document_id');
_.each(entities, function(list, docId) {
$.get('/documents/entities.json', {'ids[]' : _.pluck(missing, 'id')}, function(response) {
_.each(response, function(docEntityResponse, docId) {
var collection = Documents.get(docId).entities;
collection.loaded = true;
collection.reset(list);
collection.errors = docEntityResponse.error
collection.reset(docEntityResponse.entities);
});
dc.ui.spinner.hide();
callback();
Expand Down
2 changes: 2 additions & 0 deletions public/javascripts/ui/documents/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ dc.ui.Document = Backbone.View.extend({
_renderEntities : function() {
if (this.model.entities.length) {
this.entitiesView.show();
} else if (this.model.entities.errors != null) {
dc.ui.Dialog.alert( this.model.entities.errors );
} else {
dc.ui.Dialog.alert( _.t('has_no_entities', this.model.get('title') ) );
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
VCR.configure do |config|
config.cassette_library_dir = "test/vcr_cassettes"
config.allow_http_connections_when_no_cassette = true
config.hook_into :webmock # or :fakeweb
#config.hook_into :webmock # or :fakeweb
end

PROCESSING_JOBS = []
Expand Down
X Tutup