Class: BEL::Model::Statement
- Inherits:
-
Object
- Object
- BEL::Model::Statement
- Defined in:
- lib/bel/evidence_model/bel_statement.rb,
lib/bel/extensions/rdf/rdf.rb
Overview
A Statement captures a BEL statement composed of a subject Term, relationship
, and object Term. A Statement may be one of the following common forms:
-
SUBJECT
-
complex(p(HGNC:F3),p(HGNC:F7))
-
-
SUBJECT RELATIONSHIP OBJECT(Term)
-
pep(complex(p(HGNC:F3),p(HGNC:F7))) => pep(p(HGNC:F9))
-
-
SUBJECT RELATIONSHIP OBJECT(Statement)
-
p(HGNC:VHL) -> (p(HGNC:TNF) -> bp(GOBP:“cell death”))
-
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#object ⇒ Object
Returns the value of attribute object.
-
#relationship ⇒ Object
Returns the value of attribute relationship.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #annotations ⇒ Object
- #annotations=(annotations) ⇒ Object
- #hash ⇒ Object
-
#initialize(subject = nil, relationship = nil, object = nil, comment = nil) ⇒ Statement
constructor
Creates a Statement with
subject
,relationship
, andobject
. - #nested? ⇒ Boolean
- #simple? ⇒ Boolean
- #subject_only? ⇒ Boolean
- #to_bel ⇒ Object (also: #to_s)
- #to_rdf ⇒ Object
- #to_uri ⇒ Object
Constructor Details
#initialize(subject = nil, relationship = nil, object = nil, comment = nil) ⇒ Statement
Creates a BEL::Model::Statement with subject
, relationship
, and object
.
25 26 27 28 29 30 31 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 25 def initialize(subject = nil, relationship = nil, object = nil, comment = nil) @subject = subject @relationship = relationship @object = object @comment = comment @annotations = annotations end |
Instance Attribute Details
#comment ⇒ Object
Returns the value of attribute comment.
15 16 17 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 15 def comment @comment end |
#object ⇒ Object
Returns the value of attribute object.
15 16 17 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 15 def object @object end |
#relationship ⇒ Object
Returns the value of attribute relationship.
15 16 17 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 15 def relationship @relationship end |
#subject ⇒ Object
Returns the value of attribute subject.
15 16 17 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 15 def subject @subject end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
57 58 59 60 61 62 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 57 def ==(other) return false if other == nil @subject == other.subject && @relationship == other.relationship && @object == other.object end |
#annotations ⇒ Object
33 34 35 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 33 def annotations @annotations ||= [] end |
#annotations=(annotations) ⇒ Object
37 38 39 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 37 def annotations=(annotations) @annotations = annotations end |
#hash ⇒ Object
53 54 55 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 53 def hash [@subject, @relationship, @object].hash end |
#nested? ⇒ Boolean
49 50 51 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 49 def nested? @object and @object.is_a? Statement end |
#simple? ⇒ Boolean
45 46 47 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 45 def simple? @object and @object.is_a? Term end |
#subject_only? ⇒ Boolean
41 42 43 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 41 def subject_only? !@relationship end |
#to_bel ⇒ Object Also known as: to_s
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/bel/evidence_model/bel_statement.rb', line 65 def to_bel lbl = case when subject_only? @subject.to_s when simple? "#{@subject.to_s} #{@relationship} #{@object.to_s}" when nested? "#{@subject.to_s} #{@relationship} (#{@object.to_s})" else '' end comment ? lbl + ' //' + comment : lbl end |
#to_rdf ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/bel/extensions/rdf/rdf.rb', line 218 def to_rdf uri = to_uri statements = [] case when subject_only? (sub_uri, sub_statements) = @subject.to_rdf statements << [uri, BEL::RDF::BELV.hasSubject, sub_uri] statements += sub_statements when simple? (sub_uri, sub_statements) = @subject.to_rdf statements += sub_statements (obj_uri, obj_statements) = @object.to_rdf statements += obj_statements rel = BEL::RDF::RELATIONSHIP_TYPE[@relationship.to_s] statements << [uri, BEL::RDF::BELV.hasSubject, sub_uri] statements << [uri, BEL::RDF::BELV.hasObject, obj_uri] statements << [uri, BEL::RDF::BELV.hasRelationship, rel] when nested? (sub_uri, sub_statements) = @subject.to_rdf (nsub_uri, nsub_statements) = @object.subject.to_rdf (nobj_uri, nobj_statements) = @object.object.to_rdf statements += sub_statements statements += nsub_statements statements += nobj_statements rel = BEL::RDF::RELATIONSHIP_TYPE[@relationship.to_s] nrel = BEL::RDF::RELATIONSHIP_TYPE[@object.relationship.to_s] nuri = BEL::RDF::BELR["#{strip_prefix(nsub_uri)}_#{nrel}_#{strip_prefix(nobj_uri)}"] # inner statements << [nuri, BEL::RDF::BELV.hasSubject, nsub_uri] statements << [nuri, BEL::RDF::BELV.hasObject, nobj_uri] statements << [nuri, BEL::RDF::BELV.hasRelationship, nrel] # outer statements << [uri, BEL::RDF::BELV.hasSubject, sub_uri] statements << [uri, BEL::RDF::BELV.hasObject, nuri] statements << [uri, BEL::RDF::BELV.hasRelationship, rel] end # common statement triples statements << [uri, BEL::RDF::RDF.type, BEL::RDF::BELV.Statement] statements << [uri, RDF::RDFS.label, to_s.force_encoding('UTF-8')] # evidence evidence_bnode = BEL::RDF::RDF::Node.uuid statements << [evidence_bnode, BEL::RDF::RDF.type, BEL::RDF::BELV.Evidence] statements << [uri, BEL::RDF::BELV.hasEvidence, evidence_bnode] statements << [evidence_bnode, BEL::RDF::BELV.hasStatement, uri] # citation citation = @annotations.delete('Citation') if citation value = citation.value.map{|x| x.gsub('"', '')} if citation and value[0] == 'PubMed' pid = value[2] statements << [ evidence_bnode, BEL::RDF::BELV.hasCitation, BEL::RDF::RDF::URI(BEL::RDF::PUBMED[pid]) ] end end # evidence evidence_text = @annotations.delete('Evidence') if evidence_text value = evidence_text.value.gsub('"', '').force_encoding('UTF-8') statements << [evidence_bnode, BEL::RDF::BELV.hasEvidenceText, value] end # annotations @annotations.each do |name, anno| name = anno.name.gsub('"', '') if BEL::RDF::const_defined? name annotation_scheme = BEL::RDF::const_get name [anno.value].flatten.map{|x| x.gsub('"', '')}.each do |val| value_uri = BEL::RDF::RDF::URI(Addressable::URI.encode(annotation_scheme[val.to_s])) statements << [evidence_bnode, BEL::RDF::BELV.hasAnnotation, value_uri] end end end return [uri, statements] end |
#to_uri ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/bel/extensions/rdf/rdf.rb', line 183 def to_uri case when subject_only? tid = @subject.to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') BEL::RDF::BELR[URI::encode(tid)] when simple? sub_id = @subject.to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') obj_id = @object.to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') rel = BEL::RDF::RELATIONSHIP_TYPE[@relationship.to_s] if rel rel = rel.path.split('/')[-1] else rel = @relationship.to_s end BEL::RDF::BELR[URI::encode("#{sub_id}_#{rel}_#{obj_id}")] when nested? sub_id = @subject.to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') nsub_id = @object.subject.to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') nobj_id = @object.object.to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_') rel = BEL::RDF::RELATIONSHIP_TYPE[@relationship.to_s] if rel rel = rel.path.split('/')[-1] else rel = @relationship.to_s end nrel = BEL::RDF::RELATIONSHIP_TYPE[@object.relationship.to_s] if nrel nrel = nrel.path.split('/')[-1] else nrel = @object.relationship.to_s end BEL::RDF::BELR[URI::encode("#{sub_id}_#{rel}_#{nsub_id}_#{nrel}_#{nobj_id}")] end end |