rtriplify 0.0.1 → 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/README +4 -5
- data/lib/app/controllers/triplify_controller.rb +7 -5
- data/lib/config/{database_1.yml → triplify_demo.yml} +101 -142
- data/lib/tripleizer.rb +40 -61
- metadata +3 -3
data/README
CHANGED
@@ -2,18 +2,17 @@ rTriplify
|
|
2
2
|
========
|
3
3
|
|
4
4
|
rTriplify is a ruby clone of the triplify-php version. It is used to create
|
5
|
-
a rdf-mapping of your existing database and
|
5
|
+
a rdf-mapping of your existing database and serves it out to the (semantic)-web.
|
6
6
|
|
7
7
|
rTriplify uses the rails database models to generate your rdf-data.
|
8
|
-
|
9
8
|
It comes with most of the origin features of triplify.
|
10
|
-
|
9
|
+
I will go on detail on this later.
|
11
10
|
|
12
11
|
In addition you have the possibility to generate RDFa -Data and place it inside of
|
13
12
|
your webpage as a hidden div. Please be aware that this is not the clean way to
|
14
13
|
serve your content as RDFa. But I think, if you have generated the mapping file
|
15
14
|
for your database it's just the consequence to place RDFa on your page instead.
|
16
|
-
|
15
|
+
RTriplify gives you the right tools to place RDFa tags on your Webpage without having
|
17
16
|
to do a full code review of your templates. And of course, search engines like google
|
18
17
|
and yahoo already watch for these tags. Google already rewards RDFa tags with some specials.
|
19
18
|
For further informations please see here [1] or [2] here
|
@@ -30,7 +29,7 @@ gem install rtriplify
|
|
30
29
|
|
31
30
|
then place a triplify.yml file in the config folder of your RoR-application.
|
32
31
|
Probably it's the best idea to use the sample config file included in the gem or
|
33
|
-
you can download
|
32
|
+
you can download a clean sample file here [3] too.
|
34
33
|
|
35
34
|
Usaly the sample config has all configuration possibilitys inside of it and
|
36
35
|
it's well documented. I think you can start now and change the config so that it
|
@@ -5,6 +5,7 @@ class TriplifyController < ActionController::Base
|
|
5
5
|
def tripleize
|
6
6
|
t = Tripleizer.new
|
7
7
|
t.base_uri = t.uri request.env['REQUEST_URI'].to_s
|
8
|
+
depth = configatron.linked_data_depth.to_i
|
8
9
|
|
9
10
|
filename = 'data.n3'
|
10
11
|
headers.merge!(
|
@@ -15,20 +16,21 @@ class TriplifyController < ActionController::Base
|
|
15
16
|
|
16
17
|
t.output_json = request.content_type.try(:to_sym)==:json
|
17
18
|
content_type = t.output_json ? 'application/json' : 'text/plain'
|
19
|
+
|
18
20
|
render :content_type => content_type , :text => proc { |response, output|
|
19
21
|
t.output = output
|
20
22
|
case params[:specs].length
|
21
23
|
when 0
|
22
24
|
t.write_rdf_head
|
23
|
-
all t
|
25
|
+
all t if depth > -1
|
24
26
|
when 1
|
25
27
|
t.base_uri = t.base_uri.to_s[0..t.base_uri.to_s.index(params[:specs][0].to_s)-1]
|
26
28
|
t.write_rdf_head
|
27
|
-
model t, params[:specs][0]
|
29
|
+
model t, params[:specs][0] if depth >0
|
28
30
|
when 2
|
29
31
|
t.base_uri = t.base_uri.to_s[0..t.base_uri.to_s.index(params[:specs][0].to_s)-1]
|
30
32
|
t.write_rdf_head
|
31
|
-
index t, params[:specs]
|
33
|
+
index t, params[:specs] if depth > 1
|
32
34
|
end
|
33
35
|
|
34
36
|
t_metadata = TriplifyMetadata.new
|
@@ -58,7 +60,7 @@ class TriplifyController < ActionController::Base
|
|
58
60
|
|
59
61
|
#get all models
|
60
62
|
def model t, model_group
|
61
|
-
models = t.
|
63
|
+
models = t.find_models model_group
|
62
64
|
models.values[0].each do |model_name, model_attributes|
|
63
65
|
if model_name.to_s =="sql_query"
|
64
66
|
t.write_sql(model_group_name,model_attributes,output)
|
@@ -71,7 +73,7 @@ class TriplifyController < ActionController::Base
|
|
71
73
|
# get a defined model with given id
|
72
74
|
def index t,param
|
73
75
|
subclass,id = param
|
74
|
-
models = t.
|
76
|
+
models = t.find_models subclass
|
75
77
|
models.values[0].each do |model_name, model_attributes|
|
76
78
|
if model_name.to_s =="sql_query"
|
77
79
|
#some magic is needed here ..parse the sql query?
|
@@ -5,15 +5,16 @@
|
|
5
5
|
# an editor for it. For example Netbeans already have a build in one.
|
6
6
|
|
7
7
|
# Please be sure having configured your database configuration properly
|
8
|
+
# Now let's start with the Configuration
|
8
9
|
|
9
10
|
|
10
11
|
# all namespaces for your application. Please use them in your application to
|
11
12
|
# get the data better linked
|
12
13
|
namespaces:
|
13
|
-
|
14
|
+
xmlns: http://www.w3.org/1999/xhtml/
|
14
15
|
rdf: http://www.w3.org/1999/02/22-rdf-syntax-ns#
|
15
16
|
rdfs: http://www.w3.org/2000/01/rdf-schema#
|
16
|
-
|
17
|
+
xsd: http://www.w3.org/2001/XMLSchema#
|
17
18
|
foaf: http://xmlns.com/foaf/0.1/
|
18
19
|
sioc: http://rdfs.org/sioc/ns#
|
19
20
|
sioctypes: http://rdfs.org/sioc/types#
|
@@ -21,21 +22,22 @@ namespaces:
|
|
21
22
|
dcterms: http://purl.org/dc/terms/
|
22
23
|
skos: http://www.w3.org/2004/02/skos/core#
|
23
24
|
tag: http://www.holygoat.co.uk/owl/redwood/0.1/tags/
|
24
|
-
|
25
|
+
|
25
26
|
update: http://triplify.org/vocabulary/update#
|
26
27
|
gr: http://purl.org/goodrelations/v1#
|
27
|
-
|
28
|
+
vc: http://www.w3.org/2006/vcard/ns#
|
28
29
|
daml: http://www.daml.org/2001/09/countries/iso-3166-ont#
|
29
30
|
|
30
|
-
#
|
31
|
+
#query:
|
31
32
|
# In general there are two possibilites to configure your rdf Data. First is by
|
32
33
|
# using sql queries like in the php version of triplify. Please have a look at
|
33
34
|
# http://triplify.svn.sourceforge.net/viewvc/triplify/triplify-php/config.dist.php?view=markup
|
34
|
-
# to find out how
|
35
|
+
# to find out how model your querys
|
35
36
|
#
|
36
37
|
# Secound possibility and may be the more "rails-way" is to use active record.
|
37
|
-
# you have two hierarchy levels for configuration. First, the
|
38
|
+
# you have two hierarchy levels for configuration. First-level, the RDF-Resource-class and in secound-level,
|
38
39
|
# the Active record model.
|
40
|
+
#
|
39
41
|
# A configuration line in the model has always the Schema
|
40
42
|
# nameOfField: ar_field
|
41
43
|
# ID field has a special meaning. The ID field is always the Subject of the RDF
|
@@ -48,143 +50,95 @@ namespaces:
|
|
48
50
|
# filter:
|
49
51
|
# ID: ">213 and id <224"
|
50
52
|
# Note: in some case lower and Uppercase Notation is Important.
|
51
|
-
# the "id" field is alway written uppercase
|
52
|
-
#
|
53
|
-
# Model are written Capitalized like using it in ruby.
|
54
|
-
# first time you may be a little bit irritated, but up to now there is
|
55
|
-
# no better solution for this issue.
|
56
|
-
|
53
|
+
# the "id" field is alway written uppercase.#
|
54
|
+
# Models are written Capitalized like using it in ruby.
|
57
55
|
|
58
|
-
query:
|
59
|
-
shipping: #the group write it lowercase
|
60
56
|
|
61
|
-
ShippingMethod:
|
62
|
-
gr:DeliveryModeParcelService: name
|
63
|
-
zone->zone: zone
|
64
57
|
|
65
|
-
Zone:
|
66
|
-
rdfs:label: name
|
67
|
-
rdfs:comment: description
|
68
58
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
#
|
82
|
-
#
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
59
|
+
query: #starting the query section
|
60
|
+
# The best way always is
|
61
|
+
Offer: #the RDF-resource-class
|
62
|
+
Variant: # the model
|
63
|
+
# the simple predicate: field_name config
|
64
|
+
hasStockKeepingUnit: sku
|
65
|
+
# use
|
66
|
+
# gr:hasStockKeepingUnit: sku to set the rdf-schema class
|
67
|
+
|
68
|
+
#predicate "gr:name" has the value field product.name
|
69
|
+
gr:name: product.name
|
70
|
+
gr:description: product.description
|
71
|
+
# if you have some constant strings use this function
|
72
|
+
# CONST( predicate, LINK) or
|
73
|
+
# CONST( predicate, datatype) datatype is e.g. xsd:string
|
74
|
+
# please refer to UnitPriceSpecification for an example
|
75
|
+
gr:hasBusinessFunction: CONST(gr:Sell,LINK)
|
76
|
+
# you have a reference to another object the config qoes like:
|
77
|
+
# predicate->RDF-Resource-class: id of the referenced RDF-Resource-class
|
78
|
+
# please see UnitPriceSpecification
|
79
|
+
gr:hasPriceSpecification->UnitPriceSpecification: id
|
80
|
+
# Sometime it can happen thate you have a static ref to some Values
|
81
|
+
# MODEL( 'model-class','rdf-resource class').field_name or, if multiple values
|
82
|
+
# MODEL( 'model-class','rdf-resource class')*field_name or, if multiple values
|
83
|
+
gr:acceptedPaymentMethods->Payment: MODEL('PaymentMethod','Payment')*id
|
84
|
+
|
85
|
+
# A Variant of a Product
|
86
|
+
Variant: #the RDF-resource-class
|
87
|
+
Variant: # the Model
|
88
|
+
gr:name: product.name
|
89
|
+
gr:description: product.description
|
90
|
+
gr:hasStockKeepingUnit: sku
|
91
|
+
gr:isVariantOf->Product: product.permalink
|
92
|
+
# predicate->RDF-ressource-class and a link on multiple id values
|
93
|
+
gr:qualitativeProductOrServiceProperty->VariantProp: option_values*id
|
94
|
+
# add one or multiple fields by direct sql command
|
95
|
+
# better not to use this feature! Please proof if there is not another configuration possibility
|
96
|
+
sql_query:
|
97
|
+
query1: Select v.id, ov.name as 'gr:Color' from Variants v, option_values_variants ovv,option_values ov,option_types ot where ovv.variant_id=v.id and ov.id = ovv.option_value_id and ov.option_type_id=ot.id and ot.id =643188970
|
98
|
+
# some properties of the Variant
|
99
|
+
VariantProp:
|
100
|
+
OptionValue:
|
101
|
+
rdfs:subClassOf: CONST(gr:QualitativeValue,LINK)
|
90
102
|
name: name
|
91
|
-
abrr: abbr
|
92
|
-
Country->Country: country
|
93
|
-
|
94
|
-
product: #the group write it lowercase
|
95
|
-
Product: #the model name...write it capitalized
|
96
|
-
rdfs:label: name
|
97
|
-
rdfs:comment: description
|
98
|
-
ID: permalink
|
99
|
-
Property->Property: properties
|
100
|
-
PropertyValue->ProductProperty: product_properties
|
101
|
-
OptionType->OptionType: option_types
|
102
|
-
CategoryName: tax_category.name
|
103
|
-
CategoryDescription: tax_category.description
|
104
|
-
|
105
|
-
Property: #the model name...write it capitalized
|
106
|
-
ID: name
|
107
103
|
presentation: presentation
|
108
|
-
|
109
|
-
|
104
|
+
# a prodct e.g. a T-shirt or a bag...
|
105
|
+
Product:
|
106
|
+
Product:
|
107
|
+
ID: permalink
|
108
|
+
gr:name: name
|
109
|
+
gr:description: description
|
110
|
+
# again some multiple sub-properties
|
111
|
+
gr:qualitativeProductOrServiceProperty->ProductProp: product_properties*id
|
112
|
+
#gr:category
|
113
|
+
# some subproperties of the product..e.g. the color or size
|
114
|
+
ProductProp:
|
110
115
|
ProductProperty:
|
116
|
+
rdfs:subClassOf: CONST(gr:QualitativeValue,LINK)
|
111
117
|
value: value
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
Prototype:
|
124
|
-
name: name
|
125
|
-
Property->Property: properties
|
126
|
-
OptionType->OptionType: option_types
|
127
|
-
|
128
|
-
OptionType:
|
129
|
-
ID: name
|
130
|
-
presentation: presentation
|
131
|
-
Prototype->Prototype: prototypes
|
132
|
-
|
133
|
-
|
134
|
-
Variant:
|
135
|
-
gr:hasBusinessFunction: "gr:Sell"
|
136
|
-
Product->Product: product
|
137
|
-
ID: sku
|
138
|
-
#gr:hasCurrency
|
139
|
-
gr:hasCurrencyValue: price
|
140
|
-
gr:weight: weight
|
141
|
-
gr:height: height
|
142
|
-
gr:width: width
|
143
|
-
gr:depth: depth
|
144
|
-
#count_on_hand: count_on_hand
|
145
|
-
OptionValue->OptionValue: option_values
|
146
|
-
|
147
|
-
Taxon:
|
148
|
-
ID: name
|
149
|
-
name: taxonomy.name
|
150
|
-
permalink: permalink
|
151
|
-
Parent->Taxon: parent
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
OptionValue:
|
156
|
-
ID: name
|
157
|
-
position: position
|
158
|
-
presentation: presentation
|
159
|
-
Variant->Variant: variants
|
160
|
-
OptionType->OptionType: option_type
|
161
|
-
|
162
|
-
user:
|
163
|
-
User:
|
164
|
-
firstname: ship_address.firstname
|
165
|
-
lastname: ship_address.lastname
|
166
|
-
role->Role: roles
|
167
|
-
|
168
|
-
Role:
|
169
|
-
name: name
|
170
|
-
ID: name
|
171
|
-
|
172
|
-
paymentmethod: #the group write it lowercase
|
173
|
-
PaymentMethod: #the model name...write it capitalized
|
174
|
-
gr:PaymentMethod: name
|
175
|
-
description: description
|
118
|
+
propertyName: property.name
|
119
|
+
rdfs:label: property.presentation
|
120
|
+
# accepted payment methods
|
121
|
+
Payment:
|
122
|
+
PaymentMethod:
|
123
|
+
#rdfs:type: type
|
124
|
+
rdf:label: name
|
125
|
+
rdf:description: description
|
126
|
+
# a filter description
|
127
|
+
# up to now there are only static filters possible
|
176
128
|
filter:
|
129
|
+
# field_to_filter: filter value.... in sql its the " where active = 't' "
|
177
130
|
active: = 't'
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
131
|
+
environment: = 'development'
|
132
|
+
# the price specification for the offer
|
133
|
+
UnitPriceSpecification:
|
134
|
+
Variant:
|
135
|
+
ID: id
|
136
|
+
gr:hasCurrencyValue: price
|
137
|
+
gr:hasCurrency: CONST(EUR,xsd:string) # adds the [ subject has_curency "EUR" ] triple
|
184
138
|
|
185
139
|
# Some of the columns of the Triplify queries will contain references to other
|
186
140
|
# objects rather than literal values. The following configuration array
|
187
|
-
# specifies, which columns are references to objects of which type.
|
141
|
+
# specifies, which columns are references to objects of which type. (same like in origin triplify)
|
188
142
|
|
189
143
|
objectProperties:
|
190
144
|
has_creator: person
|
@@ -192,13 +146,17 @@ objectProperties:
|
|
192
146
|
# Objects are classified according to their type. However, you can specify
|
193
147
|
# a mapping here, if objects of a certain type should be associated with a
|
194
148
|
# different class (e.g. classify all users as 'foaf:person'). If you are
|
195
|
-
# unsure it is safe to leave this configuration array empty.
|
149
|
+
# unsure it is safe to leave this configuration array empty. (same like in origin triplify)
|
196
150
|
#
|
197
151
|
classMap:
|
198
|
-
|
199
|
-
Product: gr:ProductOrServiceModel
|
200
|
-
|
201
|
-
|
152
|
+
Offer: gr:Offering #the offer
|
153
|
+
Product: gr:ProductOrServiceModel # the product, for Example the ruby_on_rails t-shirt
|
154
|
+
Variant: gr:ProductOrServiceModel # for example the blue / XL variant of the ruy_on_rails t-shirt
|
155
|
+
ProductProp: gr:ProductOrServiceProperty
|
156
|
+
UnitPriceSpecification: gr:UnitPriceSpecification
|
157
|
+
Payment: gr:PaymentMethod
|
158
|
+
|
159
|
+
|
202
160
|
|
203
161
|
#the licence under which you publish your data
|
204
162
|
license: http://creativecommons.org/licenses/by/3.0/us/
|
@@ -208,8 +166,8 @@ license: http://creativecommons.org/licenses/by/3.0/us/
|
|
208
166
|
# properties, the values will be represented as respective property values.
|
209
167
|
|
210
168
|
metadata:
|
211
|
-
dc:title:
|
212
|
-
dc:publisher:
|
169
|
+
dc:title: spree-demo Shop
|
170
|
+
dc:publisher: Nico Patitz
|
213
171
|
|
214
172
|
# not yet
|
215
173
|
# Set this to true in order to register your linked data endpoint with the
|
@@ -236,7 +194,8 @@ register: true
|
|
236
194
|
# content will be exposed on the instance level, e.g. when /triplify/user/1/
|
237
195
|
# is accessed.
|
238
196
|
#
|
239
|
-
|
197
|
+
|
198
|
+
linked_data_depth: 2
|
240
199
|
|
241
200
|
# Callback Functions
|
242
201
|
#
|
@@ -245,9 +204,9 @@ register: true
|
|
245
204
|
# column names to respective functions, which have to take the data value as a
|
246
205
|
# parameter and return it processed.
|
247
206
|
|
207
|
+
#not yet implemented
|
248
208
|
CallbackFunctions:
|
249
209
|
|
250
|
-
|
251
210
|
# Semantic Pingback
|
252
211
|
#
|
253
212
|
# This section contains the Semantic Pingback configuration.
|
@@ -256,9 +215,9 @@ pingback:
|
|
256
215
|
# Whether X-Pingback header should be exposed and XML-RPC is active.
|
257
216
|
enabled: true
|
258
217
|
#Whether to write Pingbacks with the instance data.
|
259
|
-
write: true
|
218
|
+
write: true
|
260
219
|
|
261
|
-
# metadata
|
220
|
+
# metadata #most of this is the same like you know from the php- triplify
|
262
221
|
|
263
222
|
##
|
264
223
|
## BEGIN OF CONFIGURATION
|
data/lib/tripleizer.rb
CHANGED
@@ -2,6 +2,7 @@ require 'configatron'
|
|
2
2
|
require 'json'
|
3
3
|
|
4
4
|
class Tripleizer
|
5
|
+
# constructor
|
5
6
|
def initialize output=nil
|
6
7
|
@object_properties = configatron.objectProperties.to_hash
|
7
8
|
@object_namespaces = configatron.namespaces.to_hash
|
@@ -10,39 +11,19 @@ class Tripleizer
|
|
10
11
|
@version="0.0.1"
|
11
12
|
@json_hash = Hash.new
|
12
13
|
@output_json = nil;
|
13
|
-
@base_uri = "
|
14
|
+
@base_uri = "http://example.com/"
|
14
15
|
end
|
15
|
-
|
16
|
+
|
17
|
+
# stores RDF output as string
|
16
18
|
attr_accessor :output
|
19
|
+
# rtriplify version in RDF
|
17
20
|
attr_reader :version
|
21
|
+
# get a json object of the RDF
|
18
22
|
attr_accessor :output_json
|
23
|
+
# base uri..if not set, std. from config is used
|
19
24
|
attr_accessor :base_uri
|
20
25
|
|
21
|
-
|
22
|
-
# def all request,headers
|
23
|
-
# #get all models
|
24
|
-
# #render all models
|
25
|
-
# ret=""
|
26
|
-
# t = Tripleizer.new
|
27
|
-
# $base_uri= t.uri request.env['REQUEST_URI'].to_s[0..-5]
|
28
|
-
# #t.output_json = request.content_type.try(:to_sym)==:json
|
29
|
-
# #content_type = t.output_json ? 'application/json' : 'text/plain'
|
30
|
-
# ret << t.write_rdf_head
|
31
|
-
# model_groups = eval("configatron.query").to_hash
|
32
|
-
# model_groups.each do |model_group_name,model_group|
|
33
|
-
# model_group.each do |model_name,model_attributes|
|
34
|
-
# if model_name.to_s =="sql_query"
|
35
|
-
# ret<<t.write_sql(model_group_name,model_attributes,t.output)
|
36
|
-
# else
|
37
|
-
# ret<<t.write_model(model_name,model_group_name)
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
# end
|
41
|
-
# t_metadata = TriplifyMetadata.new
|
42
|
-
# ret<<t_metadata.write_metadata(t).to_s
|
43
|
-
# ret
|
44
|
-
# end
|
45
|
-
|
26
|
+
#Generation of N3 RDF with iterative depth
|
46
27
|
def rdf rdf_start_class , var=[]
|
47
28
|
class_map = Hash.new
|
48
29
|
var.each do |c|
|
@@ -50,7 +31,7 @@ class Tripleizer
|
|
50
31
|
end
|
51
32
|
rdf_string =""
|
52
33
|
#get configuration start ->classes
|
53
|
-
m =
|
34
|
+
m = find_models(rdf_start_class)
|
54
35
|
|
55
36
|
m.values[0].each do |mod,attributes|
|
56
37
|
unless mod.eql?("sql_query")
|
@@ -65,7 +46,8 @@ class Tripleizer
|
|
65
46
|
rdf_string
|
66
47
|
end
|
67
48
|
|
68
|
-
#
|
49
|
+
# get a RDFa note by its ID and resource-class.
|
50
|
+
# Iterative Function, so be carefull with your config not to produce endless loops
|
69
51
|
def rdf_by_id model_name, class_name, id
|
70
52
|
puts model_name
|
71
53
|
ret=""
|
@@ -106,7 +88,7 @@ class Tripleizer
|
|
106
88
|
ref_pred,ref_model=k.to_s.split"->"
|
107
89
|
#write referenced model
|
108
90
|
#ret<< make_triples({:id=>id,k=>sub_id },class_name,"",Array.new,false)
|
109
|
-
m=
|
91
|
+
m= find_models(ref_model)
|
110
92
|
m.values[0].each do |mod,val|
|
111
93
|
ret<<(rdf_by_id mod, ref_model, eval("item."+v.to_s)).to_s
|
112
94
|
end
|
@@ -139,19 +121,19 @@ class Tripleizer
|
|
139
121
|
extract_id_line(model.model_attributes, line, item,data_types)
|
140
122
|
remove.each { |rem_attrib| line.delete(rem_attrib) }
|
141
123
|
#get triples of row
|
142
|
-
ret<<make_triples(line, class_name , "", data_types)
|
143
|
-
#render :text => t.make_triples(c1, controller , "", t.dbd_types)
|
124
|
+
ret<<make_triples(line, class_name , "", data_types)
|
144
125
|
ret
|
145
126
|
end
|
146
127
|
|
147
|
-
# rdfa generation
|
148
|
-
|
128
|
+
# rdfa generation
|
129
|
+
# iterative and returns "hidden" rdfa-div-tags
|
130
|
+
def rdfa rdf_start_class , var=[]
|
149
131
|
#write namespace
|
150
|
-
"<div #{@object_namespaces.collect {|pre,ns| "xmlns:"<<pre.to_s<<"=\""<<ns.to_s<<"\" " }}>\n #{
|
132
|
+
"<div #{@object_namespaces.collect {|pre,ns| "xmlns:"<<pre.to_s<<"=\""<<ns.to_s<<"\" " }}>\n #{rdfa_root(rdf_start_class,var)} </div>"
|
151
133
|
end
|
152
134
|
|
153
135
|
# the root rdf node
|
154
|
-
def
|
136
|
+
def rdfa_root rdf_start_class , var=[]
|
155
137
|
#map each var on its classname
|
156
138
|
rdfa_string = ""
|
157
139
|
class_map = Hash.new
|
@@ -160,7 +142,7 @@ class Tripleizer
|
|
160
142
|
end
|
161
143
|
|
162
144
|
#get configuration start ->classes
|
163
|
-
m =
|
145
|
+
m = find_models(rdf_start_class)
|
164
146
|
|
165
147
|
m.values[0].each do |mod,attributes|
|
166
148
|
unless mod.eql?("sql_query")
|
@@ -168,7 +150,7 @@ class Tripleizer
|
|
168
150
|
#if sql...
|
169
151
|
key = t_mod.get_key
|
170
152
|
t_mod.get_rows.each do |item|
|
171
|
-
rdfa_string<<
|
153
|
+
rdfa_string<<find_rdfa_by_id(rdf_start_class,eval("item.#{key}"))
|
172
154
|
end
|
173
155
|
end
|
174
156
|
end
|
@@ -176,12 +158,12 @@ class Tripleizer
|
|
176
158
|
end
|
177
159
|
|
178
160
|
# generate RDFa tags by a specified ID
|
179
|
-
def
|
161
|
+
def find_rdfa_by_id rdf_start_class , id
|
180
162
|
#map each var on its classname
|
181
163
|
id = id.to_s
|
182
164
|
rdfa_string = "<div about=\"#{rdf_start_class+"/"<<id}\" typeof=\"#{@class_map[rdf_start_class.to_sym]}\">\n"
|
183
165
|
#get configuration start ->classes
|
184
|
-
m =
|
166
|
+
m = find_models(rdf_start_class)
|
185
167
|
m.values[0].each do |mod,attributes|
|
186
168
|
unless mod.to_s.eql?("sql_query")
|
187
169
|
t_mod = Model.new(mod, rdf_start_class)
|
@@ -203,20 +185,20 @@ class Tripleizer
|
|
203
185
|
submodel= eval(field_class.to_s).get_rows
|
204
186
|
rdfa_string<<"<div rel=\"#{m_class}\">\n"
|
205
187
|
submodel.each do |line|
|
206
|
-
rdfa_string<<
|
188
|
+
rdfa_string<<find_rdfa_by_id(role_mod , eval("line.#{field.to_s}"))
|
207
189
|
end
|
208
190
|
rdfa_string<<"</div>\n"
|
209
191
|
else
|
210
192
|
subitem = eval("item.#{field_class}")
|
211
193
|
rdfa_string<<"<div rel=\"#{m_class}\">\n"
|
212
194
|
subitem.each do |subline|
|
213
|
-
rdfa_string<<
|
195
|
+
rdfa_string<< find_rdfa_by_id(role_mod , eval("subline.#{field.to_s}"))
|
214
196
|
end
|
215
197
|
rdfa_string<<"</div>\n"
|
216
198
|
end
|
217
199
|
else
|
218
200
|
rdfa_string<<"<div rel=\"#{m_class}\">\n"
|
219
|
-
rdfa_string <<
|
201
|
+
rdfa_string << find_rdfa_by_id(role_mod , eval("item.#{link_field.to_s}"))
|
220
202
|
rdfa_string<<"</div>\n"
|
221
203
|
end
|
222
204
|
end
|
@@ -247,7 +229,7 @@ class Tripleizer
|
|
247
229
|
end
|
248
230
|
if field
|
249
231
|
write = false
|
250
|
-
#rdfa_string<<
|
232
|
+
#rdfa_string<<find_rdfa_by_id("","")
|
251
233
|
end
|
252
234
|
end
|
253
235
|
rdfa_string<<"<div property= \"#{name}\" content=\"#{eval("item.#{link_field}")}\"></div>\n" if write
|
@@ -260,12 +242,11 @@ class Tripleizer
|
|
260
242
|
|
261
243
|
#not used
|
262
244
|
def tripleize (tr_self,c =nil,id=nil)
|
263
|
-
|
264
245
|
end
|
265
246
|
|
266
247
|
# Find all the models to the given key ( the RDF-Class name)
|
267
248
|
# returns a hash with the RDF-Class name as key and the models as value
|
268
|
-
def
|
249
|
+
def find_models key
|
269
250
|
model_groups = eval("configatron.query").to_hash
|
270
251
|
model_groups.each do |model_group_name,model_group|
|
271
252
|
if model_group_name.to_s.downcase == key.downcase
|
@@ -407,11 +388,13 @@ class Tripleizer
|
|
407
388
|
c1.delete :id unless rdf_type
|
408
389
|
|
409
390
|
c1.each do |k,v|
|
391
|
+
#FIXME: not quite satisfied with this source part
|
410
392
|
dtype=""
|
411
393
|
k=k.to_s
|
412
394
|
if v.to_s.empty?
|
413
395
|
next
|
414
396
|
end
|
397
|
+
|
415
398
|
# beinhaltet key ^^ dann type oder sprache richtig setzen
|
416
399
|
if k.index("^^")
|
417
400
|
#TODO: k,dtype = k.split("^^")
|
@@ -425,7 +408,7 @@ class Tripleizer
|
|
425
408
|
end
|
426
409
|
end
|
427
410
|
end
|
428
|
-
#
|
411
|
+
#
|
429
412
|
if k.index("->")
|
430
413
|
k, object_property = k.split("->")
|
431
414
|
else
|
@@ -437,15 +420,12 @@ class Tripleizer
|
|
437
420
|
#
|
438
421
|
|
439
422
|
prop= self.uri(k,@object_namespaces[:vocabulary])
|
440
|
-
|
441
423
|
unless object_property
|
442
424
|
is_literal= true
|
443
425
|
object= v.to_s
|
444
426
|
else
|
445
|
-
is_literal= false
|
446
|
-
#
|
447
|
-
#TODO: fixme "/" in the middle
|
448
|
-
#object= uri "#{object_property}/#{object_property && object_property[-1,1].to_s !="/" ?"/":":"}#{v}"
|
427
|
+
is_literal= false
|
428
|
+
#TODO: fixme "/" in the middle
|
449
429
|
object= uri "#{object_property}#{object_property[-1,1].to_s !="/" ? "/":":"}#{v}"
|
450
430
|
if object[0..1] == "t/"
|
451
431
|
object = object.to_s[2..-1]
|
@@ -463,10 +443,9 @@ class Tripleizer
|
|
463
443
|
oa['datatype']=dtype if is_literal && dtype
|
464
444
|
oa['language']=lang if is_literal && lang
|
465
445
|
add_json_pair subject, predicate,oa
|
466
|
-
|
446
|
+
return ""
|
467
447
|
else
|
468
448
|
#(lang?"@#{lang}":'')
|
469
|
-
|
470
449
|
#define the object
|
471
450
|
if(is_literal)
|
472
451
|
object = "\"#{object.to_s.gsub('"','%22')}\""+ (dtype.empty? ? (lang.empty? ? "": "@#{lang}" ):"^^<#{dtype}>" )
|
@@ -485,24 +464,21 @@ class Tripleizer
|
|
485
464
|
|
486
465
|
#generates an uri with the given name
|
487
466
|
def uri (name,default="")
|
467
|
+
|
488
468
|
name=name.to_s
|
489
|
-
|
469
|
+
#FIXME: bad urls (for example just www.example.com will produce an endless-loop
|
490
470
|
if name.try(:include?, "://")
|
491
471
|
return name[0..name.length-2] if name[-1,1]=="/"
|
492
472
|
return name[0..name.length]
|
493
473
|
else
|
494
474
|
name +="/" unless (name[name.length-1..name.length-1] == ("/" || "#")) || name.try(:include?, ":")
|
495
475
|
|
496
|
-
if name.index(":")
|
497
|
-
#$this->ns[substr($name,0,strpos($name,':'))].$this->normalizeLocalName(substr($name,strpos($name,':')+1))
|
476
|
+
if name.index(":")
|
498
477
|
t= @object_namespaces[name.split(":")[0].to_sym]
|
499
478
|
t ||=""
|
500
479
|
t += "/" unless (t[t.length-1..t.length-1] == ("/" || "#") || t.blank?) || name.try(:include?, ":")
|
501
480
|
return uri( t+ normalize_local_name(name.split(":")[1])+"/")
|
502
|
-
else
|
503
|
-
##($default?$default:$GLOBALS['baseURI']).$this->normalizeLocalName($name));
|
504
|
-
#falls bei default hinten ein "/" ist abschneiden
|
505
|
-
#default= default[0.. default.length-2] unless default[default.length-1..default.length-1] == "/"
|
481
|
+
else
|
506
482
|
t= default.blank? ? @base_uri : default
|
507
483
|
t += "/" unless t[t.length-1..t.length-1]=="/"
|
508
484
|
return uri( t + normalize_local_name(name))
|
@@ -538,10 +514,12 @@ class Tripleizer
|
|
538
514
|
CGI::escape(name).gsub(/%2F/,'/').gsub(/%23/,'#')
|
539
515
|
end
|
540
516
|
|
517
|
+
# if output var is set to jason, you get the json source here
|
541
518
|
def json
|
542
519
|
@json_hash.to_json
|
543
520
|
end
|
544
521
|
|
522
|
+
# adds a pair to the json hash tree
|
545
523
|
def add_json_pair subject, predicate,oa
|
546
524
|
if @json_hash.key? subject
|
547
525
|
if @json_hash[subject].key? predicate
|
@@ -552,6 +530,7 @@ class Tripleizer
|
|
552
530
|
else
|
553
531
|
@json_hash[subject]=Hash.new
|
554
532
|
@json_hash[subject][predicate]=oa
|
533
|
+
hello="test"
|
555
534
|
end
|
556
535
|
end
|
557
536
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Nico Patitz
|
@@ -44,7 +44,7 @@ files:
|
|
44
44
|
- README
|
45
45
|
- MIT-LICENSE
|
46
46
|
- rails/init.rb
|
47
|
-
- lib/config/
|
47
|
+
- lib/config/triplify_demo.yml
|
48
48
|
- lib/app/controllers/triplify_controller.rb
|
49
49
|
- lib/app/helpers/triplify_helper.rb
|
50
50
|
- lib/app/models/triplify.rb
|