<commit_before>/*
 *  eXist Open Source Native XML Database
 *  Copyright (C) 2001-09 The eXist Team
 *
 *  http://exist-db.org
 *  
 *  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$
 */
package org.exist.xquery.functions.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.apache.log4j.Logger;
import org.exist.EXistException;
import org.exist.dom.DocumentImpl;
import org.exist.dom.QName;
import org.exist.dom.StoredNode;
import org.exist.stax.EmbeddedXMLStreamReader;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.xquery.BasicFunction;
import org.exist.xquery.Cardinality;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.value.FunctionParameterSequenceType;
import org.exist.xquery.value.FunctionReturnSequenceType;
import org.exist.xquery.value.NodeValue;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.SequenceType;
import org.exist.xquery.value.StringValue;
import org.exist.xquery.value.Type;
import org.exist.xquery.value.ValueSequence;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Delivers the fragment between two nodes (normally milestones) of a document.
 * It leads to more performance for most XML documents because it
 * determines the fragment directly by the EmbeddedXmlReader and not by 
 * XQL operators.
 * @author <NAME>, Max Planck Institute for the history of science,
 * http://www.mpiwg-berlin.mpg.de, <EMAIL> 
 */
public class GetFragmentBetween extends BasicFunction {
	
	protected static final Logger logger = Logger.getLogger(GetFragmentBetween.class);

  public final static FunctionSignature signature =
    new FunctionSignature(
      new QName("get-fragment-between", UtilModule.NAMESPACE_URI, UtilModule.PREFIX),
        "A function which delivers the xml fragment between two elements (normally milestone elements)" +
        "The first argument represents the first node/milestone element, the second argument the second" +
        "node/milestone element between which the fragment should be determined. The third argument is " +
        "a boolean value for the path completion. If the third argument is set to true() open and " +
        "closing tags before and after the two nodes/milestones are appended. " +
        "Example call of the function for getting the fragment between two page breaks: " +
        "  let $fragment := util:get-fragment-between(//pb[1], //pb[2], true())" ,
        new SequenceType[] { 
                             new FunctionParameterSequenceType("beginning-node", Type.NODE, Cardinality.ZERO_OR_ONE, "The first node/milestone element"),
                             new FunctionParameterSequenceType("ending-node", Type.NODE, Cardinality.ZERO_OR_ONE, "The second node/milestone element"),
                             new FunctionParameterSequenceType("add-open-close-tags", Type.BOOLEAN, Cardinality.ZERO_OR_ONE, "The flag indicating if open and closing tags before and after the two node/milestones are appended.")
                           },
        new FunctionReturnSequenceType(Type.STRING, Cardinality.ONE, "the string containing the fragments between the two node/milestone elements."));

  public GetFragmentBetween(XQueryContext context) {
    super(context, signature);
	}

  /**<commit_msg>[documentation-fix] Changed util:get-fragment-between() function docs (thanks JoeW for getting me on it) + license + svn:keywords.<commit_after>/*
 * eXist Open Source Native XML Database
 * Copyright (C) 2009 The eXist Project
 * http://exist-db.org
 *
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *  
 *  $Id$
 */
package org.exist.xquery.functions.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

import org.apache.log4j.Logger;
import org.exist.EXistException;
import org.exist.dom.DocumentImpl;
import org.exist.dom.QName;
import org.exist.dom.StoredNode;
import org.exist.stax.EmbeddedXMLStreamReader;
import org.exist.storage.BrokerPool;
import org.exist.storage.DBBroker;
import org.exist.xquery.BasicFunction;
import org.exist.xquery.Cardinality;
import org.exist.xquery.FunctionSignature;
import org.exist.xquery.XPathException;
import org.exist.xquery.XQueryContext;
import org.exist.xquery.value.FunctionParameterSequenceType;
import org.exist.xquery.value.FunctionReturnSequenceType;
import org.exist.xquery.value.NodeValue;
import org.exist.xquery.value.Sequence;
import org.exist.xquery.value.SequenceType;
import org.exist.xquery.value.StringValue;
import org.exist.xquery.value.Type;
import org.exist.xquery.value.ValueSequence;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * Delivers the fragment between two nodes (normally milestones) of a document.
 * It leads to more performance for most XML documents because it
 * determines the fragment directly by the EmbeddedXmlReader and not by 
 * XQL operators.
 * @author <NAME>, Max Planck Institute for the history of science,
 * http://www.mpiwg-berlin.mpg.de, <EMAIL> 
 */
public class GetFragmentBetween extends BasicFunction {
	
	protected static final Logger logger = Logger.getLogger(GetFragmentBetween.class);

  public final static FunctionSignature signature =
    new FunctionSignature(
      new QName("get-fragment-between", UtilModule.NAMESPACE_URI, UtilModule.PREFIX),
        "Returns an xml fragment or a sequence of nodes between two elements (normally milestone elements). " +
        "The $beginning-node represents the first node/milestone element, $ending-node, the second one. " +
        "The third argument, $make-fragment, is " +
        "a boolean value for the path completion. If it is set to true() the " +
        "result sequence is wrapped into a parent element node. " +
        "Example call of the function for getting the fragment between two TEI page break element nodes: " +
        "  let $fragment := util:get-fragment-between(//pb[1], //pb[2], true())" ,
        new SequenceType[] { 
                             new FunctionParameterSequenceType("beginning-node", Type.NODE, Cardinality.ZERO_OR_ONE, "The first node/milestone element"),
                             new FunctionParameterSequenceType("ending-node", Type.NODE, Cardinality.ZERO_OR_ONE, "The second node/milestone element"),
                             new FunctionParameterSequenceType("make-fragment", Type.BOOLEAN, Cardinality.ZERO_OR_ONE, "The flag make a fragment.")
                           },
        new FunctionReturnSequenceType(Type.STRING, Cardinality.ONE, "the string containing the fragments between the two node/milestone elements."));

  public GetFragmentBetween(XQueryContext context) {
    super(context, signature);
	}

  /**
{'fraction_non_alphanumeric': 0.08734549735138317, 'fraction_numerical': 0.0050618010594467334, 'mean_word_length': 3.865979381443299, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6437952', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2288, 'n_words': 793}