ldpath 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.circleci/config.yml +49 -0
- data/.rubocop.yml +40 -1
- data/.travis.yml +3 -1
- data/CHANGELOG.md +9 -0
- data/CONTRIBUTING.md +45 -13
- data/Gemfile +3 -6
- data/README.md +15 -4
- data/Rakefile +2 -0
- data/bin/ldpath +6 -1
- data/ldpath.gemspec +11 -8
- data/lib/ldpath/field_mapping.rb +2 -0
- data/lib/ldpath/functions.rb +4 -4
- data/lib/ldpath/loaders/direct.rb +17 -0
- data/lib/ldpath/loaders/graph.rb +15 -0
- data/lib/ldpath/loaders/linked_data_fragment.rb +31 -0
- data/lib/ldpath/loaders.rb +9 -0
- data/lib/ldpath/parser.rb +4 -2
- data/lib/ldpath/program.rb +19 -9
- data/lib/ldpath/result.rb +7 -13
- data/lib/ldpath/selectors.rb +45 -26
- data/lib/ldpath/tests.rb +26 -5
- data/lib/ldpath/transform.rb +16 -14
- data/lib/ldpath/version.rb +3 -1
- data/lib/ldpath.rb +15 -8
- data/spec/ldpath_parser_spec.rb +6 -4
- data/spec/ldpath_program_spec.rb +113 -70
- data/spec/ldpath_spec.rb +2 -0
- data/spec/ldpath_transform_spec.rb +5 -3
- data/spec/lib/functions/list_spec.rb +2 -0
- data/spec/spec_helper.rb +2 -18
- metadata +51 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 82871915420d36fcd416a717f35185c1c1ab830390a65b071ea3740301d066b1
|
4
|
+
data.tar.gz: 41ecdc3227ddbf93b00dfe7929a4efaae21a31188a87fab19695958e3d946bfa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b924bc7118ed584e4b0cf140ee51655b969a0ea7c0740ad17aae8732204833b6588971518e1db7e96ed6702f460098caa1f0cf83f2e49ed393dd229b7c158cd
|
7
|
+
data.tar.gz: dc0452a7565fb8d26ae1c078cd756479d88b2008aaf5faf8a64e7e6b17e667de358ac8836efd1296feb4662bd4ae31574c05b322995d7d42768aa138ca180a1a
|
@@ -0,0 +1,49 @@
|
|
1
|
+
---
|
2
|
+
version: 2.1
|
3
|
+
orbs:
|
4
|
+
samvera: samvera/circleci-orb@1.0
|
5
|
+
|
6
|
+
jobs:
|
7
|
+
bundle_and_test:
|
8
|
+
parameters:
|
9
|
+
ruby_version:
|
10
|
+
type: string
|
11
|
+
bundler_version:
|
12
|
+
type: string
|
13
|
+
default: 2.3.10
|
14
|
+
|
15
|
+
executor:
|
16
|
+
name: 'samvera/ruby'
|
17
|
+
ruby_version: << parameters.ruby_version >>
|
18
|
+
|
19
|
+
environment:
|
20
|
+
COVERAGE: true
|
21
|
+
|
22
|
+
working_directory: ~/ldpath
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- samvera/cached_checkout
|
26
|
+
|
27
|
+
- run: 'sudo apt-get update'
|
28
|
+
|
29
|
+
- samvera/bundle:
|
30
|
+
ruby_version: << parameters.ruby_version >>
|
31
|
+
bundler_version: << parameters.bundler_version >>
|
32
|
+
cache_version: "2"
|
33
|
+
|
34
|
+
- samvera/rubocop
|
35
|
+
|
36
|
+
- samvera/parallel_rspec
|
37
|
+
|
38
|
+
workflows:
|
39
|
+
ci:
|
40
|
+
jobs:
|
41
|
+
- bundle_and_test:
|
42
|
+
name: "ruby3-1"
|
43
|
+
ruby_version: "3.1.2"
|
44
|
+
- bundle_and_test:
|
45
|
+
name: "ruby3-0"
|
46
|
+
ruby_version: "3.0.0"
|
47
|
+
- bundle_and_test:
|
48
|
+
name: "ruby2-7"
|
49
|
+
ruby_version: "2.7.5"
|
data/.rubocop.yml
CHANGED
@@ -1,8 +1,47 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
bixby: bixby_default.yml
|
3
|
+
|
1
4
|
inherit_from:
|
2
5
|
- .rubocop_todo.yml
|
3
6
|
|
4
|
-
|
7
|
+
Layout/LineLength:
|
5
8
|
Max: 140
|
9
|
+
Exclude:
|
10
|
+
- 'lib/ldpath/parser.rb'
|
11
|
+
|
12
|
+
Metrics/AbcSize:
|
13
|
+
Exclude:
|
14
|
+
- 'lib/ldpath/selectors.rb'
|
15
|
+
|
16
|
+
Metrics/CyclomaticComplexity:
|
17
|
+
Exclude:
|
18
|
+
- 'lib/ldpath/selectors.rb'
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Exclude:
|
22
|
+
- 'spec/ldpath_parser_spec.rb'
|
23
|
+
- 'spec/ldpath_program_spec.rb'
|
24
|
+
- 'spec/ldpath_transform_spec.rb'
|
25
|
+
- 'spec/lib/functions/list_spec.rb'
|
26
|
+
|
27
|
+
Metrics/ClassLength:
|
28
|
+
Exclude:
|
29
|
+
- 'lib/ldpath/parser.rb'
|
30
|
+
- 'lib/ldpath/transform.rb'
|
31
|
+
|
32
|
+
Metrics/MethodLength:
|
33
|
+
Exclude:
|
34
|
+
- 'lib/ldpath/field_mapping.rb'
|
35
|
+
- 'lib/ldpath/selectors.rb'
|
36
|
+
- 'lib/ldpath/transform.rb'
|
37
|
+
|
38
|
+
Metrics/ModuleLength:
|
39
|
+
Exclude:
|
40
|
+
- 'lib/ldpath/functions.rb'
|
41
|
+
|
42
|
+
Metrics/ParameterLists:
|
43
|
+
Exclude:
|
44
|
+
- 'lib/ldpath/functions.rb'
|
6
45
|
|
7
46
|
Style/WordArray:
|
8
47
|
Enabled: false
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
### 1.1.0 (2020-01-21)
|
2
|
+
|
3
|
+
* replace linkeddata dependency with rdf and nokogiri
|
4
|
+
* update dependency on bundler to ~> 2.0
|
5
|
+
|
6
|
+
### 1.0.1 (2019-04-23)
|
7
|
+
|
8
|
+
* remove version restriction for linkeddata dependency
|
9
|
+
|
1
10
|
### 1.0.0 (2019-03-29)
|
2
11
|
|
3
12
|
* add ability to restrict results to passed in context
|
data/CONTRIBUTING.md
CHANGED
@@ -22,6 +22,28 @@ https://wiki.duraspace.org/display/samvera/Samvera+Community+Intellectual+Proper
|
|
22
22
|
|
23
23
|
You should also add yourself to the `CONTRIBUTORS.md` file in the root of the project.
|
24
24
|
|
25
|
+
## Language
|
26
|
+
|
27
|
+
The language we use matters. Today, tomorrow, and for years to come
|
28
|
+
people will read the code we write. They will judge us for our
|
29
|
+
design, logic, and the words we use to describe the system.
|
30
|
+
|
31
|
+
Our words should be accessible. Favor descriptive words that give
|
32
|
+
meaning while avoiding reinforcing systemic inequities. For example,
|
33
|
+
in the Samvera community, we should favor using allowed\_list instead
|
34
|
+
of whitelist, denied\_list instead of blacklist, or source/copy
|
35
|
+
instead of master/slave.
|
36
|
+
|
37
|
+
We're going to get it wrong, but this is a call to keep working to
|
38
|
+
make it right. View our code and the words we choose as a chance to
|
39
|
+
have a conversation. A chance to grow an understanding of the systems
|
40
|
+
we develop as well as the systems in which we live.
|
41
|
+
|
42
|
+
See [“Blacklists” and “whitelists”: a salutary warning concerning the
|
43
|
+
prevalence of racist language in discussions of predatory
|
44
|
+
publishing](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6148600/) for
|
45
|
+
further details.
|
46
|
+
|
25
47
|
## Contribution Tasks
|
26
48
|
|
27
49
|
* Reporting Issues
|
@@ -34,7 +56,7 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
|
|
34
56
|
### Reporting Issues
|
35
57
|
|
36
58
|
* Make sure you have a [GitHub account](https://github.com/signup/free)
|
37
|
-
* Submit a [Github issue](https://github.com/samvera/
|
59
|
+
* Submit a [Github issue](https://github.com/samvera-labs/ldpath/issues) by:
|
38
60
|
* Clearly describing the issue
|
39
61
|
* Provide a descriptive summary
|
40
62
|
* Explain the expected behavior
|
@@ -45,15 +67,22 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
|
|
45
67
|
|
46
68
|
* Fork the repository on GitHub
|
47
69
|
* Create a topic branch from where you want to base your work.
|
48
|
-
* This is usually the
|
49
|
-
* To quickly create a topic branch based on
|
50
|
-
* Then checkout the new branch with `git checkout fix/
|
51
|
-
* Please avoid working directly on the `
|
70
|
+
* This is usually the `main` branch.
|
71
|
+
* To quickly create a topic branch based on `main`; `git branch fix/main/my_contribution main`
|
72
|
+
* Then checkout the new branch with `git checkout fix/main/my_contribution`.
|
73
|
+
* Please avoid working directly on the `main` branch.
|
74
|
+
* Please do not create a branch called `master`. (See note below.)
|
52
75
|
* You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
|
53
76
|
* Make sure you have added sufficient tests and documentation for your changes.
|
54
77
|
* Test functionality with RSpec; Test features / UI with Capybara.
|
55
78
|
* Run _all_ the tests to assure nothing else was accidentally broken.
|
56
79
|
|
80
|
+
NOTE: This repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct)
|
81
|
+
and [language recommendations](#language).
|
82
|
+
Please ***do not*** create a branch called `master` for this repository or as part of
|
83
|
+
your pull request; the branch will either need to be removed or renamed before it can
|
84
|
+
be considered for inclusion in the code base and history of this repository.
|
85
|
+
|
57
86
|
### Documenting Code
|
58
87
|
|
59
88
|
* All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
|
@@ -109,15 +138,15 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
|
|
109
138
|
### Submitting Changes
|
110
139
|
|
111
140
|
* Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
|
112
|
-
* Make sure your branch is up to date with its parent branch (i.e.
|
113
|
-
* `git checkout
|
141
|
+
* Make sure your branch is up to date with its parent branch (i.e. main)
|
142
|
+
* `git checkout main`
|
114
143
|
* `git pull --rebase`
|
115
144
|
* `git checkout <your-branch>`
|
116
|
-
* `git rebase
|
145
|
+
* `git rebase main`
|
117
146
|
* It is a good idea to run your tests again.
|
118
147
|
* If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
|
119
148
|
* [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
|
120
|
-
* `git rebase --interactive
|
149
|
+
* `git rebase --interactive main` ([See Github help](https://help.github.com/articles/interactive-rebase))
|
121
150
|
* Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
|
122
151
|
* Push your changes to a topic branch in your fork of the repository.
|
123
152
|
* Submit a pull request from your fork to the project.
|
@@ -127,12 +156,15 @@ You should also add yourself to the `CONTRIBUTORS.md` file in the root of the pr
|
|
127
156
|
We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
|
128
157
|
Common checks that may occur in our repositories:
|
129
158
|
|
130
|
-
1.
|
131
|
-
2.
|
159
|
+
1. [CircleCI](https://circleci.com/gh/samvera) - where our automated tests are running
|
160
|
+
2. RuboCop/Bixby - where we check for style violations
|
161
|
+
3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
|
162
|
+
4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
|
163
|
+
|
132
164
|
|
133
165
|
If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
|
134
166
|
|
135
|
-
*Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (
|
167
|
+
*Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (CI tests are usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request.*
|
136
168
|
|
137
169
|
#### Things to Consider When Reviewing
|
138
170
|
|
@@ -149,7 +181,7 @@ This is your chance for a mentoring moment of another developer. Take time to gi
|
|
149
181
|
* Do new or changed methods, modules, and classes have documentation?
|
150
182
|
* Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
|
151
183
|
* Does the description of the new/changed specs match your understanding of what the spec is doing?
|
152
|
-
* Did the
|
184
|
+
* Did the Continuous Integration tests complete successfully?
|
153
185
|
|
154
186
|
If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
|
155
187
|
|
data/Gemfile
CHANGED
@@ -1,8 +1,5 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
source 'https://rubygems.org'
|
4
4
|
|
5
|
-
|
6
|
-
gem 'coveralls', require: false
|
7
|
-
gem 'simplecov', require: false
|
8
|
-
end
|
5
|
+
gemspec path: File.expand_path(__dir__)
|
data/README.md
CHANGED
@@ -3,11 +3,12 @@
|
|
3
3
|
This is a ruby implementation of [LDPath](http://marmotta.apache.org/ldpath/language.html), a language for selecting values linked data resources.
|
4
4
|
|
5
5
|
[![Gem Version](https://badge.fury.io/rb/ldpath.png)](http://badge.fury.io/rb/ldpath)
|
6
|
-
[![Build Status](https://
|
7
|
-
[![Coverage Status](https://coveralls.io/repos/github/samvera-labs/ldpath/badge.svg?branch=master)](https://coveralls.io/github/samvera-labs/ldpath?branch=master)
|
6
|
+
[![Build Status](https://circleci.com/gh/samvera-labs/ldpath.svg?style=svg)]
|
8
7
|
|
9
8
|
## Installation
|
10
9
|
|
10
|
+
### Required gem installation
|
11
|
+
|
11
12
|
Add this line to your application's Gemfile:
|
12
13
|
|
13
14
|
gem 'ldpath'
|
@@ -20,6 +21,10 @@ Or install it yourself as:
|
|
20
21
|
|
21
22
|
$ gem install ldpath
|
22
23
|
|
24
|
+
### Additional gem installations
|
25
|
+
|
26
|
+
To support RDF serializations, you will need to either install the [linkeddata gem](https://github.com/ruby-rdf/linkeddata) which installs a large set of RDF serializations or, in order to have a smaller dependency footprint, install gems for only the serializations your plan to use in your app. The list of serializations are in the [README](https://github.com/ruby-rdf/linkeddata/blob/develop/README.md#features) for the linkeddata gem.
|
27
|
+
|
23
28
|
## Usage
|
24
29
|
|
25
30
|
```ruby
|
@@ -35,14 +40,20 @@ uri = RDF::URI.new "info:a"
|
|
35
40
|
context = RDF::Graph.new << [uri, RDF::Vocab::DC.title, "Some Title"]
|
36
41
|
|
37
42
|
program = Ldpath::Program.parse my_program
|
38
|
-
output = program.evaluate uri, context
|
43
|
+
output = program.evaluate uri, context: context
|
39
44
|
# => { ... }
|
40
45
|
```
|
41
|
-
|
46
|
+
|
42
47
|
## Compatibility
|
43
48
|
|
44
49
|
* Ruby 2.5 or the latest 2.4 version is recommended. Later versions may also work.
|
45
50
|
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
If you're working on PR for this project, create a feature branch off of `main`.
|
54
|
+
|
55
|
+
This repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct) and [language recommendations](https://github.com/samvera/maintenance/blob/master/templates/CONTRIBUTING.md#language). Please ***do not*** create a branch called `master` for this repository or as part of your pull request; the branch will either need to be removed or renamed before it can be considered for inclusion in the code base and history of this repository.
|
56
|
+
|
46
57
|
## Product Owner & Maintenance
|
47
58
|
|
48
59
|
LDPath is moving toward being a Core Component of the Samvera community. The documentation for
|
data/Rakefile
CHANGED
data/bin/ldpath
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require 'optparse'
|
4
5
|
require 'open-uri'
|
@@ -6,8 +7,10 @@ require 'ldpath'
|
|
6
7
|
|
7
8
|
begin
|
8
9
|
require 'rest-client'
|
10
|
+
# rubocop:disable Lint/SuppressedException
|
9
11
|
rescue LoadError
|
10
12
|
end
|
13
|
+
# rubocop:enable Lint/SuppressedException
|
11
14
|
|
12
15
|
options = {}
|
13
16
|
opt_parser = OptionParser.new do |opts|
|
@@ -15,7 +18,9 @@ opt_parser = OptionParser.new do |opts|
|
|
15
18
|
|
16
19
|
opts.on("--program=STRING_URI_OR_FILE", "LDPath program to run (reads from STDIN by default)") do |program|
|
17
20
|
options[:program] = if File.exist?(program) || program =~ /^http/
|
21
|
+
# rubocop:disable Security/Open
|
18
22
|
open(program).read
|
23
|
+
# rubocop:enable Security/Open
|
19
24
|
elsif program.strip == "-"
|
20
25
|
$stdin.read
|
21
26
|
else
|
@@ -29,7 +34,7 @@ opt_parser.parse!
|
|
29
34
|
uri = ARGV.shift
|
30
35
|
|
31
36
|
if uri.nil?
|
32
|
-
|
37
|
+
warn opt_parser
|
33
38
|
raise OptionParser::MissingArgument, "URI" unless uri
|
34
39
|
end
|
35
40
|
|
data/ldpath.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'ldpath/version'
|
5
6
|
|
@@ -16,17 +17,19 @@ Gem::Specification.new do |spec|
|
|
16
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
19
|
spec.require_paths = ["lib"]
|
20
|
+
spec.required_ruby_version = ">= 2.7.5"
|
19
21
|
|
22
|
+
spec.add_dependency "nokogiri", "~> 1.8"
|
20
23
|
spec.add_dependency "parslet"
|
21
|
-
spec.add_dependency "
|
24
|
+
spec.add_dependency "rdf", '~> 3.0'
|
25
|
+
spec.add_dependency 'rdf-vocab', '~> 3.0'
|
22
26
|
|
23
|
-
|
24
|
-
spec.add_development_dependency "bundler", "~> 1.5"
|
27
|
+
spec.add_development_dependency "bixby", "~> 5.0"
|
25
28
|
spec.add_development_dependency "byebug"
|
26
29
|
spec.add_development_dependency "rake"
|
27
|
-
spec.add_development_dependency "rspec"
|
28
30
|
spec.add_development_dependency "rdf-reasoner"
|
29
|
-
spec.add_development_dependency "
|
30
|
-
spec.add_development_dependency
|
31
|
+
spec.add_development_dependency "rspec"
|
32
|
+
spec.add_development_dependency 'rspec_junit_formatter'
|
33
|
+
spec.add_development_dependency "rubocop-rake"
|
31
34
|
spec.add_development_dependency "webmock"
|
32
35
|
end
|
data/lib/ldpath/field_mapping.rb
CHANGED
data/lib/ldpath/functions.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# rubocop:disable Style/MethodName
|
2
4
|
module Ldpath
|
3
5
|
module Functions
|
@@ -60,13 +62,11 @@ module Ldpath
|
|
60
62
|
end
|
61
63
|
|
62
64
|
# collections
|
63
|
-
def flatten(uri, context, lists)
|
65
|
+
def flatten(uri, context, lists, &block)
|
64
66
|
return to_enum(:flatten, uri, context, lists) unless block_given?
|
65
67
|
|
66
68
|
deep_flatten_compact(lists).each do |x|
|
67
|
-
RDF::List.new(subject: x, graph: context).to_a.each
|
68
|
-
yield i
|
69
|
-
end
|
69
|
+
RDF::List.new(subject: x, graph: context).to_a.each(&block)
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ldpath
|
4
|
+
module Loaders
|
5
|
+
class Direct
|
6
|
+
def load(uri)
|
7
|
+
Ldpath.logger.debug "Loading #{uri.inspect}"
|
8
|
+
|
9
|
+
reader_types = RDF::Format.reader_types.reject { |t| t.to_s =~ /html/ }.map do |t|
|
10
|
+
%r{text/(?:plain|html)}.match?(t.to_s) ? "#{t};q=0.5" : t
|
11
|
+
end
|
12
|
+
|
13
|
+
RDF::Graph.load(uri, headers: { 'Accept' => reader_types.join(", ") })
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'cgi'
|
4
|
+
|
5
|
+
module Ldpath
|
6
|
+
module Loaders
|
7
|
+
class LinkedDataFragment
|
8
|
+
NEXT_PAGE = RDF::URI('http://www.w3.org/ns/hydra/core#nextPage')
|
9
|
+
|
10
|
+
def initialize(endpoint)
|
11
|
+
@endpoint = endpoint
|
12
|
+
end
|
13
|
+
|
14
|
+
def load(uri)
|
15
|
+
Ldpath.logger.debug "Loading LDF data for #{uri.inspect}"
|
16
|
+
|
17
|
+
graph = RDF::Graph.new
|
18
|
+
request_uri = RDF::URI("#{@endpoint}?subject=#{CGI.escape(uri)}")
|
19
|
+
|
20
|
+
while request_uri
|
21
|
+
Ldpath.logger.debug " -- querying #{request_uri}"
|
22
|
+
request_graph = RDF::Graph.load(request_uri)
|
23
|
+
graph.insert_statements(request_graph)
|
24
|
+
request_uri = request_graph.first_object([request_uri, NEXT_PAGE, nil])
|
25
|
+
end
|
26
|
+
|
27
|
+
graph
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/ldpath/parser.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'parslet'
|
2
4
|
|
3
5
|
module Ldpath
|
@@ -39,7 +41,7 @@ module Ldpath
|
|
39
41
|
|
40
42
|
rule(:exponent) { match('[Ee]') >> match("[+-]").maybe >> match("\\d").repeat(1) }
|
41
43
|
rule(:numeric_literal) { integer.as(:integer) | decimal.as(:decimal) | double.as(:double) }
|
42
|
-
rule(:boolean_literal) { str('true').as(
|
44
|
+
rule(:boolean_literal) { str('true').as(true) | str('false').as(false) }
|
43
45
|
|
44
46
|
rule(:string) { string_literal_quote | string_literal_single_quote | string_literal_long_single_quote | string_literal_long_quote }
|
45
47
|
|
@@ -150,7 +152,7 @@ module Ldpath
|
|
150
152
|
(identifier | str("")).as(:id) >> wsp? >>
|
151
153
|
colon >> wsp? >>
|
152
154
|
iriref >> space? >> scolon.maybe
|
153
|
-
|
155
|
+
).as(:prefixID)
|
154
156
|
end
|
155
157
|
|
156
158
|
# @graph iri, iri, iri ;
|
data/lib/ldpath/program.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Ldpath
|
2
4
|
class Program
|
3
5
|
ParseError = Class.new StandardError
|
@@ -6,7 +8,7 @@ module Ldpath
|
|
6
8
|
def parse(program, transform_context = {})
|
7
9
|
ast = transform.apply load(program), transform_context
|
8
10
|
|
9
|
-
Ldpath::Program.new ast.compact, transform_context
|
11
|
+
Ldpath::Program.new ast.compact, **transform_context
|
10
12
|
end
|
11
13
|
|
12
14
|
def load(program)
|
@@ -26,20 +28,28 @@ module Ldpath
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
|
29
|
-
attr_reader :mappings, :prefixes, :filters
|
30
|
-
|
31
|
-
|
32
|
-
@
|
33
|
-
@
|
31
|
+
attr_reader :mappings, :prefixes, :filters, :default_loader, :loaders
|
32
|
+
|
33
|
+
def initialize(mappings, default_loader: Ldpath::Loaders::Direct.new, prefixes: {}, filters: [], loaders: {})
|
34
|
+
@mappings = mappings
|
35
|
+
@default_loader = default_loader
|
36
|
+
@loaders = loaders
|
37
|
+
@prefixes = prefixes
|
38
|
+
@filters = filters
|
34
39
|
end
|
35
40
|
|
36
41
|
def evaluate(uri, context: nil, limit_to_context: false)
|
37
42
|
result = Ldpath::Result.new(self, uri, context: context, limit_to_context: limit_to_context)
|
38
|
-
|
39
|
-
return {} unless filters.all? { |f| f.evaluate(result, uri, result.context) }
|
40
|
-
end
|
43
|
+
return {} if !filters.empty? && !filters.all? { |f| f.evaluate(result, uri, result.context) }
|
41
44
|
|
42
45
|
result.to_hash
|
43
46
|
end
|
47
|
+
|
48
|
+
def load(uri)
|
49
|
+
loader = loaders.find { |k, _v| uri =~ k }&.last
|
50
|
+
loader ||= default_loader
|
51
|
+
|
52
|
+
loader.load(uri)
|
53
|
+
end
|
44
54
|
end
|
45
55
|
end
|
data/lib/ldpath/result.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/module/delegation'
|
4
|
+
|
1
5
|
module Ldpath
|
2
6
|
class Result
|
3
7
|
include Ldpath::Functions
|
@@ -13,7 +17,7 @@ module Ldpath
|
|
13
17
|
end
|
14
18
|
|
15
19
|
def loading(uri, context)
|
16
|
-
return unless uri.to_s
|
20
|
+
return unless /^http/.match?(uri.to_s)
|
17
21
|
return if loaded[uri.to_s]
|
18
22
|
|
19
23
|
context << load_graph(uri.to_s) unless limit_to_context?
|
@@ -21,15 +25,7 @@ module Ldpath
|
|
21
25
|
end
|
22
26
|
|
23
27
|
def load_graph(uri)
|
24
|
-
cache[uri] ||=
|
25
|
-
Ldpath.logger.debug "[#{object_id}] Loading #{uri.inspect}"
|
26
|
-
|
27
|
-
reader_types = RDF::Format.reader_types.reject { |t| t.to_s =~ /html/ }.map do |t|
|
28
|
-
t.to_s =~ %r{text/(?:plain|html)} ? "#{t};q=0.5" : t
|
29
|
-
end
|
30
|
-
|
31
|
-
RDF::Graph.load(uri, headers: { 'Accept' => reader_types.join(", ") }).tap { loaded[uri] = true }
|
32
|
-
end
|
28
|
+
cache[uri] ||= program.load(uri).tap { loaded[uri] = true }
|
33
29
|
end
|
34
30
|
|
35
31
|
def [](key)
|
@@ -54,9 +50,7 @@ module Ldpath
|
|
54
50
|
@context ||= load_graph(uri.to_s)
|
55
51
|
end
|
56
52
|
|
57
|
-
|
58
|
-
program.prefixes
|
59
|
-
end
|
53
|
+
delegate :prefixes, to: :program
|
60
54
|
|
61
55
|
def meta
|
62
56
|
@meta ||= {}
|