odrl-ruby 0.1.0 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb0c189a2525a3571135dcf826b1564c4fe2b7cba12cb1da11070b14b02b8d7f
4
- data.tar.gz: 8fd96e53f85538edaf482bb8a3a70fc2f41963e1e33815ce86dc07385d8c6ad8
3
+ metadata.gz: cd4c38460e3d26b41639c01c44e7a84210e6dbfc50c90cc85f1ba182b39d82cd
4
+ data.tar.gz: f1d15fb48ff0ace8c6f8f4a23f7818746b2a2d6855ba8478b6df366ae6e66cde
5
5
  SHA512:
6
- metadata.gz: 73442b39ecdfa15aa2a1e5901916bc6302bc3af4b29b445f452982fa395cc10b272ed360b50262e350eaf3f5f748e7492b3a8293841baf82035ededb1abb986f
7
- data.tar.gz: 2dd24c86e07382a59f47cfc50a1c047a948328c47e19ca499c68afc988ce74d3141d8d8522ce368adc5af3439cbe3bb871dbed3d0e357d1cff9117b387adf551
6
+ metadata.gz: 977bbda8a99bb0b309315f444ed039c3805c77fdc6bf8c771a01acb89ca37488d6d966c825408d4499d4da3868e6cbac9d16cca01c53a61f06bdfebba46b178c
7
+ data.tar.gz: 1adf615dcbd6f2306a9a15e2f5bfaa61df4ff521c9bfe6202fd84d111f6fc89045c2a3030e68332dd809fa36e97f8d7f9d3020d53da6ed855d78efae9993efd9
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- odrl-ruby (0.1.0)
4
+ odrl-ruby (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
@@ -2,11 +2,28 @@
2
2
 
3
3
  module ODRL
4
4
 
5
- class Action < Base
5
+ # ODRL::Action
6
+ # Describes an action like "use"
7
+ #
8
+ # @author Mark D Wilkinson
9
+ # @attr [URI] (optional) uid the URI of the Action node
10
+ # @attr [[ODRL::Refinement]] (optional) ODRL Refinement objects
11
+ # @attr [URI] predicate (optional) the predicate you wish to use with this action
12
+ # @attr [string] value (required) a string like "use"
13
+ # @attr [string] vallabel (optional) a string like "use"
14
+ class Action < Base
15
+
6
16
  attr_accessor :uid, :refinements, :predicate, :type, :value, :vallabel
7
- def initialize(args)
8
- @value = args[:value]
9
- @vallabel = args[:value]
17
+
18
+
19
+ # constructor
20
+ # @param [Hash] opts the options to create a message with.
21
+ # @option opts [String] :value the string value of rthe action, like "use"
22
+ # @option opts [String] :vallabel the string for the label, like "use"
23
+ #
24
+ def initialize(value:, vallabel: "", type: CACTION, **args)
25
+ @value = value
26
+ @vallabel = vallabel || @value
10
27
  raise "Actions must haves a value such as 'use' - I'm dead!" unless @value
11
28
  @value = "http://www.w3.org/ns/odrl/2/#{@value}" unless @value =~ /http:\/\// # if it is already a URI, then let it go
12
29
 
@@ -14,9 +31,8 @@ module ODRL
14
31
  # unless @uid
15
32
  # self.uid = Base.baseURI + "#action_" + Base.getuuid
16
33
  # end
17
- super(args.merge({uid: @uid}))
34
+ super(uid: @uid, type: type, **args)
18
35
 
19
- self.type="http://www.w3.org/ns/odrl/2/Action"
20
36
 
21
37
  @refinements = Hash.new
22
38
 
@@ -31,6 +47,10 @@ module ODRL
31
47
 
32
48
  end
33
49
 
50
+ # Adds an ODRL Refinement
51
+ #
52
+ # @param refinement [ODRL::Refinement] the refinement to the action
53
+ #
34
54
  def addRefinement(refinement: args)
35
55
  unless refinement.is_a?(Constraint)
36
56
  raise "Refinement is not an ODRL Constraint"
@@ -40,6 +60,9 @@ module ODRL
40
60
  end
41
61
 
42
62
 
63
+ # Causes the triples of this object to be formed in the in-memory store
64
+ # This includes any "cascading" objects for which this is the subject of the triple
65
+ #
43
66
  def load_graph
44
67
  super
45
68
  # TODO This is bad DRY!! Put the bulk of this method into the base object
@@ -65,7 +88,11 @@ module ODRL
65
88
  triplify(subject, predicate, object, repo)
66
89
  end
67
90
 
68
- def serialize
91
+ # Returns the serialized RDF for this object and cascading related objects
92
+ #
93
+ # @param format [Symbol] a valid RDF::Writer format (e.g. :turtle)
94
+ #
95
+ def serialize(format:)
69
96
  super
70
97
  end
71
98
 
@@ -74,15 +101,13 @@ module ODRL
74
101
 
75
102
 
76
103
  class Use < Action
77
- def initialize(args)
78
- super(args)
79
- self.type = "http://www.w3.org/ns/odrl/2/Action" unless self.type
104
+ def initialize(type: CACTION, **args)
105
+ super(type: :type, **args)
80
106
  end
81
107
  end
82
108
  class Transfer < Action
83
- def initialize(args)
84
- super(args)
85
- self.type = "http://www.w3.org/ns/odrl/2/Action" unless self.type
109
+ def initialize(type: CACTION, **args)
110
+ super(type: :type, **args)
86
111
  end
87
112
  end
88
113
 
data/lib/odrl/asset.rb CHANGED
@@ -2,20 +2,23 @@
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
 
8
- def initialize(args)
9
- @uid = args[:uid]
13
+ def initialize(type: CASSET, hasPolicy: nil, refinements: nil, partOf: nil, **args)
14
+ @uid = uid
10
15
  unless @uid
11
16
  self.uid = Base.baseURI + "#asset_" + Base.getuuid
12
17
  end
13
- super(args.merge({uid: @uid}))
14
- self.type="http://www.w3.org/ns/odrl/2/Asset"
18
+ super(type: type, uid: @uid, **args)
15
19
 
16
- @refinements = Hash.new
17
- @partOf = args[:partOf]
18
- @hasPolicy = args[:hasPolicy]
20
+ @partOf = partOf
21
+ @hasPolicy = hasPolicy
19
22
 
20
23
  if @hasPolicy and !(@hasPolicy.is_a? Policy) # if it exists and is the wrong type
21
24
  raise "The policy of an Asset must be of type ODRL::Policy. The provided value will be discarded"
@@ -26,9 +29,10 @@ module ODRL
26
29
  @partOf = nil
27
30
  end
28
31
 
29
- args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
30
- if !(args[:refinements].first.nil?)
31
- args[:refinements].each do |c|
32
+ @refinements = Hash.new
33
+ refinements = [refinements] unless refinements.is_a? Array
34
+ if !(refinements.first.nil?)
35
+ refinements.each do |c|
32
36
  self.addRefinement(refinement: c)
33
37
  end
34
38
  end
@@ -77,9 +81,8 @@ module ODRL
77
81
 
78
82
  class AssetCollection < Asset
79
83
 
80
- def initialize(args)
81
- super(args)
82
- self.type="http://www.w3.org/ns/odrl/2/AssetCollection"
84
+ def initialize(type: CASSETCOLLECTION, **args)
85
+ super(type: type, **args)
83
86
  end
84
87
  end
85
88
 
data/lib/odrl/base.rb CHANGED
@@ -2,57 +2,63 @@
2
2
 
3
3
  require_relative "odrl/version"
4
4
 
5
- # one day move these all to ODRLV.xxxx
6
- CPOLICY= "http://www.w3.org/ns/odrl/2/Policy"
7
5
 
8
- CSET= "http://www.w3.org/ns/odrl/2/Set"
9
- COFFER= "http://www.w3.org/ns/odrl/2/Offer"
10
- CREQUEST= "http://www.w3.org/ns/odrl/2/Request"
11
- CAGREEMENT= "http://www.w3.org/ns/odrl/2/Agreement"
6
+ CPOLICY= ODRLV.Policy.to_s
12
7
 
13
- PASSET = "http://www.w3.org/ns/odrl/2/target"
14
- CASSET= "http://www.w3.org/ns/odrl/2/Asset"
8
+ CSET= ODRLV.Set.to_s
9
+ COFFER= ODRLV.Offer.to_s
10
+ CREQUEST= ODRLV.Request.to_s
11
+ CAGREEMENT= ODRLV.Agreement.to_s
12
+ CPRIVACY= ODRLV.Privacy.to_s
13
+ PASSET = ODRLV.target.to_s
14
+ CASSET= ODRLV.Asset.to_s
15
+ CASSETCOLLECTION= ODRLV.Asset.to_s
15
16
 
16
- CPERMISSION= "http://www.w3.org/ns/odrl/2/Permission"
17
- PPERMISSION = "http://www.w3.org/ns/odrl/2/permission"
18
- CPROHIBITION= "http://www.w3.org/ns/odrl/2/Prohibition"
19
- PPROHIBITION = "http://www.w3.org/ns/odrl/2/prohibition"
20
- PDUTY= "http://www.w3.org/ns/odrl/2/obligation"
21
- CDUTY = "http://www.w3.org/ns/odrl/2/Duty"
17
+ CRULE= ODRLV.Rule.to_s
18
+ CPERMISSION= ODRLV.Permission.to_s
19
+ PPERMISSION = ODRLV.permission.to_s
20
+ CPROHIBITION= ODRLV.Prohibition.to_s
21
+ PPROHIBITION = ODRLV.prohibition.to_s
22
+ PDUTY= ODRLV.obligation.to_s
23
+ CDUTY = ODRLV.Duty.to_s
22
24
 
23
- PRULE = "http://www.w3.org/ns/odrl/2/Rule"
25
+ PRULE = ODRLV.Rule.to_s
24
26
 
25
27
 
26
- PACTION = "http://www.w3.org/ns/odrl/2/action"
27
- CACTION= "http://www.w3.org/ns/odrl/2/Action"
28
+ PACTION = ODRLV.action.to_s
29
+ VUSE = ODRLV.use.to_s # this is goofy ODRL stuff...
30
+ VTRANSFER = ODRLV.transfer.to_s # this is goofy ODRL stuff...
31
+ CACTION= ODRLV.Action.to_s
28
32
 
29
- PREFINEMENT = "http://www.w3.org/ns/odrl/2/refinement"
33
+ PREFINEMENT = ODRLV.refinement.to_s
30
34
 
31
- PASSIGNER = "http://www.w3.org/ns/odrl/2/assigner"
32
- PASSIGNEE = "http://www.w3.org/ns/odrl/2/assignee"
33
- CPARTY= "http://www.w3.org/ns/odrl/2/Party"
35
+ PASSIGNER = ODRLV.assigner.to_s
36
+ PASSIGNEE = ODRLV.assignee.to_s
37
+ CPARTY= ODRLV.Party.to_s
38
+ CPARTYCOLLECTION= ODRLV.Party.to_s
34
39
 
35
- PCONSTRAINT = "http://www.w3.org/ns/odrl/2/constraint"
36
- CCONSTRAINT = "http://www.w3.org/ns/odrl/2/Constraint"
37
- PLEFT = "http://www.w3.org/ns/odrl/2/leftOperand"
38
- PRIGHT = "http://www.w3.org/ns/odrl/2/rightOperand"
39
- POPERATOR = "http://www.w3.org/ns/odrl/2/operator"
40
- POPERANDREFERENCE = "http://www.w3.org/ns/odrl/2/rightOperandReference"
41
- PDATATYPE = "http://www.w3.org/ns/odrl/2/dataType"
42
- PUNIT = "http://www.w3.org/ns/odrl/2/unit"
43
- PSTATUS = "http://www.w3.org/ns/odrl/2/status"
40
+ PCONSTRAINT = ODRLV.constraint.to_s
41
+ CCONSTRAINT = ODRLV.Constraint.to_s
42
+ PLEFT = ODRLV.leftOperand.to_s
43
+ PRIGHT = ODRLV.rightOperand.to_s
44
+ POPERATOR = ODRLV.operator.to_s
45
+ POPERANDREFERENCE = ODRLV.rightOperandReference.to_s
46
+ PDATATYPE = ODRLV.dataType.to_s
47
+ PUNIT = ODRLV.unit.to_s
48
+ PSTATUS = ODRLV.status.to_s
44
49
 
45
- PPARTOF = "http://www.w3.org/ns/odrl/2/partOf"
50
+ PPARTOF = ODRLV.partOf.to_s
46
51
 
47
52
 
48
53
  PROPERTIES = {
49
54
  title: DCT.title,
50
55
  creator: DCT.creator,
51
56
  description: DCT.description,
52
- uid: DCT.identifier,
57
+ id: DCT.identifier,
53
58
  type: RDF.type,
54
- subject: DCT.subject
55
-
59
+ subject: DCT.subject,
60
+ uid: ODRLV.uid,
61
+ label: RDFS.label,
56
62
  }
57
63
 
58
64
  module ODRL
@@ -60,7 +66,7 @@ module ODRL
60
66
 
61
67
  @@repository = RDF::Repository.new()
62
68
 
63
- attr_accessor :title, :creator, :description, :subject, :baseURI, :uid, :type
69
+ attr_accessor :title, :creator, :description, :subject, :baseURI, :uid, :id, :type, :label
64
70
 
65
71
  def self.baseURI
66
72
  return ENV['ODRL_BASEURI'] || "http://example.org"
@@ -78,19 +84,31 @@ module ODRL
78
84
  return true
79
85
  end
80
86
 
81
- def initialize(args)
82
- #args = defaults.merge(args)
83
-
84
- @title = args[:title]
85
- @creator = args[:creator]
86
- @description = args[:description]
87
- @subject = args[:subject]
88
- @baseURI = args[:baseURI] || self.baseURI
89
- @uid = args[:uid]
90
- @type = args[:type]
91
- #@repository = RDF::Repository.new() unless self.repository
87
+ def initialize(
88
+ title: nil,
89
+ creator: nil,
90
+ description: nil,
91
+ subject: nil,
92
+ baseURI: "http://example.org",
93
+ uid:,
94
+ id: nil,
95
+ type:,
96
+ label: nil,
97
+ **_)
98
+
99
+ @title = title
100
+ @creator = creator
101
+ @description = description
102
+ @subject = subject
103
+ @baseURI = baseURI || ODRL::Base.baseURI
104
+ @uid = uid
105
+ @type = type
106
+ @label = label || @title
107
+ @id = @uid
92
108
 
93
109
  raise "Every object must have a uid - attempt to create #{@type}" unless @uid
110
+ raise "Every object must have a type - " unless @type
111
+
94
112
 
95
113
  $g = RDF::Graph.new()
96
114
  if ENV["TRIPLES_FORMAT"]
@@ -98,23 +116,25 @@ module ODRL
98
116
  else
99
117
  $format = :jsonld
100
118
  end
101
- $writer = get_writer(type: $format) # set it by default
102
119
 
103
120
  end
104
121
 
105
122
  def get_writer(type:)
106
- $writer = RDF::Writer.for(type).buffer do |w|
107
- w.prefix(:foaf, RDF::URI.new("http://xmlns.com/foaf/0.1/"))
108
- w.prefix(:dc, RDF::URI.new("http://purl.org/dc/terms/"))
109
- w.prefix(:rdf, RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
110
- w.prefix(:rdfs, RDF::URI.new("http://www.w3.org/2000/01/rdf-schema#"))
111
- w.prefix(:vcard, RDF::URI.new("http://www.w3.org/2006/vcard/ns#"))
112
- w.prefix(:odrl, RDF::URI.new("http://www.w3.org/ns/odrl/2/"))
113
- w.prefix(:this, RDF::URI.new("http://w3id.org/FAIR_Training_LDP/DAV/home/LDP/DUC-CCE/IPGB#"))
114
- w.prefix(:obo, RDF::URI.new("http://purl.obolibrary.org/obo/"))
115
- w.prefix(:xsd, RDF::URI.new("http://www.w3.org/2001/XMLSchema#"))
116
- end
117
- return $writer
123
+ w = RDF::Writer.for(type)
124
+ # w.prefix(:foaf, RDF::URI.new("http://xmlns.com/foaf/0.1/"))
125
+ # w.prefix(:dc, RDF::URI.new("http://purl.org/dc/terms/"))
126
+ # w.prefix(:rdf, RDF::URI.new("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
127
+ # w.prefix(:rdfs, RDF::URI.new("http://www.w3.org/2000/01/rdf-schema#"))
128
+ # w.prefix(:vcard, RDF::URI.new("http://www.w3.org/2006/vcard/ns#"))
129
+ # w.prefix(:odrl, RDF::URI.new("http://www.w3.org/ns/odrl/2/"))
130
+ # w.prefix(:this, RDF::URI.new("http://w3id.org/FAIR_Training_LDP/DAV/home/LDP/DUC-CCE/IPGB#"))
131
+ # w.prefix(:obo, RDF::URI.new("http://purl.obolibrary.org/obo/"))
132
+ # w.prefix(:xsd, RDF::URI.new("http://www.w3.org/2001/XMLSchema#"))
133
+ # w.prefix(:orcid, RDF::URI.new("https://orcid.org/"))
134
+ # warn "W"
135
+ # warn w.prefixes.inspect
136
+
137
+ return w
118
138
  end
119
139
 
120
140
  def triplify(s, p, o, repo)
@@ -171,12 +191,12 @@ module ODRL
171
191
  end
172
192
 
173
193
  def load_graph
174
- [:title, :creator, :description, :subject, :uid, :type].each do |method|
194
+ [:title, :label, :creator, :description, :subject, :uid, :id, :type].each do |method|
175
195
  next unless self.send(method)
176
196
  next if self.send(method).empty?
177
197
  subject = self.uid
178
198
  predicate = PROPERTIES[method]
179
- #warn "prediate #{predicate} for method #{method}"
199
+ # warn "prediate #{predicate} for method #{method}"
180
200
  object = self.send(method)
181
201
  repo = self.repository
182
202
  triplify(subject, predicate, object, repo)
@@ -185,7 +205,8 @@ module ODRL
185
205
 
186
206
  def serialize(format: $format)
187
207
  format = format.to_sym
188
- return self.repository.dump(format)
208
+ w = get_writer(type: format)
209
+ return w.dump(self.repository)
189
210
  end
190
211
 
191
212
  private
@@ -5,31 +5,40 @@ module ODRL
5
5
  class Constraint < Base
6
6
 
7
7
  attr_accessor :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
8
- def initialize(args)
9
- @uid = args[:uid]
8
+ def initialize(
9
+ uid: nil,
10
+ rightOperand:,
11
+ operator:,
12
+ leftOperand:,
13
+ rightOPerandReference: nil,
14
+ dataType: nil,
15
+ unit: nil,
16
+ status: nil,
17
+ type: CCONSTRAINT,
18
+ **args)
19
+
20
+ @uid = uid
10
21
  unless @uid
11
22
  @uid = Base.baseURI + "#constraint_" + Base.getuuid
12
23
  end
13
- super(args.merge({uid: @uid}))
14
-
15
- self.type = "http://www.w3.org/ns/odrl/2/Constraint"
24
+ super(uid: @uid, type: type, **args)
16
25
 
17
- @rightOperand = args[:rightOperand]
26
+ @rightOperand = rightOperand
18
27
  raise "Constraints must haves a Right operand such as 'event' - I'm dead!" unless @rightOperand
19
28
  @rightOperand = "http://www.w3.org/ns/odrl/2/#{@rightOperand}" unless @rightOperand =~ /https?:\/\// # if it is already a URI, then let it go
20
29
 
21
- @leftOperand = args[:leftOperand]
30
+ @leftOperand = leftOperand
22
31
  raise "Constraints must haves a Left Operand such as 'http://some.event.org/on-now' - I'm dead!" unless @leftOperand
23
32
  @leftOperand = "http://www.w3.org/ns/odrl/2/#{@leftOperand}" unless @leftOperand =~ /https?:\/\// # if it is already a URI, then let it go
24
33
 
25
- @operator = args[:operator]
34
+ @operator = operator
26
35
  raise "Constraints must haves an operator such as 'eq' - I'm dead!" unless @operator
27
36
  @operator = "http://www.w3.org/ns/odrl/2/#{@operator}" unless @operator =~ /https?:\/\// # if it is already a URI, then let it go
28
37
 
29
- @rightOperandReference = args[:rightOperandReference]
30
- @dataType = args[:dataType]
31
- @unit = args[:unit]
32
- @status = args[:status]
38
+ @rightOperandReference = rightOperandReference
39
+ @dataType = dataType
40
+ @unit = unit
41
+ @status = status
33
42
  end
34
43
 
35
44
  def load_graph
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ODRL
4
4
  module ODRL
5
- VERSION = "0.1.0"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
data/lib/odrl/party.rb CHANGED
@@ -4,19 +4,25 @@ module ODRL
4
4
 
5
5
  class Party < Base
6
6
  attr_accessor :uid, :refinements, :partOf, :predicate, :type
7
- def initialize(args)
8
- @uid = args[:uid]
7
+ def initialize(
8
+ uid: nil,
9
+ refinements: nil,
10
+ partOf: nil,
11
+ predicate: nil,
12
+ type: CPARTY,
13
+ **args
14
+ )
15
+
16
+ @uid = uid
9
17
  unless @uid
10
18
  @uid = Base.baseURI + "#party_" + Base.getuuid
11
19
  end
12
- super(args.merge({uid: @uid}))
13
- self.type="http://www.w3.org/ns/odrl/2/Party"
20
+ super(uid: @uid, type: type, **args)
14
21
 
15
22
 
16
23
  @refinements = Hash.new
17
- @partOf = args[:partOf]
18
- @predicate = args[:predicate]
19
- @type = CPARTY
24
+ @partOf = partOf
25
+ @predicate = predicate
20
26
 
21
27
  unless @predicate
22
28
  raise "If you don't indicate a predicate (assigner/assignee) we will default to assigner. This may not be what you want!"
@@ -30,9 +36,9 @@ module ODRL
30
36
 
31
37
 
32
38
 
33
- args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
34
- if !(args[:refinements].first.nil?)
35
- args[:refinements].each do |c|
39
+ refinements = [refinements] unless refinements.is_a? Array
40
+ if !(refinements.first.nil?)
41
+ refinements.each do |c|
36
42
  self.addRefinement(refinement: c)
37
43
  end
38
44
  end
@@ -85,9 +91,8 @@ module ODRL
85
91
  end
86
92
  class PartyCollection < Party
87
93
 
88
- def initialize(args)
89
- super(args)
90
- self.type = "http://www.w3.org/ns/odrl/2/PartyCollection"
94
+ def initialize(type: CPARTYCOLLECTION, **args)
95
+ super(type: type, **args)
91
96
  end
92
97
  end
93
98
 
data/lib/odrl/policy.rb CHANGED
@@ -9,12 +9,12 @@ module ODRL
9
9
  class Policy < Base
10
10
  attr_accessor :rules
11
11
 
12
- def initialize(args)
13
- @uid = args[:uid]
12
+ def initialize(uid: nil, type: CPOLICY, **args)
13
+ @uid = uid
14
14
  unless @uid
15
15
  self.uid = Base.baseURI + "#policy_" + Base.getuuid
16
16
  end
17
- super(args.merge({uid: @uid}))
17
+ super(uid: @uid, type: type, **args)
18
18
 
19
19
  @rules = Hash.new
20
20
  end
@@ -53,24 +53,30 @@ module ODRL
53
53
  end
54
54
 
55
55
  class Set < Policy
56
- def initialize(args)
57
- super({type: CSET}.merge(args))
56
+ def initialize(type: CSET, **args)
57
+ super(type: type, **args)
58
58
  end
59
59
  end
60
60
 
61
61
  class Offer < Set
62
- def initialize(args)
63
- super({type: COFFER}.merge(args))
62
+ def initialize(type: COFFER, **args)
63
+ super(type: type, **args)
64
64
  end
65
65
  end
66
66
  class Agreement < Set
67
- def initialize(args)
68
- super({type: CAGREEMENT}.merge(args))
67
+ def initialize(type: CAGREEMENT, **args)
68
+ super(type: type, **args)
69
69
  end
70
70
  end
71
71
  class Request < Set
72
- def initialize(args)
73
- super({type: CREQUEST}.merge(args))
72
+ def initialize(type: CREQUEST, **args)
73
+ super(type: type, **args)
74
+ end
75
+ end
76
+
77
+ class Privacy < Set
78
+ def initialize(type: CPRIVACY, **args)
79
+ super(type: type, **args)
74
80
  end
75
81
  end
76
82
  # ====================================================
data/lib/odrl/rule.rb CHANGED
@@ -7,13 +7,22 @@ require_relative "odrl/version"
7
7
  module ODRL
8
8
  class Rule < Base
9
9
  attr_accessor :uid, :constraints, :assets, :predicate, :type, :action, :assigner, :assignee
10
- def initialize(args)
11
- @uid = args[:uid]
10
+ def initialize(
11
+ uid: nil,
12
+ constraints: nil,
13
+ assets: nil,
14
+ predicate: nil,
15
+ action: nil,
16
+ assigner: nil,
17
+ assignee: nil,
18
+ type: CRULE,
19
+ **args)
20
+ @uid = uid
12
21
 
13
22
  unless @uid
14
23
  @uid = Base.baseURI + "#rule_" + Base.getuuid
15
24
  end
16
- super(args.merge({uid: @uid}))
25
+ super(uid: @uid, type: type, **args)
17
26
 
18
27
  @constraints = Hash.new
19
28
  @assets = Hash.new
@@ -21,15 +30,15 @@ module ODRL
21
30
  @assignee = Hash.new
22
31
  @action = Hash.new
23
32
 
24
- args[:assets] = [args[:assets]] unless args[:assets].is_a? Array
25
- if !(args[:assets].first.nil?)
26
- args[:assets].each do |c|
33
+ assets = [assets] unless assets.is_a? Array
34
+ if !assets.first.nil?
35
+ assets.each do |c|
27
36
  self.addAsset(asset: c)
28
37
  end
29
38
  end
30
- args[:constraints] = [args[:constraints]] unless args[:constraints].is_a? Array
31
- if !(args[:constraints].first.nil?)
32
- args[:constraints].each do |c|
39
+ constraints = [constraints] unless constraints.is_a? Array
40
+ if !constraints.first.nil?
41
+ constraints.each do |c|
33
42
  self.addConstraint(constraint: c)
34
43
  end
35
44
  end
@@ -99,32 +108,20 @@ module ODRL
99
108
 
100
109
 
101
110
  class Permission < Rule
102
- def initialize(args)
103
- super(args)
104
- self.predicate = PPERMISSION
105
- self.type = CPERMISSION
106
-
107
-
111
+ def initialize(predicate: PPERMISSION, type: CPERMISSION, **args)
112
+ super(predicate: predicate, type: type, **args)
108
113
  end
109
114
  end
110
115
 
111
116
  class Duty < Rule
112
- def initialize(args)
113
- super(args)
114
- self.predicate = PDUTY
115
- self.type = CDUTY
116
-
117
-
117
+ def initialize(predicate: PDUTY, type: CDUTY, **args)
118
+ super(predicate: predicate, type: type, **args)
118
119
  end
119
120
  end
120
121
 
121
122
  class Prohibition < Rule
122
- def initialize(args)
123
- super(args)
124
- self.predicate = PPROHIBITION
125
- self.type = CPROHIBITION
126
-
127
-
123
+ def initialize(predicate: PPROHIBITION, type: CPROHIBITION, **args)
124
+ super(predicate: predicate, type: type, **args)
128
125
  end
129
126
  end
130
127
 
metadata CHANGED
@@ -1,14 +1,14 @@
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Wilkinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-27 00:00:00.000000000 Z
11
+ date: 2023-06-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: builds ODRL files nicely.
14
14
  email:
@@ -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