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,64 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Entity
4
+ include Prov::Element
5
+
6
+ attr_accessor :derived_from
7
+ attr_accessor :attributed_to
8
+
9
+ class Derivations < Array
10
+ include PubliSci::Prov::Dereferencable
11
+ def method
12
+ :entities
13
+ end
14
+ end
15
+
16
+
17
+ def source(s=nil)
18
+ if s
19
+ (@sources ||= []) << s
20
+ else
21
+ @sources
22
+ end
23
+ end
24
+
25
+ def generated_by(activity=nil)
26
+ basic_keyword(:generated_by,:activities,activity)
27
+ end
28
+
29
+ def attributed_to(agent=nil)
30
+ basic_keyword(:attributed_to,:agents,agent)
31
+ end
32
+
33
+ def derived_from(entity=nil,&block)
34
+ block_list(:derived_from,:derivations,Derivation,Derivations,entity,&block)
35
+ end
36
+
37
+ def to_n3
38
+ str = "<#{subject}> a prov:Entity ;\n"
39
+ str << "\tprov:wasGeneratedBy <#{generated_by}> ;\n" if generated_by
40
+ str << "\tprov:wasAttributedTo <#{attributed_to}> ;\n" if attributed_to
41
+ if derived_from
42
+ derived_from.size.times.each{|k|
43
+ der = derived_from[k] # if der.is_a?(Symbol) && Prov.entities[der]
44
+
45
+ if der.is_a? Derivation
46
+ str << "\tprov:wasDerivedFrom <#{der.entity}> ;\n"
47
+ str << "\tprov:qualifiedDerivation <#{der.subject}> ;\n"
48
+ else
49
+ str << "\tprov:wasDerivedFrom <#{der}> ;\n"
50
+ end
51
+ }
52
+ end
53
+
54
+ add_custom(str)
55
+
56
+ str << %Q(\trdfs:label "#{__label}" .\n\n)
57
+ end
58
+
59
+ def to_s
60
+ subject
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,109 @@
1
+ require 'rdf/4store'
2
+
3
+ begin
4
+ require 'spira'
5
+
6
+ module PubliSci
7
+ class Prov
8
+ module Model
9
+ PROV ||= RDF::Vocabulary.new(RDF::URI.new('http://www.w3.org/ns/prov#'))
10
+
11
+ class Entity < Spira::Base
12
+ type PROV.Entity
13
+ property :label, predicate: RDF::RDFS.label
14
+ property :wasGeneratedBy, predicate: PROV.wasGeneratedBy
15
+ has_many :wasAttributedTo, predicate: PROV.wasAttributedTo
16
+ has_many :wasDerivedFrom, predicate: PROV.wasDerivedFrom
17
+ has_many :qualifiedAssociation, predicate: PROV.qualifiedAssociation
18
+
19
+ def organization
20
+ wasAttributedTo.map{|src|
21
+ if Agent.for(src).actedOnBehalfOf
22
+ Agent.for(Agent.for(src).actedOnBehalfOf).label
23
+ end
24
+ }
25
+ end
26
+
27
+ def all_types
28
+ me = self.subject
29
+ type_query = RDF::Query.new do
30
+ pattern [me, RDF.type, :type]
31
+ end
32
+
33
+ type_query.execute(self.class.repository).map{|t| t[:type]}
34
+ end
35
+
36
+ def has_data?
37
+ all_types.include?('http://purl.org/linked-data/cube#DataSet')
38
+ end
39
+
40
+ end
41
+
42
+ class Agent < Spira::Base
43
+ type PROV.Agent
44
+ type PROV.Organization
45
+ type PROV.SoftwareAgent
46
+ type PROV.Person
47
+ property :label, predicate: RDF::RDFS.label
48
+ property :foaf_name, predicate: RDF::FOAF.name
49
+ property :foaf_given, predicate: RDF::FOAF.givenName
50
+ property :actedOnBehalfOf, predicate: PROV.actedOnBehalfOf
51
+
52
+
53
+ def name
54
+ foaf_given || foaf_name
55
+ end
56
+
57
+ def name=(name)
58
+ foaf_given = name
59
+ foaf_name = name
60
+
61
+ end
62
+
63
+ def activities
64
+ #should do this in a SPARQL query instead
65
+ Activity.enum_for.map{|act|
66
+ subj = subject()
67
+ act if act.wasAssociatedWith.any?{|assoc| assoc == subj}
68
+ }.reject{|x| x==nil}
69
+ end
70
+ end
71
+
72
+ class Activity < Spira::Base
73
+ type PROV.Activity
74
+ property :label, predicate: RDF::RDFS.label
75
+ has_many :generated, predicate: PROV.generated
76
+ has_many :used, predicate: PROV.used
77
+ has_many :wasAssociatedWith, predicate: PROV.wasAssociatedWith
78
+ has_many :qualifiedAssociation, predicate: PROV.qualifiedAssociation
79
+ end
80
+
81
+ class Association < Spira::Base
82
+ type PROV.Association
83
+ property :label, predicate: RDF::RDFS.label
84
+ property :agent, predicate: PROV.agent
85
+ property :hadPlan, predicate: PROV.hadPlan
86
+
87
+ def activity
88
+ Activity.each.to_a.select{|act| act.qualifiedAssociation.include? self}
89
+ end
90
+ end
91
+
92
+ class Derivation < Spira::Base
93
+ type PROV.Derivation
94
+ property :label, predicate: RDF::RDFS.label
95
+ property :agent, predicate: PROV.agent
96
+ property :hadPlan, predicate: PROV.hadPlan
97
+ end
98
+
99
+ class Plan < Spira::Base
100
+ type PROV.Plan
101
+ property :label, predicate: RDF::RDFS.label
102
+ property :comment, predicate: RDF::RDFS.comment
103
+ end
104
+ end
105
+ end
106
+ end
107
+ rescue LoadError
108
+ # puts "spira not installed, ORM unavailable"
109
+ end
@@ -0,0 +1,32 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Plan
4
+ include Prov::Element
5
+
6
+ def steps(steps=nil)
7
+ if steps
8
+ if File.exist? steps
9
+ steps = Array[IO.read(steps).split("\n")]
10
+ end
11
+ @steps = Array[steps]
12
+ else
13
+ @steps
14
+ end
15
+ end
16
+
17
+ def to_n3
18
+ str = "<#{subject}> a prov:Plan ;\n"
19
+ if steps
20
+ str << "\trdfs:comment (\"#{steps.join('" "')}\") ;\n"
21
+ end
22
+ add_custom(str)
23
+
24
+ str << "\trdfs:label \"#{__label}\" .\n\n"
25
+ end
26
+
27
+ def to_s
28
+ subject
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,78 @@
1
+ module PubliSci
2
+ class Prov
3
+ extend PubliSci::Registry
4
+
5
+ def self.configuration
6
+ @config ||= Configuration.new
7
+ end
8
+
9
+ def self.symbol_for(object)
10
+ if object.is_a? Agent
11
+ :agents
12
+ elsif object.is_a? Entity
13
+ :entities
14
+ elsif object.is_a? Activity
15
+ :activities
16
+ elsif object.is_a? Association
17
+ :associations
18
+ elsif object.is_a? Plan
19
+ :plans
20
+ else
21
+ false
22
+ end
23
+ end
24
+
25
+
26
+ def self.run(string)
27
+ sing =DSL::Instance.new
28
+ if File.exists? string
29
+ sing.instance_eval(IO.read(string),string)
30
+ else
31
+ sing.instance_eval(string)
32
+ end
33
+ sing.output
34
+ end
35
+
36
+ def self.reset_settings
37
+ Configuration.defaults.map{|k,v| configuration.send("#{k}=",v)}
38
+ @base_url=nil
39
+ end
40
+
41
+ def self.agents
42
+ registry[:agents] ||= {}
43
+ end
44
+
45
+ def self.entities
46
+ registry[:entities] ||= {}
47
+ end
48
+
49
+ def self.activities
50
+ registry[:activities] ||= {}
51
+ end
52
+
53
+ def self.associations
54
+ registry[:associations] ||= {}
55
+ end
56
+
57
+ def self.plans
58
+ registry[:plans] ||= {}
59
+ end
60
+
61
+ def self.base_url
62
+ @base_url ||= "http://rqtl.org/ns"
63
+ end
64
+
65
+ def self.base_url=(url)
66
+ @base_url = url
67
+ end
68
+
69
+ def self.prefixes
70
+ <<-EOF
71
+ @prefix prov: <http://www.w3.org/ns/prov#> .
72
+ @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
73
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
74
+ @prefix foaf: <http://xmlns.com/foaf/0.1/> .
75
+ EOF
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,40 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Role
4
+ # attr_writer :comment
5
+
6
+ include Prov::Element
7
+
8
+ def comment(str=nil)
9
+ if str
10
+ @comment = str
11
+ else
12
+ @comment
13
+ end
14
+ end
15
+
16
+ # def steps(steps=nil)
17
+ # if steps
18
+ # if File.exist? steps
19
+ # steps = Array[IO.read(steps).split("\n")]
20
+ # end
21
+ # @steps = Array[steps]
22
+ # else
23
+ # @steps
24
+ # end
25
+ # end
26
+
27
+ def to_n3
28
+ str = "<#{subject}> a prov:Role ;\n"
29
+ str << "\trdfs:comment \"#{comment}\" ;\n" if comment
30
+ add_custom(str)
31
+
32
+ str << "\trdfs:label \"#{__label}\" .\n\n"
33
+ end
34
+
35
+ def to_s
36
+ subject
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,64 @@
1
+ module PubliSci
2
+ class Prov
3
+ class Usage
4
+ include Prov::Element
5
+
6
+ def __label
7
+ @__label ||= Time.now.nsec.to_s(32)
8
+ end
9
+
10
+ def entity(entity=nil)
11
+ basic_keyword(:entity,:entities,entity)
12
+ end
13
+
14
+ def had_role(*args, &block)
15
+ if block_given?
16
+ p = Prov::Role.new
17
+ p.instance_eval(&block)
18
+ p.__label=args[0]
19
+ @role = p
20
+ # puts p.class
21
+ Prov.register(args[0], p)
22
+ elsif args.size == 0
23
+ if @role.is_a? Symbol
24
+ raise "UnknownRole: #{@role}" unless (Prov.registry[:role]||={})[@role]
25
+ @role = Prov.registry[:role][@role]
26
+ end
27
+ @role
28
+ elsif args.size == 1
29
+ unless (Prov.registry[:role]||={})[args[0]]
30
+ p = Prov::Role.new
31
+ p.__label=args[0]
32
+ @role = p
33
+ Prov.register(args[0], p)
34
+ end
35
+ else
36
+ name = args.shift
37
+ args = Hash[*args]
38
+ p = Prov::Role.new
39
+
40
+ p.__label=name
41
+ p.subject args[:subject]
42
+ (args.keys - [:subject]).map{|k|
43
+ raise "Unkown Role setting #{k}" unless try_auto_set(p,k,args[k])
44
+ }
45
+ @role = p
46
+ Prov.register(name, p)
47
+ end
48
+ end
49
+ alias_method :role, :had_role
50
+
51
+ def to_n3
52
+ str = "<#{subject}> a prov:Usage ;\n"
53
+ str << "\tprov:entity <#{entity}> ;\n"
54
+ str << "\tprov:hadRole <#{had_role}> ;\n" if had_role
55
+ str[-2] = ".\n"
56
+ str
57
+ end
58
+
59
+ def to_s
60
+ subject
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,25 @@
1
+ module PubliSci
2
+ class Metadata
3
+ class Publisher
4
+
5
+ def uri(uri=nil)
6
+ if uri
7
+ @uri = uri
8
+ else
9
+ @uri
10
+ end
11
+ end
12
+ alias_method :url, :uri
13
+
14
+ def label(label=nil)
15
+ if label
16
+ @label = label
17
+ else
18
+ @label
19
+ end
20
+ end
21
+ alias_method :name, :label
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ module PubliSci
2
+ module CustomPredicate
3
+ def has(predicate, object)
4
+ if object.is_a? Symbol
5
+ obj = object
6
+ else
7
+ predicate = RDF::Resource(predicate) if RDF::Resource(predicate).valid?
8
+ obj = RDF::Resource(object)
9
+ obj = RDF::Literal(object) unless obj.valid?
10
+ end
11
+ ((@custom ||= {})[predicate] ||= []) << obj
12
+ end
13
+ alias_method :set, :has
14
+
15
+ def custom
16
+ @custom
17
+ end
18
+
19
+ def add_custom(str)
20
+ if custom
21
+ custom.map{|k,v|
22
+ pk = k.respond_to?(:to_base) ? k.to_base : k
23
+ v.map{|vv|
24
+ if vv.is_a? Symbol
25
+
26
+ deref = Prov.registry.values.map{|h|
27
+ h[vv] if vv
28
+ }.reject{|x| x==nil}
29
+ raise "Unknown Element #{vv}" unless deref.size > 0
30
+ vv = RDF::Resource(deref.first)
31
+ end
32
+ str << "\t#{pk} #{vv.to_base} ;\n"
33
+ }
34
+ }
35
+ end
36
+ end
37
+ end
38
+ end