// Path: apex/src/main/java/com/sixthsolution/apex/nlp/ner/Label.java
// public enum Label {
//     NONE, DATE, TIME, LOCATION, TITLE,
//     FIXED_TIME,
//     RELATIVE_TIME,
//     RANGE_TIME,
//     /**
//      * Formal dates are those in which the month, day, and year are represented as integers
//      * separated by a common separator character. The year is optional and may proceed the month or
//      * succeed the day of month. If a two-digit year is given, it must succeed the day of month.
//      */
//     FORMAL_DATE,
//     RELAX_DATE,
//     RELATIVE_DATE,
//     EXPLICIT_RELATIVE_DATE,
//     GLOBAL_DATE,
//     FOREVER_DATE,
//     LIMITED_DATE,
//     DATE_RULES,
//     RECURRENCE,
// 
// 
// }
// 
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/ner/regex/ChunkDetectionFilter.java
// public abstract class ChunkDetectionFilter {
// 
//     public abstract boolean accept(Label label, TaggedWords taggedWords, int startIndex, int endIndex);
// }
// 
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/tagger/TaggedWords.java
// public class TaggedWords extends ArrayList<TaggedWord> {
// 
//     public TaggedWords (){
//     }
// 
//     public TaggedWords (List<TaggedWord> in){
//         this.addAll(in);
//     }
// 
//     public void removeRange(int fromIndex, int toIndex) {
//         super.removeRange(fromIndex, toIndex);
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder sb = new StringBuilder();
//         Iterator<TaggedWord> itr = iterator();
//         while (itr.hasNext()) {
//             TaggedWord next = itr.next();
//             sb.append(next.getWord()).append(" [").append(next.getTags().toString()).append("]");
//             if (itr.hasNext()) {
//                 sb.append(", ");
//             }
//         }
//         return sb.toString();
//     }
// 
//     public List<TaggedWord> newSubList(int startIndex, int endIndex) {
//         List<TaggedWord> taggedWords = new ArrayList<>();
//         for (int i = startIndex; i < endIndex; i++) {
//             taggedWords.add(get(i));
//         }
//         return taggedWords;
//     }
// }
// 
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/dict/Tag.java
// public enum Tag {
//     NONE(97),
//     NUMBER(98),
//     PREPOSITION(99),
//     RELATIVE_PREPOSITION(100),
//     RELATIVE_SUFFIX(101),
//     //LOCATION
//     LOCATION_PREFIX(102),
//     LOCATION_SUFFIX(103),
//     LOCATION_NAME(137),
//     //TIME
//     TIME_PREFIX(104),                //e.g. at, in ,the
//     TIME_START_RANGE(105),       //e.g. from
//     TIME_RANGE(106),
//     TIME_RELATIVE_PREFIX(107),   //e.g. for
//     TIME_RELATIVE(108),              //e.g. morning
//     TIME_RELATIVE_INDICATOR(109),   //e.g. before,after
//     TIME_HOUR(110),                 //e.g. hour
//     TIME_MIN(111),                   //e.g. minutes
//     TIME_SEC(112),                   //e.g. seconds
//     TIME_MERIDIEM(113),            //e.g am, pm
//     TIME_SEPARATOR(114),             //e.g :, .
//     //DATE
//     DATE_PREPOSITION(115),
//     DATE_SEEKBY(116),
//     DATE_START_RANGE(117),
//     DATE_SUFFIX(118),
//     DATE_DURATION_SUFFIX(119),
//     DATE_SEPARATOR(120),
//     WEEK_DAY(121),
//     MONTH_NAME(122),
//     SEASON(123),
//     DATE_PREFIX(124),
//     //RECURRENCE
//     REC_WEEK_DAYS(125),
//     NAMED_DATE(126),
//     GLOBAL_PREPOSITION(127),
//     DATE_RECURRENCE(128),
//     DATE_RANGE(129),
//     DATE_FOREVER_KEY(130),
//     THE_PREFIX(131),
//     DATE_BAND(132),
//     YEAR_SEEK(133),
//     MONTH_SEEK(134),
//     WEEK_SEEK(135),
//     DAY_SEEK(136),
//     CURRENT(138);
// 
//     public int id;
// 
//     Tag(int id) {
//         this.id = id;
//     }
// 
//     @Override
//     public String toString() {
//         return String.valueOf((char) id);
//     }
// }


import com.sixthsolution.apex.nlp.ner.Label;
import com.sixthsolution.apex.nlp.ner.regex.ChunkDetectionFilter;
import com.sixthsolution.apex.nlp.tagger.TaggedWords;
import static com.sixthsolution.apex.nlp.dict.Tag.*;
package com.sixthsolution.apex.nlp.persian.filter;



/**
 * @author Saeed Masoumi (s-masoumi@live.com)
 * @author Rozhin Bayati
 */

public class TimeDetectionFilter extends ChunkDetectionFilter {

    @Override
    public boolean accept(Label label, TaggedWords taggedWords, int startIndex, int endIndex) {
        switch (label) {
            case FIXED_TIME:
            //ignore single number
            if (startIndex == endIndex - 1 &&
                    taggedWords.get(startIndex).getTags().containsTag(NUMBER)) {
                return false;
            }
            //ignore date formats like 12.02.2012
            if (taggedWords.size() > endIndex &&
                    taggedWords.get(endIndex - 1).getTags().containsTag(NUMBER) &&
                    taggedWords.get(endIndex).getTags().containsTag(DATE_SEPARATOR)) {
                return false;
            }
            return true;
            case RANGE_TIME:
                //ignore like فروردین 13-17
                if (startIndex > 0 && taggedWords.get(startIndex - 1).hasTag(MONTH_NAME)) {
                    return false;
                }
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/ner/Label.java
// public enum Label {
//     NONE, DATE, TIME, LOCATION, TITLE,
//     FIXED_TIME,
//     RELATIVE_TIME,
//     RANGE_TIME,
//     /**
//      * Formal dates are those in which the month, day, and year are represented as integers
//      * separated by a common separator character. The year is optional and may proceed the month or
//      * succeed the day of month. If a two-digit year is given, it must succeed the day of month.
//      */
//     FORMAL_DATE,
//     RELAX_DATE,
//     RELATIVE_DATE,
//     EXPLICIT_RELATIVE_DATE,
//     GLOBAL_DATE,
//     FOREVER_DATE,
//     LIMITED_DATE,
//     DATE_RULES,
//     RECURRENCE,
// 
// 
// }
// 
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/ner/regex/ChunkDetectionFilter.java
// public abstract class ChunkDetectionFilter {
// 
//     public abstract boolean accept(Label label, TaggedWords taggedWords, int startIndex, int endIndex);
// }
// 
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/tagger/TaggedWords.java
// public class TaggedWords extends ArrayList<TaggedWord> {
// 
//     public TaggedWords (){
//     }
// 
//     public TaggedWords (List<TaggedWord> in){
//         this.addAll(in);
//     }
// 
//     public void removeRange(int fromIndex, int toIndex) {
//         super.removeRange(fromIndex, toIndex);
//     }
// 
//     @Override
//     public String toString() {
//         StringBuilder sb = new StringBuilder();
//         Iterator<TaggedWord> itr = iterator();
//         while (itr.hasNext()) {
//             TaggedWord next = itr.next();
//             sb.append(next.getWord()).append(" [").append(next.getTags().toString()).append("]");
//             if (itr.hasNext()) {
//                 sb.append(", ");
//             }
//         }
//         return sb.toString();
//     }
// 
//     public List<TaggedWord> newSubList(int startIndex, int endIndex) {
//         List<TaggedWord> taggedWords = new ArrayList<>();
//         for (int i = startIndex; i < endIndex; i++) {
//             taggedWords.add(get(i));
//         }
//         return taggedWords;
//     }
// }
// 
// Path: apex/src/main/java/com/sixthsolution/apex/nlp/dict/Tag.java
// public enum Tag {
//     NONE(97),
//     NUMBER(98),
//     PREPOSITION(99),
//     RELATIVE_PREPOSITION(100),
//     RELATIVE_SUFFIX(101),
//     //LOCATION
//     LOCATION_PREFIX(102),
//     LOCATION_SUFFIX(103),
//     LOCATION_NAME(137),
//     //TIME
//     TIME_PREFIX(104),                //e.g. at, in ,the
//     TIME_START_RANGE(105),       //e.g. from
//     TIME_RANGE(106),
//     TIME_RELATIVE_PREFIX(107),   //e.g. for
//     TIME_RELATIVE(108),              //e.g. morning
//     TIME_RELATIVE_INDICATOR(109),   //e.g. before,after
//     TIME_HOUR(110),                 //e.g. hour
//     TIME_MIN(111),                   //e.g. minutes
//     TIME_SEC(112),                   //e.g. seconds
//     TIME_MERIDIEM(113),            //e.g am, pm
//     TIME_SEPARATOR(114),             //e.g :, .
//     //DATE
//     DATE_PREPOSITION(115),
//     DATE_SEEKBY(116),
//     DATE_START_RANGE(117),
//     DATE_SUFFIX(118),
//     DATE_DURATION_SUFFIX(119),
//     DATE_SEPARATOR(120),
//     WEEK_DAY(121),
//     MONTH_NAME(122),
//     SEASON(123),
//     DATE_PREFIX(124),
//     //RECURRENCE
//     REC_WEEK_DAYS(125),
//     NAMED_DATE(126),
//     GLOBAL_PREPOSITION(127),
//     DATE_RECURRENCE(128),
//     DATE_RANGE(129),
//     DATE_FOREVER_KEY(130),
//     THE_PREFIX(131),
//     DATE_BAND(132),
//     YEAR_SEEK(133),
//     MONTH_SEEK(134),
//     WEEK_SEEK(135),
//     DAY_SEEK(136),
//     CURRENT(138);
// 
//     public int id;
// 
//     Tag(int id) {
//         this.id = id;
//     }
// 
//     @Override
//     public String toString() {
//         return String.valueOf((char) id);
//     }
// }


// Path: persian-nlp/src/main/java/com/sixthsolution/apex/nlp/persian/filter/TimeDetectionFilter.java
import com.sixthsolution.apex.nlp.ner.Label;
import com.sixthsolution.apex.nlp.ner.regex.ChunkDetectionFilter;
import com.sixthsolution.apex.nlp.tagger.TaggedWords;
import static com.sixthsolution.apex.nlp.dict.Tag.*;

package com.sixthsolution.apex.nlp.persian.filter;



/**
 * @author Saeed Masoumi (s-masoumi@live.com)
 * @author Rozhin Bayati
 */

public class TimeDetectionFilter extends ChunkDetectionFilter {

    @Override
    public boolean accept(Label label, TaggedWords taggedWords, int startIndex, int endIndex) {
        switch (label) {
            case FIXED_TIME:
            //ignore single number
            if (startIndex == endIndex - 1 &&
                    taggedWords.get(startIndex).getTags().containsTag(NUMBER)) {
                return false;
            }
            //ignore date formats like 12.02.2012
            if (taggedWords.size() > endIndex &&
                    taggedWords.get(endIndex - 1).getTags().containsTag(NUMBER) &&
                    taggedWords.get(endIndex).getTags().containsTag(DATE_SEPARATOR)) {
                return false;
            }
            return true;
            case RANGE_TIME:
                //ignore like فروردین 13-17
                if (startIndex > 0 && taggedWords.get(startIndex - 1).hasTag(MONTH_NAME)) {
                    return false;
                }
                else if (startIndex > 0 && taggedWords.get(startIndex - 1).hasTag(DATE_SEPARATOR)) { // edited by scrc