Esempio n. 1
0
    def __get_semantic_relations_for_organization(self, cleaned_entity,
                                                  raw_entity):
        print('Searching {}'.format(cleaned_entity))
        relation_list = []
        query_results = self.__get_dbpedia_results(
            ceo_query.format(cleaned_entity))

        if query_results['results']['bindings']:
            ceoUri = query_results['results']['bindings'][0]['ceoUri']
            if ceoUri['type'] == "typed-literal":
                cleaned_dbpedia_text = self.__clean_dbpedia_text(
                    ceoUri['value'])
                relation_list.append(
                    Relation(Entity('ORGANIZATION', raw_entity, -1),
                             Entity('PERSON', cleaned_dbpedia_text, -1),
                             'dirigida por', 1, []))
            elif ceoUri['type'] == "uri":
                name_query_results = self.__get_dbpedia_results(
                    ceo_name_query.format(ceoUri['value']))
                if name_query_results['results']['bindings']:
                    relation_list.append(
                        Relation(
                            Entity('ORGANIZATION', raw_entity, -1),
                            Entity(
                                'PERSON', name_query_results['results']
                                ['bindings'][0]['ceoName']['value'], -1),
                            'dirigida por', 1, []))

        return relation_list
Esempio n. 2
0
 def __relation_list_builder(self, query_results, entity_text,
                             relation_text, first_entity_type,
                             second_entity_type):
     relation_list = []
     for result in query_results['results']['bindings']:
         relation_list.append(
             Relation(
                 Entity(first_entity_type, entity_text, -1),
                 Entity(second_entity_type, result['info']['value'], -1),
                 relation_text, 1, []))
     return relation_list
    def handle_action(self, action):
        if action.type == ActionTag.ProgramMemoryAdd:
            position = action.data['position']
            parent_id = action.data['parent_id']

            world_data_for_position = self.manager.get_world_data_for_position(
                position)
            if not entities_occupy_position(parent_id,
                                            world_data_for_position):
                #todo - consider making this an explicit action instead of just chucking it into the manager? for now, this is fine
                memory_segment = Entity([
                    Attribute(AttributeTag.ProgramMemory,
                              {'parent_id': parent_id}),
                    Attribute(AttributeTag.Visible),
                    Attribute(AttributeTag.WorldPosition, {'value': position}),
                    Attribute(
                        AttributeTag.DrawInfo, {
                            'draw_type': WorldRenderType.Memory,
                            'draw_type': WorldRenderType.Memory,
                            'z_level': 2
                        })
                ])
                self.manager.add_entity(memory_segment)

                parent = self.manager.get_entity_by_id(parent_id)
                parent.get_attribute(
                    AttributeTag.OwnedMemory).data['segments'].append(
                        memory_segment)

        return []
Esempio n. 4
0
 def __extract_entities_with_standford(self, text):
     r = requests.post(self.standfor_model_url,
                       params=self.stanford_params_map,
                       data=text.encode('utf-8'))
     result = r.json()['sentences'][0]['entitymentions']
     return [
         Entity(self.__unify_types(entity['ner']), entity['text'], 0)
         for entity in result if self.__is_valid_entity(entity['text'])
     ]
Esempio n. 5
0
 def __extract_entities_with_vision(self, text):
     result = self.vision_model.get_entities(text)
     entities = []
     for key in result:
         for entity in result[key]:
             if (self.__is_valid_entity(entity)):
                 e = Entity(self.__unify_types(key), entity, 0)
                 entities.append(e)
     return entities
    def test_is_input_row_in_capital_group_should_be_false4(self):
        entity = Entity("1111111111", "other", "Test sp. zoo",
                        "audit restricted client - PL SLP assigned")
        engagement = Engagement(entity, "XXXXX1", "bez znaczenia",
                                "Jan Kowalski", "21-02-2015", "Active")

        self.assertFalse(
            self.__strategy.is_input_row_in_capital_group(engagement),
            msg="Should not be in capital group")
Esempio n. 7
0
    def _parse_object_from_csv_line(self, line):

        try:
            line = line.strip('\n').split(sep=';')
            input_entity = Entity(line[0])

            return input_entity

        except IndexError as e:
            print(e)
    def generate_floor(self, width, height):

        ####make tiles####

        tiles = [[DungeonTile(CanvasTile(tcod.Color(0, 0, 0), tcod.Color(255, 255, 255), '.'), False) for i in range(height)] for j in range(width)]
        for i in range(width):
            for j in range(height):
                if i == 0 or j == 0 or i == width-1 or j == height-1:
                    tiles[i][j].canvas_tile.character = '#'
                    tiles[i][j].is_obstacle = True

        floor = Floor(width, height, tiles)

        ####populate with necessary entities####

        #Stairs
        up_stair_x = random.randint(1, width-2)
        up_stair_y = random.randint(1, height-2)
        while True:
            down_stair_x = random.randint(1, width-2)
            down_stair_y = random.randint(1, height-2)
            if down_stair_x != up_stair_x or down_stair_y != up_stair_y:
                break
        up_stair = Entity("up_stair", up_stair_x, up_stair_y)
        down_stair = Entity("down_stair", down_stair_x, down_stair_y)
        up_stair.add_component(StairComponent(up_stair, True))
        up_stair.add_component(VisibleComponent(up_stair, CanvasTile(None, tcod.Color(255, 0, 0), '<')))
        down_stair.add_component(StairComponent(up_stair, False))
        down_stair.add_component(VisibleComponent(up_stair, CanvasTile(None, tcod.Color(255, 0, 0), '>')))
        floor.add_entity(up_stair)
        floor.add_entity(down_stair)

        #monsters
        for i in range(random.randint(1,20)):
            monster = Entity("monster " + str(i), random.randint(1, width-2), random.randint(1, height-2), True)
            monster.add_component(AIComponent(monster))
            monster.add_component(VisibleComponent(monster, CanvasTile(None, tcod.Color(0, 0, 255), '&')))
            monster.add_component(HealthComponent(monster, 1))
            floor.add_entity(monster)

        return floor
Esempio n. 9
0
 def __order_entities(self, unified_entities, text):
     # remove duplicated entities
     unique_entities = set(unified_entities)
     for entity in unique_entities:
         entity.index = [m.start() for m in re.finditer(entity.text, text)]
     entities_with_index_normalized = []
     for entity_indexed in unique_entities:
         if len(entity_indexed.index) > 0:
             for index in entity_indexed.index:
                 entities_with_index_normalized.append(
                     Entity(entity_indexed.entity_type, entity_indexed.text,
                            index))
     entities_with_index_normalized.sort(key=lambda x: x.position)
     return entities_with_index_normalized
Esempio n. 10
0
    def __init__(self, width, height):
        Menu.__init__(self, width, height)

        self.queued_actions_cost_so_far = 0
        self.action_history = []
        self.flagged_exit = False
        self.entity_manager = None
        self.game_state = GameState.TakingInput
        self.current_input_tree = innates_input_tree

        player_hardcoded_libraries = [
            Library('atk', 'temporary test library',
                    [config.game_functions.master_available_functions[0]])
        ]

        #try and load a save game. if that fails, initialize a baseline entity manager and try to feed in an action history. If both fail, the game simply ends up in a newgame state
        self.entity_manager = self.try_load_savegame()
        if not self.entity_manager:
            #currently hardcoded to test player movement
            self.entity_manager = EntityManager(self)
            self.entity_manager.add_entity(
                Entity([
                    Attribute(AttributeTag.Player,
                              {'max_actions_per_cycle': max_actions}),
                    Attribute(AttributeTag.Visible),
                    Attribute(AttributeTag.OwnedMemory, {'segments': []}),
                    Attribute(AttributeTag.WorldPosition,
                              {'value': Vec2d(2, 2)}),
                    Attribute(AttributeTag.MaxProgramSize, {'value': 5}),
                    Attribute(AttributeTag.ClockRate, {'value': 2}),
                    Attribute(
                        AttributeTag.DrawInfo, {
                            'character': 64,
                            'fore_color': libtcod.Color(157, 205, 255),
                            'back_color': libtcod.black,
                            'draw_type': WorldRenderType.Character,
                            'z_level': 2
                        }),
                    Attribute(AttributeTag.Libraries,
                              {'value': player_hardcoded_libraries})
                ]))
            #for x in range(10):
            self.entity_manager.add_entity(
                Entity([
                    Attribute(AttributeTag.HostileProgram),
                    Attribute(AttributeTag.Visible),
                    Attribute(AttributeTag.OwnedMemory, {'segments': []}),
                    Attribute(
                        AttributeTag.WorldPosition, {'value': Vec2d(20, 10)}
                    ),  #libtcod.random_get_int(0, 5, 45), libtcod.random_get_int(0, 5, 45))}),
                    Attribute(AttributeTag.MaxProgramSize, {'value': 5}),
                    Attribute(AttributeTag.ClockRate, {'value': 2}),
                    Attribute(
                        AttributeTag.DrawInfo, {
                            'character': 121,
                            'fore_color': libtcod.Color(255, 0, 0),
                            'back_color': libtcod.black,
                            'draw_type': WorldRenderType.Character,
                            'z_level': 2
                        })
                ]))

            self.try_load_action_history()
        else:
            self.entity_manager.parent_menu = self

        self.entity_manager.player_id = 1

        self.init_ui()
Esempio n. 11
0
 def get(self):
     entity = Entity('the5fire\'s blog')
     self.render('index.html', entity=entity)
Esempio n. 12
0
for i in range(NUM_FLOORS):
    newfloor = generator.generate_floor(random.randint(15, 25),
                                        random.randint(15, 25))
    floors.append(newfloor)

for i in range(NUM_FLOORS):
    if i > 0:
        floors[i].get_entity("up_stair").get_component(
            StairComponent).set_destination_floor(floors[i - 1])
    if i < NUM_FLOORS - 1:
        floors[i].get_entity("down_stair").get_component(
            StairComponent).set_destination_floor(floors[i + 1])

current_floor = floors[0]
player = Entity("player",
                current_floor.get_entity("up_stair").x,
                current_floor.get_entity("up_stair").y, True)
player.add_component(PlayerComponent(player))
player.add_component(
    VisibleComponent(player, CanvasTile(None, tcod.Color(0, 255, 0), '@')))
current_floor.add_entity(player)


def go_up_to_floor(new_floor):
    change_floor(new_floor)
    put_player_on_downstair()


def go_down_to_floor(new_floor):
    change_floor(new_floor)
    put_player_on_upstair()
Esempio n. 13
0
def discover_semantic_relations():
    entity = Entity('PERSON', 'iván Duque márquez', 0)
    response, relations = personal_knowledge.discover_semantic_relation(entity)
    print(relations)