// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/IndexRange.java
// public class IndexRange {
//     private final int fromIdx;
//     private final int toIdx;
// 
//     public IndexRange(int fromIdx, int toIdx) {
//         this.fromIdx = fromIdx;
//         this.toIdx = toIdx;
//     }
// 
//     public int getFromIdx() {
//         return fromIdx;
//     }
// 
//     public int getToIdx() {
//         return toIdx;
//     }
// 
//     @Override
//     public String toString() {
//         return "(" + fromIdx + " | " + toIdx + ")";
//     }
// }
// 
// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/ner/NERExtractionUtils.java
// public class NERExtractionUtils {
// 
//     public static List<IndexRange> getNERIndexRanges(NERString nerString) {
//         List<IndexRange> res = new ArrayList<>();
// 
//         for (NERTokenGroup group : nerString.getGroups()) {
//             res.add(new IndexRange(group.getFromTokenIndex(), group.getToTokenIndex()));
//         }
// 
//         return res;
//     }
// }
// 
// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/ner/NERString.java
// public class NERString {
//     public static final String NO_CATEGORY = "O";
// 
//     protected final List<NERToken> tokens;
//     private List<NERTokenGroup> groups;
// 
//     public NERString(List<NERToken> tokens) {
//         this.tokens = tokens;
//         this.createGroups();
//     }
// 
//     private void createGroups() {
//         this.groups = new ArrayList<>();
// 
//         String lastCategory = null;
//         List<NERToken> currGroupTokens = new ArrayList<>();
//         for (NERToken nerToken : this.tokens) {
// 
//             if ((lastCategory != null) && (!nerToken.getCategory().equals(lastCategory))) {
//                 // add
//                 this.groups.add(new NERTokenGroup(currGroupTokens));
//                 currGroupTokens = new ArrayList<>();
//             }
// 
//             currGroupTokens.add(nerToken);
//             lastCategory = nerToken.getCategory();
//         }
// 
//         // add
//         this.groups.add(new NERTokenGroup(currGroupTokens));
//     }
// 
//     public List<NERToken> getTokens() {
//         return tokens;
//     }
// 
//     public List<NERTokenGroup> getGroups() {
//         return groups;
//     }
// 
//     private List<Word> getWords(int fromIndex, int toIndex) {
//         return tokens.subList(fromIndex, toIndex).stream().map(t -> new Word(t.getText())).collect(Collectors.toList());
//     }
// 
//     public List<Word> getWords() {
//         return getWords(0, tokens.size());
//     }
// 
//     @Override
//     public String toString() {
//         return tokens.stream().map(NERToken::toString).collect(Collectors.joining("\n"));
//     }
// }


import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import edu.stanford.nlp.ling.Word;
import edu.stanford.nlp.trees.Tree;
import org.lambda3.text.simplification.discourse.utils.IndexRange;
import org.lambda3.text.simplification.discourse.utils.ner.NERExtractionUtils;
import org.lambda3.text.simplification.discourse.utils.ner.NERString;
import java.util.ArrayList;
import java.util.Collections;
/*
 * ==========================License-Start=============================
 * DiscourseSimplification : ParseTreeExtractionUtils
 *
 * Copyright © 2017 Lambda³
 *
 * GNU General Public License 3
 * This program 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/.
 * ==========================License-End==============================
 */

package org.lambda3.text.simplification.discourse.utils.parseTree;



public class ParseTreeExtractionUtils {

    public interface INodeChecker {
        boolean check(Tree anchorTree, Tree node);
    }


    public static List<Integer> getLeafNumbers(Tree anchorTree, Tree node) {
        List<Integer> res = new ArrayList<>();
        for (Tree leaf : node.getLeaves()) {
            res.add(leaf.nodeNumber(anchorTree));
        }
        return res;
    }

// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/IndexRange.java
// public class IndexRange {
//     private final int fromIdx;
//     private final int toIdx;
// 
//     public IndexRange(int fromIdx, int toIdx) {
//         this.fromIdx = fromIdx;
//         this.toIdx = toIdx;
//     }
// 
//     public int getFromIdx() {
//         return fromIdx;
//     }
// 
//     public int getToIdx() {
//         return toIdx;
//     }
// 
//     @Override
//     public String toString() {
//         return "(" + fromIdx + " | " + toIdx + ")";
//     }
// }
// 
// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/ner/NERExtractionUtils.java
// public class NERExtractionUtils {
// 
//     public static List<IndexRange> getNERIndexRanges(NERString nerString) {
//         List<IndexRange> res = new ArrayList<>();
// 
//         for (NERTokenGroup group : nerString.getGroups()) {
//             res.add(new IndexRange(group.getFromTokenIndex(), group.getToTokenIndex()));
//         }
// 
//         return res;
//     }
// }
// 
// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/ner/NERString.java
// public class NERString {
//     public static final String NO_CATEGORY = "O";
// 
//     protected final List<NERToken> tokens;
//     private List<NERTokenGroup> groups;
// 
//     public NERString(List<NERToken> tokens) {
//         this.tokens = tokens;
//         this.createGroups();
//     }
// 
//     private void createGroups() {
//         this.groups = new ArrayList<>();
// 
//         String lastCategory = null;
//         List<NERToken> currGroupTokens = new ArrayList<>();
//         for (NERToken nerToken : this.tokens) {
// 
//             if ((lastCategory != null) && (!nerToken.getCategory().equals(lastCategory))) {
//                 // add
//                 this.groups.add(new NERTokenGroup(currGroupTokens));
//                 currGroupTokens = new ArrayList<>();
//             }
// 
//             currGroupTokens.add(nerToken);
//             lastCategory = nerToken.getCategory();
//         }
// 
//         // add
//         this.groups.add(new NERTokenGroup(currGroupTokens));
//     }
// 
//     public List<NERToken> getTokens() {
//         return tokens;
//     }
// 
//     public List<NERTokenGroup> getGroups() {
//         return groups;
//     }
// 
//     private List<Word> getWords(int fromIndex, int toIndex) {
//         return tokens.subList(fromIndex, toIndex).stream().map(t -> new Word(t.getText())).collect(Collectors.toList());
//     }
// 
//     public List<Word> getWords() {
//         return getWords(0, tokens.size());
//     }
// 
//     @Override
//     public String toString() {
//         return tokens.stream().map(NERToken::toString).collect(Collectors.joining("\n"));
//     }
// }


// Path: src/main/java/org/lambda3/text/simplification/discourse/utils/parseTree/ParseTreeExtractionUtils.java
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import edu.stanford.nlp.ling.Word;
import edu.stanford.nlp.trees.Tree;
import org.lambda3.text.simplification.discourse.utils.IndexRange;
import org.lambda3.text.simplification.discourse.utils.ner.NERExtractionUtils;
import org.lambda3.text.simplification.discourse.utils.ner.NERString;
import java.util.ArrayList;
import java.util.Collections;

/*
 * ==========================License-Start=============================
 * DiscourseSimplification : ParseTreeExtractionUtils
 *
 * Copyright © 2017 Lambda³
 *
 * GNU General Public License 3
 * This program 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/.
 * ==========================License-End==============================
 */

package org.lambda3.text.simplification.discourse.utils.parseTree;



public class ParseTreeExtractionUtils {

    public interface INodeChecker {
        boolean check(Tree anchorTree, Tree node);
    }


    public static List<Integer> getLeafNumbers(Tree anchorTree, Tree node) {
        List<Integer> res = new ArrayList<>();
        for (Tree leaf : node.getLeaves()) {
            res.add(leaf.nodeNumber(anchorTree));
        }
        return res;
    }

    private static IndexRange getLeafIndexRange(Tree anchorTree, Tree node) {