Esempio n. 1
0
    def __init__(self, broker, downloader_prx, transfer_prx):
        """
        @param broker: for orchestrator adapter
        @param downloader_prx: downloader proxy
        """
        self.orchestrators_dic = {}  # Orchestrators Dictionary {key = proxy, value = broker}
        self.files_dic = {}  # Files Dictionary {key = file_hash, value = file_name}

        self.adapter = broker.createObjectAdapter('OrchestratorAdapter')
        self.downloader_factory = TrawlNet.DownloaderFactoryPrx.checkedCast(
            broker.stringToProxy(downloader_prx))
        properties = broker.getProperties()

        self.id = properties.getProperty('Identity')

        if not self.downloader_factory:
            raise ValueError('Invalid proxy for DownloaderFactory')

        # Get transfer factory
        self.transfer_factory = TrawlNet.TransferFactoryPrx.checkedCast(
            broker.stringToProxy(transfer_prx))

        if not self.transfer_factory:
            raise ValueError('Invalid proxy for TransferFactory')

        # Get topics with my_storm
        topic_manager = get_topic_manager(broker)
        self.topic_orchestrator = get_topic(
            topic_manager, ORCHESTRATOR_TOPIC_NAME)
        self.topic_updates = get_topic(
            topic_manager, DOWNLOADER_TOPIC_NAME)

        # Orchestrator subscriber event
        sync_subscriber = OrchestratorEventI(self)
        sync_subscriber_prx = self.adapter.add(sync_subscriber, Ice.stringToIdentity(
            properties.getProperty("Sync")))
        self.sync_subscriber_prx = self.adapter.createDirectProxy(
            sync_subscriber_prx.ice_getIdentity())
        self.topic_orchestrator.subscribeAndGetPublisher({}, self.sync_subscriber_prx)

        # Orchestrator publisher event
        self.publisher = TrawlNet.OrchestratorEventPrx.uncheckedCast(
            self.topic_orchestrator.getPublisher())

        # Updates Event subscriber
        updates_subscriber = UpdateEventI(self)
        updates_subscriber_prx = self.adapter.add(updates_subscriber, Ice.stringToIdentity(
            properties.getProperty("Update")))
        self.updates_subscriber_prx = self.adapter.createDirectProxy(
            updates_subscriber_prx.ice_getIdentity())
        self.topic_updates.subscribeAndGetPublisher({}, self.updates_subscriber_prx)

        # Orchestrator servant
        servant = OrchestratorI(self)
        servant_prx = self.adapter.add(servant, Ice.stringToIdentity(
            properties.getProperty("Identity")))
        print(servant_prx)
        self.servant_prx = self.adapter.createDirectProxy(servant_prx.ice_getIdentity())
Esempio n. 2
0
    def reg_process(self, templates, triples, entitymap):
        '''
        Process for lexicalization of the templates (referring expression genenation)
        :param self:
        :param templates:
        :param triples:
        :param entitymap:
        :return:
        '''
        new_templates = []
        for template in templates:
            topic = utils.get_topic(triples, entitymap)
            # Replace WIKI-IDS for simple tags (ENTITY-1, etc). In order to make it easier for the parser
            new_entitymap = self.get_new_entitymap(entitymap)
            for entity, tag in sorted(new_entitymap.items(),
                                      key=lambda x: len(x[0].name),
                                      reverse=True):
                name = '_'.join(
                    entity.name.replace('\'', '').replace('\"', '').split())
                template = template.replace(name, tag)

            # map the topic to the right tag
            for entity, tag in new_entitymap.items():
                if entity.name == entitymap[topic].name:
                    topic = tag
                    break

            # Generating referring expressions
            new_entitymap = dict(
                map(lambda x: (x[1], x[0]), new_entitymap.items()))
            template = self.reg.generate(template, new_entitymap, topic)
            new_templates.append(template)
        return new_templates
Esempio n. 3
0
    def update_offer(payload, offer_id):
        body = request.get_json()
        if not body:
            abort(400, 'Request body is missing.')

        o = Offer.query.get(offer_id)
        if not o:
            abort(404, 'Offer record does not exist.')

        # Update the record
        if body.get('title'):
            o.title = body.get('title')
        if body.get('contents'):
            o.contents = body.get('contents')
        if body.get('event_time'):
            o.event_time = body.get('event_time')
        if body.get('finalized'):
            o.finalized = body.get('finalized')
        if body.get('topics'):
            o.topics = [get_topic(name=t) for t in body.get('topics')]
        if body.get('panelists'):
            o.panelists = [get_panelist(name=p) for p in body.get('panelists')]
        try:
            o.update()
        except Exception:
            abort(422, 'Database error: Update failed.')

        return jsonify({
            'success': True,
            'message': 'Offer record has been updated successfully.',
            'id': offer_id
        }), 200
Esempio n. 4
0
    def create_offer(payload):
        body = request.get_json()
        if not body:
            abort(400, 'Request body is missing.')
        if body.get('title') is None:
            abort(400, '"title" is required in the request body.')

        # Create a new record
        o = Offer(
            title=body.get('title'),
            contents=body.get('contents', ''),
            event_time=body.get('event_time'),  # Null if not found
            finalized=body.get('finalized', False),
            topics=[get_topic(name=t) for t in body.get('topics', [])],
            panelists=[
                get_panelist(name=p) for p in body.get('panelists', [])
            ]
        )
        try:
            o.insert()
            offer_id = o.id
        except Exception:
            abort(422, 'Database error: Insertion failed.')

        return jsonify({
            'success': True,
            'message': 'Offer record has been created successfully.',
            'id': offer_id
        }), 201
Esempio n. 5
0
    def update_call(payload, call_id):
        body = request.get_json()
        if not body:
            abort(400, 'Request body is missing.')

        c = Call.query.get(call_id)
        if not c:
            abort(404, 'Call record does not exist.')

        # Update the record
        if body.get('question'):
            c.question = body.get('question')
        if body.get('description'):
            c.description = body.get('description')
        if body.get('topics'):
            c.topics = [get_topic(name=t) for t in body.get('topics')]
        try:
            c.update()
        except Exception:
            abort(422, 'Database error: Update failed.')

        return jsonify({
            'success': True,
            'message': 'Call record has been updated successfully.',
            'id': call_id
        }), 200
Esempio n. 6
0
def print_topics(F, id_to_wrd, fname, top=9):
    import os

    path = './results/' + fname

    if not os.path.exists(os.path.split(path)[0]):
        os.makedirs(os.path.split(path)[0])

    f = open(path, 'w')
    for i in xrange(F.shape[1]):
        cmd = 'Topic %s: ' % i + ' '.join(map(lambda x: id_to_wrd[x], get_topic(F, i, top))).encode('utf-8') + '\n'
        f.write(cmd)
    f.close()
    def run(self, args):
        """Definicion del metodo run"""

        broker = self.communicator()
        args = self.arguments()

        # Proxy del evento
        servant_transfer_event = TransferEventI(broker)
        adapter_event = broker.createObjectAdapter("TransferEventAdapter")
        adapter_event.activate()
        subscriber = adapter_event.addWithUUID(servant_transfer_event)

        # Object for event channel
        topic = utils.get_topic(broker)
        if not topic:
            raise ValueError("Proxy is not IceStorm")

        ## Canales de eventos
        topic_peer_event = "PeerEventSync"
        topic_transfer_event = "TransferEventSync"

        peer_topic = utils.retieve_topic(topic, topic_peer_event)
        transfer_topic = utils.retieve_topic(topic, topic_transfer_event)

        # Subscriber
        utils.create_subscriber(subscriber, transfer_topic)

        # Publisher
        peer_event = utils.create_publisher(peer_topic, topic_peer_event)

        # Proxy del transfer factory
        proxy = broker.stringToProxy(args.transfer_factory)
        transfer_factory = TrawlNet.TransferFactoryPrx.checkedCast(proxy)

        ## Creamos el proxy del receiver factory
        adapter = broker.createObjectAdapter("ReceiverAdapter")
        adapter.activate()
        servant = ReceiverFactoryI(peer_event)
        proxy_receiver_factory = adapter.add(
            servant, broker.stringToIdentity("receiverFactory"))
        receiver_factory = TrawlNet.ReceiverFactoryPrx.checkedCast(
            proxy_receiver_factory)

        self.startDataTransfer(broker, args, transfer_factory,
                               receiver_factory)

        broker.waitForShutdown()

        return 0
Esempio n. 8
0
    def create(self, current=None):
        """
        For create a downloader
        @param current:
        @return: the downloader
        """
        topic_manager = get_topic_manager(self.broker)
        sync_topic = get_topic(topic_manager, DOWNLOADER_TOPIC_NAME)
        publisher = TrawlNet.UpdateEventPrx.uncheckedCast(
            sync_topic.getPublisher())

        servant = DownloaderI(publisher, self.downloads_directory)
        proxy = current.adapter.addWithUUID(servant)

        return TrawlNet.DownloaderPrx.checkedCast(proxy)
Esempio n. 9
0
def print_topics(F, id_to_wrd, fname, top=9):
    import os

    path = './results/' + fname

    if not os.path.exists(os.path.split(path)[0]):
        os.makedirs(os.path.split(path)[0])

    f = open(path, 'w')
    for i in xrange(F.shape[1]):
        cmd = 'Topic %s: ' % i + ' '.join(
            map(lambda x: id_to_wrd[x], get_topic(F, i,
                                                  top))).encode('utf-8') + '\n'
        f.write(cmd)
    f.close()
    def run(self, argv):
        """Definicion del metodo run"""

        broker = self.communicator()
        args = self.arguments()

        # Proxy del evento
        servant_peer_event = PeerEventI()
        adapter_event = broker.createObjectAdapter("PeerEventAdapter")
        subscriber = adapter_event.addWithUUID(servant_peer_event)

        # Object for event channel
        topic = utils.get_topic(broker)
        if not topic:
            raise ValueError("Proxy is not IceStorm")

        ## Canales de eventos
        topic_peer_event = "PeerEventSync"
        topic_transfer_event = "TransferEventSync"

        peer_topic = utils.retieve_topic(topic, topic_peer_event)
        transfer_topic = utils.retieve_topic(topic, topic_transfer_event)

        # Subscriber
        utils.create_subscriber(subscriber, peer_topic)

        # Publisher
        transfer_event = utils.create_publisher(transfer_topic,
                                                topic_transfer_event)

        # Proxy del sender factory
        proxy = broker.stringToProxy(args.sender_factory)
        sender_factory = TrawlNet.SenderFactoryPrx.checkedCast(proxy)

        # Proxy del transfer factory
        adapter = broker.createObjectAdapter("TransferAdapter")
        servant = TransferFactoryI(sender_factory, broker, transfer_event)
        proxy_transfer_factory = adapter.add(
            servant, broker.stringToIdentity("transferFactory"))
        print("Transfer Factory: {}".format(proxy_transfer_factory),
              flush=True)

        adapter_event.activate()
        adapter.activate()
        self.shutdownOnInterrupt()
        broker.waitForShutdown()

        return 0
Esempio n. 11
0
    def create_call(payload):
        body = request.get_json()
        if not body:
            abort(400, 'Request body is missing.')
        if body.get('question') is None:
            abort(400, '"question" is required in the request body.')

        # Create a new record
        c = Call(
            question=body.get('question'),
            description=body.get('description', ''),
            topics=[get_topic(name=t) for t in body.get('topics', [])]
        )
        try:
            c.insert()
            call_id = c.id
        except Exception:
            abort(422, 'Database error: Insertion failed.')

        return jsonify({
            'success': True,
            'message': 'Call record has been created successfully.',
            'id': call_id
        }), 201