diff --git a/app/controllers/citations_controller.rb b/app/controllers/citations_controller.rb index c859e1a..28927de 100644 --- a/app/controllers/citations_controller.rb +++ b/app/controllers/citations_controller.rb @@ -1,4 +1,11 @@ +require 'bibmix' + class CitationsController < ApplicationController + + PARSER_FREECITE = 'freecite' + PARSER_PARSCIT = 'parscit' + DEFAULT_PARSER = PARSER_PARSCIT + # GET /citations # GET /citations.xml def index @@ -83,4 +90,35 @@ def destroy format.xml { head :ok } end end + + def parse + citation = params[:citation] + parser = params.fetch('parser', DEFAULT_PARSER) + + if citation + + # First parse the citation with parscit. + if parser == PARSER_PARSCIT + hash = Reference.create_with_parscit(citation).to_hash + elsif parser == PARSER_FREECITE + hash = Reference.create_with_freecite(citation).to_hash + end + + # Convert it to a Bibmix::Record so that it can be merged with data + # from bibsonomy. + record = Bibmix::Record.from_hash(hash) + + + # Execute the mixing process. + enhanced_record = Bibmix::Bibsonomy::MixingProcess.new(record).execute + end + + respond_to do |format| + format.json { + render :json => { + :parsed => record, + :enhanced => enhanced_record + } + } + end end diff --git a/app/controllers/parscit_controller.rb b/app/controllers/parscit_controller.rb index d20d25b..9a5f93f 100644 --- a/app/controllers/parscit_controller.rb +++ b/app/controllers/parscit_controller.rb @@ -34,43 +34,6 @@ def show } end end - -private - def parse_with_parscit(str) - if str.nil? || str.eql?("") - raise 'Citation string is nil or empty' - end - - #parscit_dir = "/home/bas/Documents/parscit-100401" - parscit_dir = "/Users/bas/Documents/parscit-100401" - parscit_cmd = "#{parscit_dir}/bin/parseRefStrings.pl" - - # Convert the passed string to UTF-8, this prevents possible - # seg faults in parseRefStrings.pl. - ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') - valid_string = ic.iconv(str << ' ')[0..-2] - - # The ParsCit executable only reads from file so create a - # temporary file and fill it with the citation string. - tmp = Tempfile.new("parscit_parser_tmp") - tmp.binmode - tmp.puts(valid_string) - tmp.close() - - xml = `perl "#{parscit_cmd}" "#{tmp.path()}"` - hsh = Hash.from_xml(xml) - - citation = hsh['algorithm']['citationList']['citation'] - - tmp.unlink - - if citation.is_a?(Hash) - citation - elsif citation.is_a?(Array) && citation.length - citation[0] - else - raise "Invalid citation datatype or no citations found (ln=#{citation.length})" - end - end + end diff --git a/public/javascripts/evaluation/record_comparison_table.js b/public/javascripts/evaluation/record_comparison_table.js index f7553ac..fed5a21 100644 --- a/public/javascripts/evaluation/record_comparison_table.js +++ b/public/javascripts/evaluation/record_comparison_table.js @@ -10,7 +10,7 @@ var RecordComparisonTable = Class.create(AbstractComparisonTable, { 'loadComparisonData': function(item) { item = item || this.item; - new Ajax.Request('/parscit/show', + new Ajax.Request('/citations/parse_with_parscit', { method: 'post', parameters: {