odrl-ruby 0.1.0 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb0c189a2525a3571135dcf826b1564c4fe2b7cba12cb1da11070b14b02b8d7f
4
- data.tar.gz: 8fd96e53f85538edaf482bb8a3a70fc2f41963e1e33815ce86dc07385d8c6ad8
3
+ metadata.gz: e96a449f1af06d063a0a7e7f60b9fe1785c150a5370774336b5967b049b98a5b
4
+ data.tar.gz: 9e4e6b649170abea6f73afe667e7f9368a713d8cfaf81b08bfa76c31ac6b2c9e
5
5
  SHA512:
6
- metadata.gz: 73442b39ecdfa15aa2a1e5901916bc6302bc3af4b29b445f452982fa395cc10b272ed360b50262e350eaf3f5f748e7492b3a8293841baf82035ededb1abb986f
7
- data.tar.gz: 2dd24c86e07382a59f47cfc50a1c047a948328c47e19ca499c68afc988ce74d3141d8d8522ce368adc5af3439cbe3bb871dbed3d0e357d1cff9117b387adf551
6
+ metadata.gz: d85cc899a5b73c9a1e48d0df3b1e87eca4e7a2d711c074a6988cec7b58570d3c09b9f21dd3fe7f2b72fa432efefe25885d64e901d7bd0835f8d4176f4e025f65
7
+ data.tar.gz: 4b6538ebe4be2c357da2b5ea41d2ca4db21b3e61e7413ebba5bbdd75cd4642854d1936f2d43201e138d80906b793dc19b7bcd3ba458ee8f724428efc887fd221
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
- # THIS IS NOT READY FOR USE! ...SO DON'T! :-)
1
+ # THIS IS BARELY READY FOR USE! DON'T EXPECT MIRACLES
2
2
 
3
3
  # ODRL::Ruby
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/odrl/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
6
-
7
- TODO: Delete this and the text above, and describe your gem
5
+ This is a gem to build ODRL records, and serialize them
8
6
 
9
7
  ## Installation
10
8
 
@@ -24,17 +22,51 @@ Or install it yourself as:
24
22
 
25
23
  ## Usage
26
24
 
27
- TODO: Write usage instructions here
28
-
29
- ## Development
30
-
31
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
-
33
- 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`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
-
35
- ## Contributing
25
+ ```
26
+ require 'odrl/ruby'
27
+
28
+ # an offer to toshiaki from mark to use the polyA resource during the biohackathon
29
+
30
+ # core annotatons are: :title, :creator, :description, :subject :baseURI, :uid, :type
31
+ policy = ODRL::Offer.new(
32
+ title: "Offer to Toshiaki-san",
33
+ creator: "https://orcid.org/0000-0001-6960-357X",
34
+ description: "An offer for Toshiaki-san to use the polyA data during the hackathon",
35
+ subject: "collaboration", # this is the CCE category - useful for EJP-RD ONLYU
36
+ )
37
+
38
+ asset = ODRL::Asset.new(uid: "http://mark.wilkinson.org/data/polyA", title: "Mark's PolyA Database")
39
+
40
+ # you indicate the type of party by assigning the predicate (either assigner or assignee)
41
+ # ODRLV is the RDF::Vocabulary for ODRL, exported to this namespace
42
+ mark = ODRL::Party.new(uid: "https://orcid.org/0000-0001-6960-357X", predicate: ODRLV.assigner, title: "Mark D Wilkinson" )
43
+ toshiaki = ODRL::Party.new(uid: "https://orcid.org/0000-0003-2391-0384", predicate: ODRLV.assignee, title: "Toshiaki Katayama")
44
+
45
+ # Rules
46
+ permission = ODRL::Permission.new(title: "Permission to use")
47
+
48
+ use = ODRL::Use.new(value: "use") # subclass of ODRL::Action
49
+
50
+ # Constraints: :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
51
+ constraint = ODRL::Constraint.new(
52
+ title: "Only during the hackathon",
53
+ leftOperand: "event",
54
+ operator: "eq",
55
+ rightOperand: "https://2023.biohackathon.org"
56
+ )
57
+ permission.addConstraint(constraint: constraint)
58
+ permission.addAsset(asset: asset)
59
+ permission.addAssigner(party: toshiaki)
60
+ permission.addAssignee(party: mark)
61
+ permission.addAction(action: use)
62
+
63
+ policy.addPermission(rule: permission)
64
+
65
+ policy.load_graph # this brings the triples into memory, cascading down all objects conneted to "policuy"
66
+ result = policy.serialize(format: 'turtle') # get the RDF string
67
+ puts result
68
+ ```
36
69
 
37
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/odrl-ruby.
38
70
 
39
71
  ## License
40
72
 
File without changes
@@ -0,0 +1,47 @@
1
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2
+
3
+ <http://example.org#action_68785487525736>
4
+ <http://purl.org/dc/terms/identifier> <http://example.org#action_68785487525736> ;
5
+ a <http://www.w3.org/ns/odrl/2/Action> .
6
+
7
+ <http://example.org#constraint_68785487525880>
8
+ <http://purl.org/dc/terms/identifier> <http://example.org#constraint_68785487525880> ;
9
+ <http://purl.org/dc/terms/title> "Only during the hackathon"@en ;
10
+ a <http://www.w3.org/ns/odrl/2/Constraint> ;
11
+ <http://www.w3.org/ns/odrl/2/leftOperand> <http://www.w3.org/ns/odrl/2/event> ;
12
+ <http://www.w3.org/ns/odrl/2/operator> <http://www.w3.org/ns/odrl/2/eq> ;
13
+ <http://www.w3.org/ns/odrl/2/rightOperand> <https://2023.biohackathon.org> .
14
+
15
+ <http://example.org#policy_68785487446247>
16
+ <http://purl.org/dc/terms/creator> <https://orcid.org/0000-0001-6960-357X> ;
17
+ <http://purl.org/dc/terms/description> "An offer for Toshiaki-san to use the polyA data during the hackathon"@en ;
18
+ <http://purl.org/dc/terms/identifier> <http://example.org#policy_68785487446247> ;
19
+ <http://purl.org/dc/terms/subject> "collaboration"@en ;
20
+ <http://purl.org/dc/terms/title> "Offer to Toshiaki-san"@en ;
21
+ a <http://www.w3.org/ns/odrl/2/Offer> ;
22
+ <http://www.w3.org/ns/odrl/2/permission> <http://example.org#rule_68785487525598> .
23
+
24
+ <http://example.org#rule_68785487525598>
25
+ <http://purl.org/dc/terms/identifier> <http://example.org#rule_68785487525598> ;
26
+ <http://purl.org/dc/terms/title> "Permission to use"@en ;
27
+ a <http://www.w3.org/ns/odrl/2/Permission> ;
28
+ <http://www.w3.org/ns/odrl/2/action> <http://example.org#action_68785487525736> ;
29
+ <http://www.w3.org/ns/odrl/2/assignee> <https://orcid.org/0000-0001-6960-357X> ;
30
+ <http://www.w3.org/ns/odrl/2/assigner> <https://orcid.org/0000-0003-2391-0384> ;
31
+ <http://www.w3.org/ns/odrl/2/constraint> <http://example.org#constraint_68785487525880> ;
32
+ <http://www.w3.org/ns/odrl/2/target> <http://mark.wilkinson.org/data/polyA> .
33
+
34
+ <http://mark.wilkinson.org/data/polyA>
35
+ <http://purl.org/dc/terms/identifier> <http://mark.wilkinson.org/data/polyA> ;
36
+ <http://purl.org/dc/terms/title> "Mark's PolyA Database"@en ;
37
+ a <http://www.w3.org/ns/odrl/2/Asset> .
38
+
39
+ <https://orcid.org/0000-0001-6960-357X>
40
+ <http://purl.org/dc/terms/identifier> <https://orcid.org/0000-0001-6960-357X> ;
41
+ <http://purl.org/dc/terms/title> "Mark D Wilkinson"@en ;
42
+ a <http://www.w3.org/ns/odrl/2/Party> .
43
+
44
+ <https://orcid.org/0000-0003-2391-0384>
45
+ <http://purl.org/dc/terms/identifier> <https://orcid.org/0000-0003-2391-0384> ;
46
+ <http://purl.org/dc/terms/title> "Toshiaki Katayama"@en ;
47
+ a <http://www.w3.org/ns/odrl/2/Party> .
data/lib/odrl/action.rb CHANGED
@@ -3,7 +3,24 @@
3
3
  module ODRL
4
4
 
5
5
  class Action < Base
6
+ # ODRL::Action
7
+ # Describes an action like "use"
8
+ #
9
+ # @author Mark D Wilkinson
10
+ # @attr [URI] (optional) uid the URI of the Action node
11
+ # @attr [[ODRL::Refinement]] (optional) ODRL Refinement objects
12
+ # @attr [URI] predicate (optional) the predicate you wish to use with this action
13
+ # @attr [string] value (required) a string like "use"
14
+ # @attr [string] vallabel (optional) a string like "use"
15
+
6
16
  attr_accessor :uid, :refinements, :predicate, :type, :value, :vallabel
17
+
18
+
19
+ # constructor
20
+ # @param [Hash] opts the options to create a message with.
21
+ # @option :value the string value of rthe action, like "use"
22
+ # @option :vallabel the string for the label, like "use"
23
+ #
7
24
  def initialize(args)
8
25
  @value = args[:value]
9
26
  @vallabel = args[:value]
@@ -31,6 +48,10 @@ module ODRL
31
48
 
32
49
  end
33
50
 
51
+ # Adds an ODRL Refinement
52
+ #
53
+ # @param refinement [ODRL::Refinement] the refinement to the action
54
+ #
34
55
  def addRefinement(refinement: args)
35
56
  unless refinement.is_a?(Constraint)
36
57
  raise "Refinement is not an ODRL Constraint"
@@ -40,6 +61,9 @@ module ODRL
40
61
  end
41
62
 
42
63
 
64
+ # Causes the triples of this object to be formed in the in-memory store
65
+ # This includes any "cascading" objects for which this is the subject of the triple
66
+ #
43
67
  def load_graph
44
68
  super
45
69
  # TODO This is bad DRY!! Put the bulk of this method into the base object
@@ -65,7 +89,11 @@ module ODRL
65
89
  triplify(subject, predicate, object, repo)
66
90
  end
67
91
 
68
- def serialize
92
+ # Returns the serialized RDF for this object and cascading related objects
93
+ #
94
+ # @param format [Symbol] a valid RDF::Writer format (e.g. :turtle)
95
+ #
96
+ def serialize(format:)
69
97
  super
70
98
  end
71
99
 
data/lib/odrl/asset.rb CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  module ODRL
4
4
 
5
+
6
+ # ODRL::Action
7
+ # Describes an action like "use"
8
+ #
9
+ # @author Mark D Wilkinson
5
10
  class Asset < Base
6
11
  attr_accessor :uid, :hasPolicy, :refinements, :partOf
7
12
 
data/lib/odrl/base.rb CHANGED
@@ -49,10 +49,11 @@ PROPERTIES = {
49
49
  title: DCT.title,
50
50
  creator: DCT.creator,
51
51
  description: DCT.description,
52
- uid: DCT.identifier,
52
+ id: DCT.identifier,
53
53
  type: RDF.type,
54
- subject: DCT.subject
55
-
54
+ subject: DCT.subject,
55
+ uid: ODRLV.uid,
56
+ label: RDFS.label,
56
57
  }
57
58
 
58
59
  module ODRL
@@ -60,7 +61,7 @@ module ODRL
60
61
 
61
62
  @@repository = RDF::Repository.new()
62
63
 
63
- attr_accessor :title, :creator, :description, :subject, :baseURI, :uid, :type
64
+ attr_accessor :title, :creator, :description, :subject, :baseURI, :uid, :id, :type, :label
64
65
 
65
66
  def self.baseURI
66
67
  return ENV['ODRL_BASEURI'] || "http://example.org"
@@ -88,6 +89,8 @@ module ODRL
88
89
  @baseURI = args[:baseURI] || self.baseURI
89
90
  @uid = args[:uid]
90
91
  @type = args[:type]
92
+ @label = args[:label] || @title
93
+ @id = args[:uid] || nil
91
94
  #@repository = RDF::Repository.new() unless self.repository
92
95
 
93
96
  raise "Every object must have a uid - attempt to create #{@type}" unless @uid
@@ -171,12 +174,12 @@ module ODRL
171
174
  end
172
175
 
173
176
  def load_graph
174
- [:title, :creator, :description, :subject, :uid, :type].each do |method|
177
+ [:title, :label, :creator, :description, :subject, :uid, :type].each do |method|
175
178
  next unless self.send(method)
176
179
  next if self.send(method).empty?
177
180
  subject = self.uid
178
181
  predicate = PROPERTIES[method]
179
- #warn "prediate #{predicate} for method #{method}"
182
+ # warn "prediate #{predicate} for method #{method}"
180
183
  object = self.send(method)
181
184
  repo = self.repository
182
185
  triplify(subject, predicate, object, repo)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ODRL
4
4
  module ODRL
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odrl-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wilkinson
@@ -26,7 +26,9 @@ files:
26
26
  - Rakefile
27
27
  - bin/console
28
28
  - bin/setup
29
+ - examples/builder-translator-output.ttl
29
30
  - examples/create-biohackathon-offer.rb
31
+ - examples/output.ttl
30
32
  - launch.json
31
33
  - lib/odrl/action.rb
32
34
  - lib/odrl/asset.rb
@@ -37,7 +39,6 @@ files:
37
39
  - lib/odrl/policy.rb
38
40
  - lib/odrl/ruby.rb
39
41
  - lib/odrl/rule.rb
40
- - testme.rb
41
42
  homepage: https://example.org
42
43
  licenses:
43
44
  - MIT
data/testme.rb DELETED
@@ -1,28 +0,0 @@
1
- require_relative "./lib/odrl/policy.rb"
2
- require_relative "./lib/odrl/rule.rb"
3
- require_relative "./lib/odrl/base.rb"
4
- require_relative "./lib/odrl/asset.rb"
5
- require_relative "./lib/odrl/constraint.rb"
6
-
7
-
8
- t = ODRL::Policy.new(
9
- title: "this",
10
- author: "mark",
11
- baseURI: "http://adsjfhalsdjfasdh",
12
-
13
- )
14
-
15
- pro = ODRL::Prohibition.new({})
16
- # puts t.methods
17
- # abort
18
- # t.addProhibition(rule: pro)
19
- # puts t.rules.length
20
- # puts t.rules[t.rules.keys.first][1].inspect
21
- # puts t.rules[t.rules.keys.first][1].class.to_s == "ODRL::Prohibition"
22
-
23
- #p t.inspect
24
- c1 = ODRL::Constraint.new({})
25
- #p c1.inspect
26
- c2 = ODRL::Constraint.new({})
27
- d = ODRL::Duty.new({constraints: c1})
28
- puts d.inspect