<commit_before>require 'ubl/invoice'
require 'xa/transforms/parse'

namespace :db do
  desc "add a new user"
  task :add_user, [:email, :password, :fullname] => :environment do |t, args|
    args.with_defaults(fullname: args.email)
    
    if args.email && args.password
      u = User.find_by_email(args.email)
      if u.nil?
        puts "# creating user (email=#{args.email})"
        User.create(email: args.email, full_name: args.fullname, password: args.password)
      else
        puts "# user exists (email=#{args.email})"
      end
    else
      puts "! email and password are required"
    end
  end

  desc 'update rule reference'
  task :update_rule_reference, [:rule_id, :rule_ref] => :environment do |t, args|
    rm = Rule.find_by(public_id: args.rule_id)
    rm.update_attributes(reference: args.rule_ref)
  end
  
  desc 'add testing document'
  task :add_document, [:user_id, :path, :transform_path, :rule_ref] => :environment do |t, args|
    class InvoiceParser
      include UBL::Invoice
    end
<commit_msg>Rake task to list the rules<commit_after>require 'ubl/invoice'
require 'xa/transforms/parse'

namespace :db do
  desc "add a new user"
  task :add_user, [:email, :password, :fullname] => :environment do |t, args|
    args.with_defaults(fullname: args.email)
    
    if args.email && args.password
      u = User.find_by_email(args.email)
      if u.nil?
        puts "# creating user (email=#{args.email})"
        User.create(email: args.email, full_name: args.fullname, password: args.password)
      else
        puts "# user exists (email=#{args.email})"
      end
    else
      puts "! email and password are required"
    end
  end

  desc 'list all rules'
  task :list_rules, [] => :environment do |t, args|
    Rule.all.each do |rm|
      puts "id=#{rm.public_id}; reference=#{rm.reference}"
    end
  end
  
  desc 'update rule reference'
  task :update_rule_reference, [:rule_id, :rule_ref] => :environment do |t, args|
    rm = Rule.find_by(public_id: args.rule_id)
    rm.update_attributes(reference: args.rule_ref)
    rm.reload
    puts "id=#{rm.public_id}; reference=#{rm.reference}"
  end
  
  desc 'add testing document'
  task :add_document, [:user_id, :path, :transform_path, :rule_ref] => :environment do |t, args|
    class InvoiceParser
      include UBL::Invoice
    end

{'fraction_non_alphanumeric': 0.1258050665521683, 'fraction_numerical': 0.0, 'mean_word_length': 3.2673992673992673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, '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': '2834194', 'n_tokens_mistral': 783, 'n_tokens_neox': 786, 'n_words': 211}