publisci 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +13 -0
  5. data/Gemfile +36 -0
  6. data/LICENSE.txt +20 -0
  7. data/README.md +51 -0
  8. data/README.rdoc +48 -0
  9. data/Rakefile +68 -0
  10. data/bin/bio-publisci +106 -0
  11. data/bin/bio-publisci-server +50 -0
  12. data/examples/bio-band_integration.rb +9 -0
  13. data/examples/no_magic.prov +58 -0
  14. data/examples/no_magic.rb +58 -0
  15. data/examples/orm.prov +48 -0
  16. data/examples/primer-full.prov +120 -0
  17. data/examples/primer.prov +66 -0
  18. data/examples/prov_dsl.prov +85 -0
  19. data/examples/safe_gen.rb +7 -0
  20. data/examples/visualization/primer.prov +66 -0
  21. data/examples/visualization/prov_viz.rb +140 -0
  22. data/examples/visualization/viz.rb +35 -0
  23. data/features/create_generator.feature +21 -0
  24. data/features/integration.feature +12 -0
  25. data/features/integration_steps.rb +10 -0
  26. data/features/metadata.feature +37 -0
  27. data/features/metadata_steps.rb +40 -0
  28. data/features/orm.feature +60 -0
  29. data/features/orm_steps.rb +74 -0
  30. data/features/prov_dsl.feature +14 -0
  31. data/features/prov_dsl_steps.rb +11 -0
  32. data/features/reader.feature +25 -0
  33. data/features/reader_steps.rb +61 -0
  34. data/features/step_definitions/bio-publisci_steps.rb +0 -0
  35. data/features/store.feature +27 -0
  36. data/features/store_steps.rb +42 -0
  37. data/features/support/env.rb +13 -0
  38. data/features/writer.feature +14 -0
  39. data/features/writer_steps.rb +24 -0
  40. data/lib/bio-publisci.rb +64 -0
  41. data/lib/bio-publisci/analyzer.rb +57 -0
  42. data/lib/bio-publisci/datacube_model.rb +111 -0
  43. data/lib/bio-publisci/dataset/ORM/data_cube_orm.rb +240 -0
  44. data/lib/bio-publisci/dataset/ORM/observation.rb +20 -0
  45. data/lib/bio-publisci/dataset/configuration.rb +31 -0
  46. data/lib/bio-publisci/dataset/data_cube.rb +418 -0
  47. data/lib/bio-publisci/dataset/dataset.rb +11 -0
  48. data/lib/bio-publisci/dataset/dataset_for.rb +186 -0
  49. data/lib/bio-publisci/dataset/interactive.rb +72 -0
  50. data/lib/bio-publisci/dsl/config.rb +34 -0
  51. data/lib/bio-publisci/dsl/dataset_dsl.rb +93 -0
  52. data/lib/bio-publisci/dsl/dsl.rb +72 -0
  53. data/lib/bio-publisci/dsl/metadata_dsl.rb +85 -0
  54. data/lib/bio-publisci/dsl/prov_dsl.rb +143 -0
  55. data/lib/bio-publisci/metadata/generator.rb +323 -0
  56. data/lib/bio-publisci/metadata/metadata.rb +5 -0
  57. data/lib/bio-publisci/metadata/metadata_model.rb +25 -0
  58. data/lib/bio-publisci/metadata/prov/activity.rb +88 -0
  59. data/lib/bio-publisci/metadata/prov/agent.rb +100 -0
  60. data/lib/bio-publisci/metadata/prov/association.rb +107 -0
  61. data/lib/bio-publisci/metadata/prov/config.rb +34 -0
  62. data/lib/bio-publisci/metadata/prov/derivation.rb +60 -0
  63. data/lib/bio-publisci/metadata/prov/element.rb +120 -0
  64. data/lib/bio-publisci/metadata/prov/entity.rb +64 -0
  65. data/lib/bio-publisci/metadata/prov/model/prov_models.rb +109 -0
  66. data/lib/bio-publisci/metadata/prov/plan.rb +32 -0
  67. data/lib/bio-publisci/metadata/prov/prov.rb +78 -0
  68. data/lib/bio-publisci/metadata/prov/role.rb +40 -0
  69. data/lib/bio-publisci/metadata/prov/usage.rb +64 -0
  70. data/lib/bio-publisci/metadata/publisher.rb +25 -0
  71. data/lib/bio-publisci/mixins/custom_predicate.rb +38 -0
  72. data/lib/bio-publisci/mixins/dereferencable.rb +34 -0
  73. data/lib/bio-publisci/mixins/registry.rb +27 -0
  74. data/lib/bio-publisci/mixins/vocabulary.rb +8 -0
  75. data/lib/bio-publisci/output.rb +27 -0
  76. data/lib/bio-publisci/parser.rb +266 -0
  77. data/lib/bio-publisci/post_processor.rb +95 -0
  78. data/lib/bio-publisci/query/query_helper.rb +123 -0
  79. data/lib/bio-publisci/r_client.rb +54 -0
  80. data/lib/bio-publisci/readers/arff.rb +49 -0
  81. data/lib/bio-publisci/readers/base.rb +57 -0
  82. data/lib/bio-publisci/readers/csv.rb +88 -0
  83. data/lib/bio-publisci/readers/dataframe.rb +67 -0
  84. data/lib/bio-publisci/readers/maf.rb +199 -0
  85. data/lib/bio-publisci/readers/r_cross.rb +112 -0
  86. data/lib/bio-publisci/readers/r_matrix.rb +176 -0
  87. data/lib/bio-publisci/store.rb +56 -0
  88. data/lib/bio-publisci/writers/arff.rb +91 -0
  89. data/lib/bio-publisci/writers/base.rb +93 -0
  90. data/lib/bio-publisci/writers/csv.rb +31 -0
  91. data/lib/bio-publisci/writers/dataframe.rb +81 -0
  92. data/lib/bio-publisci/writers/json.rb +18 -0
  93. data/lib/r2rdf.rb +226 -0
  94. data/lib/template_bak.rb +12 -0
  95. data/lib/template_bak/publisci.rb +3 -0
  96. data/lib/vocabs/cc.rb +18 -0
  97. data/lib/vocabs/cert.rb +13 -0
  98. data/lib/vocabs/dc.rb +63 -0
  99. data/lib/vocabs/dc11.rb +23 -0
  100. data/lib/vocabs/doap.rb +45 -0
  101. data/lib/vocabs/exif.rb +168 -0
  102. data/lib/vocabs/foaf.rb +69 -0
  103. data/lib/vocabs/geo.rb +13 -0
  104. data/lib/vocabs/http.rb +26 -0
  105. data/lib/vocabs/ma.rb +78 -0
  106. data/lib/vocabs/owl.rb +59 -0
  107. data/lib/vocabs/rdfs.rb +17 -0
  108. data/lib/vocabs/rsa.rb +12 -0
  109. data/lib/vocabs/rss.rb +14 -0
  110. data/lib/vocabs/sioc.rb +93 -0
  111. data/lib/vocabs/skos.rb +36 -0
  112. data/lib/vocabs/wot.rb +21 -0
  113. data/lib/vocabs/xhtml.rb +9 -0
  114. data/lib/vocabs/xsd.rb +58 -0
  115. data/resources/maf_example.maf +10 -0
  116. data/resources/maf_rdf.ttl +1173 -0
  117. data/resources/primer.ttl +38 -0
  118. data/resources/queries/code_resources.rq +10 -0
  119. data/resources/queries/codes.rq +18 -0
  120. data/resources/queries/dataset.rq +7 -0
  121. data/resources/queries/dimension_ranges.rq +8 -0
  122. data/resources/queries/dimensions.rq +12 -0
  123. data/resources/queries/gene.rq +16 -0
  124. data/resources/queries/hugo_to_ensembl.rq +7 -0
  125. data/resources/queries/maf_column.rq +26 -0
  126. data/resources/queries/measures.rq +12 -0
  127. data/resources/queries/observation_labels.rq +8 -0
  128. data/resources/queries/observations.rq +13 -0
  129. data/resources/queries/patient.rq +11 -0
  130. data/resources/queries/patient_list.rq +11 -0
  131. data/resources/queries/patients_with_mutation.rq +18 -0
  132. data/resources/queries/properties.rq +8 -0
  133. data/resources/queries/test.rq +3 -0
  134. data/resources/weather.numeric.arff +28 -0
  135. data/scripts/get_gene_lengths.rb +50 -0
  136. data/scripts/islet_mlratio.rb +6 -0
  137. data/scripts/scan_islet.rb +6 -0
  138. data/scripts/update_reference.rb +25 -0
  139. data/server/helpers.rb +215 -0
  140. data/server/public/src-min-noconflict/LICENSE +24 -0
  141. data/server/public/src-min-noconflict/ace.js +11 -0
  142. data/server/public/src-min-noconflict/ext-chromevox.js +1 -0
  143. data/server/public/src-min-noconflict/ext-elastic_tabstops_lite.js +1 -0
  144. data/server/public/src-min-noconflict/ext-emmet.js +1 -0
  145. data/server/public/src-min-noconflict/ext-keybinding_menu.js +1 -0
  146. data/server/public/src-min-noconflict/ext-language_tools.js +1 -0
  147. data/server/public/src-min-noconflict/ext-modelist.js +1 -0
  148. data/server/public/src-min-noconflict/ext-old_ie.js +1 -0
  149. data/server/public/src-min-noconflict/ext-searchbox.js +1 -0
  150. data/server/public/src-min-noconflict/ext-settings_menu.js +1 -0
  151. data/server/public/src-min-noconflict/ext-spellcheck.js +1 -0
  152. data/server/public/src-min-noconflict/ext-split.js +1 -0
  153. data/server/public/src-min-noconflict/ext-static_highlight.js +1 -0
  154. data/server/public/src-min-noconflict/ext-statusbar.js +1 -0
  155. data/server/public/src-min-noconflict/ext-textarea.js +1 -0
  156. data/server/public/src-min-noconflict/ext-themelist.js +1 -0
  157. data/server/public/src-min-noconflict/ext-whitespace.js +1 -0
  158. data/server/public/src-min-noconflict/keybinding-emacs.js +1 -0
  159. data/server/public/src-min-noconflict/keybinding-vim.js +1 -0
  160. data/server/public/src-min-noconflict/mode-ruby.js +1 -0
  161. data/server/public/src-min-noconflict/snippets/ruby.js +1 -0
  162. data/server/public/src-min-noconflict/theme-twilight.js +1 -0
  163. data/server/public/src-min-noconflict/worker-coffee.js +1 -0
  164. data/server/public/src-min-noconflict/worker-css.js +1 -0
  165. data/server/public/src-min-noconflict/worker-javascript.js +1 -0
  166. data/server/public/src-min-noconflict/worker-json.js +1 -0
  167. data/server/public/src-min-noconflict/worker-lua.js +1 -0
  168. data/server/public/src-min-noconflict/worker-php.js +1 -0
  169. data/server/public/src-min-noconflict/worker-xquery.js +1 -0
  170. data/server/routes.rb +123 -0
  171. data/server/views/dsl.haml +65 -0
  172. data/server/views/dump.haml +3 -0
  173. data/server/views/import.haml +35 -0
  174. data/server/views/new_repository.haml +25 -0
  175. data/server/views/query.haml +28 -0
  176. data/server/views/repository.haml +25 -0
  177. data/spec/ORM/data_cube_orm_spec.rb +33 -0
  178. data/spec/ORM/prov_model_spec.rb +72 -0
  179. data/spec/analyzer_spec.rb +36 -0
  180. data/spec/bnode_spec.rb +66 -0
  181. data/spec/csv/bacon.csv +4 -0
  182. data/spec/csv/moar_bacon.csv +11 -0
  183. data/spec/data_cube_spec.rb +169 -0
  184. data/spec/dataset_for_spec.rb +77 -0
  185. data/spec/dsl_spec.rb +134 -0
  186. data/spec/generators/csv_spec.rb +44 -0
  187. data/spec/generators/dataframe_spec.rb +44 -0
  188. data/spec/generators/maf_spec.rb +40 -0
  189. data/spec/generators/r_cross_spec.rb +51 -0
  190. data/spec/generators/r_matrix_spec.rb +44 -0
  191. data/spec/length_lookup_spec.rb +0 -0
  192. data/spec/maf_query_spec.rb +343 -0
  193. data/spec/metadata/metadata_dsl_spec.rb +68 -0
  194. data/spec/prov/activity_spec.rb +74 -0
  195. data/spec/prov/agent_spec.rb +54 -0
  196. data/spec/prov/association_spec.rb +55 -0
  197. data/spec/prov/config_spec.rb +28 -0
  198. data/spec/prov/derivation_spec.rb +30 -0
  199. data/spec/prov/entity_spec.rb +52 -0
  200. data/spec/prov/role_spec.rb +94 -0
  201. data/spec/prov/usage_spec.rb +98 -0
  202. data/spec/queries/integrity/1.rq +21 -0
  203. data/spec/queries/integrity/11.rq +29 -0
  204. data/spec/queries/integrity/12.rq +37 -0
  205. data/spec/queries/integrity/14.rq +25 -0
  206. data/spec/queries/integrity/19_1.rq +21 -0
  207. data/spec/queries/integrity/19_2.rq +15 -0
  208. data/spec/queries/integrity/2.rq +22 -0
  209. data/spec/queries/integrity/3.rq +19 -0
  210. data/spec/queries/integrity/4.rq +13 -0
  211. data/spec/queries/integrity/5.rq +14 -0
  212. data/spec/r_builder_spec.rb +33 -0
  213. data/spec/resource/.RData +0 -0
  214. data/spec/resource/example.Rhistory +3 -0
  215. data/spec/spec_helper.rb +17 -0
  216. data/spec/turtle/bacon +147 -0
  217. data/spec/turtle/reference +2064 -0
  218. data/spec/turtle/weather +275 -0
  219. data/spec/writer_spec.rb +75 -0
  220. metadata +589 -0
@@ -0,0 +1,5 @@
1
+ module PubliSci
2
+ class Metadata
3
+ extend PubliSci::Registry
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ begin
2
+ require 'spira'
3
+ module PubliSci
4
+ class Metadata
5
+ module Model
6
+ PROV ||= RDF::Vocabulary.new(RDF::URI.new('http://www.w3.org/ns/prov#'))
7
+ QB ||= RDF::Vocabulary.new(RDF::URI.new('http://purl.org/linked-data/cube#'))
8
+ DCT ||= RDF::Vocabulary.new(RDF::URI.new('http://purl.org/dc/terms/'))
9
+
10
+
11
+ class Meta < Spira::Base
12
+ type PROV.Entity
13
+ type QB.DataSet
14
+ property :label, predicate: RDF::RDFS.label
15
+ property :comment, predicate: RDF::RDFS.comment
16
+ property :description, predicate: DCT.description
17
+ property :creator, predicate: DCT.creator
18
+ property :issued, predicate: DCT.issued
19
+ end
20
+ end
21
+ end
22
+ end
23
+ rescue LoadError
24
+ # puts "spira not installed, ORM unavailable"
25
+ end
@@ -0,0 +1,88 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Activity
4
+ include Prov::Element
5
+ class Associations < Array
6
+ include PubliSci::Prov::Dereferencable
7
+ def method
8
+ :agents
9
+ end
10
+ end
11
+
12
+ class Generations < Array
13
+ include PubliSci::Prov::Dereferencable
14
+ def method
15
+ :entities
16
+ end
17
+ end
18
+
19
+ class Usages < Array
20
+ include PubliSci::Prov::Dereferencable
21
+ def method
22
+ :entities
23
+ end
24
+ end
25
+
26
+ def generated(entity=nil)
27
+ if entity.is_a? Entity
28
+ entity.generated_by self
29
+ elsif Prov.entities[entity]
30
+ Prov.entities[entity].generated_by self
31
+ end
32
+ basic_list(:generated,:entities,Generations,entity)
33
+ end
34
+
35
+ def associated_with(agent=nil, &block)
36
+ block_list(:associated,:associations,Association,Associations,agent,&block)
37
+ end
38
+ alias_method :wasAssociatedWith, :associated_with
39
+
40
+ def used(entity=nil, &block)
41
+ block_list(:use,:usages,Usage,Usages,entity, &block)
42
+ end
43
+
44
+ def to_n3
45
+ str = "<#{subject}> a prov:Activity ;\n"
46
+
47
+ if generated
48
+ str << "\tprov:generated "
49
+ generated.dereference.map{|src|
50
+ str << "<#{src}>, "
51
+ }
52
+ str[-2]=" "
53
+ str[-1]=";\n"
54
+ end
55
+
56
+ if used
57
+ used.dereference.map{|u|
58
+ if u.is_a? Usage
59
+ str << "\tprov:used <#{u.entity}> ;\n"
60
+ str << "\tprov:qualifiedUsage <#{u}> ;\n"
61
+ else
62
+ str << "\tprov:used <#{u}> ;\n"
63
+ end
64
+ }
65
+ end
66
+
67
+ if associated_with
68
+ associated_with.dereference.map{|assoc|
69
+ if assoc.is_a? Association
70
+ str << "\tprov:wasAssociatedWith <#{assoc.agent}> ;\n"
71
+ str << "\tprov:qualifiedAssociation <#{assoc}> ;\n"
72
+ else
73
+ str << "\tprov:wasAssociatedWith <#{assoc}> ;\n"
74
+ end
75
+ }
76
+ end
77
+
78
+ add_custom(str)
79
+
80
+ str << "\trdfs:label \"#{__label}\" .\n\n"
81
+ end
82
+
83
+ def to_s
84
+ subject
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,100 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Agent
4
+ include Prov::Element
5
+ attr_accessor :organization
6
+ attr_accessor :behalf_of
7
+
8
+ def type(t=nil)
9
+ if t
10
+ @type = t.to_sym
11
+ else
12
+ @type
13
+ end
14
+ end
15
+
16
+ def type=(t)
17
+ @type = t.to_sym
18
+ end
19
+
20
+ def name(name=nil)
21
+ if name
22
+ @name = name
23
+ else
24
+ @name
25
+ end
26
+ end
27
+
28
+ def name=(name)
29
+ @name = name
30
+ end
31
+
32
+ def organization(organization=nil)
33
+ basic_keyword(:organization,:agents,organization)
34
+ # if organization
35
+ # @organization = organization
36
+ # elsif @organization.is_a? Symbol
37
+ # raise "UnknownAgent: #{@organization}" unless Prov.agents[@organization]
38
+ # @organization = Prov.agents[@organization]
39
+ # else
40
+ # @organization
41
+ # end
42
+ end
43
+
44
+ # def organization=(organization)
45
+ # @organization = organization
46
+ # end
47
+
48
+ def on_behalf_of(other_agent=nil)
49
+ basic_keyword(:behalf_of,:agents,other_agent)
50
+ # if other_agent
51
+ # @behalf_of = other_agent
52
+ # elsif @on_behalf_of.is_a? Symbol
53
+ # raise "UnknownAgent: #{@on_behalf_of}" unless Prov.agents.has_key?(@on_behalf_of)
54
+ # @behalf_of = Prov.agents[@on_behalf_of]
55
+ # else
56
+ # @behalf_of
57
+ # end
58
+
59
+ # @behalf_of
60
+ end
61
+ alias_method :worked_for, :on_behalf_of
62
+
63
+ def to_n3
64
+ str = "<#{subject}> a"
65
+ if type
66
+ case type.to_sym
67
+ when :software
68
+ str << " prov:SoftwareAgent ;\n"
69
+ when :person
70
+ str << " prov:Person ;\n"
71
+ when :organization
72
+ str << " prov:Organization ;\n"
73
+ end
74
+ else
75
+ str << " prov:Agent ;\n"
76
+ end
77
+
78
+ if name
79
+ if type && type.to_sym == :person
80
+ str << "\tfoaf:givenName \"#{name}\" ;\n"
81
+ else
82
+ str << "\tfoaf:name \"#{name}\" ;\n"
83
+ end
84
+ end
85
+
86
+ if on_behalf_of
87
+ str << "\tprov:actedOnBehalfOf <#{on_behalf_of}> ;\n"
88
+ end
89
+
90
+ add_custom(str)
91
+
92
+ str << "\trdfs:label \"#{__label}\" .\n\n"
93
+ end
94
+
95
+ def to_s
96
+ subject
97
+ end
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,107 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Association
4
+ include Prov::Element
5
+
6
+
7
+ def __label
8
+ # raise "MissingInternalLabel: no __label for #{self.inspect}" unless @__label
9
+ @__label ||= Time.now.nsec.to_s(32)
10
+ end
11
+
12
+ def agent(agent=nil)
13
+ basic_keyword(:agent,:agents,agent)
14
+ end
15
+
16
+ def had_plan(*args, &block)
17
+ if block_given?
18
+ p = Prov::Plan.new
19
+ p.instance_eval(&block)
20
+ p.__label=args[0]
21
+ @plan = p
22
+ Prov.register(args[0], p)
23
+ elsif args.size == 0
24
+ if @plan.is_a? Symbol
25
+ raise "UnknownPlan: #{@plan}" unless Prov.plans[@plan]
26
+ @plan = Prov.plans[@plan]
27
+ end
28
+ @plan
29
+ elsif args.size == 1
30
+ if Prov.plans[args[0]]
31
+ @plan = args[0]
32
+ else
33
+ p = Prov::Plan.new
34
+ p.__label=args[0]
35
+ @plan = p
36
+ Prov.register(args[0], p)
37
+ end
38
+ else
39
+ name = args.shift
40
+ args = Hash[*args]
41
+ p = Prov::Plan.new
42
+
43
+ p.__label=name
44
+ p.subject args[:subject]
45
+ (args.keys - [:subject]).map{|k|
46
+ raise "Unkown plan setting #{k}" unless try_auto_set(p,k,args[k])
47
+ }
48
+ @plan = p
49
+ Prov.register(name, p)
50
+ end
51
+ end
52
+ alias_method :plan, :had_plan
53
+
54
+ def had_role(*args, &block)
55
+ if block_given?
56
+ p = Prov::Role.new
57
+ p.instance_eval(&block)
58
+ p.__label=args[0]
59
+ @role = p
60
+ # puts p.class
61
+ Prov.register(args[0], p)
62
+ elsif args.size == 0
63
+ if @role.is_a? Symbol
64
+ raise "UnknownRole: #{@role}" unless (Prov.registry[:role]||={})[@role]
65
+ @role = Prov.registry[:role][@role]
66
+ end
67
+ @role
68
+ elsif args.size == 1
69
+ if (Prov.registry[:role]||={})[args[0]]
70
+ @role = args[0]
71
+ else
72
+ p = Prov::Role.new
73
+ p.__label=args[0]
74
+ @role = p
75
+ Prov.register(args[0], p)
76
+ end
77
+ else
78
+ name = args.shift
79
+ args = Hash[*args]
80
+ p = Prov::Role.new
81
+
82
+ p.__label=name
83
+ p.subject args[:subject]
84
+ (args.keys - [:subject]).map{|k|
85
+ raise "Unkown Role setting #{k}" unless try_auto_set(p,k,args[k])
86
+ }
87
+ @role = p
88
+ Prov.register(name, p)
89
+ end
90
+ end
91
+ alias_method :role, :had_role
92
+
93
+ def to_n3
94
+ str = "<#{subject}> a prov:Association ;\n"
95
+ str << "\tprov:agent <#{agent}> ;\n"
96
+ str << "\tprov:hadPlan <#{plan}> ;\n" if plan
97
+ str << "\tprov:hadRole <#{role}> ;\n" if role
98
+ str << "\trdfs:label \"#{__label}\".\n\n"
99
+ str
100
+ end
101
+
102
+ def to_s
103
+ subject
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,34 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Configuration
4
+ def self.defaults
5
+ {
6
+ output: :generate_n3,
7
+ abbreviate: false,
8
+ repository: :in_memory,
9
+ repository_url: 'http://localhost:8080/'
10
+ }
11
+ end
12
+
13
+ defaults.keys.each{|k|
14
+ default = defaults[k]
15
+ define_method(k) do |input=nil|
16
+ var = instance_variable_get :"@#{k}"
17
+ if var
18
+ var
19
+ else
20
+ instance_variable_set :"@#{k}", default
21
+ end
22
+
23
+ if input
24
+ instance_variable_set :"@#{k}", input
25
+ end
26
+
27
+ instance_variable_get :"@#{k}"
28
+ end
29
+
30
+ attr_writer k
31
+ }
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,60 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Derivation
4
+
5
+ include PubliSci::CustomPredicate
6
+
7
+ def __label
8
+ # raise "MissingInternalLabel: no __label for #{self.inspect}" unless @__label
9
+ @__label ||= Time.now.nsec.to_s(32)
10
+ end
11
+
12
+ def subject(sub=nil)
13
+ if sub
14
+ @subject = sub
15
+ else
16
+ @subject ||= "#{Prov.base_url}/derivation/#{Time.now.nsec.to_s(32)}"
17
+ end
18
+ end
19
+
20
+ def had_activity(activity=nil)
21
+ if activity
22
+ @had_activity = activity
23
+ elsif @had_activity.is_a? Symbol
24
+ raise "UnknownActivity #{@had_activity}" unless Prov.activities[@had_activity]
25
+ @had_activity = Prov.activities[@had_activity]
26
+ else
27
+ @had_activity
28
+ end
29
+ end
30
+ alias_method :activity, :had_activity
31
+
32
+ def entity(entity=nil)
33
+ if entity
34
+ @entity = entity
35
+ elsif @entity.is_a? Symbol
36
+ raise "UnknownEntity #{@entity}" unless Prov.entities[@entity]
37
+ @entity = Prov.entities[@entity]
38
+ else
39
+ @entity
40
+ end
41
+ end
42
+ alias_method :data, :entity
43
+
44
+ def to_n3
45
+ str = "<#{subject}> a prov:Derivation ;\n"
46
+ str << "\tprov:entity <#{entity}> ;\n" if entity
47
+ str << "\tprov:hadActivity <#{had_activity}> ;\n" if had_activity
48
+ str << "\trdfs:label \"#{__label}\".\n\n"
49
+
50
+ add_custom(str)
51
+
52
+ str
53
+ end
54
+
55
+ def to_s
56
+ subject
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,120 @@
1
+ module PubliSci
2
+ class Prov
3
+ module Element
4
+ include PubliSci::Vocabulary
5
+ include PubliSci::CustomPredicate
6
+
7
+ def subject(s=nil)
8
+ if s
9
+ if s.is_a? Symbol
10
+ raise "subject generation from symbol not yet implemented!"
11
+ else
12
+ @subject = s
13
+ end
14
+ else
15
+ @subject ||= generate_subject
16
+ end
17
+ end
18
+
19
+ def subject=(s)
20
+ @subject = s
21
+ end
22
+
23
+ def subject_id
24
+ self.class.to_s.split('::').last.downcase
25
+ end
26
+
27
+ def __label=(l)
28
+ @__label = l
29
+ end
30
+
31
+ def __label
32
+ raise "MissingInternalLabel: no __label for #{self.inspect}" unless @__label
33
+ @__label
34
+ end
35
+
36
+ private
37
+ def generate_subject
38
+ # puts self.class == Prov::Activity
39
+ category = case self
40
+ when Agent
41
+ "agent"
42
+ when Entity
43
+ "entity"
44
+ when Activity
45
+ "activity"
46
+ when Plan
47
+ "plan"
48
+ when Association
49
+ "assoc"
50
+ else
51
+ subject_id()
52
+ # raise "MissingSubject: No automatic subject generation for #{self}"
53
+ end
54
+
55
+ "#{Prov.base_url}/#{category}/#{__label}"
56
+ end
57
+
58
+ def try_auto_set(object,method,args)
59
+ if object.methods.include? method
60
+ object.send(method,args)
61
+ true
62
+ else
63
+ false
64
+ end
65
+ end
66
+
67
+ def basic_keyword(var,type,identifier=nil)
68
+ ivar = instance_variable_get("@#{var}")
69
+
70
+ if identifier
71
+ instance_variable_set("@#{var}", identifier)
72
+ elsif ivar.is_a? Symbol
73
+ raise "NotRegistered: #{type}" unless Prov.registry[type]
74
+ raise "Unknown#{type.capitalize}: #{ivar}" unless Prov.registry[type][ivar]
75
+ instance_variable_set("@#{var}", Prov.registry[type][ivar])
76
+ else
77
+ ivar
78
+ end
79
+ end
80
+
81
+ def basic_list(var,type,collection_class,identifier=nil)
82
+
83
+ if identifier
84
+ unless instance_variable_get("@#{var}")
85
+ instance_variable_set("@#{var}",collection_class.new)
86
+ end
87
+ instance_variable_get("@#{var}") << identifier
88
+ # (@used ||= Uses.new) << identifier
89
+ # elsif @used
90
+ # @used.map{|u| u.is_a?(Symbol) ? Prov.entities[u] : u}
91
+ # elsif instance_variable_get("@#{var}")
92
+ # @used.dereference
93
+ else
94
+ instance_variable_get("@#{var}")
95
+ end
96
+ end
97
+
98
+ def block_list(var,type,instance_class,collection_class,name=nil,&block)
99
+ if block_given?
100
+ inst = instance_class.new
101
+ inst.instance_eval(&block)
102
+ unless instance_variable_get("@#{var}")
103
+ instance_variable_set("@#{var}",collection_class.new)
104
+ end
105
+ instance_variable_get("@#{var}") << inst
106
+ Prov.register(inst.__label,inst)
107
+ else
108
+ if name
109
+ unless instance_variable_get("@#{var}")
110
+ instance_variable_set("@#{var}",collection_class.new)
111
+ end
112
+ instance_variable_get("@#{var}") << name
113
+ else
114
+ instance_variable_get("@#{var}")
115
+ end
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end