<commit_before>require 'facter'
require 'jgrep'

module FacterDB

  def self.get_os_facts(facter_version='*', filter=[])
    filter_str = filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(' or ')

    jsons = Dir.glob("facts/#{facter_version}/*.facts").map { |f| File.read(f) }
    json = "[#{jsons.join(',')}]\n"
    JGrep.jgrep(json, filter_str)
  end
end<commit_msg>Use a relative factsdir for the lib<commit_after>require 'facter'
require 'jgrep'

module FacterDB

  def self.get_os_facts(facter_version='*', filter=[])
    facts_dir = File.expand_path(File.join(File.dirname(__FILE__), '../facts'))
    filter_str = filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(' or ')

    jsons = Dir.glob("#{facts_dir}/#{facter_version}/*.facts").map { |f| File.read(f) }
    json = "[#{jsons.join(',')}]\n"
    JGrep.jgrep(json, filter_str)
  end
end
{'fraction_non_alphanumeric': 0.22360953461975028, 'fraction_numerical': 0.0, 'mean_word_length': 4.157894736842105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3047470', 'n_tokens_mistral': 366, 'n_tokens_neox': 357, 'n_words': 66}