// Path: src/main/java/de/danielbasedow/prospecter/core/MatchCondition.java
// public enum MatchCondition {
//     EQUALS,
//     LESS_THAN,
//     GREATER_THAN,
//     LESS_THAN_EQUALS,
//     GREATER_THAN_EQUALS,
//     NONE,
//     IN,
//     RADIUS
// }
// 
// Path: src/main/java/de/danielbasedow/prospecter/core/Token.java
// public class Token<T> {
//     private final T token;
//     private final MatchCondition condition;
// 
//     public Token(T token) {
//         this(token, MatchCondition.NONE);
//     }
// 
//     public Token(T token, MatchCondition condition) {
//         this.token = token;
//         this.condition = condition;
//     }
// 
//     public T getToken() {
//         return token;
//     }
// 
//     public int hashCode() {
//         return token.hashCode();
//     }
// 
//     public boolean equals(Object compare) {
//         if (compare instanceof Token) {
//             return token.equals(((Token) compare).getToken());
//         }
//         return false;
//     }
// 
//     public MatchCondition getCondition() {
//         return condition;
//     }
// }


import aima.core.logic.propositional.parsing.ast.Connective;
import aima.core.logic.propositional.parsing.ast.Sentence;
import aima.core.logic.propositional.visitors.ConvertToCNF;
import de.danielbasedow.prospecter.core.MatchCondition;
import de.danielbasedow.prospecter.core.Token;
import de.danielbasedow.prospecter.core.query.build.*;
import java.util.*;
package de.danielbasedow.prospecter.core.query;



/**
 * represents a Query (a tuple of queryId, bitmask and a list of conditions)
 */
public class Query {
    protected final int queryId;
    protected final int bits;
    protected final QueryNegativeCounter negativeMask = new QueryNegativeCounter();

    protected final ClauseNode clauseNode;
    protected final Map<Condition, Long> postings = new HashMap<Condition, Long>();

    public int getQueryId() {
        return queryId;
    }

    public Query(int queryId, ClauseNode clauseNode) {
        this.clauseNode = clauseNode;
        this.queryId = queryId;

        Sentence cnf = getCNF(clauseNode);

        int tmpBits = 0;
        for (int bit = 0; bit < cnf.getNumberSimplerSentences(); bit++) {
            tmpBits++;
            Sentence disjunction = cnf.getSimplerSentence(bit);
            for (int p = 0; p < disjunction.getNumberSimplerSentences(); p++) {
                Sentence sentence = disjunction.getSimplerSentence(p);
                boolean isNegativeCondition = false;
                if (sentence.isNotSentence()) {
                    sentence = sentence.getSimplerSentence(0);
                    isNegativeCondition = true;
                }
                Condition condition = ((PropositionSymbol) sentence).getCondition();
                if (condition.getToken().getCondition() == MatchCondition.IN) {
                    //If this is an IN query we're dealing with a Token containing a List<Token>
                    Object t = condition.getToken().getToken();
                    if (t instanceof List) {
// Path: src/main/java/de/danielbasedow/prospecter/core/MatchCondition.java
// public enum MatchCondition {
//     EQUALS,
//     LESS_THAN,
//     GREATER_THAN,
//     LESS_THAN_EQUALS,
//     GREATER_THAN_EQUALS,
//     NONE,
//     IN,
//     RADIUS
// }
// 
// Path: src/main/java/de/danielbasedow/prospecter/core/Token.java
// public class Token<T> {
//     private final T token;
//     private final MatchCondition condition;
// 
//     public Token(T token) {
//         this(token, MatchCondition.NONE);
//     }
// 
//     public Token(T token, MatchCondition condition) {
//         this.token = token;
//         this.condition = condition;
//     }
// 
//     public T getToken() {
//         return token;
//     }
// 
//     public int hashCode() {
//         return token.hashCode();
//     }
// 
//     public boolean equals(Object compare) {
//         if (compare instanceof Token) {
//             return token.equals(((Token) compare).getToken());
//         }
//         return false;
//     }
// 
//     public MatchCondition getCondition() {
//         return condition;
//     }
// }


// Path: src/main/java/de/danielbasedow/prospecter/core/query/Query.java
import aima.core.logic.propositional.parsing.ast.Connective;
import aima.core.logic.propositional.parsing.ast.Sentence;
import aima.core.logic.propositional.visitors.ConvertToCNF;
import de.danielbasedow.prospecter.core.MatchCondition;
import de.danielbasedow.prospecter.core.Token;
import de.danielbasedow.prospecter.core.query.build.*;
import java.util.*;

package de.danielbasedow.prospecter.core.query;



/**
 * represents a Query (a tuple of queryId, bitmask and a list of conditions)
 */
public class Query {
    protected final int queryId;
    protected final int bits;
    protected final QueryNegativeCounter negativeMask = new QueryNegativeCounter();

    protected final ClauseNode clauseNode;
    protected final Map<Condition, Long> postings = new HashMap<Condition, Long>();

    public int getQueryId() {
        return queryId;
    }

    public Query(int queryId, ClauseNode clauseNode) {
        this.clauseNode = clauseNode;
        this.queryId = queryId;

        Sentence cnf = getCNF(clauseNode);

        int tmpBits = 0;
        for (int bit = 0; bit < cnf.getNumberSimplerSentences(); bit++) {
            tmpBits++;
            Sentence disjunction = cnf.getSimplerSentence(bit);
            for (int p = 0; p < disjunction.getNumberSimplerSentences(); p++) {
                Sentence sentence = disjunction.getSimplerSentence(p);
                boolean isNegativeCondition = false;
                if (sentence.isNotSentence()) {
                    sentence = sentence.getSimplerSentence(0);
                    isNegativeCondition = true;
                }
                Condition condition = ((PropositionSymbol) sentence).getCondition();
                if (condition.getToken().getCondition() == MatchCondition.IN) {
                    //If this is an IN query we're dealing with a Token containing a List<Token>
                    Object t = condition.getToken().getToken();
                    if (t instanceof List) {
                        for (Token token : (List<Token>) t) {