Esempio n. 1
0
 def __tester_init():
     topics = Topics('g:\\myq\\testers\\')
     p0 = {t.name
           for t in topics.topics
           } == {'TA', 'TA -> TB', 'TA -> TB -> TC', 'TD', 'TD -> TE'}
     ta = Topic(name='TA', priority='A', i_row=1)
     tb = Topic(name='TA -> TB', priority='A', i_row=1)
     tc = Topic(name='TA -> TB -> TC', priority='A', i_row=1)
     td = Topic(name='TD', priority='A', i_row=1)
     te = Topic(name='TD -> TE', priority='A', i_row=1)
     p1 = topics.level == {0: [ta, td], 1: [tb, te], 2: [tc]}
     p2 = topics.is_valid
     u_tester.run(p0, p1, p2)
Esempio n. 2
0
    def create_topic_by_subject_locator(self, subject_locator):
        """Returns a `Topic` instance with the specified subject locator.

        This method returns either an existing `Topic` or creates a
        new `Topic` instance with the specified subject locator.

        :param subject_locator: the subject locator the topic should
          contain
        :type subject_locator: `Locator`
        :rtype: `Topic`

        """
        if subject_locator is None:
            raise ModelConstraintException(
                self, 'The subject locator may not be None')
        reference = subject_locator.to_external_form()
        try:
            topic = self.topic_constructs.get(
                subject_locators__address=reference)
        except Topic.DoesNotExist:
            topic = Topic(topic_map=self)
            topic.save()
            sl = SubjectLocator(topic=topic,
                                address=reference,
                                containing_topic_map=self)
            sl.save()
            topic.subject_locators.add(sl)
        return topic
Esempio n. 3
0
def topics_page():
    if request.method == 'GET':
        topics = app.store.get_topics()
        categories = app.store.get_categories()
        now = datetime.datetime.now()
        return render_template('topics.html',
                               topics=topics,
                               categories=categories,
                               current_time=now.ctime())
    elif 'topics_to_delete' in request.form or 'search' in request.form:
        if request.form['submit'] == 'Delete':
            keys = request.form.getlist('topics_to_delete')
            for key in keys:
                app.store.delete_topic(int(key))
                return redirect(url_for('topics_page'))
        elif request.form['submit'] == 'Search':
            keyword = request.form['search']
            topics = app.store.search_topic(keyword)
            now = datetime.datetime.now()
            return render_template('topics.html',
                                   topics=topics,
                                   current_time=now.ctime())
    else:
        title = request.form['title']
        text = request.form['text']
        time = str((datetime.datetime.now()))
        time = time[:-7]
        category_id = request.form.get('categoryId')
        #time=request.form['time']
        topic = Topic(title, text, time, category_id)
        app.store.add_topic(topic)
        return redirect(url_for('topic_page', key=app.store.topic_last_key))
    def handle_publisher(self, connection, message):
        self.publishers[str(datetime.now())] = connection

        new_topic = Topic(
            ' '.join(self.separate_str_by_space(message)[1:]).rstrip('\n'),
            connection)
        self.topics[str(datetime.now())] = new_topic

        reply = "Server: topic \'" + new_topic.get_name(
        ) + "\' has been published."
        print(reply)

        try:
            connection.sendall(str.encode(reply + '\n'))

            self.receive_topic_messages_and_respond(connection)
        except:
            print('Connection to ' +
                  ':'.join(map(str, connection.getpeername())) + ' lost.\n')

            for topic in self.topics.values():
                if topic.get_publisher() == connection:
                    topic.set_is_active(False)

                    self.send_inactive_topic_message_to_subs(topic)

            self.remove_client_from_clients_list(connection)
            self.remove_client_from_publishers_list(connection)

        return
Esempio n. 5
0
    def on_message(self, client, userdata, msg):

        _topic = Topic(msg.topic)

        if _topic.get_prefix() != "device":
            LOGGER.error("Unknown message")

        # # 1. /device/<device_type>/<device_id>/connect
        # # 2. /device/<device_type>/<device_id>/disconnect
        # # 3. /device/<device_type>/<device_id>/set
        # # 4. /device/<device_type>/<device_id>/get
        # # 5. /device/<device_type>/<device_id>/update
        else:
            state = msg.payload
            LOGGER.info('the device:{}` has been `{}`, device Type: {}'.format(
                _topic.get_device_id(), _topic.get_action(),
                _topic.device_type()))
            id = tinydb.Query()
            if (self._database.search(
                    id.device_id == str(_topic.get_device_id()))):
                # is exists
                self._database.update({'state': str(state)},
                                      id.device_id == str(
                                          _topic.get_device_id()))
            else:
                self._database.insert({
                    'device_id':
                    str(_topic.get_device_id()),
                    'device_type':
                    str(_topic.get_device_id()),
                    'action':
                    str(_topic.get_action())
                })  # Was state and changed to action
 def topic_proc(self, topic, country, epoch):
     """
     Every topic ingested needs to be added to the memory and to the expiration queue
     """
     new_topic = Topic(topic)
     self.memory.increase_counter(country, new_topic)
     self.queue.push(epoch, country, new_topic)
Esempio n. 7
0
def prepocess(topics):
    pre_list = []
    for topic in topics:
        topic = topic.strip()
        tp = Topic(topic, comma=True, num=False)
        pre_list.append(tp)
    return pre_list
Esempio n. 8
0
 def __tester_init():
     t = Topic(name='A -> B -> C', priority='ABA', i_row=8)
     p0 = t.name == 'A -> B -> C'
     p1 = t.priority == 'ABA'
     p2 = t.i_row == 8
     p3 = t.level == 2
     u_tester.run(p0, p1, p2, p3)
Esempio n. 9
0
 def get_topic(self, key):
     with dbapi2.connect(self.app.config['dsn']) as connection:
         cursor = connection.cursor()
         query = "SELECT TITLE, TEXT, CURTIME,CATEGORYID FROM TOPIC WHERE (ID = %s)"
         cursor.execute(query, (key,))
         title,text,time, categoryId = cursor.fetchone()
     return Topic(title,text,time,categoryId)
Esempio n. 10
0
    def register_topic(self, type, name, period):
        topic = self._get_topic(name)
        if type == 'publish':
            # 이미 있는 토픽에 publish.
            if topic:
                topic.append_publisher(self._address)

                return self.send_data(
                    (1, f'Publisher register complete: {name}'))
            # 없는 토픽 생성.
            else:
                new_topic = Topic(name, period, self._address)
                self._topics.append(new_topic)

                return self.send_data(
                    f'Topic publish register complete: {name}')
        elif type == 'subscribe':
            if topic:
                topic.append_subscriber(self._address)

                return self.send_data(f'Subscriber register complete: {name}')
            else:
                self.send_data(f'No such topic: {name}')

        else:
            self.send_data(f'Wrong topic type: {type}')
Esempio n. 11
0
def from_topic_list(topic_list):
    """Generates a Window from a list of "topics", in which each "topic" is a list of tuples of (message, reason))

    Parameters
    ----------
    topic_list : list(tuples(|message|, str))
        List of lists of tuples of (message, reason)

    Returns
    -------
    TYPE
        :class:`nlp.text.window.Window`
    """
    _window = Window()
    for topic in topic_list[::-1]:
        # Append topics from oldest to most recent
        uninit = True

        for m, r in topic:
            if uninit:
                # generate new topic and append to window
                _window.activate_topic(Topic(start_message=m, reason=r))
                uninit = False  # no longer uninit
            else:
                _window.insert_message(message=m, reason=r)

    return _window
Esempio n. 12
0
 def get_topics(self):
     with dbapi2.connect(self.app.config['dsn']) as connection:
         cursor = connection.cursor()
         query = "SELECT * FROM TOPIC ORDER BY ID"
         cursor.execute(query)
         topics = [(key, Topic(title,text,time,categoryId))
                   for key, title,text,time,categoryId in cursor]
     return topics
 def test_predict_topic_when_doc_length_less_than_min_words(self):
     min_words = 20
     t = Topic(lang_code=self.lang_code, min_words=min_words)
     pred = t.predict_topic(self.text)
     self.assertTrue(isinstance(pred, str))
     self.assertEqual(
         "required at least {} words for prediction".format(min_words),
         pred)
Esempio n. 14
0
def topic_add_page():
    if request.method == 'GET':
        return render_template('topic_add.html')
    else:
        content = str(request.form['content'])
        writer = app.moderatorlist.get_moderator(current_user.nickname)
        topic = Topic(content, writer)
        current_app.topiclist.add_topic(topic)
        return redirect(url_for('Topics.topics_page'))
Esempio n. 15
0
 def search_topic(self, key):
     with dbapi2.connect(self.app.config['dsn']) as connection:
         cursor = connection.cursor()
         query = "SELECT * FROM TOPIC WHERE (TITLE ILIKE %s OR TEXT ILIKE %s)"
         key = '%'+key+'%'
         cursor.execute(query, (key, key))
         topics = [(key, Topic(title, text, time, categoryId))
                   for key, title, text, time, categoryId in cursor]
     return topics
Esempio n. 16
0
    def create_empty_topic(self):
        """Returns a `Topic` instance with no other information.

        :rtype: `Topic`

        """
        topic = Topic(topic_map=self)
        topic.save()
        return topic
Esempio n. 17
0
 def childTopicsFormChildsUrlPage(html, currentTopic):
     topics = []
     soup = BeautifulSoup(html, "html.parser")
     all = soup.find_all("a", {"class", "zm-item-tag"})
     for i in all:
         t = Topic(unicode(i.attrs['data-token']),
                   unicode(i.string).strip(), currentTopic.id)
         if (currentTopic.id != t.id):
             topics.append(t)
     return topics
Esempio n. 18
0
 def getTopics(self):
     global conn
     global cur
     cur.execute("SELECT * FROM topics")
     topicsData = cur.fetchall()
     allTopicObjs = []
     for topic in topicsData:
         topicObj = Topic(topic['id'], topic['name'])
         allTopicObjs.append(topicObj)
     return allTopicObjs
Esempio n. 19
0
 def get_TopicList(self):
         with dbapi2.connect(app.config['dsn']) as connection:
            cursor = connection.cursor()
            query = """SELECT TOP_ID, CONTENT, WRITER, NICKNAME FROM TOPICS JOIN
             MODERATORS ON WRITER=ID
             ORDER BY TOP_ID"""
            cursor.execute(query)
            topicTable = [(id, Topic(content, writer), modname)
                       for id, content, writer, modname in cursor]
         return topicTable
Esempio n. 20
0
    def get_topic(self, topic_name):
        """ 获取Account的一个Topic对象

            @type topic_name: string
            @param topic_name: 主题名称

            @rtype: Topic object
            @return: 返回该Account的一个Topic对象
        """
        return Topic(topic_name, self.mns_client, self.debug)
Esempio n. 21
0
def topic():
    # group = u"爱吃早餐群"
    group = u"养老区交流协会V2.0"
    a, b, c, d = Topic().start()
    msg = "今日学位英语: (难度" + d + ")\n\n" + a + "\n\n" + b
    send_group(group, msg)
    time.sleep(60)
    send_group(group, c)
    timer = threading.Timer(86400, topic)
    timer.start()
    def test_predict_topic_for_invalid_language_model(self):
        text = """ La Ligue des champions de l'UEFA (UEFA Champions League), parfois abrégée en C1 et anciennement 
                  dénommée Coupe des clubs champions européens (de sa création en 1955 jusqu'en 1992), est une compétition 
                  annuelle de football organisée par l'Union des associations européennes de football (UEFA) et regroupant 
                  les meilleurs clubs du continent européen1. """

        t = Topic(lang_code="fr")
        pred = t.predict_topic(text)
        self.assertTrue(isinstance(pred, str))
        self.assertEqual(pred, 'language not supported')
Esempio n. 23
0
    def get_topic_node(self, topic_path, operation):
        if topic_path is None:
            return None

        topic_node = self.trie.find_node(topic_path)
        if topic_node is None and operation in (OperationType.SUBSCRIBE.value,
                                                OperationType.PUBLISH.value):
            new_topic = Topic(topic_path)
            return self.trie.add(new_topic)

        return topic_node
Esempio n. 24
0
    def from_dict(self, dic):
        if 'topics' not in dic:
            print("Research: from_dict: 'topics' not in dic. Dic:", dic)
            exit(-1)

        self.topics = []

        for dic_topic in dic['topics']:
            topic = Topic()
            topic.from_dict(dic_topic)
            self.topics.append(topic)
Esempio n. 25
0
    def retrieve_topic(self, topic):
        """

    @param change:
    @return:
    """
        url = self.agent_lib.get_query_for_topic(topic)
        s = self.request(url)
        changes = Change.parseJson(s)
        main_change_number = topic.number
        changes = [x for x in changes if x.number != main_change_number]
        return Topic(topic, changes)
Esempio n. 26
0
    def get_topic(self, topic_name):
        for topic in self.topics:
            if topic.topic_name == topic_name:
                return topic

        print("App: processTopic: Tried to parse an unknown topic", topic_name)
        print("\tCreating a new Topic to match request.")

        topic = Topic({'topic-name': topic_name})
        self.add_topic(topic)  

        return topic
Esempio n. 27
0
def main():
    topic = Topic()

    observer_one = TopicSubscriber("Topic subscriber 1")
    observer_two = TopicSubscriber("Topic subscriber 2")
    observer_three = TopicSubscriber("Topic subscriber 3")

    topic.subscribe(observer_one)
    topic.subscribe(observer_two)
    topic.subscribe(observer_three)

    topic.set_topic("Programming is fun!")
Esempio n. 28
0
    def monit(self):
        try:
            auth = Auth(self._session, self._user, self._config)
            auth.confirm()

            topic = Topic(self._session, self._user, self._config)
            nt = Post(self._session, self._user, self._config,
                      topic.locate_post_url())

            nt.reply()
        except Exception as e:
            Recorder.error(self, self._user, "init the watchdog", e)
            return None
Esempio n. 29
0
 def get_all_topics(self):
     self.exe_query(
         "SELECT T_NAME, OFSET, rcd_date FROM TOPIC WHERE ISACTIVE=1;")
     all_topics = self.cur.fetchall()
     topics_dict = {}
     # topics_list = []
     # for topic in all_topics:
     #     topics_set.add(topic[0])
     # return topics_set
     for topic in all_topics:
         t = Topic(topic[0], topic[1], topic[2])
         topics_dict[topic[0]] = t
     print("**** topics dict **** : ", topics_dict)
     return topics_dict
def topic_test():
    start = time.time()
    topic = Topic("http://www.zhihu.com/topic/19550429")
    topic.parser()
    print "Title of the topic is ", topic.get_title()
    print "Introduction of the topic is ", topic.get_introduction()
    print "Number of follower of the topic is ", topic.get_follower_num()
    print "Parent topics are ", topic.get_parent_topic()
    print "Sample child topics are ", topic.get_sample_child_topic()
    print "Top answerers of this topic are ", topic.get_top_answerer()
    topic.save_latest_feed()
    topic.save_top_answers()  # might be time-consuming
    end = time.time()
    print "Time used is", end - start