-def execute_and_verify_add_word(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type):
- _process_amenity(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type, '')
-
- with temp_db_conn.cursor() as temp_db_cursor:
- temp_db_cursor.execute(f"""
- SELECT * FROM word
- WHERE word_token=' {normalized_label}'
- AND word='{normalized_label}'
- AND class='{phrase_class}'
- AND type='{phrase_type}'
- AND type='{phrase_type}'""")
- return temp_db_cursor.fetchone()
-
-def execute_and_verify_add_word_with_operator(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type, phrase_operator):
- _process_amenity(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type, phrase_operator)
-
- with temp_db_conn.cursor() as temp_db_cursor:
- temp_db_cursor.execute(f"""
- SELECT * FROM word
- WHERE word_token=' {normalized_label}'
- AND word='{normalized_label}'
- AND class='{phrase_class}'
- AND type='{phrase_type}'
- AND operator='{phrase_operator}'""")
- return temp_db_cursor.fetchone()
-
-def test_process_amenity_with_near_operator(temp_db_conn, word_table, amenity_operator_funcs):
- phrase_label = ' label '
- normalized_label = 'label'
- phrase_class = 'class'
- phrase_type = 'type'
-
- assert execute_and_verify_add_word(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type)
- assert execute_and_verify_add_word_with_operator(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type, 'near')
- assert execute_and_verify_add_word_with_operator(temp_db_conn, phrase_label, normalized_label,
- phrase_class, phrase_type, 'in')
-
-def index_exists(db_connect, index):
- """ Check that an index with the given name exists in the database.
- """
- with db_connect.cursor() as cur:
- cur.execute("""SELECT tablename FROM pg_indexes
- WHERE indexname = %s and schemaname = 'public'""", (index, ))
- if cur.rowcount == 0:
- return False
- return True