<commit_before>require 'open3'
require 'json'
cmd = "gringo ./script/facts.lp ./script/timetabling.lp | clasp --outf=2 --quiet=0 --verbose=0"


def parse_assigned(assigned_string)
  elements = assigned_string.scan(/assigned\((.*),(.*),(.*),(.*)\)/)
  Hash[[:course, :room, :day, :time].zip(*elements)]
end


def parse(output)
json = JSON.parse(output)
witnesses = json["Call"][0]["Witnesses"]
witnesses.each_with_index do |w, i|
  #cost = w["Costs"][0]
  timetable = Timetable.new
  timetable.id = i
  w["Value"].each do |v| 
    assigned_hash = parse_assigned(v)
    entry = TimetableEntry.new
    #entry.cost = cost
    entry.timetable_id = timetable.id
    entry.course = assigned_hash[:course]
    entry.room   = assigned_hash[:room]
    entry.day    = assigned_hash[:day]
    entry.time   = assigned_hash[:time]
    entry.save!
  end
  timetable.save!
end
end


Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
  parse(stdout.read) 
end
<commit_msg>rebased to master, adaption of parser script necessary<commit_after>require 'open3'
require 'json'
cmd = "gringo ./script/facts.lp ./script/timetabling.lp | clasp --outf=2 --quiet=0 --verbose=0"


def parse_assigned(assigned_string)
  elements = assigned_string.scan(/assigned\((.*),(.*),(.*),(.*)\)/)
  Hash[[:course, :room, :day, :time].zip(*elements)]
end


def parse(output)
json = JSON.parse(output)
witnesses = json["Call"][0]["Witnesses"]
witnesses.each_with_index do |w, i|
  #cost = w["Costs"][0]
  timetable = Timetable.new
  timetable.id = i
  w["Value"].each do |v| 
    assigned_hash = parse_assigned(v)
    entry = TimetableEntry.new
    #entry.cost = cost
    entry.timetable_id = timetable.id
    entry.course       = assigned_hash[:course]
    entry.room_id      = assigned_hash[:room]
    entry.weekday_id   = assigned_hash[:day]
    entry.timeframe_id = assigned_hash[:time]
    entry.save!
  end
  timetable.save!
end
end


Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
  parse(stdout.read) 
end

{'fraction_non_alphanumeric': 0.16171284634760705, 'fraction_numerical': 0.008060453400503778, 'mean_word_length': 3.9158415841584158, 'pattern_counts': {'":': 0, '<': 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': '1428379', 'n_tokens_mistral': 769, 'n_tokens_neox': 728, 'n_words': 145}