Skip to content

Commit

Permalink
Started implementing freecite backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bas Wenneker committed May 9, 2010
1 parent 7234215 commit 05f718c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
38 changes: 38 additions & 0 deletions app/controllers/citations_controller.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
39 changes: 1 addition & 38 deletions app/controllers/parscit_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion public/javascripts/evaluation/record_comparison_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 05f718c

Please sign in to comment.