Commit 91c84051210619299c15fffba2fbb477e3c58134
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'virtuoso_integration' into stable
Showing
1 changed file
with
34 additions
and
7 deletions
Show diff stats
plugins/virtuoso/lib/virtuoso_plugin/noosfero_harvest.rb
1 | 1 | class VirtuosoPlugin::NoosferoHarvest |
2 | 2 | |
3 | 3 | COMMON_MAPPING = { |
4 | - :type => {:predicate => "http://purl.org/dc/terms/type", :value => lambda {|s, t| t.class.name}}, | |
4 | + :type => {:predicate => ["http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://purl.org/dc/terms/type"], :value => lambda {|s, t| t.class.name}}, | |
5 | 5 | :created_at => {:predicate => "http://purl.org/dc/terms/created"}, |
6 | 6 | :updated_at => {:predicate => "http://purl.org/dc/terms/modified"}, |
7 | 7 | } |
... | ... | @@ -10,19 +10,32 @@ class VirtuosoPlugin::NoosferoHarvest |
10 | 10 | :title => {:predicate => "http://purl.org/dc/terms/title"}, |
11 | 11 | :abstract => {:predicate => "http://purl.org/dc/terms/abstract"}, |
12 | 12 | :body => {:predicate => "http://purl.org/dc/terms/description"}, |
13 | + :participation => {:predicate => "http://purl.org/socialparticipation/ops#performsParticipation", :value => lambda {|s,t| url_for(t.url)}, :subject => lambda {|s,t| url_for(s.url)} }, | |
13 | 14 | :part_of => {:predicate => "http://purl.org/dc/terms/isPartOf", :value => lambda {|s, t| url_for(s.url)} }, |
14 | 15 | :published_at => {:predicate => "http://purl.org/dc/terms/issued"}, |
15 | 16 | :author => {:predicate => "http://purl.org/dc/terms/creator", :value => lambda {|s, t| url_for(t.author_url) if t.author_url} }, |
16 | 17 | } |
17 | 18 | PROFILE_MAPPING = { |
18 | - :name => {:predicate => "http://purl.org/dc/terms/title"}, | |
19 | + :name => {:predicate => "http://xmlns.com/foaf/0.1/name"}, | |
20 | + :contributor => {:predicate => "http://purl.org/dc/terms/contributor", :value => lambda {|s, t| url_for(s.top_url)} }, | |
19 | 21 | :public? => {:predicate => "http://purl.org/socialparticipation/opa#publicProfile"}, |
22 | + :visible => {:predicate => "http://purl.org/socialparticipation/opa#visibleProfile"}, | |
23 | + :lat => {:predicate => "http://www.w3.org/2003/01/geo/wgs84_pos#lat"}, | |
24 | + :lng => {:predicate => "http://www.w3.org/2003/01/geo/wgs84_pos#lng"}, | |
25 | + :type_community => {:predicate => "http://xmlns.com/foaf/0.1/Group", :condition => lambda {|s,t| t.community?} }, | |
26 | + :type_organization => {:predicate => "http://xmlns.com/foaf/0.1/Organization", :condition => lambda {|s,t| !t.person? && !t.community?} }, | |
27 | + } | |
28 | + PERSON_MAPPING = { | |
29 | + :type_participant => {:predicate => "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", :value => "http://purl.org/socialparticipation/ops#Participant"}, | |
30 | + :type_person => {:predicate => "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", :value => "http://xmlns.com/foaf/0.1/Person"}, | |
31 | + :email => {:predicate => "http://xmlns.com/foaf/0.1/mbox", :condition => lambda {|s,t| t.public? } } | |
20 | 32 | } |
21 | 33 | COMMENT_MAPPING = { |
22 | 34 | :title => {:predicate => "http://purl.org/dc/terms/title"}, |
23 | - :body => {:predicate => "http://purl.org/dc/terms/description"}, | |
35 | + :body => {:predicate => "http://schema.org/text"}, | |
24 | 36 | :part_of => {:predicate => "http://purl.org/dc/terms/isPartOf", :value => lambda {|s, t| url_for(s.url)} }, |
25 | 37 | :author => {:predicate => "http://purl.org/dc/terms/creator", :value => lambda {|s, t| url_for(t.author_url) if t.author_url} }, |
38 | + :participation => {:predicate => "http://purl.org/socialparticipation/ops#performsParticipation", :value => lambda {|s,t| url_for(t.url)}, :subject => lambda {|s,t| url_for(s.profile.url)} }, | |
26 | 39 | } |
27 | 40 | FRIENDSHIP_MAPPING = { |
28 | 41 | :knows => {:predicate => "http://xmlns.com/foaf/0.1/knows", :value => lambda {|s, t| url_for(t.url)} }, |
... | ... | @@ -97,7 +110,10 @@ class VirtuosoPlugin::NoosferoHarvest |
97 | 110 | puts "triplify #{subject_identifier} profile (#{count+=1}/#{total})" |
98 | 111 | triplify_mappings(PROFILE_MAPPING, subject_identifier, environment, profile) |
99 | 112 | triplify_articles(profile) if profile.public? |
100 | - triplify_friendship(profile) if profile.person? | |
113 | + if profile.person? | |
114 | + triplify_friendship(profile) | |
115 | + triplify_mappings(PERSON_MAPPING, subject_identifier, environment, profile, false) | |
116 | + end | |
101 | 117 | rescue => ex |
102 | 118 | puts "FAILED: #{ex}" |
103 | 119 | end |
... | ... | @@ -110,16 +126,23 @@ class VirtuosoPlugin::NoosferoHarvest |
110 | 126 | |
111 | 127 | protected |
112 | 128 | |
113 | - def triplify_mappings(mapping, subject_identifier, source, target) | |
114 | - COMMON_MAPPING.merge(mapping).each do |k, v| | |
129 | + def triplify_mappings(mapping, subject_identifier, source, target, include_common = true) | |
130 | + target_mapping = include_common ? COMMON_MAPPING.merge(mapping) : mapping | |
131 | + target_mapping.each do |k, v| | |
115 | 132 | next unless v |
133 | + next if v[:condition] && v[:condition].call(source, target) | |
134 | + | |
135 | + subject_identifier = v[:subject].call(source, target) if v[:subject] | |
136 | + | |
116 | 137 | value = nil |
117 | 138 | if v[:value] |
118 | 139 | value = v[:value].kind_of?(Proc) ? v[:value].call(source, target) : v[:value] |
119 | 140 | elsif target.respond_to?(k) |
120 | 141 | value = target.send(k) |
121 | 142 | end |
122 | - insert_triple(RDF::URI.new(subject_identifier), RDF::URI.new(v[:predicate]), value) if value.present? | |
143 | + [v[:predicate]].flatten.compact.each do |predicate| | |
144 | + insert_triple(RDF::URI.new(subject_identifier), RDF::URI.new(predicate), value) if value.present? | |
145 | + end | |
123 | 146 | end |
124 | 147 | end |
125 | 148 | |
... | ... | @@ -130,6 +153,10 @@ class VirtuosoPlugin::NoosferoHarvest |
130 | 153 | value = RDF::Literal::DateTime.new(value) |
131 | 154 | elsif !!value == value |
132 | 155 | value = RDF::Literal::Boolean.new(value) |
156 | + elsif value.kind_of?(Float) | |
157 | + value = RDF::Literal::Double.new(value) | |
158 | + else | |
159 | + value | |
133 | 160 | end |
134 | 161 | end |
135 | 162 | ... | ... |