<commit_before>require_dependency "citation/application_controller"
require "citation/engine"

require 'open-uri'
module Citation
  class CiteController < ApplicationController
    def redir
      puts "{request.env['PATH_INFO']}"
      if( params[:format].nil? )
        raise ArgumentError, 'Missing Output Format'
      end
      if( request.env['PATH_INFO'].eql? "/cite" )
        openurl
      else
        recordID
      end
    end
    
    def index
      render :text => "Citation Mounted"
    end
    
    def recordID
      if( params[:format].eql?("refworks") || params[:format].eql?("endnote") )
        export
      else
        record = Record.find_by_title(params[:id])
        send_data( Citation.map(record[:raw]).from(record[:formatting]).to(params[:format]) , :filename => "export."+params[:format], :type => "text/plain")
      end
    end
    
    def openurl
      if( params[:format].eql?("refworks") || params[:format].eql?("endnote") )
        export
      else
        send_data( Citation.map(request.fullpath).from("openurl").to(params[:format]) , :filename => "export."+params[:format], :type => "text/plain")
      end
    end
    
    def export
      callback = params[:format].eql?("refworks") ? "http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RIS%20Format&encoding=65001&url="
                                                  : "http://www.myendnoteweb.com/?func=directExport&partnerName=Primo&dataIdentifier=1&dataRequestUrl=" 
      callback += ERB::Util.url_encode("#{request.protocol}#{request.host_with_port}#{request.fullpath.sub(/refworks/, 'ris' )}" )
      redirect_to callback, :status => 303
    end
    
    def create
      r = Record.create(:raw => params[:data], :formatting => params[:from], :title => params[:ttl])
      if r.valid?
        r.save
        redirect_to "/cite", "id"=>params[:ttl], "format"=>params[:from], :status => 303
      else
        raise ArgumentError, 'Missing Parameters'
      end
    end
    
    def translate
      if( params[:data].nil? or params[:from].nil? or params[:to].nil? )
        raise ArgumentError, 'Missing Parameters'
      end
      send_data( Citation.map(params[:data]).from(params[:from]).to(params[:to]) , :type => "text/plain")
    end
  end
end<commit_msg>Forgot to replace endnote with RIS<commit_after>require_dependency "citation/application_controller"
require "citation/engine"

require 'open-uri'
module Citation
  class CiteController < ApplicationController
    def redir
      puts "{request.env['PATH_INFO']}"
      if( params[:format].nil? )
        raise ArgumentError, 'Missing Output Format'
      end
      if( request.env['PATH_INFO'].eql? "/cite" )
        openurl
      else
        recordID
      end
    end
    
    def index
      render :text => "Citation Mounted"
    end
    
    def recordID
      if( params[:format].eql?("refworks") || params[:format].eql?("endnote") )
        export
      else
        record = Record.find_by_title(params[:id])
        send_data( Citation.map(record[:raw]).from(record[:formatting]).to(params[:format]) , :filename => "export."+params[:format], :type => "text/plain")
      end
    end
    
    def openurl
      if( params[:format].eql?("refworks") || params[:format].eql?("endnote") )
        export
      else
        send_data( Citation.map(request.fullpath).from("openurl").to(params[:format]) , :filename => "export."+params[:format], :type => "text/plain")
      end
    end
    
    def export
      callback = params[:format].eql?("refworks") ? "http://www.refworks.com/express/ExpressImport.asp?vendor=Primo&filter=RIS%20Format&encoding=65001&url="
                                                  : "http://www.myendnoteweb.com/?func=directExport&partnerName=Primo&dataIdentifier=1&dataRequestUrl=" 
      callback += ERB::Util.url_encode("#{request.protocol}#{request.host_with_port}#{request.fullpath.sub(/refworks/, 'ris' ).sub(/endnote/, 'ris')}" )
      redirect_to callback, :status => 303
    end
    
    def create
      r = Record.create(:raw => params[:data], :formatting => params[:from], :title => params[:ttl])
      if r.valid?
        r.save
        redirect_to "/cite", "id"=>params[:ttl], "format"=>params[:from], :status => 303
      else
        raise ArgumentError, 'Missing Parameters'
      end
    end
    
    def translate
      if( params[:data].nil? or params[:from].nil? or params[:to].nil? )
        raise ArgumentError, 'Missing Parameters'
      end
      send_data( Citation.map(params[:data]).from(params[:from]).to(params[:to]) , :type => "text/plain")
    end
  end
end
{'fraction_non_alphanumeric': 0.15498154981549817, 'fraction_numerical': 0.006077707835901888, 'mean_word_length': 2.878787878787879, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2000851', 'n_tokens_mistral': 1422, 'n_tokens_neox': 1395, 'n_words': 264}