bio-publisci 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 017f15f45cc8f40401aebe96aaf5dd886ba602e7
4
- data.tar.gz: f59abde75019333ff918968a8717f51f419946ee
3
+ metadata.gz: 89e183556979b5f6ddcdd98d3a88c990d352eaea
4
+ data.tar.gz: c4497bc982cb6452d648066dc1bb642bdd6ab315
5
5
  SHA512:
6
- metadata.gz: 7c80715a4e5354b330c93591b812f5a6c5105fbf6be2fe3d3028721796246e8a13cd1410af29411ba46d396cb82e494319f7137cd1aa2985e0e5d6cf08ce2422
7
- data.tar.gz: 96dd7d0f7fb252837524640f21ec6513197366c2455ce3691b8c2a36ba9dd7acfa438eb87cb2b0c3b6560a54fc87e3ab972fd7ae9e5ebec515f74869ac87334c
6
+ metadata.gz: 10abfdbb88cf57d251f784e4106ea9f42b1fbe56fd75fcddc02dd329a32e0b1b3ac130f152aaf4d8d7d3e3f7a98a56236d27a5f444f695401a6281c8d9ecc488
7
+ data.tar.gz: f1c4888880e431f668f47e80786855953acb1edd61395f3c32135a063ed583ef5dde9002433fe338462034af17863bf58377da5aba8fe99f74e5ae83d55bf56b
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ Jeweler::Tasks.new do |gem|
21
21
  gem.description = %Q{A toolkit for publishing scientific results and datasets using RDF, OWL, and related technologies }
22
22
  gem.email = "wstrinz@gmail.com"
23
23
  gem.authors = ["Will Strinz"]
24
- gem.version = "0.0.5"
24
+ gem.version = "0.0.6"
25
25
 
26
26
  # dependencies defined in Gemfile
27
27
  end
@@ -0,0 +1,58 @@
1
+ # Example using as little generation "magic" as possible, for execution
2
+ # as plain Ruby script.
3
+ #
4
+ # Run using "ruby no_magic.prov"
5
+
6
+ require 'bio-publisci'
7
+ include PubliSci::Prov::DSL
8
+
9
+
10
+ # Subject and type for most elements can be set manually
11
+ agent :publisci, subject: 'http://gsocsemantic.wordpress.com/publisci', type: "software"
12
+ agent :R, subject: "http://r-project.org"
13
+ agent :sciruby, subject: "http://sciruby.com", type: "organization"
14
+
15
+ plan :R_steps, subject: "http://example.org/plan/R_steps", steps: "spec/resource/example.Rhistory"
16
+
17
+ agent :Will do
18
+ # subject can be called within a block as well
19
+ subject "http://gsocsemantic.wordpress.com/me"
20
+ type "person"
21
+ name "Will Strinz"
22
+ on_behalf_of "http://sciruby.com"
23
+ end
24
+
25
+ # The wasGeneratedBy relationship is usually created automatically when an activitiy
26
+ # is associated with an entity, but it can be specified manually
27
+ entity :triplified_example, subject: "http://example.org/dataset/ex", generated_by: :triplify
28
+
29
+ entity :original do
30
+ generated_by :use_R
31
+ subject "http://example.org/R/ex"
32
+ source "./example.RData"
33
+
34
+ # Custom predicates and objects can be used for flexibility and extensibility
35
+ has "http://purl.org/dc/terms/title", "original data object"
36
+ end
37
+
38
+ activity :triplify do
39
+ # Most methods will take either Symbols or Strings, and correctly handle
40
+ # resources vs literals
41
+ subject "http://example.org/activity/triplify"
42
+ generated "http://example.org/dataset/ex"
43
+ associated_with :publisci
44
+ used :original
45
+ end
46
+
47
+ activity :use_R do
48
+ subject "http://example.org/activity/use_R"
49
+ generated "http://example.org/R/ex"
50
+
51
+ associated_with :R
52
+ associated_with :Will
53
+ end
54
+
55
+ # Running a prov script using the gem executable will print the result, but
56
+ # if you use the DSL you'll have to do it manually. You also read out to a file
57
+ # or other method/object of course (eg "open('out.ttl','w'){|file| file.write generate_n3}")
58
+ puts generate_n3
data/examples/orm.prov ADDED
@@ -0,0 +1,48 @@
1
+ agent :R, subject: "http://r-project.org"
2
+ agent :publisci, type: "software"
3
+ plan :R_steps, steps: "spec/resource/example.Rhistory"
4
+ organization :sciruby, subject: "http://sciruby.com"
5
+
6
+ foaf = vocabulary "http://xmlns.com/foaf/0.1/"
7
+
8
+ agent :Will do
9
+ type "person"
10
+ name "Will Strinz"
11
+ on_behalf_of :sciruby
12
+
13
+ has foaf.mailbox, "wstrinz@gmail.com"
14
+ has "http://xmlns.com/foaf/0.1/", "http://gsocsemantic.wordpress.com/"
15
+ end
16
+
17
+ data :field_work
18
+
19
+ data :original do
20
+ attributed_to :R
21
+ derived_from :field_work
22
+ end
23
+
24
+ data :triplified_example do
25
+ attributed_to :Will
26
+ derived_from do
27
+ entity :original
28
+ activity :triplify
29
+ end
30
+ end
31
+
32
+ activity :triplify do
33
+ generated :triplified_example
34
+ associated_with :publisci
35
+ used :original
36
+ end
37
+
38
+
39
+ activity :use_R do
40
+ generated :original
41
+ associated_with do
42
+ agent :R
43
+ plan :R_steps
44
+ end
45
+ associated_with :Will
46
+ end
47
+
48
+ to_repository
@@ -0,0 +1,120 @@
1
+ ###
2
+ #
3
+ # Complete PROV-O primer example,
4
+ # as shown in http://www.w3.org/TR/prov-primer/images/everything.png
5
+ # (some prefixes are different)
6
+ #
7
+ # See Section 3.10 of http://www.w3.org/TR/prov-primer/
8
+ #
9
+
10
+ base_url "http://example.org"
11
+
12
+ dct = vocabulary "http://purl.org/dc/terms/"
13
+ prov = vocabulary "http://www.w3.org/ns/prov#"
14
+
15
+ ###
16
+ # Entities
17
+ ###
18
+
19
+ entity :dataSet1
20
+ entity :regionList
21
+ entity :composition1
22
+
23
+ entity :chart1 do
24
+ attributed_to :derek
25
+ has prov.generatedAtTime, "2012-03-02T10:30:00"
26
+ end
27
+
28
+ entity :dataSet2 do
29
+ has prov.wasRevisionOf, :dataSet1
30
+ end
31
+
32
+ entity :chart2 do
33
+ derived_from :dataSet2
34
+ has prov.wasRevisionOf, :chart1
35
+ end
36
+
37
+ entity :article do
38
+ has dct.title, "Crime rises in cities"
39
+ end
40
+
41
+ entity :articleV1 do
42
+ has prov.specializationOf, :article
43
+ end
44
+
45
+ entity :articleV2 do
46
+ has prov.specializationOf, :article
47
+ has prov.alternateOf, :articleV1
48
+ end
49
+
50
+ entity :quoteInBlogEntry20130326 do
51
+ subject "http://example.com/blog_entry"
52
+ has prov.wasQuotedFrom, :article
53
+ end
54
+
55
+ ###
56
+ # Agents
57
+ ###
58
+
59
+ agent :edith, type: "person"
60
+
61
+ organization :chartgen, name: "Chart Generators Inc"
62
+
63
+ agent :derek do
64
+ name "Derek"
65
+ on_behalf_of :chartgen
66
+ end
67
+
68
+ ###
69
+ # Activities
70
+ ###
71
+
72
+ activity :illustrate1 do
73
+ generated :chart1
74
+ associated_with :derek
75
+ used :composition1
76
+ end
77
+
78
+ activity :compose1 do
79
+ generated :composition1
80
+
81
+ associated_with do
82
+ agent :derek
83
+ role :analyst
84
+ end
85
+
86
+ used do
87
+ entity :regionList
88
+ role :regionsToAggregateBy
89
+ end
90
+
91
+ used do
92
+ entity :dataSet1
93
+ role :dataToCompose
94
+ end
95
+ end
96
+
97
+ activity :correct1 do
98
+ generated :dataSet2
99
+ used :dataSet1
100
+
101
+ associated_with do
102
+ agent :edith
103
+ plan :instructions
104
+ end
105
+
106
+ has prov.startedAtTime, "2012-03-31T09:21:00"
107
+ has prov.endedAtTime, "2012-04-01T15:21:00"
108
+ end
109
+
110
+ activity :compile1 do
111
+ generated :chart1
112
+ used :dataSet1
113
+ end
114
+
115
+ activity :compile2 do
116
+ generated :chart2
117
+ used :dataSet2
118
+ end
119
+
120
+ generate_n3 true
@@ -63,10 +63,12 @@ end
63
63
  activity :triplify do
64
64
  generated :triplified_example
65
65
  associated_with :publisci
66
- used :original
66
+ used do
67
+ entity :original
68
+ role :generation_input, comment: "source data for triplification"
69
+ end
67
70
  end
68
71
 
69
-
70
72
  activity :use_R do
71
73
  generated :original
72
74
 
@@ -4,7 +4,7 @@ Feature: Receive metadata as user input or extract from data sources
4
4
  I want to use a DSL for the PROV ontology
5
5
 
6
6
  Scenario: Generate based on example for w3.org
7
- Given the prov DSL string from file examples/primer.prov
7
+ Given the prov DSL string from file examples/primer-full.prov
8
8
  When I call Prov.run on it
9
9
  Then I should receive a provenance string
10
10
 
data/lib/bio-publisci.rb CHANGED
@@ -34,6 +34,7 @@ load File.dirname(__FILE__) + '/bio-publisci/metadata/prov/element.rb'
34
34
 
35
35
  load_folder('bio-publisci/metadata')
36
36
  load_folder('bio-publisci/metadata/prov')
37
+ load_folder('bio-publisci/metadata/prov/model')
37
38
  load_folder('bio-publisci/readers')
38
39
  load_folder('bio-publisci/writers')
39
40
  load_folder('bio-publisci/dataset/ORM')
@@ -34,7 +34,7 @@ module R2RDF
34
34
  def self.load(graph,options={},verbose=false)
35
35
 
36
36
 
37
- graph = create_graph(graph) unless graph =~ /^http/
37
+ graph = load_string(graph) unless graph =~ /^http/
38
38
 
39
39
  # puts get_hashes(execute_from_file('dimension_ranges.rq',graph))
40
40
  dimensions = Hash[get_hashes(execute_from_file('dimension_ranges.rq',graph),"to_s").map{|solution|
@@ -3,59 +3,39 @@ module Prov
3
3
  class Activity
4
4
  include Prov::Element
5
5
  class Associations < Array
6
- def [](index)
7
- if self.fetch(index).is_a? Symbol
8
- Prov.agents[self.fetch(index)]
9
- else
10
- self.fetch(index)
11
- end
6
+ include PubliSci::Prov::Dereferencable
7
+ def method
8
+ :agents
12
9
  end
13
10
  end
14
11
 
15
- def generated(entity=nil)
16
- if entity
17
- # if entity.is_a? Symbol
18
- # entity = Prov.entities[entity.to_sym]
19
- # end
20
-
21
- if entity.is_a? Entity
22
- entity.generated_by self
23
- end
12
+ class Generations < Array
13
+ include PubliSci::Prov::Dereferencable
14
+ def method
15
+ :entities
16
+ end
17
+ end
24
18
 
25
- (@generated ||= []) << entity
26
- elsif @generated.is_a? Symbol
27
- @generated = Prov.entities[@generated]
28
- else
29
- @generated
19
+ class Usages < Array
20
+ include PubliSci::Prov::Dereferencable
21
+ def method
22
+ :entities
30
23
  end
31
24
  end
32
25
 
33
- def generated=(gen)
34
- @generated = gen
26
+ def generated(entity=nil)
27
+ if entity.is_a? Entity
28
+ entity.generated_by self
29
+ end
30
+ basic_list(:generated,:entities,Generations,entity)
35
31
  end
36
32
 
37
33
  def associated_with(agent=nil, &block)
38
- if agent
39
- (@associated ||= Associations.new) << agent
40
- # Prov.register(nil,assoc)
41
- elsif block_given?
42
- assoc = Association.new
43
- assoc.instance_eval(&block)
44
- (@associated ||= Associations.new) << assoc
45
- Prov.register(nil,assoc)
46
- else
47
- @associated
48
- end
34
+ block_list(:associated,:associations,Association,Associations,agent,&block)
49
35
  end
50
36
 
51
- def used(entity=nil)
52
- if entity
53
- (@used ||= []) << entity
54
- elsif @used
55
- @used.map{|u| u.is_a?(Symbol) ? Prov.entities[u] : u}
56
- else
57
- @used
58
- end
37
+ def used(entity=nil, &block)
38
+ block_list(:use,:usages,Usage,Usages,entity, &block)
59
39
  end
60
40
 
61
41
  def to_n3
@@ -63,8 +43,7 @@ module Prov
63
43
 
64
44
  if generated
65
45
  str << "\tprov:generated "
66
- generated.map{|src|
67
- src = Prov.entities[src] if src.is_a?(Symbol) && Prov.entities[src]
46
+ generated.dereference.map{|src|
68
47
  str << "<#{src}>, "
69
48
  }
70
49
  str[-2]=" "
@@ -72,18 +51,18 @@ module Prov
72
51
  end
73
52
 
74
53
  if used
75
- str << "\tprov:used "
76
- used.map{|used|
77
- str << "<#{used}>, "
54
+ used.dereference.map{|u|
55
+ if u.is_a? Usage
56
+ str << "\tprov:used <#{u.entity}> ;\n"
57
+ str << "\tprov:qualifiedUsage <#{u}> ;\n"
58
+ else
59
+ str << "\tprov:used <#{u}> ;\n"
60
+ end
78
61
  }
79
- str[-2]=";"
80
- str[-1]="\n"
81
62
  end
82
63
 
83
64
  if associated_with
84
- associated_with.map{|assoc|
85
- assoc = Prov.agents[assoc] if assoc.is_a?(Symbol) && Prov.agents[assoc]
86
-
65
+ associated_with.dereference.map{|assoc|
87
66
  if assoc.is_a? Association
88
67
  str << "\tprov:wasAssociatedWith <#{assoc.agent}> ;\n"
89
68
  str << "\tprov:qualifiedAssociation <#{assoc}> ;\n"
@@ -1,95 +1,100 @@
1
1
  module PubliSci
2
- module Prov
3
- class Agent
4
- include Prov::Element
2
+ module Prov
3
+ class Agent
4
+ include Prov::Element
5
+ attr_accessor :organization
6
+ attr_accessor :behalf_of
5
7
 
6
- def type(t=nil)
7
- if t
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)
8
17
  @type = t.to_sym
9
- else
10
- @type
11
18
  end
12
- end
13
19
 
14
- def type=(t)
15
- @type = t.to_sym
16
- end
20
+ def name(name=nil)
21
+ if name
22
+ @name = name
23
+ else
24
+ @name
25
+ end
26
+ end
17
27
 
18
- def name(name=nil)
19
- if name
28
+ def name=(name)
20
29
  @name = name
21
- else
22
- @name
23
30
  end
24
- end
25
31
 
26
- def name=(name)
27
- @name = name
28
- end
29
-
30
- def organization(organization=nil)
31
- if organization
32
- @organization = organization
33
- elsif @organization.is_a? Symbol
34
- @organization = Prov.agents[@organization]
35
- else
36
- @organization
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
37
42
  end
38
- end
39
43
 
40
- def organization=(organization)
41
- @organization = organization
42
- end
43
-
44
- def on_behalf_of(other_agent=nil)
45
- if other_agent
46
- @on_behalf_of = other_agent
47
- elsif @on_behalf_of.is_a? Symbol
48
- raise "UnknownAgent: #{@on_behalf_of}" unless Prov.agents.has_key?(@on_behalf_of)
49
- @on_behalf_of = Prov.agents[@on_behalf_of]
50
- else
51
- @on_behalf_of
52
- end
44
+ # def organization=(organization)
45
+ # @organization = organization
46
+ # end
53
47
 
54
- @on_behalf_of
55
- end
56
- alias_method :worked_for, :on_behalf_of
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
57
58
 
58
- def to_n3
59
- str = "<#{subject}> a prov:Agent"
60
- if type
61
- case type.to_sym
62
- when :software
63
- str << ", prov:SoftwareAgent ;\n"
64
- when :person
65
- str << ", prov:Person ;\n"
66
- when :organization
67
- str << ", prov:Organization ;\n"
68
- end
69
- else
70
- str << " ;\n"
59
+ # @behalf_of
71
60
  end
61
+ alias_method :worked_for, :on_behalf_of
72
62
 
73
- if name
74
- if type && type.to_sym == :person
75
- str << "\tfoaf:givenName \"#{name}\" ;\n"
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
76
74
  else
77
- str << "\tfoaf:name \"#{name}\" ;\n"
75
+ str << " prov:Agent ;\n"
78
76
  end
79
- end
80
77
 
81
- if on_behalf_of
82
- str << "\tprov:actedOnBehalfOf <#{on_behalf_of}> ;\n"
83
- end
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
84
85
 
85
- add_custom(str)
86
+ if on_behalf_of
87
+ str << "\tprov:actedOnBehalfOf <#{on_behalf_of}> ;\n"
88
+ end
86
89
 
87
- str << "\trdfs:label \"#{__label}\" .\n\n"
88
- end
90
+ add_custom(str)
89
91
 
90
- def to_s
91
- subject
92
+ str << "\trdfs:label \"#{__label}\" .\n\n"
93
+ end
94
+
95
+ def to_s
96
+ subject
97
+ end
92
98
  end
93
99
  end
94
- end
95
100
  end