Skip to content

Commit

Permalink
started modifying rdfmodeler
Browse files Browse the repository at this point in the history
  • Loading branch information
bensinober committed May 11, 2014
1 parent c33b1b1 commit 5cf4045
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 5,268 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ config/settings.json
config/repository.yml
config/harvesting.yml
oai_updates/*
coverage
spec/reports
# keep empty directories with .gitignore in them
#!.gitignore
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ group :test do
gem "minitest"
gem "guard"
gem "guard-rspec"
gem 'simplecov', '~> 0.7.1'
end
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ GEM
safe_yaml (0.9.7)
shotgun (0.9)
rack (>= 1.0)
simplecov (0.7.1)
multi_json (~> 1.0)
simplecov-html (~> 0.7.1)
simplecov-html (0.7.1)
sinatra (1.4.3)
rack (~> 1.4)
rack-protection (~> 1.4)
Expand Down Expand Up @@ -188,6 +192,7 @@ DEPENDENCIES
rspec
rufus-scheduler
shotgun
simplecov (~> 0.7.1)
sinatra
sinatra-contrib
sinatra-reloader
Expand Down
5 changes: 5 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ task :spec do
end
end

task :coverage do
ENV['COVERAGE'] = 'true'
Rake::Task["spec"].execute
end

desc "Run CI rspec"
task "ci_rspec" => ["ci:setup:rspec", "^spec"]

Expand Down
2 changes: 2 additions & 0 deletions api/conversion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Conversion < Grape::API
requires :uri, type: String, desc: "URI of resource"
end
get "/marcxml" do
#format :xml
#content_type :xml, 'text/xml'
content_type 'text/xml'
library = Library.find(:id => params[:id])
marc = MARCModeler.new(library)
Expand Down
20 changes: 13 additions & 7 deletions lib/rdfmodeler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@
# Struct for RDFModeler
require 'rdf/ntriples'

RDFModeler = Struct.new(:library_id, :record, :uri, :tags, :statements, :rdf)
RDFModeler = Struct.new(:library_id, :record, :uri, :map, :statements, :rdf)
class RDFModeler

## Instance Methods
def initialize(library, record, params={})
# lookup library by id unless given as param
library = Library.find(:id => library) unless library.is_a? Library
library = Library.find(:id => library) unless library.is_a?(Library)

self.library_id = library.id
self.record = record
id = self.record[library.config["resource"]["identifier_tag"]]
self.uri = RDF::URI(library.config["resource"]["base"] + library.config["resource"]["prefix"] + "#{id.value}")
# choose library's selected mapping if not given as parameter
params[:mapping] ? mapping = Mapping.find(:id => params[:mapping]) : mapping = Mapping.find(:id => library.mapping)
self.tags = mapping.mapping["tags"] if mapping
# mapping is either passed as param (full mapping or id) or selected from library
if params[:mapping]
params[:mapping].is_a?(Mapping) ? self.map = params[:mapping] :
self.map = Mapping.find(:id => params[:mapping])
else
self.map = Mapping.find(:id => library.mapping)
end
return nil unless self.map
#self.tags = mapping.mapping["tags"] if mapping
self.statements = []
end

Expand Down Expand Up @@ -143,8 +149,8 @@ def convert
self.record.tags.each do | marctag |
# put all marc tag fields into array object 'marcfields' for later use
marcfields = self.record.find_all { |field| field.tag == marctag }
# start matching MARC tags against @tags from mapping, put results in match array
match = self.tags.select { |k,v| marctag =~ /#{k}/ }
# start matching MARC tags against tags from mapping, put results in match array
match = self.map.mapping["tags"].select { |k,v| marctag =~ /#{k}/ }
match.each do |yamlkey,yamlvalue|
# iterate each marc tag array object to catch multiple marc fields
marcfields.each do | marcfield |
Expand Down
Loading

0 comments on commit 5cf4045

Please sign in to comment.