Sha256: bb2079a57595747f955af3b3ebbaf5ca9ca92d7b1a31ebdec509ff8e06fa6950

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'open-uri'
require 'net/http'

module Chronicle
  module Schema
    module RDFParsing
      module Schemaorg
        @memoized_graphs = {}

        DEFAULT_NAMESPACE = 'https://schema.org/'.freeze

        def self.graph_for_version(version)
          @memoized_graphs[version] ||= build_graph(version)
        end

        def self.build_graph(version)
          ttl = ttl_for_version(version)
          Chronicle::Schema::RDFParsing::TTLGraphBuilder.build_from_ttl(ttl, default_namespace: DEFAULT_NAMESPACE)
        end

        def self.ttl_for_version(version)
          url = url_for_version(version)
          ttl_via_download(url)
        end

        def self.ttl_via_download(url)
          uri = URI(url)
          response = Net::HTTP.get_response(uri)
          raise "Error: #{response.message}" unless response.is_a?(Net::HTTPSuccess)

          response.body
        end

        def self.seed_graph_from_file(version, file_path)
          ttl = File.read(file_path)
          graph = Chronicle::Schema::RDFParsing::TTLGraphBuilder.build_from_ttl(ttl,
            default_namespace: DEFAULT_NAMESPACE)
          @memoized_graphs[version] = graph
        end

        def self.url_for_version(version)
          # Previously just used this one but it's missing ontologies
          # 'https://raw.githubusercontent.com/schemaorg/schemaorg/main/data/schema.ttl'

          "https://raw.githubusercontent.com/schemaorg/schemaorg/main/data/releases/#{version}/schemaorg-all-https.ttl"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chronicle-core-0.3.0 lib/chronicle/schema/rdf_parsing/schemaorg.rb