Skip to content

Commit

Permalink
Created quick ParsCit lookup controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
baswenneker committed May 4, 2010
1 parent 6ea9298 commit 393b723
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 2 deletions.
38 changes: 38 additions & 0 deletions INSTALL.mkdn
Original file line number Diff line number Diff line change
@@ -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 [email protected]: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
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions app/controllers/parscit_controller.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions app/helpers/parscit_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module ParscitHelper
end
22 changes: 22 additions & 0 deletions app/views/parscit/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<ul>
<li>Isaac G. Councill, C. Lee Giles, Min-Yen Kan. (2008) ParsCit: An open-source CRF reference string parsing package. To appear in the proceedings of the Language Resources and Evaluation Conference (LREC 08), Marrakesh, Morrocco, May.</li>
</ul>

<form action="" method="post">
<textarea id="citation" name="citation" style="width:600px;"><% #if(!@citation){
#puts "Isaac G. Councill, C. Lee Giles, Min-Yen Kan. (2008) ParsCit: An open-source CRF reference string parsing package. To appear in the proceedings of the Language Resources and Evaluation Conference (LREC 08), Marrakesh, Morrocco, May."
#}else{
#puts @citation
#}
%></textarea><br />
<button>Go!</button>
</form>

<br />

<div>
ParsCit:
<pre><%=@parscit_record_yaml%></pre>
Enhanced:
<pre><%=@enhanced_record_yaml%></pre>
</div>
14 changes: 14 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/functional/parscit_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions test/unit/helpers/parscit_helper_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require 'test_helper'

class ParscitHelperTest < ActionView::TestCase
end
2 changes: 1 addition & 1 deletion vendor/plugins/bibmix

0 comments on commit 393b723

Please sign in to comment.