<commit_before>/**
 * Copyright (c) 2002-2011 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.cypher.internal.pipes.matching

import org.neo4j.cypher.SyntaxException
import org.neo4j.cypher.commands._
import collection.immutable.Map
import collection.{Traversable, Seq}
import org.neo4j.cypher.symbols.{RelationshipType, NodeType, SymbolTable}

/**
 * This class is responsible for deciding how to get the parts of the pattern that are not already bound
 *
 * The deciding factor is whether or not the pattern has loops in it. If it does, we have to use the much more
 * expensive pattern matching. If it doesn't, we get away with much simpler methods
 */
class MatchingContext(patterns: Seq[Pattern], boundIdentifiers: SymbolTable, predicates: Seq[Predicate] = Seq()) {
  val patternGraph = buildPatternGraph()
  val containsHardPatterns = patterns.find(!_.isInstanceOf[RelatedTo]).nonEmpty
  val builder: MatcherBuilder = decideWhichMatcherToUse()

  def getMatches(sourceRow: Map[String, Any]): Traversable[Map[String, Any]] = {
    builder.getMatches(sourceRow)
  }

  private def decideWhichMatcherToUse() = {
    if (JoinerBuilder.canHandlePatter(patternGraph)) {
      new JoinerBuilder(patternGraph, predicates)
    } else {
      new PatterMatchingBuilder(patternGraph, predicates)
    }
  }

  private def buildPatternGraph(): PatternGraph = {
    val patternNodeMap: scala.collection.mutable.Map[String, PatternNode] = scala.collection.mutable.Map()
    val patternRelMap: scala.collection.mutable.Map[String, PatternRelationship] = scala.collection.mutable.Map()

    boundIdentifiers.identifiers.
      filter(_.typ == NodeType()). //Find all bound nodes...<commit_msg>Turned off the new faster matcher because a bug has been found in it<commit_after>/**
 * Copyright (c) 2002-2011 "Neo Technology,"
 * Network Engine for Objects in Lund AB [http://neotechnology.com]
 *
 * This file is part of Neo4j.
 *
 * Neo4j is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.neo4j.cypher.internal.pipes.matching

import org.neo4j.cypher.SyntaxException
import org.neo4j.cypher.commands._
import collection.immutable.Map
import collection.{Traversable, Seq}
import org.neo4j.cypher.symbols.{RelationshipType, NodeType, SymbolTable}

/**
 * This class is responsible for deciding how to get the parts of the pattern that are not already bound
 *
 * The deciding factor is whether or not the pattern has loops in it. If it does, we have to use the much more
 * expensive pattern matching. If it doesn't, we get away with much simpler methods
 */
class MatchingContext(patterns: Seq[Pattern], boundIdentifiers: SymbolTable, predicates: Seq[Predicate] = Seq()) {
  val patternGraph = buildPatternGraph()
  val containsHardPatterns = patterns.find(!_.isInstanceOf[RelatedTo]).nonEmpty
  val builder: MatcherBuilder = decideWhichMatcherToUse()

  def getMatches(sourceRow: Map[String, Any]): Traversable[Map[String, Any]] = {
    builder.getMatches(sourceRow)
  }

  private def decideWhichMatcherToUse() = {
//    if (JoinerBuilder.canHandlePatter(patternGraph)) {
//      new JoinerBuilder(patternGraph, predicates)
//    } else {
      new PatterMatchingBuilder(patternGraph, predicates)
//    }
  }

  private def buildPatternGraph(): PatternGraph = {
    val patternNodeMap: scala.collection.mutable.Map[String, PatternNode] = scala.collection.mutable.Map()
    val patternRelMap: scala.collection.mutable.Map[String, PatternRelationship] = scala.collection.mutable.Map()

    boundIdentifiers.identifiers.
      filter(_.typ == NodeType()). //Find all bound nodes...
{'fraction_non_alphanumeric': 0.08981424780567462, 'fraction_numerical': 0.00612369871402327, 'mean_word_length': 4.314533622559653, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1798522', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1351, 'n_words': 504}