<commit_before>
import { Relationship, Equality, Addition, Subtraction, Multiplication, Division } from "Relationships";
import { Connector, Variable, Constant } from "Connectors";

declare var Proxy;
type Proxy = any;

type Value = string | number | Connector;

export default class System {

  public $: Proxy;

  private relationships: Relationship[] = [];
  private variables:  { [name: string]: Variable; } = Object.create(null);
  private variableId = 0;

  constructor() {
    this.$ = this.proxy();
  }

  /**
   * Checks if a variable exists
   */
  has(name: string): boolean {
    return name in this.variables;
  }

  /**
   * Get a variable's value
   */
  get(name: string): number {
    return this.getVariable(name).getValue();
  }

  /**
   * Set a variable's value
   */
  set(name: string, v: number|string|any[]): void {
    this.clear(name);
    if (typeof v === "number") {
      this.getVariable(name).setValue(v);
      return;
    }
    if (typeof v === "string") {
      this.equals(name, v);
      return
    }
    if (Array.isArray(v)) {
      this.equals(name, this.evalute(v));
      return;
    }
  }

  /**
   * Clear a variable's value. If a variable name is not passed, all are cleared.
   */
  clear(name?: string): void {
    if (name) {
      this.getVariable(name).clearValue();
    } else {
      Object.keys(this.variables).forEach(name => this.clear(name))
    }
  }

  /**
   * Reset the whole system
   */
  reset(): void {
    this.variableId = 0;
    this.variables = Object.create(null);
    this.relationships = [];
  }

  /**
   * left = right
   */
  equals(left: Value, right: Value): void {
    this.relationships.push(new Equality(
      this.connectorFor(left),
      this.connectorFor(right)
    ));
  }

  /**
   * sum = addend1 + addend2
   */
  add(sum: Value, addend1: Value, addend2: Value): void {
    this.relationships.push(new Addition(
      this.connectorFor(addend1),
      this.connectorFor(addend2),
      this.connectorFor(sum)
    ));
  }

  /**
   * difference = minuend - subtrahend
   */
  subtract(difference: Value, minuend: Value, subtrahend: Value): void {
    this.relationships.push(new Subtraction(
      this.connectorFor(minuend),
      this.connectorFor(subtrahend),
      this.connectorFor(difference)
    ));
  }

  /**
   * product = mult1 * mult2
   */
  multiply(product: Value, mult1: Value, mult2: Value): void {
    this.relationships.push(new Multiplication(
      this.connectorFor(mult1),
      this.connectorFor(mult2),
      this.connectorFor(product)
    ));
  }

  /**
   * quotient = dividend / divisor
   */
  divide(quotient: Value, dividend: Value, divisor: Value): void {
    this.relationships.push(new Division(
      this.connectorFor(dividend),
      this.connectorFor(divisor),
      this.connectorFor(quotient)
    ));
  }

  private evalute(ast: any): Connector {
    if (Array.isArray(ast)) {
      if (ast.length !== 3) {
        throw new Error(`Syntax Error: ${ast}`);
      }
      let operator = ast[0];
      let param1 = this.evalute(ast[1]);
      let param2 = this.evalute(ast[2]);
      let result = this.createIntermediate();
      switch (operator) {
        case "+":
          this.add(result, param1, param2);
          break;
        case "-":
          this.subtract(result, param1, param2);
          break;
        case "*":
          this.multiply(result, param1, param2);
          break;
        case "/":
          this.divide(result, param1, param2);
          break;
        default:
          throw new Error(`Syntax Error: invalid operator ${operator}`);
      }
      return result;
    } else {
      return this.connectorFor(ast);
    }
  }

  /**
   * Dump all the relationships as strings
   */
  toString(): string {
    return this.relationships.map(rel => rel.toString()).join("\n");
  }

  private getVariable(name: string): Variable {
    if (!this.has(name)) {
      this.variables[name] = new Variable(name);
    }
    return this.variables[name];
  }

  private createIntermediate(): Variable {
    let id = this.variableId++;
    return this.getVariable(`$${id}`);
  }

  private connectorFor(v: Value): Connector {<commit_msg>Rename property<commit_after>
import { Relationship, Equality, Addition, Subtraction, Multiplication, Division } from "Relationships";
import { Connector, Variable, Constant } from "Connectors";

declare var Proxy;
type Proxy = any;

type Value = string | number | Connector;

export default class System {

  public $: Proxy;

  private relationships: Relationship[];
  private variables:     { [name: string]: Variable; };
  private idsequence:    number;

  constructor() {
    this.reset();
    this.$ = this.proxy();
  }

  /**
   * Checks if a variable exists
   */
  has(name: string): boolean {
    return name in this.variables;
  }

  /**
   * Get a variable's value
   */
  get(name: string): number {
    return this.getVariable(name).getValue();
  }

  /**
   * Set a variable's value
   */
  set(name: string, v: number|string|any[]): void {
    this.clear(name);
    if (typeof v === "number") {
      this.getVariable(name).setValue(v);
      return;
    }
    if (typeof v === "string") {
      this.equals(name, v);
      return
    }
    if (Array.isArray(v)) {
      this.equals(name, this.evalute(v));
      return;
    }
  }

  /**
   * Clear a variable's value. If a variable name is not passed, all are cleared.
   */
  clear(name?: string): void {
    if (name) {
      this.getVariable(name).clearValue();
    } else {
      Object.keys(this.variables).forEach(name => this.clear(name))
    }
  }

  /**
   * Reset the whole system
   */
  reset(): void {
    this.idsequence = 0;
    this.variables = Object.create(null);
    this.relationships = [];
  }

  /**
   * left = right
   */
  equals(left: Value, right: Value): void {
    this.relationships.push(new Equality(
      this.connectorFor(left),
      this.connectorFor(right)
    ));
  }

  /**
   * sum = addend1 + addend2
   */
  add(sum: Value, addend1: Value, addend2: Value): void {
    this.relationships.push(new Addition(
      this.connectorFor(addend1),
      this.connectorFor(addend2),
      this.connectorFor(sum)
    ));
  }

  /**
   * difference = minuend - subtrahend
   */
  subtract(difference: Value, minuend: Value, subtrahend: Value): void {
    this.relationships.push(new Subtraction(
      this.connectorFor(minuend),
      this.connectorFor(subtrahend),
      this.connectorFor(difference)
    ));
  }

  /**
   * product = mult1 * mult2
   */
  multiply(product: Value, mult1: Value, mult2: Value): void {
    this.relationships.push(new Multiplication(
      this.connectorFor(mult1),
      this.connectorFor(mult2),
      this.connectorFor(product)
    ));
  }

  /**
   * quotient = dividend / divisor
   */
  divide(quotient: Value, dividend: Value, divisor: Value): void {
    this.relationships.push(new Division(
      this.connectorFor(dividend),
      this.connectorFor(divisor),
      this.connectorFor(quotient)
    ));
  }

  private evalute(ast: any): Connector {
    if (Array.isArray(ast)) {
      if (ast.length !== 3) {
        throw new Error(`Syntax Error: ${ast}`);
      }
      let operator = ast[0];
      let param1 = this.evalute(ast[1]);
      let param2 = this.evalute(ast[2]);
      let result = this.createIntermediate();
      switch (operator) {
        case "+":
          this.add(result, param1, param2);
          break;
        case "-":
          this.subtract(result, param1, param2);
          break;
        case "*":
          this.multiply(result, param1, param2);
          break;
        case "/":
          this.divide(result, param1, param2);
          break;
        default:
          throw new Error(`Syntax Error: invalid operator ${operator}`);
      }
      return result;
    } else {
      return this.connectorFor(ast);
    }
  }

  /**
   * Dump all the relationships as strings
   */
  toString(): string {
    return this.relationships.map(rel => rel.toString()).join("\n");
  }

  private getVariable(name: string): Variable {
    if (!this.has(name)) {
      this.variables[name] = new Variable(name);
    }
    return this.variables[name];
  }

  private createIntermediate(): Variable {
    let id = this.idsequence++;
    return this.getVariable(`$${id}`);
  }

  private connectorFor(v: Value): Connector {
{'fraction_non_alphanumeric': 0.14388231072838178, 'fraction_numerical': 0.006578160507116374, 'mean_word_length': 2.5282700421940927, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 7, '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': '7091238', 'n_tokens_mistral': 2702, 'n_tokens_neox': 2615, 'n_words': 595}