src/language model based query topic analysis/src/edu/virginia/cs/model/GenerateCoverQuery.java
public ArrayList<String> generateNQueries(String query, int N, int previousQueryTopicNo, ArrayList<Integer> coverQTopics) {
        ArrayList<String> coverQueries = new ArrayList<>();
        ArrayList<Integer> scores = getScore(query);
        if (scores.get(1) == -1) {
            /* if topic of the query can not be inferred */
            return null;
        }
        currentQueryTopicNo = scores.get(1);
        if (N == 0) {
            return coverQueries;
        }

        int currentQueryTopicLevel = languageModels.get(currentQueryTopicNo).getLevel();
        int seqEdited = 0;
        if (previousQueryTopicNo != -1) {
            seqEdited = checkSequentialEdited(previousQueryTopicNo, currentQueryTopicNo);
        }
        if (seqEdited == 1) {
            try {
                fw.write("*****current query is sequentially edited from previous query*****" + "\n");
                fw.flush();
            } catch (IOException ex) {
                Logger.getLogger(GenerateCoverQuery.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        int bucketNum = scores.get(2);
        int count = 0;

        coverQueryTopics = new ArrayList<>();
        while (true) {
            String cQuery;
            if (seqEdited == 0) {
                /* Current query is not sequentially edited. */
                if (count < N / 2) {
                    /* Generating cover query from sibling topics. */
                    cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, true, -1);
                    if (cQuery == null) {
                    }
                } else {
                    /* Generating cover query from same level of original query but not from sibling topics. */
                    cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, false, -1);
                }
                if (cQuery != null) {
                    if (!cQuery.equals("CQ topic not found!")) {
                        coverQueries.add(cQuery);
                    }
                    count++;
                }
                if (count == N) {
                    break;
                }
            } else {
                /**
                 * Current query is sequentially edited, so cover queries will
                 * be generated based on previous cover query topics.
                 */
                if (count == coverQTopics.size()) {
                    break;
                }
                int coverQuTopic = coverQTopics.get(count);
                if (seqEdited == 1) {
                    /**
                     * Cover query should be generated from parent topic of the
                     * previous cover query.
                     */
                    if (languageModels.get(coverQuTopic).getParent().isEmpty()) {
                        cQuery = "CQ topic not found!";
                    } else {
                        int topicId = languageModels.get(coverQuTopic).getParent().getTopic_id();
                        cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, false, topicId);
                    }
                } else {
                    /**
                     * Cover query should be generated from child topic of the
                     * previous cover query.
                     */
                    int numChildren = languageModels.get(coverQuTopic).getListOfChildren().size();
                    if (numChildren > 0) {
                        int rand = -1;
                        for (int x = 0; x < numChildren; x++) {
                            rand = getRandom(0, numChildren);
                            LanguageModel tempLm = languageModels.get(coverQuTopic).getListOfChildren().get(rand);
                            if (!tempLm.isEmpty()) {
                                break;
                            } else {
                                rand = -1;
                            }
                        }
                        if (rand == -1) {
                            cQuery = "CQ topic not found!";
                        } else {
                            int topicId = languageModels.get(coverQuTopic).getListOfChildren().get(rand).getTopic_id();
                            cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, false, topicId);
                        }
                    } else {
                        cQuery = "CQ topic not found!";
                    }
                }
                if (cQuery != null) {
                    if (!cQuery.equals("CQ topic not found!")) {
                        coverQueries.add(cQuery);
                    }
                    count++;
                }
            }
        }
        if (coverQueries.isEmpty()) {
            return null;
        }
        return coverQueries;
    }
/**
     * Creates N cover queries based on true user query. Handle sequentially
     * edited queries by using lastQueryTopicNo.
     *
     * @param query true user query
     * @param N number of cover queries required
     * @param previousQueryTopicNo -1 if the previous query and current query
     * belong to two different session.
     * @param coverQTopics
     * @return list of cover queries
     */
Creates N cover queries based on true user query. Handle sequentially
edited queries by using lastQueryTopicNo.

@param query true user query
@param N number of cover queries required
@param previousQueryTopicNo -1 if the previous query and current query
belong to two different session.
@param coverQTopics
@return list of cover queries
Creates N cover queries based on true user query . Handle sequentially edited queries by using lastQueryTopicNo . @param query true user query @param N number of cover queries required @param previousQueryTopicNo - 1 if the previous query and current query belong to two different session . @param coverQTopics @return list of cover queries
public ArrayList<String> generateNQueries(String query, int N, int previousQueryTopicNo, ArrayList<Integer> coverQTopics) {
        ArrayList<String> coverQueries = new ArrayList<>();
        ArrayList<Integer> scores = getScore(query);
        if (scores.get(1) == -1) {
            /* if topic of the query can not be inferred */
            return null;
        }
        currentQueryTopicNo = scores.get(1);
        if (N == 0) {
            return coverQueries;
        }
        int currentQueryTopicLevel = languageModels.get(currentQueryTopicNo).getLevel();
        int seqEdited = 0;
        if (previousQueryTopicNo != -1) {
            seqEdited = checkSequentialEdited(previousQueryTopicNo, currentQueryTopicNo);
        }
        if (seqEdited == 1) {
            try {
                fw.write("*****current query is sequentially edited from previous query*****" + "\n");
                fw.flush();
            } catch (IOException ex) {
                Logger.getLogger(GenerateCoverQuery.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        int bucketNum = scores.get(2);
        int count = 0;
        coverQueryTopics = new ArrayList<>();
        while (true) {
            String cQuery;
            if (seqEdited == 0) {
                /* Current query is not sequentially edited. */
                if (count < N / 2) {
                    /* Generating cover query from sibling topics. */
                    cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, true, -1);
                    if (cQuery == null) {
                    }
                } else {
                    /* Generating cover query from same level of original query but not from sibling topics. */
                    cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, false, -1);
                }
                if (cQuery != null) {
                    if (!cQuery.equals("CQ topic not found!")) {
                        coverQueries.add(cQuery);
                    }
                    count++;
                }
                if (count == N) {
                    break;
                }
            } else {
                /**
                 * Current query is sequentially edited, so cover queries will
                 * be generated based on previous cover query topics.
                 */
                if (count == coverQTopics.size()) {
                    break;
                }
                int coverQuTopic = coverQTopics.get(count);
                if (seqEdited == 1) {
                    /**
                     * Cover query should be generated from parent topic of the
                     * previous cover query.
                     */
                    if (languageModels.get(coverQuTopic).getParent().isEmpty()) {
                        cQuery = "CQ topic not found!";
                    } else {
                        int topicId = languageModels.get(coverQuTopic).getParent().getTopic_id();
                        cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, false, topicId);
                    }
                } else {
                    /**
                     * Cover query should be generated from child topic of the
                     * previous cover query.
                     */
                    int numChildren = languageModels.get(coverQuTopic).getListOfChildren().size();
                    if (numChildren > 0) {
                        int rand = -1;
                        for (int x = 0; x < numChildren; x++) {
                            rand = getRandom(0, numChildren);
                            LanguageModel tempLm = languageModels.get(coverQuTopic).getListOfChildren().get(rand);
                            if (!tempLm.isEmpty()) {
                                break;
                            } else {
                                rand = -1;
                            }
                        }
                        if (rand == -1) {
                            cQuery = "CQ topic not found!";
                        } else {
                            int topicId = languageModels.get(coverQuTopic).getListOfChildren().get(rand).getTopic_id();
                            cQuery = generateCoverQuery(scores.get(0), bucketNum, currentQueryTopicLevel, currentQueryTopicNo, false, topicId);
                        }
                    } else {
                        cQuery = "CQ topic not found!";
                    }
                }
                if (cQuery != null) {
                    if (!cQuery.equals("CQ topic not found!")) {
                        coverQueries.add(cQuery);
                    }
                    count++;
                }
            }
        }
        if (coverQueries.isEmpty()) {
            return null;
        }
        return coverQueries;
    }
public ArrayList < String > generateNQueries ( String query , int N , int previousQueryTopicNo , ArrayList < Integer > coverQTopics ) { ArrayList < String > coverQueries = new ArrayList < > ( ) ; ArrayList < Integer > scores = getScore ( query ) ; if ( scores . get ( 1 ) == - 1 ) { /* if topic of the query can not be inferred */ return null ; } currentQueryTopicNo = scores . get ( 1 ) ; if ( N == 0 ) { return coverQueries ; } int currentQueryTopicLevel = languageModels . get ( currentQueryTopicNo ) . getLevel ( ) ; int seqEdited = 0 ; if ( previousQueryTopicNo != - 1 ) { seqEdited = checkSequentialEdited ( previousQueryTopicNo , currentQueryTopicNo ) ; } if ( seqEdited == 1 ) { try { fw . write ( "*****current query is sequentially edited from previous query*****" + "\n" ) ; fw . flush ( ) ; } catch ( IOException ex ) { Logger . getLogger ( GenerateCoverQuery . class . getName ( ) ) . log ( Level . SEVERE , null , ex ) ; } } int bucketNum = scores . get ( 2 ) ; int count = 0 ; coverQueryTopics = new ArrayList < > ( ) ; while ( true ) { String cQuery ; if ( seqEdited == 0 ) { /* Current query is not sequentially edited. */ if ( count < N / 2 ) { /* Generating cover query from sibling topics. */ cQuery = generateCoverQuery ( scores . get ( 0 ) , bucketNum , currentQueryTopicLevel , currentQueryTopicNo , true , - 1 ) ; if ( cQuery == null ) { } } else { /* Generating cover query from same level of original query but not from sibling topics. */ cQuery = generateCoverQuery ( scores . get ( 0 ) , bucketNum , currentQueryTopicLevel , currentQueryTopicNo , false , - 1 ) ; } if ( cQuery != null ) { if ( ! cQuery . equals ( "CQ topic not found!" ) ) { coverQueries . add ( cQuery ) ; } count ++ ; } if ( count == N ) { break ; } } else { /**
                 * Current query is sequentially edited, so cover queries will
                 * be generated based on previous cover query topics.
                 */ if ( count == coverQTopics . size ( ) ) { break ; } int coverQuTopic = coverQTopics . get ( count ) ; if ( seqEdited == 1 ) { /**
                     * Cover query should be generated from parent topic of the
                     * previous cover query.
                     */ if ( languageModels . get ( coverQuTopic ) . getParent ( ) . isEmpty ( ) ) { cQuery = "CQ topic not found!" ; } else { int topicId = languageModels . get ( coverQuTopic ) . getParent ( ) . getTopic_id ( ) ; cQuery = generateCoverQuery ( scores . get ( 0 ) , bucketNum , currentQueryTopicLevel , currentQueryTopicNo , false , topicId ) ; } } else { /**
                     * Cover query should be generated from child topic of the
                     * previous cover query.
                     */ int numChildren = languageModels . get ( coverQuTopic ) . getListOfChildren ( ) . size ( ) ; if ( numChildren > 0 ) { int rand = - 1 ; for ( int x = 0 ; x < numChildren ; x ++ ) { rand = getRandom ( 0 , numChildren ) ; LanguageModel tempLm = languageModels . get ( coverQuTopic ) . getListOfChildren ( ) . get ( rand ) ; if ( ! tempLm . isEmpty ( ) ) { break ; } else { rand = - 1 ; } } if ( rand == - 1 ) { cQuery = "CQ topic not found!" ; } else { int topicId = languageModels . get ( coverQuTopic ) . getListOfChildren ( ) . get ( rand ) . getTopic_id ( ) ; cQuery = generateCoverQuery ( scores . get ( 0 ) , bucketNum , currentQueryTopicLevel , currentQueryTopicNo , false , topicId ) ; } } else { cQuery = "CQ topic not found!" ; } } if ( cQuery != null ) { if ( ! cQuery . equals ( "CQ topic not found!" ) ) { coverQueries . add ( cQuery ) ; } count ++ ; } } } if ( coverQueries . isEmpty ( ) ) { return null ; } return coverQueries ; }
Creates N cover queries based on true user query.
Creates N cover queries based on true user query .