Class: Chronicle::Schema::RDFParsing::TTLGraphBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl_str, default_namespace: 'https://schema.org/') ⇒ TTLGraphBuilder

Returns a new instance of TTLGraphBuilder.



13
14
15
16
17
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 13

def initialize(ttl_str, default_namespace: 'https://schema.org/')
  @ttl_str = ttl_str
  @default_namespace = default_namespace
  @graph = Chronicle::Schema::SchemaGraph.new(default_namespace:)
end

Instance Attribute Details

#graphObject (readonly)

Returns the value of attribute graph.



11
12
13
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 11

def graph
  @graph
end

#ttl_graphObject (readonly)

Returns the value of attribute ttl_graph.



11
12
13
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 11

def ttl_graph
  @ttl_graph
end

#ttl_strObject (readonly)

Returns the value of attribute ttl_str.



11
12
13
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 11

def ttl_str
  @ttl_str
end

Class Method Details

.build_from_file(file_path, default_namespace:) ⇒ Object



31
32
33
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 31

def self.build_from_file(file_path, default_namespace:)
  new(File.read(file_path), default_namespace:).build
end

.build_from_ttl(ttl_str, default_namespace:) ⇒ Object



35
36
37
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 35

def self.build_from_ttl(ttl_str, default_namespace:)
  new(ttl_str, default_namespace:).build
end

Instance Method Details

#buildObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/chronicle/schema/rdf_parsing/ttl_graph_builder.rb', line 19

def build
  reader = RDF::Reader.for(:ttl).new(@ttl_str)
  @ttl_graph = RDF::Graph.new << reader

  @graph.version = get_version
  @graph.types = build_type_graph
  @graph.properties = build_property_graph
  # build_datatype_graph
  @graph.build_references!
  @graph
end