<commit_before>import {Component, Input, OnInit} from '@angular/core';
import {BasicLogicPhraseParser} from "../phrase/basic-logic-phrase-parser";
import {LogicPhrase} from "../phrase/logic-phrase";
import {BasicLogicPhraseInfoComponent} from "../basic-logic-phrase-info/basic-logic-phrase-info.component";
import {KVDiagramComponent} from "../kvdiagram/kvdiagram.component";
import {LogicRootExpression} from "../logicExpression/logic-root-expression";
import * as _ from 'lodash';

@Component({
  selector: 'app-logic-input',
  templateUrl: './logic-input.component.html',
  styleUrls: ['./logic-input.component.css'],
  providers: [BasicLogicPhraseParser]
})
export class LogicInputComponent implements OnInit {
  @Input()
  basicLogicPhraseInfoCom: BasicLogicPhraseInfoComponent;
  @Input()
  kvDiagramCom: KVDiagramComponent;

  logicPhraseString = "";
  logicExtraVars = "";
  private logicPhrase: LogicPhrase;
  private logicDNFPhrase: LogicPhrase;

  constructor(private basicLogicPhraseParser: BasicLogicPhraseParser) { }

  ngOnInit() {
  }

  parseLogicPhrase() {

    this.kvDiagramCom.logicInputCom = this;

    let separatedVariableString = separateVariables(this.logicPhraseString);

    let logicRootExpression = new LogicRootExpression();
    logicRootExpression.parseLogicString(separatedVariableString);

    let logicExpressionInDNF: LogicRootExpression = _.cloneDeep(logicRootExpression);
    logicExpressionInDNF.toDNF();

    this.basicLogicPhraseInfoCom.logicRootExpression = logicRootExpression;
    this.basicLogicPhraseInfoCom.logicRootExpressionInDNF = logicExpressionInDNF;

    this.logicDNFPhrase = this.basicLogicPhraseParser.parse(logicExpressionInDNF.phraseToStringWithoutBreakets(), this.logicExtraVars);
    this.logicPhrase = this.basicLogicPhraseParser.parse(separatedVariableString, this.logicExtraVars);

    this.basicLogicPhraseInfoCom.logicPhrase = this.logicPhrase;

    this.kvDiagramCom.parse(this.logicDNFPhrase);
  }


  updateDNF(newDnf: string) {
    let logicRootExpression = new LogicRootExpression();
    logicRootExpression.parseLogicString(newDnf);
    this.basicLogicPhraseInfoCom.logicRootExpressionInDNF = logicRootExpression;
  }

  separateVariables(oldString: string) {
    var array = oldString.split(/((?=[a-zA-Z])[a-zA-Z]*)/);
    var i = 0;
    var j = 0;
    var result = "";
    for (var i = 1; i < array.length-1; i++) {

      if (array[i] != "") {
        if (array[i].length > 1) {

          for (var j = 0; i < array[j].length; ++j) {
            result += array[i].charAt(j) + "*";
          }<commit_msg>fix bug causing weird expressions<commit_after>import {Component, Input, OnInit} from '@angular/core';
import {BasicLogicPhraseParser} from "../phrase/basic-logic-phrase-parser";
import {LogicPhrase} from "../phrase/logic-phrase";
import {BasicLogicPhraseInfoComponent} from "../basic-logic-phrase-info/basic-logic-phrase-info.component";
import {KVDiagramComponent} from "../kvdiagram/kvdiagram.component";
import {LogicRootExpression} from "../logicExpression/logic-root-expression";
import * as _ from 'lodash';

@Component({
  selector: 'app-logic-input',
  templateUrl: './logic-input.component.html',
  styleUrls: ['./logic-input.component.css'],
  providers: [BasicLogicPhraseParser]
})
export class LogicInputComponent implements OnInit {
  @Input()
  basicLogicPhraseInfoCom: BasicLogicPhraseInfoComponent;
  @Input()
  kvDiagramCom: KVDiagramComponent;

  logicPhraseString = "";
  logicExtraVars = "";
  private logicPhrase: LogicPhrase;
  private logicDNFPhrase: LogicPhrase;

  constructor(private basicLogicPhraseParser: BasicLogicPhraseParser) { }

  ngOnInit() {
  }

  parseLogicPhrase() {

    this.kvDiagramCom.logicInputCom = this;

    let separatedVariableString = separateVariables(this.logicPhraseString);

    let logicRootExpression = new LogicRootExpression();
    logicRootExpression.parseLogicString(separatedVariableString);

    let logicExpressionInDNF: LogicRootExpression = _.cloneDeep(logicRootExpression);
    logicExpressionInDNF.toDNF();

    this.basicLogicPhraseInfoCom.logicRootExpression = logicRootExpression;
    this.basicLogicPhraseInfoCom.logicRootExpressionInDNF = logicExpressionInDNF;

    this.logicDNFPhrase = this.basicLogicPhraseParser.parse(logicExpressionInDNF.phraseToStringWithoutBreakets(), this.logicExtraVars);
    this.logicPhrase = this.basicLogicPhraseParser.parse(separatedVariableString, this.logicExtraVars);

    this.basicLogicPhraseInfoCom.logicPhrase = this.logicPhrase;

    this.kvDiagramCom.parse(this.logicDNFPhrase);
  }


  updateDNF(newDnf: string) {
    let logicRootExpression = new LogicRootExpression();
    logicRootExpression.parseLogicString(newDnf);
    this.basicLogicPhraseInfoCom.logicRootExpressionInDNF = logicRootExpression;
  }

  separateVariables(oldString: string) {
    var array = oldString.split(/((?=[a-zA-Z])[a-zA-Z]*)/);
    var i = 0;
    var j = 0;
    var result = "";
    for (var i = 1; i < array.length-1; i++) {

      if (array[i] != "") {
        if (array[i].length > 1) {

          for (var j = 0; j < array[i].length-1; ++j) {
            result += array[i].charAt(j) + "*";
          }
{'fraction_non_alphanumeric': 0.12181467181467182, 'fraction_numerical': 0.0025096525096525097, 'mean_word_length': 4.693406593406594, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '243450', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1597, 'n_words': 272}