<commit_before>module Sirportly
  class KnowledgeBase

    attr_accessor :id
    
    class << self
      def list
        Request.request('knowledge/list')
      end

      def find_by_id(id)
        Request.request('knowledge/tree', :kb => id)
        self.new(id)
      rescue Errors::NotFound
        false
      end
    end

    def initialize(id)
      self.id = id
    end

    def page(path)
      request('page', :path => path)
    end

    def tree
      request('tree')
    end

    def add_page(options = {})
      request('add_page', options)
    end

    def edit_page(path, options = {})
      options[:path] = path
      request('edit_page', options)
    end

    def delete_page(path)
      request('delete_page', :path => path)
    end
    
    private

    def request(path, options = {})
      options[:kb] = self.id<commit_msg>avoid needing to load a tree twice<commit_after>module Sirportly
  class KnowledgeBase

    attr_accessor :id
    
    class << self
      def list
        Request.request('knowledge/list')
      end

      def find_by_id(id)
        tree = Request.request('knowledge/tree', :kb => id)
        self.new(id, tree = tree)
      rescue Errors::NotFound
        false
      end
    end

    def initialize(id, tree = nil)
      @id = id
      @tree = tree
    end

    def page(path)
      request('page', :path => path)
    end

    def tree
      @tree ||= request('tree')
    end

    def add_page(options = {})
      request('add_page', options)
    end

    def edit_page(path, options = {})
      options[:path] = path
      request('edit_page', options)
    end

    def delete_page(path)
      request('delete_page', :path => path)
    end
    
    private

    def request(path, options = {})
      options[:kb] = self.id
{'fraction_non_alphanumeric': 0.11104847801578353, 'fraction_numerical': 0.0, 'mean_word_length': 2.0238500851788754, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '2112635', 'n_tokens_mistral': 563, 'n_tokens_neox': 545, 'n_words': 139}