<commit_before>////////////////////////////////////////////////////////////////////////////////
/// @brief Aql, condition 
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author <NAME>
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#include "Condition.h"
#include "Aql/Ast.h"
#include "Aql/AstNode.h"
#include "Aql/ExecutionPlan.h"
#include "Aql/Variable.h"
#include "Basics/Exceptions.h"
#include "Basics/json.h"
#include "Basics/JsonHelper.h"

#include <iostream>

using namespace triagens::aql;
using CompareResult = ConditionPart::ConditionPartCompareResult;

// -----------------------------------------------------------------------------
// --SECTION--                                              struct ConditionPart
// -----------------------------------------------------------------------------

ConditionPart::ConditionPart (Variable const* variable,
                              std::string const& attributeName,
                              size_t sourcePosition,
                              AstNode const* operatorNode,
                              AttributeSideType side)
  : variable(variable),
    attributeName(attributeName),
    sourcePosition(sourcePosition),
    operatorType(operatorNode->type),
    operatorNode(operatorNode),
    valueNode(nullptr) {

  if (side == ATTRIBUTE_LEFT) {
    valueNode = operatorNode->getMember(1);
  }
  else {
    valueNode = operatorNode->getMember(0);
    if (Ast::IsReversibleOperator(operatorType)) {
      operatorType = Ast::ReverseOperator(operatorType);
    }
  }
}

ConditionPart::~ConditionPart () {

}

void ConditionPart::dump () const {
  std::cout << "VARIABLE NAME: " << variable->name << "." << attributeName << " " << triagens::basics::JsonHelper::toString(valueNode->toJson(TRI_UNKNOWN_MEM_ZONE, false)) << "\n";
}

// -----------------------------------------------------------------------------
// --SECTION--                                                   class Condition
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// --SECTION--                                            static helper function
// -----------------------------------------------------------------------------
static void dumpNode (AstNode const* node, int indent) {
  if (node == nullptr) {
    return;
  }

  for (int i = 0; i < indent * 2; ++i) {
    std::cout << " ";
  }

  std::cout << node->getTypeString();
  if (node->type == NODE_TYPE_VALUE) {
    TRI_json_t* jsonVal =  node->toJsonValue(TRI_UNKNOWN_MEM_ZONE);
    std::cout << "  (value " << triagens::basics::JsonHelper::toString(jsonVal) << ")";
    TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, jsonVal);
  }
  else if (node->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
    std::cout << "  (attribute " << node->getStringValue() << ")";
  }
  else if (node->type == NODE_TYPE_REFERENCE) {
    std::cout << "  (name " << node->getStringValue() << ")";
  }

  std::cout << "\n";
  for (size_t i = 0; i < node->numMembers(); ++i) {
    dumpNode(node->getMember(i), indent + 1);
  }
}

// -----------------------------------------------------------------------------
// --SECTION--                                        constructors / destructors
// -----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// @brief create the condition
////////////////////////////////////////////////////////////////////////////////

Condition::Condition (Ast* ast)
  : _ast(ast),
    _root(nullptr),
    _isNormalized(false) {

}

////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the condition
////////////////////////////////////////////////////////////////////////////////<commit_msg>fixed condition printing<commit_after>////////////////////////////////////////////////////////////////////////////////
/// @brief Aql, condition 
///
/// @file
///
/// DISCLAIMER
///
/// Copyright 2014 ArangoDB GmbH, Cologne, Germany
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
///     http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
///
/// @author <NAME>
/// @author Copyright 2014, ArangoDB GmbH, Cologne, Germany
/// @author Copyright 2012-2013, triAGENS GmbH, Cologne, Germany
////////////////////////////////////////////////////////////////////////////////

#include "Condition.h"
#include "Aql/Ast.h"
#include "Aql/AstNode.h"
#include "Aql/ExecutionPlan.h"
#include "Aql/Variable.h"
#include "Basics/Exceptions.h"
#include "Basics/json.h"
#include "Basics/JsonHelper.h"

#include <iostream>

using namespace triagens::aql;
using CompareResult = ConditionPart::ConditionPartCompareResult;

// -----------------------------------------------------------------------------
// --SECTION--                                              struct ConditionPart
// -----------------------------------------------------------------------------

ConditionPart::ConditionPart (Variable const* variable,
                              std::string const& attributeName,
                              size_t sourcePosition,
                              AstNode const* operatorNode,
                              AttributeSideType side)
  : variable(variable),
    attributeName(attributeName),
    sourcePosition(sourcePosition),
    operatorType(operatorNode->type),
    operatorNode(operatorNode),
    valueNode(nullptr) {

  if (side == ATTRIBUTE_LEFT) {
    valueNode = operatorNode->getMember(1);
  }
  else {
    valueNode = operatorNode->getMember(0);
    if (Ast::IsReversibleOperator(operatorType)) {
      operatorType = Ast::ReverseOperator(operatorType);
    }
  }
}

ConditionPart::~ConditionPart () {

}

void ConditionPart::dump () const {
  std::cout << "VARIABLE NAME: " << variable->name << "." << attributeName << " " << triagens::basics::JsonHelper::toString(valueNode->toJson(TRI_UNKNOWN_MEM_ZONE, false)) << "\n";
}

// -----------------------------------------------------------------------------
// --SECTION--                                                   class Condition
// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// --SECTION--                                            static helper function
// -----------------------------------------------------------------------------
static void dumpNode (AstNode const* node, int indent) {
  if (node == nullptr) {
    return;
  }

  for (int i = 0; i < indent * 2; ++i) {
    std::cout << " ";
  }

  std::cout << node->getTypeString();
  if (node->type == NODE_TYPE_VALUE) {
    TRI_json_t* jsonVal =  node->toJsonValue(TRI_UNKNOWN_MEM_ZONE);
    std::cout << "  (value " << triagens::basics::JsonHelper::toString(jsonVal) << ")";
    TRI_FreeJson(TRI_UNKNOWN_MEM_ZONE, jsonVal);
  }
  else if (node->type == NODE_TYPE_ATTRIBUTE_ACCESS) {
    std::cout << "  (attribute " << node->getStringValue() << ")";
  }
  else if (node->type == NODE_TYPE_REFERENCE) {
    std::cout << "  (name " << static_cast<Variable const*>(node->getData())->name << ")";
  }

  std::cout << "\n";
  for (size_t i = 0; i < node->numMembers(); ++i) {
    dumpNode(node->getMember(i), indent + 1);
  }
}

// -----------------------------------------------------------------------------
// --SECTION--                                        constructors / destructors
// -----------------------------------------------------------------------------

////////////////////////////////////////////////////////////////////////////////
/// @brief create the condition
////////////////////////////////////////////////////////////////////////////////

Condition::Condition (Ast* ast)
  : _ast(ast),
    _root(nullptr),
    _isNormalized(false) {

}

////////////////////////////////////////////////////////////////////////////////
/// @brief destroy the condition
////////////////////////////////////////////////////////////////////////////////
{'fraction_non_alphanumeric': 0.34281814363712726, 'fraction_numerical': 0.007139857202855943, 'mean_word_length': 1.2385428907168037, 'pattern_counts': {'":': 0, '<': 88, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5253632', 'n_tokens_mistral': 2283, 'n_tokens_neox': 2191, 'n_words': 551}