marmotta 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa29f4986133a699789cb672308b115155c2918b
4
+ data.tar.gz: dfb1b6ef34f841307520d15b3f04dcf042cf0ec8
5
+ SHA512:
6
+ metadata.gz: b92046a3197706f161961e3ded718fa6af5d5a02e35af3bb9d2c0db8d0b4d6551c80823e78f0fdd59bbf9acb70e57034b3201de82c33318ab08a28871ffe6f41
7
+ data.tar.gz: 9a913ddd350d40578bc4bdd58308fa5ff4b79df222a262806562e11fa478104057f9798ef61acfdd1d1af763f9a51f9a74f2ceec7a70ebb81096a7c785ac3e82
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /jetty/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in marmotta.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 TODO: Write your name
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,76 @@
1
+ # Marmotta
2
+ [![Circle CI](https://circleci.com/gh/terrellt/marmotta.svg?style=svg)](https://circleci.com/gh/terrellt/marmotta)
3
+
4
+ Marmotta is a small ruby client to abstract away interacting with the [Apache
5
+ Marmotta](http://marmotta.apache.org/) server.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'marmotta'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install marmotta
22
+
23
+ ## Usage
24
+
25
+ ### Connection
26
+
27
+ ```ruby
28
+ # Initialize Marmotta with a URI and a context.
29
+ # The context defines the named graph triples will be posted to and which one
30
+ # will be deleted when #delete_all is called.
31
+ connection = Marmotta::Connection.new(uri: "http://localhost:8983/marmotta", context: "test")
32
+
33
+ connection.delete_all # Empty out the "test" context.
34
+
35
+ # Request this URI - Marmotta will use LDCache if configured, automatically
36
+ # going out and getting the triples which resolve at this URI.
37
+ graph = connection.get("http://id.loc.gov/authorities/names/n80017721")
38
+
39
+ # Add the triples in the graph to the "test" context. Works with any
40
+ # RDF::Enumerable
41
+ connection.post(graph)
42
+ ```
43
+
44
+ ### Resource
45
+
46
+ A resource stores which subject URI you're requesting and abstracts out the
47
+ connection details.
48
+
49
+ ```ruby
50
+ # You need a connection
51
+ connection = Marmotta::Connection.new(uri: "http://localhost:8983/marmotta", context: "test")
52
+
53
+ resource = Marmotta::Resource.new("http://id.loc.gov/authorities/names/n80017721", connection: connection)
54
+
55
+ resulting_graph = resource.get # Get the graph for this resource - equivalent to connection.get(uri)
56
+
57
+ resource.delete # Delete this resource from Marmotta - equivalent to connection.delete(uri)
58
+
59
+ resource.post(graph) # Post a graph to the connection associated with this URI. Currently it does not enforce any subject requirements on the graph that's posted, so it's exactly equivalent to connection.post(graph)
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To start Marmotta run `rake jetty:start`
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it ( https://github.com/[my-github-username]/marmotta/fork )
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "jettywrapper"
3
+
4
+ MARMOTTA_HOME = ENV['MARMOTTA_HOME'] ||
5
+ File.expand_path(File.join(Jettywrapper.app_root, 'marmotta'))
6
+ Jettywrapper.url =
7
+ 'https://github.com/dpla/marmotta-jetty/archive/3.3.0-solr-4.10.3.zip'
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "marmotta"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/jetty_wait ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env sh
2
+
3
+ until $(curl --output /dev/null --silent --head --fail http://localhost:8983/marmotta); do
4
+ printf '.'
5
+ sleep 1
6
+ done
data/bin/setup ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ bundle exec rake jetty:clean
8
+
9
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,11 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.0
4
+ dependencies:
5
+ pre:
6
+ - gem install bundler
7
+ post:
8
+ - bundle exec rake jetty:clean
9
+ - cd jetty && java -Djetty.port=8983 -Dsolr.solr.home=/home/ubuntu/marmotta/jetty/solr -Dmarmotta.home=/home/ubuntu/marmotta/jetty/marmotta -XX:MaxPermSize=256m -Xmx512m -jar start.jar:
10
+ background: true
11
+ - bin/jetty_wait
@@ -0,0 +1,68 @@
1
+ module Marmotta
2
+ class Connection
3
+ attr_reader :uri, :context
4
+ def initialize(uri:, context: "default")
5
+ @uri = uri
6
+ @context = context
7
+ end
8
+
9
+ def delete_all
10
+ connection.delete("context/#{context}") do |c|
11
+ c.query.delete(:graph)
12
+ end
13
+ end
14
+
15
+ # Returns an RDFSource represented by the resource URI.
16
+ # @param [String, #to_s] resource_uri URI to request
17
+ # @return [RDF::Graph] The resulting graph
18
+ def get(resource_uri)
19
+ result = connection.get("resource") do |request|
20
+ request.query[:uri] = resource_uri.to_s
21
+ request.query.delete(:graph)
22
+ end
23
+ MaybeGraphResult.new(result).value
24
+ end
25
+
26
+ # Posts a graph to Marmotta in the appropriate context.
27
+ # @param [RDF::Enumerable] graph The graph to post.
28
+ # @return [True, False] Result of posting.
29
+ def post(graph)
30
+ sparql_update_client.insert_data(graph, :graph => context_uri.to_s)
31
+ true
32
+ end
33
+
34
+ # Deletes a subject from the context.
35
+ # @param [String, #to_s] resource_uri URI of resource to delete.
36
+ # @return [True, False] Result of deleting.
37
+ # @todo Should this only delete triples from the given context?
38
+ def delete(resource_uri)
39
+ connection.delete("resource") do |request|
40
+ request.query[:uri] = resource_uri.to_s
41
+ request.query.delete(:graph)
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def connection
48
+ @connection ||= ::Hurley::Client.new(uri).tap do |c|
49
+ c.header[:accept] = mime_type
50
+ c.header[:content_type] = mime_type
51
+ c.query[:graph] = context_uri.to_s
52
+ end
53
+ end
54
+
55
+ def sparql_update_client
56
+ @sparql_update_client ||= SPARQL::Client.new("#{uri}/sparql/update")
57
+ end
58
+
59
+ def mime_type
60
+ "application/ld+json"
61
+ end
62
+
63
+ # @todo Support arbitrary non-Marmotta contexts.
64
+ def context_uri
65
+ ::RDF::URI("#{uri}/context/#{context}")
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,28 @@
1
+ ##
2
+ # Encapsulates how to handle turning a Hurley result into an RDF::Graph.
3
+ class MaybeGraphResult
4
+ attr_reader :result
5
+
6
+ # @param [Hurley::Response] result A web response object.
7
+ def initialize(result)
8
+ @result = result
9
+ end
10
+
11
+ def value
12
+ if graph?
13
+ parsed_graph
14
+ else
15
+ RDF::Graph.new
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def graph?
22
+ result.success?
23
+ end
24
+
25
+ def parsed_graph
26
+ JSON::LD::Reader.new(result.body)
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ module Marmotta
2
+ class Resource
3
+ attr_reader :subject_uri, :connection
4
+ def initialize(subject_uri, connection:)
5
+ @subject_uri = subject_uri
6
+ @connection = connection
7
+ end
8
+
9
+ def delete
10
+ connection.delete(subject_uri)
11
+ end
12
+
13
+ def get
14
+ connection.get(subject_uri)
15
+ end
16
+
17
+ def post(graph)
18
+ connection.post(graph)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Marmotta
2
+ VERSION = "0.1.0"
3
+ end
data/lib/marmotta.rb ADDED
@@ -0,0 +1,11 @@
1
+ require "marmotta/version"
2
+ require "hurley"
3
+ require "rdf"
4
+ require "json/ld"
5
+ require "sparql/client"
6
+
7
+ module Marmotta
8
+ autoload :Connection, 'marmotta/connection'
9
+ autoload :Resource, 'marmotta/resource'
10
+ autoload :MaybeGraphResult, 'marmotta/maybe_graph_result'
11
+ end
data/marmotta.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'marmotta/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "marmotta"
8
+ spec.version = Marmotta::VERSION
9
+ spec.authors = ["Trey Terell"]
10
+ spec.email = ["treydt@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby gem to interface with Apache Marmotta}
13
+ spec.homepage = "https://github.com/terrellt/marmotta"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
17
+ # delete this section to allow pushing this gem to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "hurley"
30
+ spec.add_dependency "rdf"
31
+ spec.add_dependency "json-ld"
32
+ spec.add_dependency "sparql-client"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.9"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "webmock"
37
+ spec.add_development_dependency "jettywrapper"
38
+ spec.add_development_dependency "rspec"
39
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marmotta
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Trey Terell
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hurley
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdf
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json-ld
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sparql-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.9'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: jettywrapper
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email:
141
+ - treydt@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - ".rspec"
148
+ - ".travis.yml"
149
+ - CODE_OF_CONDUCT.md
150
+ - Gemfile
151
+ - LICENSE.txt
152
+ - README.md
153
+ - Rakefile
154
+ - bin/console
155
+ - bin/jetty_wait
156
+ - bin/setup
157
+ - circle.yml
158
+ - lib/marmotta.rb
159
+ - lib/marmotta/connection.rb
160
+ - lib/marmotta/maybe_graph_result.rb
161
+ - lib/marmotta/resource.rb
162
+ - lib/marmotta/version.rb
163
+ - marmotta.gemspec
164
+ homepage: https://github.com/terrellt/marmotta
165
+ licenses:
166
+ - MIT
167
+ metadata:
168
+ allowed_push_host: https://rubygems.org
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.4.5
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Ruby gem to interface with Apache Marmotta
189
+ test_files: []
190
+ has_rdoc: