Class: BEL::BELRDF::StatementConverter
- Inherits:
-
Object
- Object
- BEL::BELRDF::StatementConverter
- Includes:
- RDFConverter
- Defined in:
- lib/bel/translator/plugins/rdf2/statement_converter.rb
Instance Method Summary collapse
-
#convert(bel_statement) ⇒ RDF::Graph
Convert a BELParser::Expression::Model::Statement to RDF::Graph of RDF statements.
-
#initialize(term_converter, relationship_converter) ⇒ StatementConverter
constructor
A new instance of StatementConverter.
Methods included from RDFConverter
Constructor Details
#initialize(term_converter, relationship_converter) ⇒ StatementConverter
Returns a new instance of StatementConverter.
9 10 11 12 |
# File 'lib/bel/translator/plugins/rdf2/statement_converter.rb', line 9 def initialize(term_converter, relationship_converter) @term_converter = term_converter @rel_converter = relationship_converter end |
Instance Method Details
#convert(bel_statement) ⇒ RDF::Graph
Convert a BELParser::Expression::Model::Statement to RDF::Graph of RDF statements.
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 |
# File 'lib/bel/translator/plugins/rdf2/statement_converter.rb', line 19 def convert(bel_statement) # Dive into subject sub_part, sub_uri, subg = @term_converter.convert(bel_statement.subject) # Dive into object case when bel_statement.simple? obj_part, obj_uri, objg = @term_converter.convert(bel_statement.object) rel_part, rel_uri = @rel_converter.convert(bel_statement.relationship) path_part = "#{sub_part}_#{rel_part}_#{obj_part}" stmt_uri = BELR[URI::encode(path_part)] sg = RDF::Graph.new sg << subg sg << objg sg << s(stmt_uri, RDF.type, BELV2_0.Statement) sg << s(stmt_uri, BELV2_0.hasSubject, sub_uri) sg << s(stmt_uri, BELV2_0.hasObject, obj_uri) sg << s(stmt_uri, BELV2_0.hasRelationship, rel_uri) if rel_uri when bel_statement.nested? obj_part, obj_uri, objg = convert(bel_statement.object) rel_part, rel_uri = @rel_converter.convert(bel_statement.relationship) path_part = "#{sub_part}_#{rel_part}_#{obj_part}" stmt_uri = BELR[URI::encode(path_part)] sg = RDF::Graph.new sg << subg sg << objg sg << s(stmt_uri, RDF.type, BELV2_0.Statement) sg << s(stmt_uri, BELV2_0.hasSubject, sub_uri) sg << s(stmt_uri, BELV2_0.hasObject, obj_uri) sg << s(stmt_uri, BELV2_0.hasRelationship, rel_uri) if rel_uri else path_part = sub_part stmt_uri = BELR[URI::encode(path_part)] sg = RDF::Graph.new sg << subg sg << s(stmt_uri, RDF.type, BELV2_0.Statement) sg << s(stmt_uri, BELV2_0.hasSubject, sub_uri) end [path_part, stmt_uri, sg] end |