lbp 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aff42dc77762adda3fbe30e51ace4f0dea49fbf8
4
+ data.tar.gz: ffa83322779d86566f4d469b33e794328abe1b2a
5
+ SHA512:
6
+ metadata.gz: c33023bf158b98a08f4b8ca52f88292c5a7f79eaf2ac690f0188c52735b076565ba709715546d34f4bf9ba74c8c6191367825cb5ba8c6b8703bb3e738f476307
7
+ data.tar.gz: 3a39e659d08b632c0a898ef5765cfba792ebbb93b5000cb6c0c6ef0934dec0bf0d1d0d580618bc217640b8690d29b0efeb565022c2f20dfb47b9f2b5659226c7
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1 @@
1
+ lbp
@@ -0,0 +1 @@
1
+ ruby-2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lbp.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Jeffrey C. Witt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Lbp
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lbp'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lbp
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/lbp/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
8
+
data/bin/lbp ADDED
@@ -0,0 +1,115 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rdf'
4
+ require 'rdf/rdfxml'
5
+ require 'rdf/ntriples'
6
+ require 'thor'
7
+ require 'openssl'
8
+ require 'pry'
9
+ require 'uri'
10
+ require 'lbp'
11
+
12
+ class LbpCli < Thor
13
+
14
+ desc "hello", "say hello to NAME"
15
+ def hello(name)
16
+ puts "Hello #{name}!"
17
+ end
18
+
19
+ desc "init", "create projectifles dirs in current working directory"
20
+ def init(dir)
21
+ directories = ["#{dir}/Conf", "#{dir}/Textfiles", "#{dir}/citationlists"]
22
+ FileUtils.mkpath(directories)
23
+ @dir
24
+ end
25
+
26
+ desc "projecfile", "make projetfile from SCTA"
27
+ def projectfile(sctaurl, installdir)
28
+ resource = RDF::Resource.new(RDF::URI.new(sctaurl))
29
+ #resource = RDF::Resource(RDF::URI.new("http://rdf.rubyforge.org/"))
30
+ graph = RDF::Graph.load(resource)
31
+ data = graph.data
32
+ title = data.query(:predicate => RDF::DC11.title).first.object
33
+ itemarray = []
34
+
35
+ headerdata = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
36
+ <lbpProjectFile>
37
+ <header>
38
+ <collectionTitle>#{title}</collectionTitle>
39
+ <localTextsDirectory>/Users/JCWitt/WebPages/lbplib-testfiles/pp-projectfiles/GitTextfiles/</localTextsDirectory>
40
+ <citationListsDirectory>/Users/JCWitt/WebPages/lbplib-testfiles/pp-projectfiles/citationlists/</citationListsDirectory>
41
+ <xsltDirectories>
42
+ <schema version='lbp-0.0.1' default='true'>
43
+ <critical>/Users/JCWitt/WebPages/lbpwrapper/lombardpress/public/pl_xslt_stylesheets/</critical>
44
+ <documentary>/Users/JCWitt/WebPages/lbpwrapper/lombardpress/public/pl_xslt_stylesheets/</documentary>
45
+ <main_view>text_display.xsl</main_view>
46
+ <index_view>'text_display_index.xsl'</index_view>
47
+ <clean_view>clean_forStatistics.xsl</clean_view>
48
+ <plain_text>plaintext.xsl</plain_text>
49
+ <toc>lectio_outline.xsl</toc>
50
+ </schema>
51
+ <schema version='lbp-0.0.2' default='true'>
52
+ <critical>/Users/JCWitt/WebPages/lbpwrapper/lombardpress/public/pl_xslt_stylesheets/</critical>
53
+ <documentary>/Users/JCWitt/WebPages/lbpwrapper/lombardpress/public/pl_xslt_stylesheets/</documentary>
54
+ <main_view>text_display.xsl</main_view>
55
+ <index_view>'text_display_index.xsl'</index_view>
56
+ <clean_view>clean_forStatistics.xsl</clean_view>
57
+ <plain_text>plaintext.xsl</plain_text>
58
+ <toc>lectio_outline.xsl</toc>
59
+ </schema>
60
+ </xsltDirectories>
61
+ <git_repo>bitbucket.org/jeffreycwitt/</git_repo>
62
+ </header>
63
+ <listofFileNames>
64
+ <div id=\"body\">"
65
+
66
+ itemarray << headerdata
67
+
68
+ data.query(:predicate => RDF::DC.hasPart).each do |part|
69
+
70
+ newresource = RDF::Resource.new(part.object)
71
+ newgraph = RDF::Graph.load(newresource)
72
+ newdata = newgraph.data
73
+
74
+ #type = newdata.query(:predicate => RDF::RDF.type).first.object.to_s
75
+ #type_slug = URI(type.object.to_s).path.split('/').last
76
+
77
+ status = newdata.query(:predicate => RDF::URI.new("http://scta.info/property/status")).first.object
78
+
79
+ unless status == 'Not Started'
80
+ title = newdata.query(:predicate => RDF::DC11.title).first.object
81
+ id = URI(part.object.to_s).path.split('/').last
82
+ itemunit = "
83
+ <item live='#{status}'>
84
+ <fileName filestem='#{id}'>#{id}.xml</fileName>
85
+ <title>#{title}</title>
86
+ </item>\n"
87
+ itemarray << itemunit
88
+ end
89
+
90
+ end
91
+
92
+ footerdata = "</div>
93
+ </listofFileNames>
94
+ </lbpProjectFile>"
95
+
96
+ itemarray << footerdata
97
+
98
+ f = File.new("#{installdir}/Conf/projectfile.xml", 'w')
99
+
100
+ itemarray.each do |section|
101
+ f.write(section)
102
+ end
103
+ end
104
+ desc "loaed_text_files", "clone collection repos"
105
+ def load_text_files(projectfile)
106
+ collection = Lbp::Collection.new(projectfile)
107
+ collection.git_clone
108
+ end
109
+ end
110
+
111
+ LbpCli.start(ARGV)
112
+
113
+
114
+
115
+
@@ -0,0 +1,36 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lbp/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lbp"
8
+ spec.version = Lbp::VERSION
9
+ spec.authors = ["Jeffrey C. Witt"]
10
+ spec.email = ["jeffreycwitt@gmail.com"]
11
+ spec.summary = %q{A library for working XML documents conforming the TEI (lbp customized) schema}
12
+ spec.description = %q{A library for working XML documents conforming the TEI (lbp customized) schema}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "pry"
25
+ spec.add_runtime_dependency "nokogiri"
26
+ spec.add_runtime_dependency "rugged"
27
+ spec.add_runtime_dependency "thor"
28
+ spec.add_runtime_dependency "rdf"
29
+ spec.add_runtime_dependency "rdf-rdfxml"
30
+ spec.add_runtime_dependency "rest-client"
31
+
32
+
33
+
34
+
35
+
36
+ end
@@ -0,0 +1,11 @@
1
+ require "lbp/version"
2
+
3
+
4
+ require 'lbp/functions'
5
+ require 'lbp/item'
6
+ require 'lbp/paragraph'
7
+ require 'lbp/transcription'
8
+ require 'lbp/item_group'
9
+ require 'lbp/collection'
10
+
11
+
@@ -0,0 +1,131 @@
1
+ require 'nokogiri'
2
+ require 'rugged'
3
+ require 'lbp/functions'
4
+
5
+
6
+ module Lbp
7
+ class Collection
8
+ #attr_reader :confighash
9
+ def initialize(projectfile)
10
+ #@confighash = self.confighash
11
+ #@projectdatafile_dir = @confighash[:projectdatafile_dir]
12
+ @projectfile = projectfile
13
+ end
14
+
15
+ def title
16
+ file = Nokogiri::XML(File.read(@projectfile))
17
+ title = file.xpath(("//header/collectionTitle")).text
18
+ end
19
+ def local_texts_dir
20
+ file = Nokogiri::XML(File.read(@projectfile))
21
+ textdir = file.xpath(("//header/localTextsDirectory")).text
22
+ end
23
+
24
+ def citation_lists_dir
25
+ file = Nokogiri::XML(File.read(@projectfile))
26
+ citationlistdir = file.xpath(("//header/citationListsDirectory")).text
27
+ end
28
+ def git_repo
29
+ file = Nokogiri::XML(File.read(@projectfile))
30
+ gitrepo = file.xpath("//header/git_repo").text
31
+ end
32
+ #need test
33
+ def git_clone(username: nil, password: nil)
34
+ self.items.each do |item|
35
+ item.git_clone(username: username, password: password)
36
+ end
37
+ end
38
+
39
+ def xslt_dirs
40
+ #test change to hash
41
+ @xslthash = Hash.new
42
+ file = Nokogiri::XML(File.read(@projectfile))
43
+ schemas = file.xpath("//header/xsltDirectories/schema")
44
+
45
+ schemas.each do |schema|
46
+ schema_number = schema.attributes["version"].value
47
+ schema_default = schema.attributes["default"].value
48
+ @xslthash["#{schema_number}"] = {
49
+ critical: schema.children.find {|child| child.name == "critical"}.text,
50
+ documentary: schema.children.find {|child| child.name == "documentary"}.text,
51
+ main_view: schema.children.find {|child| child.name == "main_view"}.text,
52
+ index_view: schema.children.find {|child| child.name == "index_view"}.text,
53
+ clean_view: schema.children.find {|child| child.name == "clean_view"}.text,
54
+ plain_text: schema.children.find {|child| child.name == "plain_text"}.text,
55
+ toc: schema.children.find {|child| child.name == "toc"}.text
56
+ }
57
+ if schema_default == 'true'
58
+ @xslthash["default"] = {
59
+ critical: schema.children.find {|child| child.name == "critical"}.text,
60
+ documentary: schema.children.find {|child| child.name == "documentary"}.text,
61
+ main_view: schema.children.find {|child| child.name == "main_view"}.text,
62
+ index_view: schema.children.find {|child| child.name == "index_view"}.text,
63
+ clean_view: schema.children.find {|child| child.name == "clean_view"}.text,
64
+ plain_text: schema.children.find {|child| child.name == "plain_text"}.text,
65
+ toc: schema.children.find {|child| child.name == "toc"}.text
66
+ }
67
+ end
68
+
69
+ end
70
+ return @xslthash
71
+
72
+ end
73
+
74
+ def confighash
75
+ confighash = {
76
+ local_texts_dir: self.local_texts_dir,
77
+ citation_lists_dir: self.citation_lists_dir,
78
+ xslt_dirs: self.xslt_dirs,
79
+ git_repo: self.git_repo}
80
+ end
81
+
82
+ def items
83
+ file = Nokogiri::XML(File.read(@projectfile))
84
+ result = file.xpath("//div[@id='body']//item/fileName/@filestem")
85
+ fs_array = result.map do |fs|
86
+ Item.new(@projectfile, fs.value)
87
+ end
88
+ return fs_array
89
+ end
90
+ def item(fs)
91
+ Item.new(@projectfile, fs)
92
+ end
93
+
94
+ def item_filestems
95
+ file = Nokogiri::XML(File.read(@projectfile))
96
+ result = file.xpath("//div[@id='body']//item/fileName/@filestem")
97
+
98
+ fs_array = result.map do |fs|
99
+ fs.value
100
+ end
101
+ return fs_array
102
+ end
103
+
104
+ def item_titles
105
+ file = Nokogiri::XML(File.read(@projectfile))
106
+ result = file.xpath("//div[@id='body']//item/title")
107
+
108
+ title_array = result.map do |title|
109
+ title.text
110
+ end
111
+ return title_array
112
+ end
113
+
114
+ def items_fs_title_hash
115
+ file = Nokogiri::XML(File.read(@projectfile))
116
+ result = file.xpath("//div[@id='body']//item")
117
+
118
+ fs_title_hash = Hash.new
119
+
120
+ result.each do |item|
121
+ title = item.children.find {|child| child.name == "title"}.text
122
+ fs = item.children.find {|child| child.name == "fileName"}.attributes["filestem"].value
123
+ fs_title_hash[fs] = title
124
+ end
125
+ return fs_title_hash
126
+
127
+
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,12 @@
1
+
2
+ require 'nokogiri'
3
+ require 'open-uri'
4
+
5
+ def xslt_transform(xmlfile, xsltfile, xslt_param_array)
6
+ xml = Nokogiri::XML(open(xmlfile))
7
+ xslt = Nokogiri::XSLT(open(xsltfile))
8
+ result_doc = xslt.transform(xml, xslt_param_array)
9
+ return result_doc
10
+ end
11
+
12
+
@@ -0,0 +1,153 @@
1
+ require 'nokogiri'
2
+ require 'rugged'
3
+ require 'lbp/functions'
4
+ require 'lbp/transcription'
5
+
6
+ module Lbp
7
+ class Item
8
+ attr_reader :fs, :local_texts_dir, :file_dir, :projectfile, :xslt_dir
9
+
10
+ def initialize(projectfile, fs)
11
+ @fs = fs
12
+ @projectfile = projectfile
13
+
14
+ @confighash = Collection.new(projectfile).confighash
15
+ @texts_dir = @confighash[:local_texts_dir]
16
+ @file_dir = @confighash[:local_texts_dir] + @fs + "/"
17
+
18
+ end
19
+ ### Item Header Extraction and Metadata Methods
20
+ def title
21
+ transcr = Transcription.new(@projectfile, self.file_hash)
22
+ transcr.title
23
+ end
24
+
25
+ ### Begin GIT functions ###
26
+ def is_git_dir
27
+ gitpath = @file_dir + ".git"
28
+
29
+ if File.directory?(gitpath)
30
+ true
31
+ else
32
+ false
33
+ end
34
+ end
35
+ def git_branches
36
+ repo = Rugged::Repository.new(@file_dir)
37
+ branches = repo.branches.map { |branch| branch.name }
38
+ return branches
39
+ end
40
+ def git_current_branch
41
+ repo = Rugged::Repository.new(@file_dir)
42
+ current_branch = repo.head.name.gsub(%r!\Arefs/heads/(.*)\z!) { $1 }
43
+ return current_branch
44
+ end
45
+ def git_tags
46
+ repo = Rugged::Repository.new(@file_dir)
47
+ tags = repo.tags.map { |tag| tag.name }
48
+ return tags
49
+ end
50
+ #need test for this
51
+ def git_checkout(branch)
52
+ repo = Rugged::Repository.new(@file_dir)
53
+ repo.checkout(branch)
54
+ end
55
+ def git_construct_remote_path
56
+ remote_path = "https://#{@confighash[:git_repo]}#{@fs}.git";
57
+ end
58
+
59
+ def git_username_password_credentials(username, password)
60
+ Rugged::Credentials::UserPassword
61
+ credentials = Rugged::Credentials::UserPassword.new(:username=>username, :password=>password)
62
+ return credentials
63
+ end
64
+ #needs a test
65
+ def git_clone(username: nil, password: nil)
66
+ remote_path = self.git_construct_remote_path
67
+ Rugged::Repository.clone_at(remote_path, @file_dir, :credentials => self.git_username_password_credentials(username, password))
68
+ end
69
+ #nneds a test
70
+ def git_pull(username: nil, password: nil)
71
+ # not sure what the Rugged API is for this.
72
+ # doesn't like this methods has been created
73
+ # for now it may have to be constructed from fetch and merge
74
+ # or my method 'git_pull' could simply delete the existing repository and the re-lcone
75
+ #this is is what i'm doing below, but it is not ideal
76
+ self.remove_local_dir
77
+ self.git_clone(username: username, password: password)
78
+ end
79
+ #needs a test
80
+ def remove_local_dir
81
+ FileUtils.rm_rf @file_dir
82
+ end
83
+ ### End Git Methods ###
84
+ ### Begin Order Info ##
85
+
86
+ # previous and next functions don't handle ends of arrays very well
87
+ # they also rely on the "item_filestems" methods which works but should be changed see comments in collection file
88
+ def previous
89
+ sequence_array = Collection.new(@projectfile).item_filestems
90
+ #if sequence_array[sequence_array.index(@fs) - 1 ] != nil
91
+ previous_fs = sequence_array[sequence_array.index(@fs) - 1]
92
+ previous_item = Item.new(@projectfile, previous_fs)
93
+ #else
94
+ # previous_item = nil
95
+ #end
96
+ return previous_item
97
+ end
98
+ def next
99
+ sequence_array = Collection.new(@projectfile).item_filestems
100
+ #if sequence_array[@sequence_array.index(@fs) + 1 ] != nil
101
+ next_fs = sequence_array[sequence_array.index(@fs) + 1]
102
+ next_item = Item.new(@projectfile, next_fs)
103
+ #else
104
+ # next_item = nil
105
+ #end
106
+ return next_item
107
+ end
108
+ def order_number
109
+ sequence_array = Collection.new(@projectfile).item_filestems
110
+ array_number = sequence_array.index(@fs)
111
+ sequence_number = array_number + 1
112
+ return sequence_number
113
+ end
114
+
115
+ def file_path(source: 'local', wit: 'critical', ed: 'master')
116
+ if wit == 'critical'
117
+ if source == "origin"
118
+ file_path = "https://#{@confighash[:git_repo]}#{@fs}/raw/#{ed}/#{@fs}.xml"
119
+ else
120
+ file_path = @file_dir + @fs + ".xml"
121
+ end
122
+ else
123
+ if source == "origin"
124
+ file_path = "http://#{@confighash[:git_repo]}#{@fs}/raw/#{ed}/#{wit}_#{@fs}.xml"
125
+ else
126
+ file_path = @file_dir + wit + "_" + @fs + ".xml"
127
+ end
128
+ end
129
+ return file_path
130
+ end
131
+ def file_hash(source: 'local', wit: 'critical', ed: 'master')
132
+ type = if wit == "critical" then "critical" else "documentary" end
133
+ filehash = {path: self.file_path(source: source, wit: wit, ed: ed), fs: @fs, ed: ed, type: type, source: source}
134
+
135
+ return filehash
136
+ end
137
+
138
+ def transcription(source: 'local', wit: 'critical', ed: 'master')
139
+ filehash = self.file_hash(source: source, wit: wit, ed: ed)
140
+ transcr = Transcription.new(@projectfile, filehash)
141
+ end
142
+ def transcriptions(source: 'local', ed: 'master')
143
+ file = Nokogiri::XML(File.read(@projectfile))
144
+ parts = file.xpath("//item[fileName/@filestem='#{@fs}']/hasParts/part/slug")
145
+ transcription_array = parts.map do |part|
146
+ self.transcription(source: source, wit: part.text, ed: ed)
147
+ end
148
+ transcription_array << self.transcription(source: source, wit: 'critical', ed: ed)
149
+
150
+ return transcription_array
151
+ end
152
+ end
153
+ end