easy_data3 0.0.2
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.
- data/.gitignore +9 -0
- data/.idea/EasyData.iml +11 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +11 -0
- data/.idea/modules.xml +9 -0
- data/.idea/vcs.xml +7 -0
- data/Gemfile +6 -0
- data/README.md +44 -0
- data/Rakefile +12 -0
- data/bin/linked_data +5 -0
- data/easy_data.gemspec +28 -0
- data/lib/controllers/easy_datas_controller.rb +340 -0
- data/lib/data_models/RDFa.rb +100 -0
- data/lib/data_models/data_models.rb +74 -0
- data/lib/data_models/linked_data_graph.rb +80 -0
- data/lib/data_models/model_rdf.rb +344 -0
- data/lib/data_models/namespaces/cc.rb +36 -0
- data/lib/data_models/namespaces/cert.rb +33 -0
- data/lib/data_models/namespaces/dc.rb +87 -0
- data/lib/data_models/namespaces/dc11.rb +47 -0
- data/lib/data_models/namespaces/doap.rb +68 -0
- data/lib/data_models/namespaces/exif.rb +192 -0
- data/lib/data_models/namespaces/foaf.rb +93 -0
- data/lib/data_models/namespaces/geo.rb +35 -0
- data/lib/data_models/namespaces/http.rb +50 -0
- data/lib/data_models/namespaces/owl.rb +83 -0
- data/lib/data_models/namespaces/rdfs.rb +41 -0
- data/lib/data_models/namespaces/rsa.rb +35 -0
- data/lib/data_models/namespaces/rss.rb +38 -0
- data/lib/data_models/namespaces/sioc.rb +110 -0
- data/lib/data_models/namespaces/skos.rb +61 -0
- data/lib/data_models/namespaces/wot.rb +45 -0
- data/lib/data_models/namespaces/xhtml.rb +32 -0
- data/lib/data_models/namespaces/xsd.rb +77 -0
- data/lib/data_models/namespaces.rb +28 -0
- data/lib/easy_data/tasks.rb +137 -0
- data/lib/easy_data/templates/easy_datas/_data_publications.html.erb +28 -0
- data/lib/easy_data/templates/easy_datas/_footer.html.erb +5 -0
- data/lib/easy_data/templates/easy_datas/_linked_data_model.html.erb +19 -0
- data/lib/easy_data/templates/easy_datas/_linked_datas.html.erb +19 -0
- data/lib/easy_data/templates/easy_datas/_list_model_info.html.erb +23 -0
- data/lib/easy_data/templates/easy_datas/_list_properties.html.erb +24 -0
- data/lib/easy_data/templates/easy_datas/_list_properties_edit.html.erb +35 -0
- data/lib/easy_data/templates/easy_datas/_menu.html.erb +24 -0
- data/lib/easy_data/templates/easy_datas/_menu_custom.html.erb +18 -0
- data/lib/easy_data/templates/easy_datas/_model_attributes.html.erb +45 -0
- data/lib/easy_data/templates/easy_datas/_model_attributes_edit.html.erb +17 -0
- data/lib/easy_data/templates/easy_datas/_model_attributes_info.html.erb +24 -0
- data/lib/easy_data/templates/easy_datas/_settings.html.erb +33 -0
- data/lib/easy_data/templates/easy_datas/authenticate_user.html.erb +20 -0
- data/lib/easy_data/templates/easy_datas/custom_rdf.html.erb +28 -0
- data/lib/easy_data/templates/easy_datas/info_easy_data.html.erb +7 -0
- data/lib/easy_data/templates/easy_datas/show.html.erb +1 -0
- data/lib/easy_data/templates/easy_datas/show.xml.builder +18 -0
- data/lib/easy_data/templates/easy_datas/show_all.html.erb +1 -0
- data/lib/easy_data/templates/easy_datas/show_all.xml.builder +16 -0
- data/lib/easy_data/templates/easy_datas/view_settings.html.erb +32 -0
- data/lib/easy_data/templates/images/LogoEasyData.jpg +0 -0
- data/lib/easy_data/templates/images/bg_ft.png +0 -0
- data/lib/easy_data/templates/images/bg_link.jpg +0 -0
- data/lib/easy_data/templates/images/easy_data_logo.png +0 -0
- data/lib/easy_data/templates/images/lock.png +0 -0
- data/lib/easy_data/templates/images/loginBt.png +0 -0
- data/lib/easy_data/templates/images/login_bg.png +0 -0
- data/lib/easy_data/templates/images/logo_ft.png +0 -0
- data/lib/easy_data/templates/images/powerby.jpg +0 -0
- data/lib/easy_data/templates/images/rdf_icon.png +0 -0
- data/lib/easy_data/templates/images/rdf_icon_s.png +0 -0
- data/lib/easy_data/templates/images/shadow_menu.png +0 -0
- data/lib/easy_data/templates/layouts/easy_data_layout.html.erb +18 -0
- data/lib/easy_data/templates/rdf/request.xml.builder +1 -0
- data/lib/easy_data/templates/rdf/show.builder +1 -0
- data/lib/easy_data/templates/stylesheets/easy_data_style.css +62 -0
- data/lib/easy_data/version.rb +3 -0
- data/lib/easy_data.rb +107 -0
- data/lib/routes.rb +41 -0
- data/lib/tasks/testing_installation.rb +6 -0
- data/test/data_models_test.rb +11 -0
- data/test/rdfa_test.rb +18 -0
- data/test/unit/RDFa_test.rb +1 -0
- data/test/unit/data_models_test.rb +10 -0
- data/test/unit/linked_data_graph_test.rb +1 -0
- data/test/unit/model_rdf_test.rb +1 -0
- data/test/unit/namespaces_test.rb +2 -0
- metadata +172 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
class LinkedDataGraph
|
|
2
|
+
|
|
3
|
+
def self.build(models)
|
|
4
|
+
|
|
5
|
+
models.each do |model|
|
|
6
|
+
graph = {}
|
|
7
|
+
|
|
8
|
+
#graph[:models] = get_attributes_ponderations(models)
|
|
9
|
+
graph[:assoc] = get_associations(model)
|
|
10
|
+
|
|
11
|
+
generate_graph(graph,model) if !graph[:assoc].empty?
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
private
|
|
16
|
+
|
|
17
|
+
def self.get_attributes_ponderations(model)
|
|
18
|
+
associations = {}
|
|
19
|
+
|
|
20
|
+
model = eval model
|
|
21
|
+
if model.respond_to?:reflections
|
|
22
|
+
associations[model.to_s.gsub("::","_")] = model.reflections.count
|
|
23
|
+
else
|
|
24
|
+
associations[model.to_s.gsub("::","_")] = 0
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.get_associations(model)
|
|
30
|
+
assoc = []
|
|
31
|
+
|
|
32
|
+
model = eval model
|
|
33
|
+
if model.respond_to?:reflections
|
|
34
|
+
model.reflections.each do |name,info|
|
|
35
|
+
mod_assoc = info.name.to_s.camelize
|
|
36
|
+
begin
|
|
37
|
+
eval mod_assoc
|
|
38
|
+
rescue
|
|
39
|
+
begin
|
|
40
|
+
eval mod_assoc.pluralize
|
|
41
|
+
mod_assoc = (mod_assoc.pluralize)
|
|
42
|
+
rescue
|
|
43
|
+
(mod_assoc = info.options[:source].to_s.camelize)if info.options[:source]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
if mod_assoc
|
|
47
|
+
assoc << mod_assoc
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
assoc
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def self.generate_graph(graph_info,model)
|
|
55
|
+
model = model.gsub("::","_")
|
|
56
|
+
file = File.open("#{RAILS_ROOT}/public/images/linked_data_graphs/linked_data_#{model}.dot",'w')
|
|
57
|
+
|
|
58
|
+
file.puts "digraph G {"
|
|
59
|
+
#file.puts 'size="15,15";'
|
|
60
|
+
file.puts 'graph [rotate=0, rankdir="LR"]'
|
|
61
|
+
file.puts 'node [color="#333333", style=filled,shape=box, fontname="Trebuchet MS"]'
|
|
62
|
+
file.puts 'edge [color="#666666", arrowhead="open", fontname="Trebuchet MS", fontsize="11"]'
|
|
63
|
+
file.puts model.to_s+' [fillcolor="#116611", fontcolor="white"]'
|
|
64
|
+
|
|
65
|
+
#Draw nodes
|
|
66
|
+
|
|
67
|
+
graph_info[:assoc].each do |assoc|
|
|
68
|
+
file.puts assoc.to_s+' [fillcolor="#294b76", fontcolor="white"]'
|
|
69
|
+
file.puts '"'+model+'" -> "'+assoc.to_s+'"[dir=none];'
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
file.puts "}"
|
|
74
|
+
|
|
75
|
+
file.close
|
|
76
|
+
|
|
77
|
+
system "dot -Tpng #{RAILS_ROOT}/public/images/linked_data_graphs/linked_data_#{model}.dot -o #{RAILS_ROOT}/public/images/linked_data_graphs/linked_data_#{model}.png"
|
|
78
|
+
system "rm #{RAILS_ROOT}/public/images/linked_data_graphs/linked_data_#{model}.dot"
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
require "yaml"
|
|
2
|
+
|
|
3
|
+
class ModelRdf
|
|
4
|
+
|
|
5
|
+
#######################################################################
|
|
6
|
+
# Attributes declarations
|
|
7
|
+
#######################################################################
|
|
8
|
+
@@privacy = ["Hidden","Public","Authenticated"]
|
|
9
|
+
|
|
10
|
+
attr_accessor :model_rdf
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
#######################################################################
|
|
14
|
+
# Query methods
|
|
15
|
+
#######################################################################
|
|
16
|
+
|
|
17
|
+
#Read the document of attributes relations with rdf properties
|
|
18
|
+
# @return [Object] return a ModelRdf's instance whit rdf info
|
|
19
|
+
def initialize
|
|
20
|
+
@model_rdf = YAML::load(File.open("#{RAILS_ROOT}/config/easy_data/rdf_info.yaml"))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Return datas stored in the RDF informations yaml file
|
|
24
|
+
# @return [Hash] return RDF informations
|
|
25
|
+
def get_models
|
|
26
|
+
self.model_rdf
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Return data stored in the RDF informations yaml file about publicated models
|
|
30
|
+
# @return [Hash] return RDF information about public access information of publicated models
|
|
31
|
+
def get_public_models
|
|
32
|
+
models = []
|
|
33
|
+
self.load_models.each do |mod|
|
|
34
|
+
if self.public?(mod)
|
|
35
|
+
models << mod
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Return data stored in the RDF informations yaml file about publicated models.
|
|
41
|
+
# @return [Hash] return RDF information about not hidden rdf information's models.
|
|
42
|
+
def get_not_hidden_models
|
|
43
|
+
models = []
|
|
44
|
+
self.load_models.each do |mod|
|
|
45
|
+
unless self.hidden?(mod)
|
|
46
|
+
models << mod
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
models
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Check if the model is public
|
|
53
|
+
# @param [Symbol] model's name
|
|
54
|
+
# @return [Boolean] true or false
|
|
55
|
+
def public?(model)
|
|
56
|
+
self.model_rdf[model][:privacy] == "Public"
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Check if the model is private
|
|
60
|
+
# @param [Symbol] model's name
|
|
61
|
+
# @return [Boolean] true or false
|
|
62
|
+
def private?(model)
|
|
63
|
+
self.model_rdf[model][:privacy] == "Private"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Check if the model is hidden
|
|
67
|
+
# @param [Symbol] model's name
|
|
68
|
+
# @return [Boolean] true or false
|
|
69
|
+
def hidden?(model)
|
|
70
|
+
self.model_rdf[model][:privacy] == "Hidden"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Model RDF informations and privacy
|
|
74
|
+
# @param [String] model's name
|
|
75
|
+
# @return [Hash] hash with RDF and privacy information about the model
|
|
76
|
+
def get_rdf_info_model(model)
|
|
77
|
+
{:namespace => self.model_rdf[model][:namespace],:property => self.model_rdf[model][:property]}
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Return attributes of model stored in the configuration yaml file
|
|
81
|
+
# @param [String] model's name
|
|
82
|
+
# @return [Hash] Return all information about the model and his data.
|
|
83
|
+
def get_attributes_model(model)
|
|
84
|
+
self.model_rdf[model]
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Return all models which they are assocciations of current model
|
|
88
|
+
# @param [String] current model name
|
|
89
|
+
# @return [Array] list of models which the are assocciations with current model.
|
|
90
|
+
def get_associations_model(model)
|
|
91
|
+
associations = self.model_rdf[model]['associations'].keys
|
|
92
|
+
models = DataModels.load_models
|
|
93
|
+
hash_associations = {}
|
|
94
|
+
|
|
95
|
+
associations.each do |assc|
|
|
96
|
+
if models.include?assc.camelize
|
|
97
|
+
hash_associations[assc] = assc
|
|
98
|
+
elsif eval(model+'.reflections[:'+assc+'].class_name')
|
|
99
|
+
hash_associations[assc] = eval(model+'.reflections[:'+assc+'].class_name')
|
|
100
|
+
else
|
|
101
|
+
hash_associations[assc] = eval(model+'.reflections[:'+assc+'].options[:class_name]')
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
hash_associations
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# RDFa: Return attributes of model RDF info
|
|
109
|
+
# @param [String] model's name
|
|
110
|
+
# @return [String] model's rdf information to insert in HTML tag
|
|
111
|
+
def model(model)
|
|
112
|
+
info = get_rdf_info_model(model)
|
|
113
|
+
if info[:property] && info[:property]!= "not defined"
|
|
114
|
+
" typeof='#{info[:namespace]}:#{info[:property]}'"
|
|
115
|
+
else
|
|
116
|
+
" "
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def add_model(model,attributes)
|
|
121
|
+
self.model_rdf[model] = attributes
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def delete_model(model)
|
|
125
|
+
self.model_rdf.delete(model)
|
|
126
|
+
end
|
|
127
|
+
# Update model rdf info
|
|
128
|
+
# @param [String] model's name
|
|
129
|
+
# @param [String] model's property to be updated
|
|
130
|
+
# @param [Strign] new value
|
|
131
|
+
# @return [Boolean] true or false if the operation has finished correctly.
|
|
132
|
+
def update_model(model,param,value)
|
|
133
|
+
self.model_rdf[model][param.to_sym] = value
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# update attributes with rdf properties.
|
|
137
|
+
# @param [String] model's name
|
|
138
|
+
# @param [String] model's attribute
|
|
139
|
+
# @param [String] attribute's property to be updated
|
|
140
|
+
# @param [Strign] new value
|
|
141
|
+
# @return [Boolean] true or false if the operation has finished correctly.
|
|
142
|
+
def update_attributes_model(model,attribute,param,value)
|
|
143
|
+
self.model_rdf[model]['attributes'][attribute][param.to_sym] = value
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# RDFa: Return attribute rdf info
|
|
147
|
+
# @param [String] model's name
|
|
148
|
+
# @param [Strign] model's attribute
|
|
149
|
+
# @return [String] RDF information about model's attribute to insert in HTML tag.
|
|
150
|
+
def attribute(model,attribute)
|
|
151
|
+
att_rdf = self.model_rdf[model]['attributes'][attribute]
|
|
152
|
+
" property='#{att_rdf[:namespace]}:#{att_rdf[:property]}'"
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# update associations with rdf properties.
|
|
156
|
+
# @param [String] model's name
|
|
157
|
+
# @param [String] model's attribute
|
|
158
|
+
# @param [String] association's property to be updated
|
|
159
|
+
# @param [Strign] new value
|
|
160
|
+
# @return [Boolean] true or false if the operation has finished correctly.
|
|
161
|
+
def update_associations_model(model,association,param,value)
|
|
162
|
+
self.model_rdf[model]['associations'][association][param.to_sym] = value
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# RDFa: return a string with all prefix used to describes attributes
|
|
166
|
+
# @param [String] model's name
|
|
167
|
+
# @return [String] list of prefix to be used in RDFa information
|
|
168
|
+
def get_prefix(model)
|
|
169
|
+
prefix = []
|
|
170
|
+
data_model = get_attributes_model(model)
|
|
171
|
+
data_model["attributes"].each do |att,info|
|
|
172
|
+
if info[:namespace] && info[:namespace] != 'not defined'
|
|
173
|
+
puts info[:namespace]
|
|
174
|
+
prefix << "xmls:#{info[:namespace]}=#{(eval "EasyData::RDF::#{info[:namespace].upcase}.get_uri")} "
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
data_model["associations"].each do |assoc,info|
|
|
178
|
+
if info[:namespace] && info[:namespace] != 'not defined'
|
|
179
|
+
prefix << "xmls:#{info[:namespace]}=#{(eval "EasyData::RDF::#{info[:namespace].upcase}.get_uri")} "
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
|
|
183
|
+
if data_model[:namespace] && data_model[:namespace] != 'not defined'
|
|
184
|
+
prefix << "xmls:#{data_model[:namespace]}=#{(eval "EasyData::RDF::#{data_model[:namespace].upcase}.get_uri")}"
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
prefix.uniq.join(" ")
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Convert index privacy to string
|
|
191
|
+
# @param [Integer] Index of privacy
|
|
192
|
+
# @return [String] Privacy label
|
|
193
|
+
def privacy(index)
|
|
194
|
+
@@privacy[index]
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
# Save changes in rdf_info.yaml (configuration's yaml file)
|
|
198
|
+
# return [Boolean] true or false if operations has finished correctly
|
|
199
|
+
def save
|
|
200
|
+
file = File.open("#{RAILS_ROOT}/config/easy_data/rdf_info.yaml",'w')
|
|
201
|
+
file.puts YAML::dump(self.model_rdf)
|
|
202
|
+
file.close
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def refresh_information
|
|
207
|
+
end
|
|
208
|
+
#######################################################################
|
|
209
|
+
# Building RDF
|
|
210
|
+
#######################################################################
|
|
211
|
+
|
|
212
|
+
# Build a response to user's request
|
|
213
|
+
# @param [Array] Response's data
|
|
214
|
+
# @param [String] model's name
|
|
215
|
+
# @param [String] current host
|
|
216
|
+
# @return [Hash] Response to be render in rdf file.
|
|
217
|
+
def get_model_rdf(query,model,host)
|
|
218
|
+
|
|
219
|
+
if public?model
|
|
220
|
+
request = {:body => "",:header => {"xmlns:rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#"}}
|
|
221
|
+
elements = {}
|
|
222
|
+
models = []
|
|
223
|
+
query.each do |element|
|
|
224
|
+
elements[element.id] = {'description' => "#{host}/s/#{element.class.to_s}/#{element.id}",
|
|
225
|
+
'attributes' => get_properties_tag(element),
|
|
226
|
+
'associations' => get_associations_tag(element)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
models << element.class.to_s
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
attributes = {}
|
|
233
|
+
request[:body] = elements
|
|
234
|
+
models.each do |mod|
|
|
235
|
+
attributes = get_attributes_model(mod) || get_attributes_model((eval mod).base_class.to_s)
|
|
236
|
+
request[:header].merge!(get_header(attributes))
|
|
237
|
+
end
|
|
238
|
+
request
|
|
239
|
+
else
|
|
240
|
+
{}
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
# Get all namespace used to build the response
|
|
244
|
+
# @param [Array] list of attributes
|
|
245
|
+
# @return [Array] list of namespaces used to describes them.
|
|
246
|
+
def get_header(attributes)
|
|
247
|
+
headers = {}
|
|
248
|
+
|
|
249
|
+
(attributes["attributes"].merge(attributes["associations"])).each do |att,properties|
|
|
250
|
+
if properties != "no publication" && properties[:namespace] != 'not defined' && properties[:privacy]=="Public"
|
|
251
|
+
headers["xmlns:#{properties[:namespace]}"] = (eval "EasyData::RDF::#{properties[:namespace].upcase}.get_uri") #EasyData.get_uri_namespace(properties[:namespace])
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
headers
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# Return all attribute's information of a model's instance
|
|
259
|
+
# @param [Object] Model's instance
|
|
260
|
+
# @return [Hash] RDF's attributes informations about the object
|
|
261
|
+
def get_properties_tag(element)
|
|
262
|
+
|
|
263
|
+
attributes = get_attributes_model(element.class.to_s)
|
|
264
|
+
|
|
265
|
+
# If element's class is a polimorphic class, we used base class.
|
|
266
|
+
if attributes.nil?
|
|
267
|
+
attributes = get_attributes_model(element.class.base_class.to_s)
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
properties = {}
|
|
271
|
+
if element.attributes.respond_to? :each
|
|
272
|
+
element.attributes.each do |att|
|
|
273
|
+
#conditions to methods to check if can be show
|
|
274
|
+
begin
|
|
275
|
+
|
|
276
|
+
if can_see?(attributes["attributes"][att.first][:privacy]) && exist_info_att(attributes["attributes"][att.first],att.second)
|
|
277
|
+
properties["#{attributes['attributes'][att.first][:namespace]}:#{attributes["attributes"][att.first][:property]}"] = att.second
|
|
278
|
+
end
|
|
279
|
+
rescue
|
|
280
|
+
puts attributes["attributes"]
|
|
281
|
+
end
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
properties
|
|
286
|
+
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
# Return all association's information of a model's instance
|
|
290
|
+
# @param [Object] Model's instance
|
|
291
|
+
# @return [Hash] RDF's association informations about the object
|
|
292
|
+
def get_associations_tag(element)
|
|
293
|
+
|
|
294
|
+
associations = get_attributes_model(element.class.to_s)
|
|
295
|
+
class_element = element.class
|
|
296
|
+
if associations.nil?
|
|
297
|
+
associations = get_attributes_model(element.class.base_class.to_s)
|
|
298
|
+
class_element = element.class.base_class
|
|
299
|
+
end
|
|
300
|
+
properties = {}
|
|
301
|
+
|
|
302
|
+
class_element.reflections.each do |ref,value|
|
|
303
|
+
|
|
304
|
+
rel = Array(eval "element.#{ref}")||Array()
|
|
305
|
+
|
|
306
|
+
if exist_info_assoc(rel,associations["associations"][ref.to_s]) && can_see?(associations["associations"][ref.to_s][:privacy]) && !rel.empty?
|
|
307
|
+
|
|
308
|
+
properties.merge!({"#{associations['associations'][ref.to_s][:namespace]}:#{associations['associations'][ref.to_s][:property]}" => {:model => rel.first.class ,:id => rel.collect{|obj| obj.id}}
|
|
309
|
+
})
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
properties
|
|
314
|
+
end
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
private
|
|
318
|
+
########################################################################
|
|
319
|
+
## FUNCTIONS FOR CHECK IF SHOW oR NoT THE CURRENT ITEM ##
|
|
320
|
+
########################################################################
|
|
321
|
+
|
|
322
|
+
# Check if the user can see the element data
|
|
323
|
+
# @param [String] privacy
|
|
324
|
+
# @return [Boolean] true or false, if the user can see this data
|
|
325
|
+
def can_see?(privacy)
|
|
326
|
+
privacy=="Public" || (privacy=="Private" && !@current_user.nil?)
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# Check if the attribute have defined his properties
|
|
330
|
+
#
|
|
331
|
+
def exist_info_att(attributes,value)
|
|
332
|
+
attributes[:namespace] != "not defined" &&
|
|
333
|
+
attributes[:property] !="not defined" &&
|
|
334
|
+
!value.nil?
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# Fixed
|
|
338
|
+
def exist_info_assoc(rels,rdf_info)
|
|
339
|
+
!rels.nil? && !rels.empty? &&
|
|
340
|
+
rdf_info[:namespace] != "not defined" &&
|
|
341
|
+
rdf_info[:property] != "not defined"
|
|
342
|
+
|
|
343
|
+
end
|
|
344
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
module EasyData
|
|
2
|
+
module RDF
|
|
3
|
+
class CC < Namespaces
|
|
4
|
+
@@uri = "xmlns:cc=http://creativecommons.org/ns#"
|
|
5
|
+
@@properties= {"attributionName" => "<cc:attributionName>%value%</cc:attributionName>",
|
|
6
|
+
"attributionURL" => "",
|
|
7
|
+
"deprecatedOn" => "",
|
|
8
|
+
"jurisdiction" => "",
|
|
9
|
+
"legalcode" => "",
|
|
10
|
+
"license" => "",
|
|
11
|
+
"morePermissions" => "",
|
|
12
|
+
"permits" => "",
|
|
13
|
+
"prohibits" => "",
|
|
14
|
+
"requires" => ""
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
# Return Namespace URI
|
|
18
|
+
def self.get_uri
|
|
19
|
+
@@uri
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#Return a list of Namespace's properties
|
|
23
|
+
def self.properties
|
|
24
|
+
@@properties.keys
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def self.properties_form
|
|
28
|
+
list = {}
|
|
29
|
+
@@properties.keys.each do |property|
|
|
30
|
+
list[property] = property
|
|
31
|
+
end
|
|
32
|
+
list
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module EasyData
|
|
2
|
+
module RDF
|
|
3
|
+
class CERT < Namespaces
|
|
4
|
+
@@uri = "http://www.w3.org/ns/auth/cert#"
|
|
5
|
+
@@properties= {"decimal" => "",
|
|
6
|
+
"hex" => "",
|
|
7
|
+
"identity" => "",
|
|
8
|
+
"public_key" => "",
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
# Return Namespace URI
|
|
12
|
+
def self.get_uri
|
|
13
|
+
@@uri
|
|
14
|
+
end
|
|
15
|
+
# Return tag to rdf doc
|
|
16
|
+
def self.to_s(property,uri,value)
|
|
17
|
+
@@properties[property].gsub("%uri%",uri).gsub('%value%',value)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
#Return a list of Namespace's properties
|
|
21
|
+
def self.properties
|
|
22
|
+
@@properties.keys
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def self.properties_form
|
|
26
|
+
list = {}
|
|
27
|
+
@@properties.keys.each do |property|
|
|
28
|
+
list[property] = property
|
|
29
|
+
end
|
|
30
|
+
list
|
|
31
|
+
end end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
module EasyData
|
|
2
|
+
module RDF
|
|
3
|
+
class DC < Namespaces
|
|
4
|
+
@@uri = "http://purl.org/dc/elements/1.1/"
|
|
5
|
+
|
|
6
|
+
@@properties = {"abstract" => "",
|
|
7
|
+
"accessRights" => "",
|
|
8
|
+
"accrualMethod" => "",
|
|
9
|
+
"accrualPeriodicity" => "",
|
|
10
|
+
"accrualPolicy" => "",
|
|
11
|
+
"alternative" => "",
|
|
12
|
+
"audience" => "",
|
|
13
|
+
"available" => "",
|
|
14
|
+
"bibliographicCitation" => "",
|
|
15
|
+
"conformsTo" => "",
|
|
16
|
+
"contributor" => "",
|
|
17
|
+
"coverage" => "",
|
|
18
|
+
"created" => "",
|
|
19
|
+
"creator" => "",
|
|
20
|
+
"date" => "",
|
|
21
|
+
"dateAccepted" => "",
|
|
22
|
+
"dateCopyrighted" => "",
|
|
23
|
+
"dateSubmitted" => "",
|
|
24
|
+
"description" => "",
|
|
25
|
+
"educationLevel" => "",
|
|
26
|
+
"extent" => "",
|
|
27
|
+
"format" => "",
|
|
28
|
+
"hasFormat" => "",
|
|
29
|
+
"hasPart" => "",
|
|
30
|
+
"hasVersion" => "",
|
|
31
|
+
"identifier" => "",
|
|
32
|
+
"instructionalMethod" => "",
|
|
33
|
+
"isFormatOf" => "",
|
|
34
|
+
"isPartOf" => "",
|
|
35
|
+
"isReferencedBy" => "",
|
|
36
|
+
"isReplacedBy" => "",
|
|
37
|
+
"isRequiredBy" => "",
|
|
38
|
+
"isVersionOf" => "",
|
|
39
|
+
"issued" => "",
|
|
40
|
+
"language" => "",
|
|
41
|
+
"license" => "",
|
|
42
|
+
"mediator" => "",
|
|
43
|
+
"medium" => "",
|
|
44
|
+
"modified" => "",
|
|
45
|
+
"provenance" => "",
|
|
46
|
+
"publisher" => "",
|
|
47
|
+
"references" => "",
|
|
48
|
+
"relation" => "",
|
|
49
|
+
"replaces" => "",
|
|
50
|
+
"requires" => "",
|
|
51
|
+
"rights" => "",
|
|
52
|
+
"rightsHolder" => "",
|
|
53
|
+
"source" => "",
|
|
54
|
+
"spatial" => "",
|
|
55
|
+
"subject" => "",
|
|
56
|
+
"tableOfContents" => "",
|
|
57
|
+
"temporal" => "",
|
|
58
|
+
"title" => "",
|
|
59
|
+
"type" => "",
|
|
60
|
+
"valid" => ""
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Return Namespace URI
|
|
64
|
+
def self.get_uri
|
|
65
|
+
@@uri
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Return tag to rdf doc
|
|
69
|
+
def self.to_s(property,uri,value)
|
|
70
|
+
@@properties[property].gsub("%uri%",uri).gsub('%value%',value)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#Return a list of Namespace's properties
|
|
74
|
+
def self.properties
|
|
75
|
+
@@properties.keys
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def self.properties_form
|
|
79
|
+
list = {}
|
|
80
|
+
@@properties.keys.each do |property|
|
|
81
|
+
list[property] = property
|
|
82
|
+
end
|
|
83
|
+
list
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module EasyData
|
|
2
|
+
module RDF
|
|
3
|
+
class DC11 < Namespaces
|
|
4
|
+
@@uri = "http://purl.org/dc/elements/1.1/"
|
|
5
|
+
@@properties= {"contributor" => "",
|
|
6
|
+
"coverage" => "",
|
|
7
|
+
"creator" => "",
|
|
8
|
+
"date" => "",
|
|
9
|
+
"description" => "",
|
|
10
|
+
"format" => "",
|
|
11
|
+
"identifier" => "",
|
|
12
|
+
"language" => "",
|
|
13
|
+
"publisher" => "",
|
|
14
|
+
"relation" => "",
|
|
15
|
+
"rights" => "",
|
|
16
|
+
"source" => "",
|
|
17
|
+
"subject" => "",
|
|
18
|
+
"title" => "",
|
|
19
|
+
"type" => "",
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
# Return Namespace URI
|
|
23
|
+
def self.get_uri
|
|
24
|
+
@@uri
|
|
25
|
+
# "http://purl.org/dc/elements/1.1/"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Return tag to rdf doc
|
|
29
|
+
def self.to_s(property,uri,value)
|
|
30
|
+
@@properties[property].gsub("%uri%",uri).gsub('%value%',value)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
#Return a list of Namespace's properties
|
|
34
|
+
def self.properties
|
|
35
|
+
@@properties.keys
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def self.properties_form
|
|
39
|
+
list = {}
|
|
40
|
+
@@properties.keys.each do |property|
|
|
41
|
+
list[property] = property
|
|
42
|
+
end
|
|
43
|
+
list
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
module EasyData
|
|
2
|
+
module RDF
|
|
3
|
+
class DOAP < Namespaces
|
|
4
|
+
@@uri = "http://usefulinc.com/ns/doap#"
|
|
5
|
+
|
|
6
|
+
@@properties= {"'anon-root'" => "",
|
|
7
|
+
"audience" => "",
|
|
8
|
+
"blog" => "",
|
|
9
|
+
"browse" => "",
|
|
10
|
+
"'bug-database'" => "",
|
|
11
|
+
"category" => "",
|
|
12
|
+
"created" => "",
|
|
13
|
+
"description" => "",
|
|
14
|
+
"developer" => "",
|
|
15
|
+
"documenter" => "",
|
|
16
|
+
"'download-mirror'" => "",
|
|
17
|
+
"'download-page'" => "",
|
|
18
|
+
"'file-release'" => "",
|
|
19
|
+
"helper" => "",
|
|
20
|
+
"homepage" => "",
|
|
21
|
+
"implements" => "",
|
|
22
|
+
"language" => "",
|
|
23
|
+
"license" => "",
|
|
24
|
+
"location" => "",
|
|
25
|
+
"'mailing-list'" => "",
|
|
26
|
+
"maintainer" => "",
|
|
27
|
+
"module" => "",
|
|
28
|
+
"name" => "",
|
|
29
|
+
"'old-homepage'" => "",
|
|
30
|
+
"os" => "",
|
|
31
|
+
"platform" => "",
|
|
32
|
+
"'programming-language'" => "",
|
|
33
|
+
"release" => "",
|
|
34
|
+
"repository" => "",
|
|
35
|
+
"revision" => "",
|
|
36
|
+
"screenshots" => "",
|
|
37
|
+
"'service-endpoint'" => "",
|
|
38
|
+
"shortdesc" => "",
|
|
39
|
+
"tester" => "",
|
|
40
|
+
"translator" => "",
|
|
41
|
+
"vendor" => "",
|
|
42
|
+
"wiki" => ""
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
# Return Namespace URI
|
|
46
|
+
def self.get_uri
|
|
47
|
+
@@uri
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Return tag to rdf doc
|
|
51
|
+
def self.to_s(property,uri,value)
|
|
52
|
+
@@properties[property].gsub("%uri%",uri).gsub('%value%',value)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#Return a list of Namespace's properties
|
|
56
|
+
def self.properties
|
|
57
|
+
@@properties.keys
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def self.properties_form
|
|
61
|
+
list = {}
|
|
62
|
+
@@properties.keys.each do |property|
|
|
63
|
+
list[property] = property
|
|
64
|
+
end
|
|
65
|
+
list
|
|
66
|
+
end end
|
|
67
|
+
end
|
|
68
|
+
end
|