odrl-ruby 0.2.3 → 0.2.4

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.
@@ -1,44 +1,44 @@
1
- require 'odrl/ruby'
2
-
3
-
4
- # an offer to toshiaki from mark to use the polyA resource during the biohackathon
5
-
6
- # core annotatons are: :title, :creator, :description, :subject :baseURI, :uid, :type
7
- policy = ODRL::Offer.new(
8
- title: "Offer to Toshiaki-san",
9
- creator: "https://orcid.org/0000-0001-6960-357X",
10
- description: "An offer for Toshiaki-san to use the polyA data during the hackathon",
11
- subject: "collaboration", # this is the CCE category
12
- )
13
-
14
- asset = ODRL::Asset.new(uid: "http://mark.wilkinson.org/data/polyA", title: "Mark's PolyA Database")
15
-
16
- # you indicate the type of party by assigning the predicate (either assigner or assignee)
17
- # ODRLV is the RDF::Vocabulary for ODRL, exported to this namespace
18
- mark = ODRL::Party.new(uid: "https://orcid.org/0000-0001-6960-357X", predicate: ODRLV.assigner, title: "Mark D Wilkinson" )
19
- toshiaki = ODRL::Party.new(uid: "https://orcid.org/0000-0003-2391-0384", predicate: ODRLV.assignee, title: "Toshiaki Katayama")
20
-
21
- # Rules
22
- permission = ODRL::Permission.new(title: "Permission to use")
23
-
24
- use = ODRL::Use.new(value: "use") # subclass of action
25
-
26
- # Constraints: :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
27
- constraint = ODRL::Constraint.new(
28
- title: "Only during the hackathon",
29
- leftOperand: "event",
30
- operator: "eq",
31
- rightOperand: "https://2023.biohackathon.org"
32
- )
33
- permission.addConstraint(constraint: constraint)
34
- permission.addAsset(asset: asset)
35
- permission.addAssigner(party: toshiaki)
36
- permission.addAssignee(party: mark)
37
- permission.addAction(action: use)
38
-
39
- policy.addPermission(rule: permission)
40
-
41
- policy.load_graph
42
- result = policy.serialize(format: 'turtle')
43
- puts result
44
-
1
+ require 'odrl/ruby'
2
+
3
+
4
+ # an offer to toshiaki from mark to use the polyA resource during the biohackathon
5
+
6
+ # core annotatons are: :title, :creator, :description, :subject :baseURI, :uid, :type
7
+ policy = ODRL::Offer.new(
8
+ title: "Offer to Toshiaki-san",
9
+ creator: "https://orcid.org/0000-0001-6960-357X",
10
+ description: "An offer for Toshiaki-san to use the polyA data during the hackathon",
11
+ subject: "collaboration", # this is the CCE category
12
+ )
13
+
14
+ asset = ODRL::Asset.new(uid: "http://mark.wilkinson.org/data/polyA", title: "Mark's PolyA Database")
15
+
16
+ # you indicate the type of party by assigning the predicate (either assigner or assignee)
17
+ # ODRLV is the RDF::Vocabulary for ODRL, exported to this namespace
18
+ mark = ODRL::Party.new(uid: "https://orcid.org/0000-0001-6960-357X", predicate: ODRLV.assigner, title: "Mark D Wilkinson" )
19
+ toshiaki = ODRL::Party.new(uid: "https://orcid.org/0000-0003-2391-0384", predicate: ODRLV.assignee, title: "Toshiaki Katayama")
20
+
21
+ # Rules
22
+ permission = ODRL::Permission.new(title: "Permission to use")
23
+
24
+ use = ODRL::Use.new(value: "use") # subclass of action
25
+
26
+ # Constraints: :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
27
+ constraint = ODRL::Constraint.new(
28
+ title: "Only during the hackathon",
29
+ leftOperand: "event",
30
+ operator: "eq",
31
+ rightOperand: "https://2023.biohackathon.org"
32
+ )
33
+ permission.addConstraint(constraint: constraint)
34
+ permission.addAsset(asset: asset)
35
+ permission.addAssigner(party: toshiaki)
36
+ permission.addAssignee(party: mark)
37
+ permission.addAction(action: use)
38
+
39
+ policy.addPermission(rule: permission)
40
+
41
+ policy.load_graph
42
+ result = policy.serialize(format: 'turtle')
43
+ puts result
44
+
@@ -1,54 +1,54 @@
1
- require "odrl/ruby"
2
-
3
- # an offer to toshiaki from mark to use the polyA resource during the biohackathon
4
-
5
- # core annotatons are: :title, :creator, :description, :subject :baseURI, :uid, :type
6
- policy = ODRL::Offer.new(
7
- title: "Offer for the use of BGV Germplasm",
8
- creator: "https://orcid.org/0000-0001-6960-357X",
9
- description: "An offer any non-Commercial entity to use Germplasm from the BGV - UPM",
10
- subject: "nagoya-constraint", # this is a tag
11
- issued: "2022-06-29"
12
- )
13
-
14
- asset = ODRL::Asset.new(uid: "https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a",
15
- title: "César Gómez Campo Banco de Germoplasma Vegetal de la UPM")
16
-
17
- # you indicate the type of party by assigning the predicate (either assigner or assignee)
18
- # ODRLV is the RDF::Vocabulary for ODRL, exported to this namespace
19
- ministerio = ODRL::Party.new(
20
- uid: "https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2",
21
- predicate: ODRLV.assigner,
22
- title: " Ministerio para la Transición Ecológica y el Reto Demográfico",
23
- label: " Ministerio para la Transición Ecológica y el Reto Demográfico"
24
- )
25
-
26
- # Rules
27
- permission = ODRL::Permission.new(title: "Permission to use")
28
-
29
- use = ODRL::Use.new(value: "use") # subclass of action
30
-
31
- # Constraints: :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
32
- constraint_nonprofit = ODRL::Constraint.new(
33
- title: "Use by non-profit organization",
34
- leftOperand: "industry",
35
- operator: "neq",
36
- rightOperand: "https://w3id.org/dingo#ForProfitOrganisation"
37
- )
38
- constraint_noncommercial = ODRL::Constraint.new(
39
- title: "Use for non-commercial purposes",
40
- leftOperand: "purpose",
41
- operator: "neq",
42
- rightOperand: "http://purl.obolibrary.org/obo/ExO_0000085"
43
- )
44
- permission.addConstraint(constraint: constraint_nonprofit)
45
- permission.addConstraint(constraint: constraint_noncommercial)
46
- permission.addAsset(asset: asset)
47
- permission.addAssigner(party: ministerio)
48
- permission.addAction(action: use)
49
-
50
- policy.addPermission(rule: permission)
51
-
52
- policy.load_graph
53
- result = policy.serialize(format: "turtle")
54
- puts result
1
+ require "odrl/ruby"
2
+
3
+ # an offer to toshiaki from mark to use the polyA resource during the biohackathon
4
+
5
+ # core annotatons are: :title, :creator, :description, :subject :baseURI, :uid, :type
6
+ policy = ODRL::Offer.new(
7
+ title: "Offer for the use of BGV Germplasm",
8
+ creator: "https://orcid.org/0000-0001-6960-357X",
9
+ description: "An offer any non-Commercial entity to use Germplasm from the BGV - UPM",
10
+ subject: "nagoya-constraint", # this is a tag
11
+ issued: "2022-06-29"
12
+ )
13
+
14
+ asset = ODRL::Asset.new(uid: "https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a",
15
+ title: "César Gómez Campo Banco de Germoplasma Vegetal de la UPM")
16
+
17
+ # you indicate the type of party by assigning the predicate (either assigner or assignee)
18
+ # ODRLV is the RDF::Vocabulary for ODRL, exported to this namespace
19
+ ministerio = ODRL::Party.new(
20
+ uid: "https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2",
21
+ predicate: ODRLV.assigner,
22
+ title: " Ministerio para la Transición Ecológica y el Reto Demográfico",
23
+ label: " Ministerio para la Transición Ecológica y el Reto Demográfico"
24
+ )
25
+
26
+ # Rules
27
+ permission = ODRL::Permission.new(title: "Permission to use")
28
+
29
+ use = ODRL::Use.new(value: "use") # subclass of action
30
+
31
+ # Constraints: :uid, :rightOperand, :leftOperand, :operator, :rightOperandReference, :dataType, :unit, :status
32
+ constraint_nonprofit = ODRL::Constraint.new(
33
+ title: "Use by non-profit organization",
34
+ leftOperand: "industry",
35
+ operator: "neq",
36
+ rightOperand: "https://w3id.org/dingo#ForProfitOrganisation"
37
+ )
38
+ constraint_noncommercial = ODRL::Constraint.new(
39
+ title: "Use for non-commercial purposes",
40
+ leftOperand: "purpose",
41
+ operator: "neq",
42
+ rightOperand: "http://purl.obolibrary.org/obo/ExO_0000085"
43
+ )
44
+ permission.addConstraint(constraint: constraint_nonprofit)
45
+ permission.addConstraint(constraint: constraint_noncommercial)
46
+ permission.addAsset(asset: asset)
47
+ permission.addAssigner(party: ministerio)
48
+ permission.addAction(action: use)
49
+
50
+ policy.addPermission(rule: permission)
51
+
52
+ policy.load_graph
53
+ result = policy.serialize(format: "turtle")
54
+ puts result
@@ -1,66 +1,66 @@
1
- @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2
-
3
- <http://example.org#constraint_68801650224698>
4
- <http://purl.org/dc/terms/identifier> <http://example.org#constraint_68801650224698> ;
5
- <http://purl.org/dc/terms/title> "Use by non-profit organization"@en ;
6
- a <http://www.w3.org/ns/odrl/2/Constraint> ;
7
- <http://www.w3.org/2000/01/rdf-schema#label> "Use by non-profit organization"@en ;
8
- <http://www.w3.org/ns/odrl/2/leftOperand> <http://www.w3.org/ns/odrl/2/industry> ;
9
- <http://www.w3.org/ns/odrl/2/operator> <http://www.w3.org/ns/odrl/2/neq> ;
10
- <http://www.w3.org/ns/odrl/2/rightOperand> <https://w3id.org/dingo#ForProfitOrganisation> ;
11
- <http://www.w3.org/ns/odrl/2/uid> <http://example.org#constraint_68801650224698> .
12
-
13
- <http://example.org#constraint_68801650224712>
14
- <http://purl.org/dc/terms/identifier> <http://example.org#constraint_68801650224712> ;
15
- <http://purl.org/dc/terms/title> "Use for non-commercial purposes"@en ;
16
- a <http://www.w3.org/ns/odrl/2/Constraint> ;
17
- <http://www.w3.org/2000/01/rdf-schema#label> "Use for non-commercial purposes"@en ;
18
- <http://www.w3.org/ns/odrl/2/leftOperand> <http://www.w3.org/ns/odrl/2/purpose> ;
19
- <http://www.w3.org/ns/odrl/2/operator> <http://www.w3.org/ns/odrl/2/neq> ;
20
- <http://www.w3.org/ns/odrl/2/rightOperand> <http://purl.obolibrary.org/obo/ExO_0000085> ;
21
- <http://www.w3.org/ns/odrl/2/uid> <http://example.org#constraint_68801650224712> .
22
-
23
- <http://example.org#policy_68801650224632>
24
- <http://purl.org/dc/terms/creator> <https://orcid.org/0000-0001-6960-357X> ;
25
- <http://purl.org/dc/terms/description> "An offer any non-Commercial entity to use Germplasm from the BGV - UPM"@en ;
26
- <http://purl.org/dc/terms/identifier> <http://example.org#policy_68801650224632> ;
27
- <http://purl.org/dc/terms/issued> "2022-06-29"@en ;
28
- <http://purl.org/dc/terms/subject> "nagoya-constraint"@en ;
29
- <http://purl.org/dc/terms/title> "Offer for the use of BGV Germplasm"@en ;
30
- a <http://www.w3.org/ns/odrl/2/Offer> ;
31
- <http://www.w3.org/2000/01/rdf-schema#label> "Offer for the use of BGV Germplasm"@en ;
32
- <http://www.w3.org/ns/odrl/2/permission> <http://example.org#rule_68801650224680> ;
33
- <http://www.w3.org/ns/odrl/2/uid> <http://example.org#policy_68801650224632> .
34
-
35
- <http://example.org#rule_68801650224680>
36
- <http://purl.org/dc/terms/identifier> <http://example.org#rule_68801650224680> ;
37
- <http://purl.org/dc/terms/title> "Permission to use"@en ;
38
- a <http://www.w3.org/ns/odrl/2/Permission> ;
39
- <http://www.w3.org/2000/01/rdf-schema#label> "Permission to use"@en ;
40
- <http://www.w3.org/ns/odrl/2/action> <http://www.w3.org/ns/odrl/2/use> ;
41
- <http://www.w3.org/ns/odrl/2/assigner> <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2> ;
42
- <http://www.w3.org/ns/odrl/2/constraint> <http://example.org#constraint_68801650224698>, <http://example.org#constraint_68801650224712> ;
43
- <http://www.w3.org/ns/odrl/2/target> <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a> ;
44
- <http://www.w3.org/ns/odrl/2/uid> <http://example.org#rule_68801650224680> .
45
-
46
- <http://www.w3.org/ns/odrl/2/use>
47
- <http://purl.org/dc/terms/identifier> <http://www.w3.org/ns/odrl/2/use> ;
48
- a "type"@en ;
49
- <http://www.w3.org/2000/01/rdf-schema#label> ""@en ;
50
- <http://www.w3.org/ns/odrl/2/uid> <http://www.w3.org/ns/odrl/2/use> ;
51
- <https://schema.org/name> ""@en .
52
-
53
- <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2>
54
- <http://purl.org/dc/terms/identifier> <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2> ;
55
- <http://purl.org/dc/terms/title> "Ministerio para la Transición Ecológica y el Reto Demográfico"@en ;
56
- a <http://www.w3.org/ns/odrl/2/Party> ;
57
- <http://www.w3.org/2000/01/rdf-schema#label> "Ministerio para la Transición Ecológica y el Reto Demográfico"@en ;
58
- <http://www.w3.org/ns/odrl/2/uid> <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2> .
59
-
60
- <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a>
61
- <http://purl.org/dc/terms/identifier> <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a> ;
62
- <http://purl.org/dc/terms/title> "César Gómez Campo Banco de Germoplasma Vegetal de la UPM"@en ;
63
- a <http://www.w3.org/ns/odrl/2/Asset> ;
64
- <http://www.w3.org/2000/01/rdf-schema#label> "César Gómez Campo Banco de Germoplasma Vegetal de la UPM"@en ;
65
- <http://www.w3.org/ns/odrl/2/uid> <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a> .
66
-
1
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
2
+
3
+ <http://example.org#constraint_68801650224698>
4
+ <http://purl.org/dc/terms/identifier> <http://example.org#constraint_68801650224698> ;
5
+ <http://purl.org/dc/terms/title> "Use by non-profit organization"@en ;
6
+ a <http://www.w3.org/ns/odrl/2/Constraint> ;
7
+ <http://www.w3.org/2000/01/rdf-schema#label> "Use by non-profit organization"@en ;
8
+ <http://www.w3.org/ns/odrl/2/leftOperand> <http://www.w3.org/ns/odrl/2/industry> ;
9
+ <http://www.w3.org/ns/odrl/2/operator> <http://www.w3.org/ns/odrl/2/neq> ;
10
+ <http://www.w3.org/ns/odrl/2/rightOperand> <https://w3id.org/dingo#ForProfitOrganisation> ;
11
+ <http://www.w3.org/ns/odrl/2/uid> <http://example.org#constraint_68801650224698> .
12
+
13
+ <http://example.org#constraint_68801650224712>
14
+ <http://purl.org/dc/terms/identifier> <http://example.org#constraint_68801650224712> ;
15
+ <http://purl.org/dc/terms/title> "Use for non-commercial purposes"@en ;
16
+ a <http://www.w3.org/ns/odrl/2/Constraint> ;
17
+ <http://www.w3.org/2000/01/rdf-schema#label> "Use for non-commercial purposes"@en ;
18
+ <http://www.w3.org/ns/odrl/2/leftOperand> <http://www.w3.org/ns/odrl/2/purpose> ;
19
+ <http://www.w3.org/ns/odrl/2/operator> <http://www.w3.org/ns/odrl/2/neq> ;
20
+ <http://www.w3.org/ns/odrl/2/rightOperand> <http://purl.obolibrary.org/obo/ExO_0000085> ;
21
+ <http://www.w3.org/ns/odrl/2/uid> <http://example.org#constraint_68801650224712> .
22
+
23
+ <http://example.org#policy_68801650224632>
24
+ <http://purl.org/dc/terms/creator> <https://orcid.org/0000-0001-6960-357X> ;
25
+ <http://purl.org/dc/terms/description> "An offer any non-Commercial entity to use Germplasm from the BGV - UPM"@en ;
26
+ <http://purl.org/dc/terms/identifier> <http://example.org#policy_68801650224632> ;
27
+ <http://purl.org/dc/terms/issued> "2022-06-29"@en ;
28
+ <http://purl.org/dc/terms/subject> "nagoya-constraint"@en ;
29
+ <http://purl.org/dc/terms/title> "Offer for the use of BGV Germplasm"@en ;
30
+ a <http://www.w3.org/ns/odrl/2/Offer> ;
31
+ <http://www.w3.org/2000/01/rdf-schema#label> "Offer for the use of BGV Germplasm"@en ;
32
+ <http://www.w3.org/ns/odrl/2/permission> <http://example.org#rule_68801650224680> ;
33
+ <http://www.w3.org/ns/odrl/2/uid> <http://example.org#policy_68801650224632> .
34
+
35
+ <http://example.org#rule_68801650224680>
36
+ <http://purl.org/dc/terms/identifier> <http://example.org#rule_68801650224680> ;
37
+ <http://purl.org/dc/terms/title> "Permission to use"@en ;
38
+ a <http://www.w3.org/ns/odrl/2/Permission> ;
39
+ <http://www.w3.org/2000/01/rdf-schema#label> "Permission to use"@en ;
40
+ <http://www.w3.org/ns/odrl/2/action> <http://www.w3.org/ns/odrl/2/use> ;
41
+ <http://www.w3.org/ns/odrl/2/assigner> <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2> ;
42
+ <http://www.w3.org/ns/odrl/2/constraint> <http://example.org#constraint_68801650224698>, <http://example.org#constraint_68801650224712> ;
43
+ <http://www.w3.org/ns/odrl/2/target> <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a> ;
44
+ <http://www.w3.org/ns/odrl/2/uid> <http://example.org#rule_68801650224680> .
45
+
46
+ <http://www.w3.org/ns/odrl/2/use>
47
+ <http://purl.org/dc/terms/identifier> <http://www.w3.org/ns/odrl/2/use> ;
48
+ a "type"@en ;
49
+ <http://www.w3.org/2000/01/rdf-schema#label> ""@en ;
50
+ <http://www.w3.org/ns/odrl/2/uid> <http://www.w3.org/ns/odrl/2/use> ;
51
+ <https://schema.org/name> ""@en .
52
+
53
+ <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2>
54
+ <http://purl.org/dc/terms/identifier> <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2> ;
55
+ <http://purl.org/dc/terms/title> "Ministerio para la Transición Ecológica y el Reto Demográfico"@en ;
56
+ a <http://www.w3.org/ns/odrl/2/Party> ;
57
+ <http://www.w3.org/2000/01/rdf-schema#label> "Ministerio para la Transición Ecológica y el Reto Demográfico"@en ;
58
+ <http://www.w3.org/ns/odrl/2/uid> <https://absch.cbd.int/en/database/CON/ABSCH-CON-ES-241810/2> .
59
+
60
+ <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a>
61
+ <http://purl.org/dc/terms/identifier> <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a> ;
62
+ <http://purl.org/dc/terms/title> "César Gómez Campo Banco de Germoplasma Vegetal de la UPM"@en ;
63
+ a <http://www.w3.org/ns/odrl/2/Asset> ;
64
+ <http://www.w3.org/2000/01/rdf-schema#label> "César Gómez Campo Banco de Germoplasma Vegetal de la UPM"@en ;
65
+ <http://www.w3.org/ns/odrl/2/uid> <https://fdp.bgv.cbgp.upm.es/dataset/65ffbf3d-bed1-4a9a-abf9-0116cc35b40a> .
66
+
data/launch.json CHANGED
@@ -1,11 +1,11 @@
1
- {
2
- "name": "RSpec - all",
3
- "type": "Ruby",
4
- "request": "launch",
5
- "cwd": "${workspaceRoot}",
6
- "program": "/home/osboxes/.rvm/rubies/ruby-3.0.0/bin/rspec",
7
- "args": [
8
- "-I",
9
- "${workspaceRoot}"
10
- ]
1
+ {
2
+ "name": "RSpec - all",
3
+ "type": "Ruby",
4
+ "request": "launch",
5
+ "cwd": "${workspaceRoot}",
6
+ "program": "/home/osboxes/.rvm/rubies/ruby-3.0.0/bin/rspec",
7
+ "args": [
8
+ "-I",
9
+ "${workspaceRoot}"
10
+ ]
11
11
  }
data/lib/odrl/action.rb CHANGED
@@ -1,106 +1,106 @@
1
- # frozen_string_literal: true
2
-
3
- module ODRL
4
- # ODRL::Action
5
- # Describes an action like "use"
6
- #
7
- # @author Mark D Wilkinson
8
- # @attr [URI] (optional) uid the URI of the Action node
9
- # @attr [[ODRL::Refinement]] (optional) ODRL Refinement objects
10
- # @attr [URI] predicate (optional) the predicate you wish to use with this action
11
- # @attr [string] value (required) a string like "use"
12
- # @attr [string] vallabel (optional) a string like "use"
13
- class Action < Base
14
- attr_accessor :uid, :refinements, :predicate, :type, :value, :vallabel
15
-
16
- # constructor
17
- # @param [Hash] opts the options to create a message with.
18
- # @option opts [String] :value the string value of rthe action, like "use"
19
- # @option opts [String] :vallabel the string for the label, like "use"
20
- #
21
- def initialize(value:, vallabel: "", type: CACTION, **args)
22
- @value = value
23
- @vallabel = vallabel || @value
24
- raise "Actions must haves a value such as 'use' - I'm dead!" unless @value
25
-
26
- # if it is already a URI, then let it go
27
- @value = "http://www.w3.org/ns/odrl/2/#{@value}" unless @value =~ %r{http://}
28
-
29
- @uid = @value
30
- # unless @uid
31
- # self.uid = Base.baseURI + "#action_" + Base.getuuid
32
- # end
33
- super(uid: @uid, type: type, **args)
34
-
35
- @refinements = {}
36
-
37
- args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
38
- unless args[:refinements].first.nil?
39
- args[:refinements].each do |c|
40
- addRefinement(refinement: c)
41
- end
42
- end
43
-
44
- self.predicate = PACTION unless predicate
45
- end
46
-
47
- # Adds an ODRL Refinement
48
- #
49
- # @param refinement [ODRL::Refinement] the refinement to the action
50
- #
51
- def addRefinement(refinement: args)
52
- raise "Refinement is not an ODRL Constraint" unless refinement.is_a?(Constraint)
53
-
54
- refinements[refinement.uid] = [PREFINEMENT, refinement]
55
- end
56
-
57
- # Causes the triples of this object to be formed in the in-memory store
58
- # This includes any "cascading" objects for which this is the subject of the triple
59
- #
60
- def load_graph
61
- super
62
- # TODO: This is bad DRY!! Put the bulk of this method into the base object
63
- [:refinements].each do |connected_object_type|
64
- next unless send(connected_object_type)
65
-
66
- send(connected_object_type).each do |_uid, typedconnection|
67
- predicate, odrlobject = typedconnection # e.g. "refinement", RefinementObject
68
- object = odrlobject.uid
69
- subject = uid
70
- repo = repository
71
- triplify(subject, predicate, object, repo)
72
- odrlobject.load_graph # start the cascade
73
- end
74
- end
75
- subject = uid
76
- object = vallabel
77
- predicate = SCHEMA.name
78
- repo = repository
79
- triplify(subject, predicate, object, repo)
80
- object = vallabel
81
- predicate = RDFS.label
82
- repo = repository
83
- triplify(subject, predicate, object, repo)
84
- end
85
-
86
- # Returns the serialized RDF for this object and cascading related objects
87
- #
88
- # @param format [Symbol] a valid RDF::Writer format (e.g. :turtle)
89
- #
90
- def serialize(format:)
91
- super
92
- end
93
- end
94
-
95
- class Use < Action
96
- def initialize(type: CACTION, **args)
97
- super(type: :type, **args)
98
- end
99
- end
100
-
101
- class Transfer < Action
102
- def initialize(type: CACTION, **args)
103
- super(type: :type, **args)
104
- end
105
- end
106
- end
1
+ # frozen_string_literal: true
2
+
3
+ module ODRL
4
+ # ODRL::Action
5
+ # Describes an action like "use"
6
+ #
7
+ # @author Mark D Wilkinson
8
+ # @attr [URI] (optional) uid the URI of the Action node
9
+ # @attr [[ODRL::Refinement]] (optional) ODRL Refinement objects
10
+ # @attr [URI] predicate (optional) the predicate you wish to use with this action
11
+ # @attr [string] value (required) a string like "use"
12
+ # @attr [string] vallabel (optional) a string like "use"
13
+ class Action < Base
14
+ attr_accessor :uid, :refinements, :predicate, :type, :value, :vallabel
15
+
16
+ # constructor
17
+ # @param [Hash] opts the options to create a message with.
18
+ # @option opts [String] :value the string value of rthe action, like "use"
19
+ # @option opts [String] :vallabel the string for the label, like "use"
20
+ #
21
+ def initialize(value:, vallabel: "", type: CACTION, **args)
22
+ @value = value
23
+ @vallabel = vallabel || @value
24
+ raise "Actions must haves a value such as 'use' - I'm dead!" unless @value
25
+
26
+ # if it is already a URI, then let it go
27
+ @value = "http://www.w3.org/ns/odrl/2/#{@value}" unless @value =~ %r{http://}
28
+
29
+ @uid = @value
30
+ # unless @uid
31
+ # self.uid = Base.baseURI + "#action_" + Base.getuuid
32
+ # end
33
+ super(uid: @uid, type: type, **args)
34
+
35
+ @refinements = {}
36
+
37
+ args[:refinements] = [args[:refinements]] unless args[:refinements].is_a? Array
38
+ unless args[:refinements].first.nil?
39
+ args[:refinements].each do |c|
40
+ addRefinement(refinement: c)
41
+ end
42
+ end
43
+
44
+ self.predicate = PACTION unless predicate
45
+ end
46
+
47
+ # Adds an ODRL Refinement
48
+ #
49
+ # @param refinement [ODRL::Refinement] the refinement to the action
50
+ #
51
+ def addRefinement(refinement: args)
52
+ raise "Refinement is not an ODRL Constraint" unless refinement.is_a?(Constraint)
53
+
54
+ refinements[refinement.uid] = [PREFINEMENT, refinement]
55
+ end
56
+
57
+ # Causes the triples of this object to be formed in the in-memory store
58
+ # This includes any "cascading" objects for which this is the subject of the triple
59
+ #
60
+ def load_graph
61
+ super
62
+ # TODO: This is bad DRY!! Put the bulk of this method into the base object
63
+ [:refinements].each do |connected_object_type|
64
+ next unless send(connected_object_type)
65
+
66
+ send(connected_object_type).each do |_uid, typedconnection|
67
+ predicate, odrlobject = typedconnection # e.g. "refinement", RefinementObject
68
+ object = odrlobject.uid
69
+ subject = uid
70
+ repo = repository
71
+ triplify(subject, predicate, object, repo)
72
+ odrlobject.load_graph # start the cascade
73
+ end
74
+ end
75
+ subject = uid
76
+ object = vallabel
77
+ predicate = SCHEMA.name
78
+ repo = repository
79
+ triplify(subject, predicate, object, repo)
80
+ object = vallabel
81
+ predicate = RDFS.label
82
+ repo = repository
83
+ triplify(subject, predicate, object, repo)
84
+ end
85
+
86
+ # Returns the serialized RDF for this object and cascading related objects
87
+ #
88
+ # @param format [Symbol] a valid RDF::Writer format (e.g. :turtle)
89
+ #
90
+ def serialize(format:)
91
+ super
92
+ end
93
+ end
94
+
95
+ class Use < Action
96
+ def initialize(type: CACTION, **args)
97
+ super(type: :type, **args)
98
+ end
99
+ end
100
+
101
+ class Transfer < Action
102
+ def initialize(type: CACTION, **args)
103
+ super(type: :type, **args)
104
+ end
105
+ end
106
+ end