From 393b72380a65b58cf0764eaa53a64335d2dba1c7 Mon Sep 17 00:00:00 2001 From: bwenneker Date: Tue, 4 May 2010 13:09:30 +0200 Subject: [PATCH] Created quick ParsCit lookup controller. --- INSTALL.mkdn | 38 ++++++++++++ MIT-LICENSE | 20 +++++++ app/controllers/application_controller.rb | 2 +- app/controllers/parscit_controller.rb | 68 ++++++++++++++++++++++ app/helpers/parscit_helper.rb | 2 + app/views/parscit/show.html.erb | 22 +++++++ db/schema.rb | 14 +++++ test/functional/parscit_controller_test.rb | 8 +++ test/unit/helpers/parscit_helper_test.rb | 4 ++ vendor/plugins/bibmix | 2 +- 10 files changed, 178 insertions(+), 2 deletions(-) create mode 100644 INSTALL.mkdn create mode 100644 MIT-LICENSE create mode 100644 app/controllers/parscit_controller.rb create mode 100644 app/helpers/parscit_helper.rb create mode 100644 app/views/parscit/show.html.erb create mode 100644 db/schema.rb create mode 100644 test/functional/parscit_controller_test.rb create mode 100644 test/unit/helpers/parscit_helper_test.rb diff --git a/INSTALL.mkdn b/INSTALL.mkdn new file mode 100644 index 0000000..d6f5f89 --- /dev/null +++ b/INSTALL.mkdn @@ -0,0 +1,38 @@ +Installation +============ +The installation is tested on a Macbook Pro running Mac OSX 10.6 Snowleopard. It +will probably run on any *ix OS. + +Requirements +------------ + + * [soap4r](http://dev.ctor.org/soap4r) + +Mac OSX 10.6 Installation +------------------------- +Bibmix application installation from remote git repository: + + $ git clone git@github.com:bwenneker/bibmix_app.git + $ cd bibmix_app + +Then go to the bibmix plugin folder and retrieve the Bibmix submodules: + + $ cd vendor/plugins/bibmix + $ git submodule init + $ git submodule update + + + +Requirements installation +------------------------- + + $ sudo gem install soap4r + + + +rake db:create:all +rake db:test:prepare + +* * * +Copyright (c) 2010 Bas Wenneker +released under the MIT License diff --git a/MIT-LICENSE b/MIT-LICENSE new file mode 100644 index 0000000..8db8b8f --- /dev/null +++ b/MIT-LICENSE @@ -0,0 +1,20 @@ +Copyright (c) 2010 Bas Wenneker + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6635a3f..dbd0013 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,7 +3,7 @@ class ApplicationController < ActionController::Base helper :all # include all helpers, all the time - protect_from_forgery # See ActionController::RequestForgeryProtection for details + protect_from_forgery :only => [:update, :delete, :create]# See ActionController::RequestForgeryProtection for details # Scrub sensitive parameters from your log # filter_parameter_logging :password diff --git a/app/controllers/parscit_controller.rb b/app/controllers/parscit_controller.rb new file mode 100644 index 0000000..2dc6f23 --- /dev/null +++ b/app/controllers/parscit_controller.rb @@ -0,0 +1,68 @@ +require 'tempfile' +require 'bibmix' + +class ParscitController < ApplicationController + + def show + citation = params[:citation] + + @parscit_record_yaml = 'Please make a request.' + @enhanced_record_yaml = '' + if citation + + # First parse the citation with parscit. + hash = parseWithParsCit(citation) + @parscit_record_yaml = hash.to_yaml + # 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 + + @enhanced_record_yaml = @enhanced_record.to_yaml + end + + respond_to do |format| + format.html + end + end + +private + def parseWithParsCit(str) + if str.nil? || str.eql?("") + raise 'Citation string is nil or empty' + end + + parscit_dir = "/home/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 an 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/app/helpers/parscit_helper.rb b/app/helpers/parscit_helper.rb new file mode 100644 index 0000000..c1ac997 --- /dev/null +++ b/app/helpers/parscit_helper.rb @@ -0,0 +1,2 @@ +module ParscitHelper +end diff --git a/app/views/parscit/show.html.erb b/app/views/parscit/show.html.erb new file mode 100644 index 0000000..ab49683 --- /dev/null +++ b/app/views/parscit/show.html.erb @@ -0,0 +1,22 @@ + + +
+
+ +
+ +
+ +
+ ParsCit: +
<%=@parscit_record_yaml%>
+ Enhanced: +
<%=@enhanced_record_yaml%>
+
\ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 0000000..b81ae5a --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,14 @@ +# This file is auto-generated from the current state of the database. Instead of editing this file, +# please use the migrations feature of Active Record to incrementally modify your database, and +# then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your database schema. If you need +# to create the application database on another system, you should be using db:schema:load, not running +# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended to check this file into your version control system. + +ActiveRecord::Schema.define(:version => 0) do + +end diff --git a/test/functional/parscit_controller_test.rb b/test/functional/parscit_controller_test.rb new file mode 100644 index 0000000..e30faed --- /dev/null +++ b/test/functional/parscit_controller_test.rb @@ -0,0 +1,8 @@ +require 'test_helper' + +class ParscitControllerTest < ActionController::TestCase + # Replace this with your real tests. + test "the truth" do + assert true + end +end diff --git a/test/unit/helpers/parscit_helper_test.rb b/test/unit/helpers/parscit_helper_test.rb new file mode 100644 index 0000000..a5a29f3 --- /dev/null +++ b/test/unit/helpers/parscit_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ParscitHelperTest < ActionView::TestCase +end diff --git a/vendor/plugins/bibmix b/vendor/plugins/bibmix index b77c04c..ceb094e 160000 --- a/vendor/plugins/bibmix +++ b/vendor/plugins/bibmix @@ -1 +1 @@ -Subproject commit b77c04c83d12e358d54cbeca64e1b6fd16dfdb23 +Subproject commit ceb094e93da8b7276e8c103d49fd0ae4b2ff0fb9