1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
module OpenTox
module Owl
attr_reader :uri
def initialize
@model = Redland::Model.new Redland::MemoryStore.new
@parser = Redland::Parser.new
@serializer = Redland::Serializer.ntriples
# read OT Ontology
#@parser.parse_into_model(@model,"http://opentox.org/data/documents/development/RDF%20files/OpenToxOntology/at_download/file")
#@parser.parse_string_into_model(@model,File.read(File.join(File.dirname(__FILE__),"opentox.owl")),'/')
# reate an anonymous resource for metadata
# this has to be rewritten with an URI as soon as the resource has been saved at an definitive location
tmp = @model.create_resource
@model.add tmp, RDF['type'], OWL['Ontology']
@model.add tmp, RDF['type'], OT[self.owl_class]
end
def uri=(uri)
@uri = uri
uri = Redland::Uri.new(uri)
# rewrite uri
@model.subjects(RDF['type'],OT[self.owl_class]).each do |me|
@model.delete(me,RDF['type'],OT[self.owl_class])
@model.add(uri,RDF['type'],OT[self.owl_class])
id = @model.object(me, DC['identifier'])
@model.delete me, DC['identifier'], id
# find/replace metadata
@model.find(me, nil, nil) do |s,p,o|
@model.delete s,p,o
@model.add uri,p,o
end
@model.add uri, DC['identifier'], @uri
end
end
def title
# I have no idea, why 2 subjects are returned
# iterating over all subjects leads to memory allocation problems
# SPARQL queries also do not work
#me = @model.subjects(RDF['type'],OT[self.owl_class])[1]
me = @model.subject(RDF['type'],OT[self.owl_class])
@model.object(me, DC['title']).to_s
end
def title=(title)
me = @model.subject(RDF['type'],OT[self.owl_class])
begin
t = @model.object(me, DC['title'])
@model.delete me, DC['title'], t
rescue
end
@model.add me, DC['title'], title
end
def source
me = @model.subject(RDF['type'],OT[self.owl_class])
@model.object(me, DC['source']).to_s unless me.nil?
end
def source=(source)
me = @model.subject(RDF['type'],OT[self.owl_class])
begin
t = @model.object(me, DC['source'])
@model.delete me, DC['source'], t
rescue
end
@model.add me, DC['source'], source
end
def identifier
me = @model.subject(RDF['type'],OT[self.owl_class])
@model.object(me, DC['identifier']).to_s unless me.nil?
end
def owl_class
self.class.to_s.sub(/^OpenTox::/,'').sub(/::.*$/,'')
end
def read(uri)
@parser.parse_into_model(@model,uri)
@uri = uri
end
def rdf=(rdf)
@uri = '/' unless @uri
@parser.parse_string_into_model(@model,rdf,@uri)
end
def rdf
@model.to_string
end
def to_ntriples
@serializer.model_to_string(Redland::Uri.new(@uri), @model)
end
def parameters=(params)
params.each do |name, settings|
parameter = @model.create_resource
@model.add parameter, RDF['type'], OT['Parameter']
@model.add parameter, DC['title'], name
@model.add parameter, OT['paramScope'], settings[:scope]
@model.add parameter, OT['paramValue'], settings[:value]
end
end
=begin
def create_owl_statement(name,value)
r = @model.create_resource
dc_class = DC[name.gsub(/^[a-z]/) { |a| a.upcase }] # capitalize only the first letter
#puts "DC:" + name.gsub(/^[a-z]/) { |a| a.upcase }
@model.add dc_class, RDF['type'], OWL["Class"]
@model.add r, RDF['type'], dc_class
@model.add r, DC[name], value
end
def method_missing(name, *args)
# create magic setter methods
if /=/ =~ name.to_s
create_owl_statement name.to_s.sub(/=/,''), args.first
else
raise "No method #{name}"
end
end
=end
end
end
|