<commit_before>#include "helper_functions.h"
#include "operator.h"
#include "variable.h"

#include <cassert>
#include <iostream>
#include <fstream>
using namespace std;

Operator::Operator(istream &in, const vector<Variable *> &variables) {
    check_magic(in, "begin_operator");
    in >> ws;
    getline(in, name);
    int varNo;
    compoperator cop;
    in >> cop >> varNo;
    duration_cond = DurationCond(cop, variables[varNo]);
    int count;
    variables[varNo]->set_used_in_duration_condition();
    in >> count; // number of prevail at-start conditions
    for(int i = 0; i < count; i++) {
        int varNo, val;
        in >> varNo >> val;
        prevail_start.push_back(Prevail(variables[varNo], val));
    }
    in >> count; // number of prevail overall conditions
    for(int i = 0; i < count; i++) {
        int varNo, val;
        in >> varNo >> val;
        prevail_overall.push_back(Prevail(variables[varNo], val));
    }
    in >> count; // number of prevail at-end conditions
    for(int i = 0; i < count; i++) {
        int varNo, val;
        in >> varNo >> val;
        prevail_end.push_back(Prevail(variables[varNo], val));
    }
    in >> count; // number of pre_post_start conditions
    for(int i = 0; i < count; i++) {
        int eff_conds;
        vector<EffCond> ecs_start;
        vector<EffCond> ecs_overall;
        vector<EffCond> ecs_end;
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_start.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_overall.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_end.push_back(EffCond(variables[var], value));
        }
        string effect;
        in >> effect;
        if(effect.at(0) != 'm') {
            int varNo = atoi(effect.c_str());
            if(variables[varNo]->is_functional()) {
                foperator assignop;
                int varNo2;
                in >> assignop >> varNo2;
                if(eff_conds)
                    numerical_effs_start.push_back(NumericalEffect(
                            variables[varNo], ecs_start, ecs_overall, ecs_end,
                            assignop, variables[varNo2]));
                else
                    numerical_effs_start.push_back(NumericalEffect(
                            variables[varNo], assignop, variables[varNo2]));
            } else {
                int val, newVal;
                in >> val >> newVal;
                if(eff_conds)
                    pre_post_start.push_back(PrePost(variables[varNo], ecs_start,
                            ecs_overall, ecs_end, val, newVal));
                else
                    pre_post_start.push_back(PrePost(variables[varNo], val, newVal));
            }
        } else {
            if (eff_conds)
                module_effs_start.push_back(ModuleEffect(effect, ecs_start,
                        ecs_overall, ecs_end));
            else
                module_effs_start.push_back(ModuleEffect(effect));
        }
    }
    in >> count; // number of pre_post_end conditions
    for(int i = 0; i < count; i++) {
        int eff_conds;
        vector<EffCond> ecs_start;
        vector<EffCond> ecs_overall;
        vector<EffCond> ecs_end;
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_start.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_overall.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_end.push_back(EffCond(variables[var], value));
        }
        string effect;
        in >> effect;
        if(effect.at(0) != 'm') {
            int varNo = atoi(effect.c_str());
            if(variables[varNo]->is_functional()) {
                foperator assignop;
                int varNo2;
                in >> assignop >> varNo2;
                if(eff_conds)
                    numerical_effs_end.push_back(NumericalEffect(variables[varNo],
                            ecs_start, ecs_overall, ecs_end, assignop,
                            variables[varNo2]));
                else
                    numerical_effs_end.push_back(NumericalEffect(variables[varNo],
                            assignop, variables[varNo2]));
            } else {
                int val, newVal;
                in >> val >> newVal;
                if(eff_conds)
                    pre_post_end.push_back(PrePost(variables[varNo], ecs_start,
                            ecs_overall, ecs_end, val, newVal));
                else
                    pre_post_end.push_back(PrePost(variables[varNo], val, newVal));
            }
        } else {
            if (eff_conds)
                module_effs_start.push_back(ModuleEffect(effect, ecs_start,
                        ecs_overall, ecs_end));
            else
                module_effs_start.push_back(ModuleEffect(effect));
        }
    }
    check_magic(in, "end_operator");
}

void Operator::dump() const {
    cout << name << ":" << endl;
    cout << "duration:" << duration_cond.op << " "
        << duration_cond.var->get_name();
    cout << endl;
    cout << "prevail (at-start):";
    for(int i = 0; i < prevail_start.size(); i++)
        cout << "  " << prevail_start[i].var->get_name() << " := "
            << prevail_start[i].prev;
    cout << endl;
    cout << "prevail (overall):";
    for(int i = 0; i < prevail_overall.size(); i++)
        cout << "  " << prevail_overall[i].var->get_name() << " := "
            << prevail_overall[i].prev;
    cout << endl;
    cout << "prevail (at-end):";
    for(int i = 0; i < prevail_end.size(); i++)<commit_msg>fixed bug where end module effects are parsed as start<commit_after>#include "helper_functions.h"
#include "operator.h"
#include "variable.h"

#include <cassert>
#include <iostream>
#include <fstream>
using namespace std;

Operator::Operator(istream &in, const vector<Variable *> &variables) {
    check_magic(in, "begin_operator");
    in >> ws;
    getline(in, name);
    int varNo;
    compoperator cop;
    in >> cop >> varNo;
    duration_cond = DurationCond(cop, variables[varNo]);
    int count;
    variables[varNo]->set_used_in_duration_condition();
    in >> count; // number of prevail at-start conditions
    for(int i = 0; i < count; i++) {
        int varNo, val;
        in >> varNo >> val;
        prevail_start.push_back(Prevail(variables[varNo], val));
    }
    in >> count; // number of prevail overall conditions
    for(int i = 0; i < count; i++) {
        int varNo, val;
        in >> varNo >> val;
        prevail_overall.push_back(Prevail(variables[varNo], val));
    }
    in >> count; // number of prevail at-end conditions
    for(int i = 0; i < count; i++) {
        int varNo, val;
        in >> varNo >> val;
        prevail_end.push_back(Prevail(variables[varNo], val));
    }
    in >> count; // number of pre_post_start conditions
    for(int i = 0; i < count; i++) {
        int eff_conds;
        vector<EffCond> ecs_start;
        vector<EffCond> ecs_overall;
        vector<EffCond> ecs_end;
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_start.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_overall.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_end.push_back(EffCond(variables[var], value));
        }
        string effect;
        in >> effect;
        if(effect.at(0) != 'm') {
            int varNo = atoi(effect.c_str());
            if(variables[varNo]->is_functional()) {
                foperator assignop;
                int varNo2;
                in >> assignop >> varNo2;
                if(eff_conds)
                    numerical_effs_start.push_back(NumericalEffect(
                            variables[varNo], ecs_start, ecs_overall, ecs_end,
                            assignop, variables[varNo2]));
                else
                    numerical_effs_start.push_back(NumericalEffect(
                            variables[varNo], assignop, variables[varNo2]));
            } else {
                int val, newVal;
                in >> val >> newVal;
                if(eff_conds)
                    pre_post_start.push_back(PrePost(variables[varNo], ecs_start,
                            ecs_overall, ecs_end, val, newVal));
                else
                    pre_post_start.push_back(PrePost(variables[varNo], val, newVal));
            }
        } else {
            if (eff_conds)
                module_effs_start.push_back(ModuleEffect(effect, ecs_start,
                        ecs_overall, ecs_end));
            else
                module_effs_start.push_back(ModuleEffect(effect));
        }
    }
    in >> count; // number of pre_post_end conditions
    for(int i = 0; i < count; i++) {
        int eff_conds;
        vector<EffCond> ecs_start;
        vector<EffCond> ecs_overall;
        vector<EffCond> ecs_end;
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_start.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_overall.push_back(EffCond(variables[var], value));
        }
        in >> eff_conds;
        for(int j = 0; j < eff_conds; j++) {
            int var, value;
            in >> var >> value;
            ecs_end.push_back(EffCond(variables[var], value));
        }
        string effect;
        in >> effect;
        if(effect.at(0) != 'm') {
            int varNo = atoi(effect.c_str());
            if(variables[varNo]->is_functional()) {
                foperator assignop;
                int varNo2;
                in >> assignop >> varNo2;
                if(eff_conds)
                    numerical_effs_end.push_back(NumericalEffect(variables[varNo],
                            ecs_start, ecs_overall, ecs_end, assignop,
                            variables[varNo2]));
                else
                    numerical_effs_end.push_back(NumericalEffect(variables[varNo],
                            assignop, variables[varNo2]));
            } else {
                int val, newVal;
                in >> val >> newVal;
                if(eff_conds)
                    pre_post_end.push_back(PrePost(variables[varNo], ecs_start,
                            ecs_overall, ecs_end, val, newVal));
                else
                    pre_post_end.push_back(PrePost(variables[varNo], val, newVal));
            }
        } else {
            if (eff_conds)
                module_effs_end.push_back(ModuleEffect(effect, ecs_start,
                        ecs_overall, ecs_end));
            else
                module_effs_end.push_back(ModuleEffect(effect));
        }
    }
    check_magic(in, "end_operator");
}

void Operator::dump() const {
    cout << name << ":" << endl;
    cout << "duration:" << duration_cond.op << " "
        << duration_cond.var->get_name();
    cout << endl;
    cout << "prevail (at-start):";
    for(int i = 0; i < prevail_start.size(); i++)
        cout << "  " << prevail_start[i].var->get_name() << " := "
            << prevail_start[i].prev;
    cout << endl;
    cout << "prevail (overall):";
    for(int i = 0; i < prevail_overall.size(); i++)
        cout << "  " << prevail_overall[i].var->get_name() << " := "
            << prevail_overall[i].prev;
    cout << endl;
    cout << "prevail (at-end):";
    for(int i = 0; i < prevail_end.size(); i++)
{'fraction_non_alphanumeric': 0.12679100296165852, 'fraction_numerical': 0.0038421516048987433, 'mean_word_length': 1.6938335489435101, 'pattern_counts': {'":': 2, '<': 135, '<?xml version=': 0, '>': 203, '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': '2969981', 'n_tokens_mistral': 3976, 'n_tokens_neox': 3849, 'n_words': 810}