<commit_before>require 'erb'
require 'rdf'
require 'rdf/vocab'
require 'rdf/jena'

require_relative 'reader'
require_relative 'lru_reader'
require_relative 'concept'
require_relative 'concept_scheme'

module BELParser
  module Resource
    class JenaTDBReader
      include Reader
      prepend LRUReader

      BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
      SKOS = RDF::Vocab::SKOS
      DC   = RDF::Vocab::DC
      VALUE_PREDICATE_ORDER = [
        SKOS.prefLabel,
        DC.identifier,
        DC.title,
        SKOS.altLabel
      ]

      def initialize(tdb_directory_path)
        @rdf = RDF::Jena::Repository.new(tdb_directory_path)
      end

      def retrieve_resource(identifier)
        uri   = RDF::URI(identifier)
        domain, prefix, pref_label = nil
        types                      = []
        @rdf.query([:subject => uri]).each do |solution|
          case solution.predicate
          when RDF.type
            types << solution.object
          when BELV.domain
            domain = solution.object.to_s
          when BELV.prefix
            prefix = solution.object.to_s
          when SKOS.prefLabel
            pref_label = solution.object.to_s
          end
        end
        return nil unless types.any?(&method(:scheme_class?))
        ConceptScheme.new(uri, domain, prefix, pref_label, types)
      end
<commit_msg>correct jena tdb reader to only expose strings<commit_after>require 'erb'
require 'rdf'
require 'rdf/vocab'
require 'rdf/jena'

require_relative 'reader'
require_relative 'lru_reader'
require_relative 'concept'
require_relative 'concept_scheme'

module BELParser
  module Resource
    class JenaTDBReader
      include Reader
      prepend LRUReader

      BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
      SKOS = RDF::Vocab::SKOS
      DC   = RDF::Vocab::DC
      VALUE_PREDICATE_ORDER = [
        SKOS.prefLabel,
        DC.identifier,
        DC.title,
        SKOS.altLabel
      ]

      def initialize(tdb_directory_path)
        @rdf = RDF::Jena::Repository.new(tdb_directory_path)
      end

      def retrieve_resource(identifier)
        uri   = RDF::URI(identifier)
        domain, prefix, pref_label = nil
        types                      = []
        @rdf.query([:subject => uri]).each do |solution|
          case solution.predicate
          when RDF.type
            types << solution.object
          when BELV.domain
            domain = solution.object.to_s
          when BELV.prefix
            prefix = solution.object.to_s
          when SKOS.prefLabel
            pref_label = solution.object.to_s
          end
        end
        return nil unless types.any?(&method(:scheme_class?))
        ConceptScheme.new(uri.to_s, domain, prefix, pref_label, types.map(&:to_s))
      end

{'fraction_non_alphanumeric': 0.0913633119200571, 'fraction_numerical': 0.0, 'mean_word_length': 2.170814479638009, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4030839', 'n_tokens_mistral': 883, 'n_tokens_neox': 860, 'n_words': 177}