<commit_before>package eu.modelwriter.configuration.alloy.reasoning;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;

import eu.modelwriter.configuration.internal.AlloyUtilities;
import eu.modelwriter.traceability.core.persistence.AtomType;
import eu.modelwriter.traceability.core.persistence.DocumentRoot;
import eu.modelwriter.traceability.core.persistence.FieldType;
import eu.modelwriter.traceability.core.persistence.TupleType;
import eu.modelwriter.traceability.core.persistence.persistenceFactory;

public class AlloyReasoning {

  static String filename = InstanceTranslatorReasoning.baseFileDirectory + "reasoning.als";

  public boolean reasoning() {
    final File reasoningXml =
        new File(InstanceTranslatorReasoning.baseFileDirectory + "reasoning.xml");
    if (reasoningXml.exists()) {
      reasoningXml.delete();
    }
    final File reasoningAls =
        new File(InstanceTranslatorReasoning.baseFileDirectory + "reasoning.als");
    if (reasoningAls.exists()) {
      reasoningAls.delete();
    }

    if (!AlloyValidatorReasoning.validate()) {
      JOptionPane.showMessageDialog(null,
          "There is not any reasoning.", "Reason on Relations",
          JOptionPane.INFORMATION_MESSAGE);
      return false;
    }

    final AlloyParserForReasoning parser = new AlloyParserForReasoning(AlloyReasoning.filename);

    AlloyNextSolutionReasoning.getInstance()
    .setReasonRelations(AlloyValidatorReasoning.reasonRelations);

    final DocumentRoot documentRootReasoning = parser.parse();
    final DocumentRoot documentRootOriginal = AlloyUtilities.getDocumentRoot();
    if (documentRootReasoning == null) {
      System.err.println("Document root on location " + AlloyReasoning.filename + " is NULL.");
      return false;
    }

    reason(documentRootOriginal, documentRootReasoning);

    return true;
  }

  private void reason(final DocumentRoot documentRootOriginal,
      final DocumentRoot documentRootReasoning) {
    final Map<String, List<String>> reasonRelations = AlloyValidatorReasoning.reasonRelations;
    int discoveredRelationCount = 0;
    for (final FieldType fieldType_R : documentRootReasoning.getAlloy().getInstance().getField()) {<commit_msg>minor change.<commit_after>package eu.modelwriter.configuration.alloy.reasoning;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.swing.JOptionPane;

import eu.modelwriter.configuration.internal.AlloyUtilities;
import eu.modelwriter.configuration.specificreasoning.InstanceTranslatorReasoningForAtom;
import eu.modelwriter.traceability.core.persistence.AtomType;
import eu.modelwriter.traceability.core.persistence.DocumentRoot;
import eu.modelwriter.traceability.core.persistence.FieldType;
import eu.modelwriter.traceability.core.persistence.TupleType;
import eu.modelwriter.traceability.core.persistence.persistenceFactory;

public class AlloyReasoning {

  private final String alsPath =
      InstanceTranslatorReasoningForAtom.baseFileDirectory + "reasoning.als";

  private final String xmlPath =
      InstanceTranslatorReasoningForAtom.baseFileDirectory + "reasoning.xml";

  public boolean reasoning() {
    final File reasoningXml = new File(xmlPath);
    if (reasoningXml.exists()) {
      reasoningXml.delete();
    }
    final File reasoningAls = new File(alsPath);
    if (reasoningAls.exists()) {
      reasoningAls.delete();
    }

    if (!AlloyValidatorReasoning.validate()) {
      JOptionPane.showMessageDialog(null, "There is not any reasoning.", "Reason on Relations",
          JOptionPane.INFORMATION_MESSAGE);
      return false;
    }

    final AlloyParserForReasoning parser = new AlloyParserForReasoning(alsPath);

    AlloyNextSolutionReasoning.getInstance()
    .setReasonRelations(AlloyValidatorReasoning.reasonRelations);

    final DocumentRoot documentRootReasoning = parser.parse();
    final DocumentRoot documentRootOriginal = AlloyUtilities.getDocumentRoot();
    if (documentRootReasoning == null) {
      System.err.println("Document root on location " + xmlPath + " is NULL.");
      return false;
    }

    reason(documentRootOriginal, documentRootReasoning);

    return true;
  }

  private void reason(final DocumentRoot documentRootOriginal,
      final DocumentRoot documentRootReasoning) {
    final Map<String, List<String>> reasonRelations = AlloyValidatorReasoning.reasonRelations;
    int discoveredRelationCount = 0;
    for (final FieldType fieldType_R : documentRootReasoning.getAlloy().getInstance().getField()) {
{'fraction_non_alphanumeric': 0.09028522410465366, 'fraction_numerical': 0.0004289084280506112, 'mean_word_length': 4.808219178082192, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 5}, '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': '2898811', 'n_tokens_mistral': 1276, 'n_tokens_neox': 1262, 'n_words': 250}