odrl-ruby 0.1.4 → 0.2.0
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 +4 -4
- data/.rubocop.yml +5 -2
- data/Gemfile +1 -2
- data/Gemfile.lock +98 -84
- data/README.md +1 -3
- data/examples/build_profile.rb +47 -0
- data/examples/create-nagoya-es-offer.rb +54 -0
- data/examples/nagoya-output.ttl +66 -0
- data/lib/odrl/action.rb +91 -99
- data/lib/odrl/asset.rb +63 -76
- data/lib/odrl/base.rb +192 -178
- data/lib/odrl/constraint.rb +95 -89
- data/lib/odrl/odrl/version.rb +1 -1
- data/lib/odrl/party.rb +75 -84
- data/lib/odrl/policy.rb +80 -68
- data/lib/odrl/profile/builder.rb +185 -0
- data/lib/odrl/ruby.rb +12 -13
- data/lib/odrl/rule.rb +89 -101
- metadata +11 -5
- data/examples/builder-translator-output.ttl +0 -0
- /data/examples/{output.ttl → biohackathon-output.ttl} +0 -0
data/lib/odrl/rule.rb
CHANGED
@@ -5,124 +5,112 @@ require_relative "odrl/version"
|
|
5
5
|
# require "ODRL::Constraint"
|
6
6
|
|
7
7
|
module ODRL
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
constraints = [constraints] unless constraints.is_a? Array
|
40
|
-
if !constraints.first.nil?
|
41
|
-
constraints.each do |c|
|
42
|
-
self.addConstraint(constraint: c)
|
43
|
-
end
|
44
|
-
end
|
8
|
+
class Rule < Base
|
9
|
+
attr_accessor :uid, :constraints, :assets, :predicate, :type, :action, :assigner, :assignee
|
10
|
+
|
11
|
+
def initialize(
|
12
|
+
uid: nil,
|
13
|
+
constraints: nil,
|
14
|
+
assets: nil,
|
15
|
+
predicate: nil,
|
16
|
+
action: nil,
|
17
|
+
assigner: nil,
|
18
|
+
assignee: nil,
|
19
|
+
type: CRULE,
|
20
|
+
**args
|
21
|
+
)
|
22
|
+
@uid = uid
|
23
|
+
|
24
|
+
@uid ||= Base.baseURI + "#rule_" + Base.getuuid
|
25
|
+
super(uid: @uid, type: type, **args)
|
26
|
+
|
27
|
+
@constraints = {}
|
28
|
+
@assets = {}
|
29
|
+
@assigner = {}
|
30
|
+
@assignee = {}
|
31
|
+
@action = {}
|
32
|
+
|
33
|
+
assets = [assets] unless assets.is_a? Array
|
34
|
+
unless assets.first.nil?
|
35
|
+
assets.each do |c|
|
36
|
+
addAsset(asset: c)
|
45
37
|
end
|
38
|
+
end
|
39
|
+
constraints = [constraints] unless constraints.is_a? Array
|
40
|
+
return if constraints.first.nil?
|
46
41
|
|
42
|
+
constraints.each do |c|
|
43
|
+
addConstraint(constraint: c)
|
44
|
+
end
|
45
|
+
end
|
47
46
|
|
48
|
-
|
49
|
-
|
50
|
-
raise "Asset is not an ODRL Asset"
|
51
|
-
else
|
52
|
-
uid = asset.uid
|
53
|
-
self.assets[uid] = [PASSET, asset]
|
54
|
-
end
|
55
|
-
end
|
47
|
+
def addAsset(asset:)
|
48
|
+
raise "Asset is not an ODRL Asset" unless asset.is_a?(Asset)
|
56
49
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
self.constraints[constraint.uid] = [PCONSTRAINT, constraint]
|
62
|
-
end
|
63
|
-
end
|
50
|
+
uid = asset.uid
|
51
|
+
assets[uid] = [PASSET, asset]
|
52
|
+
end
|
64
53
|
|
65
|
-
|
66
|
-
|
67
|
-
raise "Action is not an ODRL Action"
|
68
|
-
else
|
69
|
-
self.action[action.uid] = [PACTION, action]
|
70
|
-
end
|
71
|
-
end
|
54
|
+
def addConstraint(constraint:)
|
55
|
+
raise "Constraint is not an ODRL Constraint" unless constraint.is_a?(Constraint)
|
72
56
|
|
73
|
-
|
74
|
-
|
75
|
-
raise "Assigner is not an ODRL Party"
|
76
|
-
else
|
77
|
-
self.assigner[party.uid] = [PASSIGNER, party]
|
78
|
-
end
|
79
|
-
end
|
57
|
+
constraints[constraint.uid] = [PCONSTRAINT, constraint]
|
58
|
+
end
|
80
59
|
|
81
|
-
|
82
|
-
|
83
|
-
raise "Asigner is not an ODRL Party"
|
84
|
-
else
|
85
|
-
self.assignee[party.uid] = [PASSIGNEE, party]
|
86
|
-
end
|
87
|
-
end
|
60
|
+
def addAction(action:)
|
61
|
+
raise "Action is not an ODRL Action" unless action.is_a?(Action)
|
88
62
|
|
89
|
-
|
90
|
-
|
91
|
-
[:constraints, :assets, :action, :assigner, :assignee].each do |connected_object_type|
|
92
|
-
next unless self.send(connected_object_type)
|
93
|
-
self.send(connected_object_type).each do |uid, typedconnection|
|
94
|
-
predicate, odrlobject = typedconnection # e.g. "action", ActionObject
|
95
|
-
object = odrlobject.uid
|
96
|
-
subject = self.uid
|
97
|
-
repo = self.repository
|
98
|
-
triplify(subject, predicate, object, repo)
|
99
|
-
odrlobject.load_graph # start the cascade
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
63
|
+
self.action[action.uid] = [PACTION, action]
|
64
|
+
end
|
103
65
|
|
104
|
-
|
105
|
-
|
106
|
-
|
66
|
+
def addAssigner(party:)
|
67
|
+
raise "Assigner is not an ODRL Party" unless party.is_a?(Party)
|
68
|
+
|
69
|
+
assigner[party.uid] = [PASSIGNER, party]
|
107
70
|
end
|
108
71
|
|
72
|
+
def addAssignee(party:)
|
73
|
+
raise "Asigner is not an ODRL Party" unless party.is_a?(Party)
|
109
74
|
|
110
|
-
|
111
|
-
def initialize(predicate: PPERMISSION, type: CPERMISSION, **args)
|
112
|
-
super(predicate: predicate, type: type, **args)
|
113
|
-
end
|
75
|
+
assignee[party.uid] = [PASSIGNEE, party]
|
114
76
|
end
|
115
77
|
|
116
|
-
|
117
|
-
|
118
|
-
|
78
|
+
def load_graph
|
79
|
+
super
|
80
|
+
%i[constraints assets action assigner assignee].each do |connected_object_type|
|
81
|
+
next unless send(connected_object_type)
|
82
|
+
|
83
|
+
send(connected_object_type).each do |_uid, typedconnection|
|
84
|
+
predicate, odrlobject = typedconnection # e.g. "action", ActionObject
|
85
|
+
object = odrlobject.uid
|
86
|
+
subject = uid
|
87
|
+
repo = repository
|
88
|
+
triplify(subject, predicate, object, repo)
|
89
|
+
odrlobject.load_graph # start the cascade
|
119
90
|
end
|
91
|
+
end
|
120
92
|
end
|
121
93
|
|
122
|
-
|
123
|
-
|
124
|
-
super(predicate: predicate, type: type, **args)
|
125
|
-
end
|
94
|
+
def serialize(format:)
|
95
|
+
super
|
126
96
|
end
|
97
|
+
end
|
127
98
|
|
99
|
+
class Permission < Rule
|
100
|
+
def initialize(predicate: PPERMISSION, type: CPERMISSION, **args)
|
101
|
+
super(predicate: predicate, type: type, **args)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class Duty < Rule
|
106
|
+
def initialize(predicate: PDUTY, type: CDUTY, **args)
|
107
|
+
super(predicate: predicate, type: type, **args)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class Prohibition < Rule
|
112
|
+
def initialize(predicate: PPROHIBITION, type: CPROHIBITION, **args)
|
113
|
+
super(predicate: predicate, type: type, **args)
|
114
|
+
end
|
115
|
+
end
|
128
116
|
end
|
metadata
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odrl-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2023-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: A builder for ODRL files. Does basic validation against core ODRL vocabularies.
|
14
|
+
Has a Builder that allows you to create ODRL Profiles to extend the core vocabulary. DOES
|
15
|
+
NOT validate against a profile. DOES NOT cover the full ODRL specificaiton, only
|
16
|
+
the bits that I needed!
|
14
17
|
email:
|
15
18
|
- markw@illuminae.com
|
16
19
|
executables: []
|
@@ -26,9 +29,11 @@ files:
|
|
26
29
|
- Rakefile
|
27
30
|
- bin/console
|
28
31
|
- bin/setup
|
29
|
-
- examples/
|
32
|
+
- examples/biohackathon-output.ttl
|
33
|
+
- examples/build_profile.rb
|
30
34
|
- examples/create-biohackathon-offer.rb
|
31
|
-
- examples/
|
35
|
+
- examples/create-nagoya-es-offer.rb
|
36
|
+
- examples/nagoya-output.ttl
|
32
37
|
- launch.json
|
33
38
|
- lib/odrl/action.rb
|
34
39
|
- lib/odrl/asset.rb
|
@@ -37,6 +42,7 @@ files:
|
|
37
42
|
- lib/odrl/odrl/version.rb
|
38
43
|
- lib/odrl/party.rb
|
39
44
|
- lib/odrl/policy.rb
|
45
|
+
- lib/odrl/profile/builder.rb
|
40
46
|
- lib/odrl/ruby.rb
|
41
47
|
- lib/odrl/rule.rb
|
42
48
|
homepage: https://example.org
|
File without changes
|
File without changes
|