# previous = ''
# for word in word_list:
#
#     if previous == word:
#         continue
#     previous = word
#
#     for idx in range(0, len(word) - 1):
#         print word[idx], ' - ', word[idx + 1]
#
#
# print '---------------------------------------------------------------------------------'

previous = ''
for item in connect_to_database.execute_select_query(SQL_SELECT_QUERY):

    for word in item['bigram'].split('-'):
        if previous == word:
            continue
        previous = word

        SQL_INSERT_QUERY = ''
        for idx in range(0, len(word) - 1):
            SQL_INSERT_QUERY += 'INSERT INTO char_bigram_feature(bigram_id, doc_id, para_id, char_bigram) ' \
                                'VALUES ({}, {}, {}, {})'.format(item['bigram_id'], item['doc_id'], item['para_id'],
                                                                 QuotedString(word[idx] + ' - ' + word[idx + 1])
                                                                 .getquoted())

        connect_to_database.execute_insert_query(SQL_INSERT_QUERY)
def get_num_of_doc_written_by_an_author(author_id):
    if type(author_id) is not int:
        return -1
    SQL_SELECT_QUERY = "SELECT COUNT(doc_id) as num FROM document WHERE author_id = {};".format(
        author_id)
    return connect_to_database.execute_select_query(SQL_SELECT_QUERY)[0]['num']
def get_all_docs_by_author_id(author_id):
    if type(author_id) is not int:
        return -1
    SQL_SELECT_QUERY = "SELECT doc_id, doc_title, year_of_pub FROM document WHERE author_id = {} ORDER " \
                       "BY doc_id;".format(author_id)
    return connect_to_database.execute_select_query(SQL_SELECT_QUERY)
def get_all_author_id_and_name():
    SQL_SELECT_QUERY = "SELECT author_id, author_name FROM author;"
    return connect_to_database.execute_select_query(SQL_SELECT_QUERY)
def get_author_and_written_docs_count():
    SQL_SELECT_QUERY = "SELECT d.author_id as aid, a.author_name as aname, COUNT(d.doc_id) as doc_num FROM document " \
                       "d INNER JOIN author a ON d.author_id = a.author_id GROUP BY d.author_id, a.author_name " \
                       "ORDER BY d.author_id;"
    return connect_to_database.execute_select_query(SQL_SELECT_QUERY)
def get_total_num_of_docs_with_stylo_values():
    SQL_SELECT_QUERY = "SELECT COUNT(DISTINCT doc_id) as number FROM fact;"
    return connect_to_database.execute_select_query(
        SQL_SELECT_QUERY)[0]['number']
def get_total_num_of_docs():
    SQL_SELECT_QUERY = "SELECT COUNT(doc_id) as number FROM document;"
    return connect_to_database.execute_select_query(
        SQL_SELECT_QUERY)[0]['number']
def get_total_num_of_authors():
    SQL_SELECT_QUERY = "SELECT COUNT(author_id) as number FROM author;"
    return connect_to_database.execute_select_query(
        SQL_SELECT_QUERY)[0]['number']