<commit_before>require 'rdf/linter/rdfa_template'

module RDF::Linter
  module Parser

    # Parse the an input file and re-serialize based on params and/or content-type/accept headers
    def parse(reader_opts)
      graph = RDF::Graph.new
      format = reader_opts[:format]

      case
      when reader_opts[:tempfile]
        RDF::Reader.for(format).new(reader_opts[:tempfile], reader_opts) {|r| graph << r}
      when  reader_opts[:content]
        @content = reader_opts[:content]
        RDF::Reader.for(format).new(@content, reader_opts) {|r| graph << r}
      when reader_opts[:base_uri]
        RDF::Reader.open(reader_opts[:base_uri], reader_opts) {|r| graph << r}
      else
        return ["text/html", ""]
      end

      writer_opts = reader_opts
      writer_opts[:haml] = LINTER_HAML
      writer_opts[:haml_options] = {:ugly => false}
      ["text/html", graph.dump(:rdfa, writer_opts)]
    rescue RDF::ReaderError => e
      @error = "RDF::ReaderError: #{e.message}"<commit_msg>Serialize with standard prefixes defined, if necessary.<commit_after>require 'rdf/linter/rdfa_template'

module RDF::Linter
  module Parser

    # Parse the an input file and re-serialize based on params and/or content-type/accept headers
    def parse(reader_opts)
      graph = RDF::Graph.new
      format = reader_opts[:format]

      case
      when reader_opts[:tempfile]
        RDF::Reader.for(format).new(reader_opts[:tempfile], reader_opts) {|r| graph << r}
      when  reader_opts[:content]
        @content = reader_opts[:content]
        RDF::Reader.for(format).new(@content, reader_opts) {|r| graph << r}
      when reader_opts[:base_uri]
        RDF::Reader.open(reader_opts[:base_uri], reader_opts) {|r| graph << r}
      else
        return ["text/html", ""]
      end

      writer_opts = reader_opts
      writer_opts = reader_opts.merge(
        :standard_prefixes => true,
        :haml => LINTER_HAML
      )
      ["text/html", graph.dump(:rdfa, writer_opts)]
    rescue RDF::ReaderError => e
      @error = "RDF::ReaderError: #{e.message}"
{'fraction_non_alphanumeric': 0.13100436681222707, 'fraction_numerical': 0.0, 'mean_word_length': 3.1488933601609657, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 8, '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': '3709429', 'n_tokens_mistral': 671, 'n_tokens_neox': 664, 'n_words': 144}