<commit_before>require "spec_helper"

RSpec.describe LearnToRank::JudgementsToSvm do
  subject(:formatted) { described_class.new(judgements).svm_format }

  describe "#svm_format" do
    context "when an empty set is provided" do
      let(:judgements) { [] }
      it "returns an empty array" do
        expect(formatted).to eq([])
      end
    end

    context "when judgements are provided" do
      let(:judgements) do
        [
          { query: "tax", rank: 2, features: { "1": 2, "2": 0.1, "3": 10 } },
          { query: "tax", rank: 0, features: { "1": 2, "2": 0.1, "3": 20 } },
          { query: "cat", rank: 3, features: { "2": 2, "3": 0.2, "2": 90 } },
          { query: "sat", rank: 2, features: { "1": 2, "3": 0.1, "2": 10 } },
          { query: "mat", rank: 3, features: { "2": 2, "1": 0.1, "3": 10 } },
          { query: "mat", rank: 1, features: { "1": 2, "2": 0.1, "3": 0 } },
          { query: "hat", rank: 0, features: { "1": 2, "2": 0.1, "3": 0 } },
        ]
      end
      it "returns an array of SVM formatted data" do
        expect(formatted).to eq([
          "2 qid:1 1:2 2:0.1 3:10",
          "0 qid:1 1:2 2:0.1 3:20",
          "3 qid:2 1:0 2:90 3:0.2",
          "2 qid:3 1:2 2:10 3:0.1",
          "3 qid:4 1:0.1 2:2 3:10",
          "1 qid:4 1:2 2:0.1 3:0",
          "0 qid:5 1:2 2:0.1 3:0",
        ])
      end
    end
  end
end
<commit_msg>Fix JudgementsToSvm spec<commit_after>require "spec_helper"

RSpec.describe LearnToRank::JudgementsToSvm do
  subject(:formatted) { described_class.new(judgements).svm_format }

  describe "#svm_format" do
    context "when an empty set is provided" do
      let(:judgements) { [] }
      it "returns an empty array" do
        expect(formatted).to eq([])
      end
    end

    context "when judgements are provided" do
      let(:judgements) do
        [
          { query: "tax", rank: 2, features: { "1": 2, "2": 0.1, "3": 10 } },
          { query: "tax", rank: 0, features: { "1": 2, "2": 0.1, "3": 20 } },
          { query: "cat", rank: 3, features: { "2": 2, "3": 0.2, "1": 90 } },
          { query: "sat", rank: 2, features: { "1": 2, "3": 0.1, "2": 10 } },
          { query: "mat", rank: 3, features: { "2": 2, "1": 0.1, "3": 10 } },
          { query: "mat", rank: 1, features: { "1": 2, "2": 0.1, "3": 0 } },
          { query: "hat", rank: 0, features: { "1": 2, "2": 0.1, "3": 0 } },
        ]
      end
      it "returns an array of SVM formatted data" do
        expect(formatted).to eq([
          "2 qid:1 1:2 2:0.1 3:10",
          "0 qid:1 1:2 2:0.1 3:20",
          "3 qid:2 1:90 2:2 3:0.2",
          "2 qid:3 1:2 2:10 3:0.1",
          "3 qid:4 1:0.1 2:2 3:10",
          "1 qid:4 1:2 2:0.1 3:0",
          "0 qid:5 1:2 2:0.1 3:0",
        ])
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.19978440531800215, 'fraction_numerical': 0.09270571325907294, 'mean_word_length': 1.9711846318036286, 'pattern_counts': {'":': 42, '<': 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': '4326279', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1102, 'n_words': 332}