<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-06 <NAME>
 *  <EMAIL>
 *  http://exist.sourceforge.net
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  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 Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  
 *  $Id: ExtRegexp.java 5578 2007-04-03 20:34:57Z wolfgang_m $
 */
package org.exist.xquery.functions;

import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;

import org.exist.dom.ExtArrayNodeSet;
import org.exist.dom.NodeSet;
import org.exist.dom.QName;
import org.exist.dom.DocumentSet;
import org.exist.storage.DBBroker;
import org.exist.storage.ElementValue;
import org.exist.storage.FulltextIndexSpec;
import org.exist.storage.analysis.Tokenizer;
import org.exist.xquery.*;
import org.exist.xquery.functions.text.TextModule;
import org.exist.xquery.util.RegexTranslator;
import org.exist.xquery.util.ExpressionDumper;
import org.exist.xquery.util.RegexTranslator.RegexSyntaxException;
import org.exist.xquery.value.Item;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.SequenceIterator;
import org.exist.xquery.value.SequenceType;
import org.exist.xquery.value.Type;
import org.exist.EXistException;
import org.exist.xmldb.XmldbURI;
import org.exist.collections.Collection;

/**
 * @author wolf
 */
public class MatchRegexp extends Function implements Optimizable {

	public final static FunctionSignature signatures[] = {
		new FunctionSignature(
			new QName("match-all", TextModule.NAMESPACE_URI, TextModule.PREFIX),
			"Tries to match each of the regular expression " +
			"strings passed in $b against the keywords contained in " +
			"the fulltext index. The keywords found are then compared to the node set in $a. Every " +
			"node containing ALL of the keywords is copied to the result sequence. By default, a keyword " +
            "is considered to match the pattern if any substring of the keyword matches. To change this behaviour, " +
            "use the 3-argument version of the function and specify flag 'w'. With 'w' specified, the regular expression " +
            "is matched against the entire keyword, i.e. 'explain.*' will match 'explained' , but not 'unexplained'.",
			new SequenceType[] {
				new SequenceType(Type.NODE, Cardinality.ZERO_OR_MORE),
				new SequenceType(Type.STRING, Cardinality.ONE_OR_MORE)
            },
			new SequenceType(Type.NODE, Cardinality.ZERO_OR_MORE)
		),
        new FunctionSignature(
			new QName("match-all", TextModule.NAMESPACE_URI, TextModule.PREFIX),
			"Tries to match each of the regular expression " +
			"strings passed in $b against the keywords contained in " +
			"the fulltext index. The keywords found are then compared to the node set in $a. Every " +
			"node containing ALL of the keywords is copied to the result sequence. By default, a keyword " +
            "is considered to match the pattern if any substring of the keyword matches. To change this behaviour, " +
            "use the 3-argument version of the function and specify flag 'w'. With 'w' specified, the regular expression " +
            "is matched against the entire keyword, i.e. 'explain.*' will match 'explained' , but not 'unexplained'.",<commit_msg>Function was in wrong package.<commit_after>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-06 <NAME>
 *  <EMAIL>
 *  http://exist.sourceforge.net
 *  
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public License
 *  as published by the Free Software Foundation; either version 2
 *  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 Lesser General Public License for more details.
 *  
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *  
 *  $Id: ExtRegexp.java 5578 2007-04-03 20:34:57Z wolfgang_m $
 */
package org.exist.xquery.functions.text;

import org.exist.collections.Collection;
import org.exist.dom.DocumentSet;
import org.exist.dom.ExtArrayNodeSet;
import org.exist.dom.NodeSet;
import org.exist.dom.QName;
import org.exist.storage.DBBroker;
import org.exist.storage.ElementValue;
import org.exist.storage.FulltextIndexSpec;
import org.exist.xmldb.XmldbURI;
import org.exist.xquery.*;
import org.exist.xquery.util.RegexTranslator;
import org.exist.xquery.util.RegexTranslator.RegexSyntaxException;
import org.exist.xquery.value.*;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @author wolf
 */
public class MatchRegexp extends Function implements Optimizable {

	public final static FunctionSignature signatures[] = {
		new FunctionSignature(
			new QName("match-all", TextModule.NAMESPACE_URI, TextModule.PREFIX),
			"Tries to match each of the regular expression " +
			"strings passed in $b against the keywords contained in " +
			"the fulltext index. The keywords found are then compared to the node set in $a. Every " +
			"node containing ALL of the keywords is copied to the result sequence. By default, a keyword " +
            "is considered to match the pattern if any substring of the keyword matches. To change this behaviour, " +
            "use the 3-argument version of the function and specify flag 'w'. With 'w' specified, the regular expression " +
            "is matched against the entire keyword, i.e. 'explain.*' will match 'explained' , but not 'unexplained'.",
			new SequenceType[] {
				new SequenceType(Type.NODE, Cardinality.ZERO_OR_MORE),
				new SequenceType(Type.STRING, Cardinality.ONE_OR_MORE)
            },
			new SequenceType(Type.NODE, Cardinality.ZERO_OR_MORE)
		),
        new FunctionSignature(
			new QName("match-all", TextModule.NAMESPACE_URI, TextModule.PREFIX),
			"Tries to match each of the regular expression " +
			"strings passed in $b against the keywords contained in " +
			"the fulltext index. The keywords found are then compared to the node set in $a. Every " +
			"node containing ALL of the keywords is copied to the result sequence. By default, a keyword " +
            "is considered to match the pattern if any substring of the keyword matches. To change this behaviour, " +
            "use the 3-argument version of the function and specify flag 'w'. With 'w' specified, the regular expression " +
            "is matched against the entire keyword, i.e. 'explain.*' will match 'explained' , but not 'unexplained'.",
{'fraction_non_alphanumeric': 0.08527448576488217, 'fraction_numerical': 0.009535485628660946, 'mean_word_length': 3.7306701030927836, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '250662', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2042, 'n_words': 815}