# Path: framework/knowledge/feedback_collector.py
# class FeedbackSource(object):
# 
#     def __init__(self, src, subref=None, reliability=None, related_tg=None):
#         self._subref = subref
#         self._name = str(src) if subref is None else str(src) + ' - ' + str(subref)
#         self._obj = src
#         self._reliability = reliability
#         self._related_tg = related_tg
# 
#     def __str__(self):
#         return self._name
# 
#     def __hash__(self):
#         return id(self._obj)
# 
#     def __eq__(self, other):
#         return id(self._obj) == id(other._obj)
# 
#     @property
#     def obj(self):
#         return self._obj
# 
#     @property
#     def related_tg(self):
#         return self._related_tg
# 
# Path: libs/utils.py
# def ensure_dir(f):
#     d = os.path.dirname(f)
#     if not os.path.exists(d):
#         os.makedirs(d)
# 
# def chunk_lines(string, length):
#     l = string.split(' ')
#     chk_list = []
#     full_line = ''
#     for wd in l:
#         full_line += wd + ' '
#         if len(full_line) > (length - 1):
#             chk_list.append(full_line)
#             full_line = ''
#     if full_line:
#         chk_list.append(full_line)
#     # remove last space char
#     if chk_list:
#         chk_list[-1] = (chk_list[-1])[:-1]
#     return chk_list


import sys
import os
import re
import math
import threading
import framework.global_resources as gr
import libs.external_modules as em
from datetime import datetime
from framework.knowledge.feedback_collector import FeedbackSource
from libs.external_modules import *
from libs.utils import ensure_dir, chunk_lines
def regexp(expr, item):
    reg = re.compile(expr)
    if item is None:
        return False
    robj = reg.search(item)
    return robj is not None

def regexp_bin(expr, item):
    expr = bytes(expr)
    reg = re.compile(expr)
    if item is None:
        return False
    robj = reg.search(item)
    return robj is not None


class FeedbackGate(object):

    def __init__(self, database):
        """
        Args:
            database (Database): database to be associated with
        """
        self.db = database

    def __iter__(self):
        for item in self.db.iter_last_feedback_entries():
            yield item

    def get_feedback_from(self, source):

# Path: framework/knowledge/feedback_collector.py
# class FeedbackSource(object):
# 
#     def __init__(self, src, subref=None, reliability=None, related_tg=None):
#         self._subref = subref
#         self._name = str(src) if subref is None else str(src) + ' - ' + str(subref)
#         self._obj = src
#         self._reliability = reliability
#         self._related_tg = related_tg
# 
#     def __str__(self):
#         return self._name
# 
#     def __hash__(self):
#         return id(self._obj)
# 
#     def __eq__(self, other):
#         return id(self._obj) == id(other._obj)
# 
#     @property
#     def obj(self):
#         return self._obj
# 
#     @property
#     def related_tg(self):
#         return self._related_tg
# 
# Path: libs/utils.py
# def ensure_dir(f):
#     d = os.path.dirname(f)
#     if not os.path.exists(d):
#         os.makedirs(d)
# 
# def chunk_lines(string, length):
#     l = string.split(' ')
#     chk_list = []
#     full_line = ''
#     for wd in l:
#         full_line += wd + ' '
#         if len(full_line) > (length - 1):
#             chk_list.append(full_line)
#             full_line = ''
#     if full_line:
#         chk_list.append(full_line)
#     # remove last space char
#     if chk_list:
#         chk_list[-1] = (chk_list[-1])[:-1]
#     return chk_list


# Path: framework/database.py
import sys
import os
import re
import math
import threading
import framework.global_resources as gr
import libs.external_modules as em
from datetime import datetime
from framework.knowledge.feedback_collector import FeedbackSource
from libs.external_modules import *
from libs.utils import ensure_dir, chunk_lines

def regexp(expr, item):
    reg = re.compile(expr)
    if item is None:
        return False
    robj = reg.search(item)
    return robj is not None

def regexp_bin(expr, item):
    expr = bytes(expr)
    reg = re.compile(expr)
    if item is None:
        return False
    robj = reg.search(item)
    return robj is not None


class FeedbackGate(object):

    def __init__(self, database):
        """
        Args:
            database (Database): database to be associated with
        """
        self.db = database

    def __iter__(self):
        for item in self.db.iter_last_feedback_entries():
            yield item

    def get_feedback_from(self, source):

        if not isinstance(source, FeedbackSource):