<commit_before>class VirtuosoPlugin::TriplesTemplate < Article

  def self.short_description
    _('Triples template')
  end

  def self.description
    _('Triples template')
  end

  def self.initial_template
    '
      {% for row in results %}
        <div>
          {{row}}
        </div>
      {% endfor %}
    '
  end

  settings_items :query, :type => :string
  settings_items :template, :type => :string, :default => initial_template
  settings_items :stylesheet, :type => :string

  attr_accessible :query, :template, :stylesheet

  def to_html(options = {})
    article = self
    proc do
      render :file => 'content_viewer/triples_template', :locals => {:article => article}
    end
  end

  def plugin
    @plugin ||= VirtuosoPlugin.new(self)
  end

  def template_content
    begin
      results = plugin.virtuoso_readonly_client.query(query)
      liquid_template = Liquid::Template.parse(template)
      page = liquid_template.render('results' => results)
      transform_html(page)
    rescue => ex
      logger.info ex.to_s
      "Failed to process the template"
    end
  end

  protected

  def transform_html(html)
    document = Roadie::Document.new(html)
    document.add_css(stylesheet) if stylesheet.present?
    document.transform
  end

end
<commit_msg>virtuoso: added infra for pagination<commit_after>class VirtuosoPlugin::TriplesTemplate < Article

  def self.short_description
    _('Triples template')
  end

  def self.description
    _('Triples template')
  end

  def self.initial_template
    '
      {% for row in results %}
        <div>
          {{row}}
        </div>
      {% endfor %}
    '
  end

  settings_items :query, :type => :string
  settings_items :template, :type => :string, :default => initial_template
  settings_items :stylesheet, :type => :string
  settings_items :per_page, :type => :integer, :default => 50

  attr_accessible :query, :template, :stylesheet

  def to_html(options = {})
    article = self
    proc do
      render :file => 'content_viewer/triples_template', :locals => {:article => article}
    end
  end

  def plugin
    @plugin ||= VirtuosoPlugin.new(self)
  end

  def template_content(page=1)
    begin
      results = plugin.virtuoso_readonly_client.query(query).paginate({:per_page => per_page, :page => page})
      liquid_template = Liquid::Template.parse(template)
      rendered_template = liquid_template.render('results' => results)
      transform_html(rendered_template)
    rescue => ex
      logger.info ex.to_s
      "Failed to process the template"
    end
  end

  protected

  def transform_html(html)
    document = Roadie::Document.new(html)
    document.add_css(stylesheet) if stylesheet.present?
    document.transform
  end

end

{'fraction_non_alphanumeric': 0.10607168983174835, 'fraction_numerical': 0.0010972933430870519, 'mean_word_length': 3.150227617602428, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 29, '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': '2492779', 'n_tokens_mistral': 861, 'n_tokens_neox': 818, 'n_words': 201}