def load_instrument_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the instruments and their
        various properties
        """
        print "\nLoading grounded knowledge: instruments"

        # This root atom is the atom that all instrument types are a subtype
        # of.
        instrument_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "INSTRUMENT_TYPE")

        # Loop over the instrument types in the spock bot library and load each
        # one into the atomspace.
        for instrument in instruments_list:
            concept_node = self._atomspace.add_node(
                types.ConceptNode, instrument["name"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by",
                                      concept_node,
                                      NumberNode(str(instrument["id"])))
            inh_node = add_predicate(
                self._atomspace,
                "be",
                instrument_type_root_atom,
                concept_node)
Ejemplo n.º 2
0
    def load_biome_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the biomes and their
        various properties
        """
        print "\nLoading grounded knowledge: biomes"

        # This root atom is the atom that all biome types are a subtype of.
        biome_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "BIOME_TYPE")

        # Loop over the biome types in the spock bot library and load each one
        # into the atomspace.
        for biome in biomes_list:
            concept_node = self._atomspace.add_node(types.ConceptNode,
                                                    biome["name"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by",
                                      concept_node,
                                      NumberNode(str(biome["id"])))
            inh_node = add_predicate(self._atomspace, "be",
                                     biome_type_root_atom, concept_node)
            # print inh_node
            # print repr_node

            color_node = add_predicate(self._atomspace, "Color", concept_node,
                                       NumberNode(str(biome["color"])))
            # print color_node
            rainfall_node = add_predicate(self._atomspace, "Rainfall",
                                          concept_node,
                                          NumberNode(str(biome["rainfall"])))
            # print color_node
            temperature_node = add_predicate(
                self._atomspace, "Temperature", concept_node,
                NumberNode(str(biome["temperature"])))
    def load_biome_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the biomes and their
        various properties
        """
        print "\nLoading grounded knowledge: biomes"

        # This root atom is the atom that all biome types are a subtype of.
        biome_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "BIOME_TYPE")

        # Loop over the biome types in the spock bot library and load each one
        # into the atomspace.
        for biome in biomes_list:
            concept_node = self._atomspace.add_node(
                types.ConceptNode, biome["name"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by",
                                      concept_node,
                                      NumberNode(str(biome["id"])))
            inh_node = add_predicate(
                self._atomspace,
                "be",
                biome_type_root_atom,
                concept_node)
            # print inh_node
            # print repr_node

            color_node = add_predicate(
                self._atomspace, "Color", concept_node, NumberNode(str(biome["color"])))
            # print color_node
            rainfall_node = add_predicate(
                self._atomspace, "Rainfall", concept_node, NumberNode(str(biome["rainfall"])))
            # print color_node
            temperature_node = add_predicate(
                self._atomspace, "Temperature", concept_node, NumberNode(str(biome["temperature"])))
    def load_item_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the items and their
        various properties
        """

        print "\nLoading grounded knowledge: items"

        item_type_root_atom = self._atomspace.add_node(types.ConceptNode, "ITEM_TYPE")

        for item in items_list:
            # print item
            atom = self._atomspace.add_node(types.ConceptNode, item["displayName"])
            repr_node = add_predicate(self._atomspace, "Represented in Minecraft by", atom, NumberNode(str(item["id"])))
            inh_node = add_predicate(self._atomspace, "be", item_type_root_atom, atom)
            # print repr_node
            # print inh_node

            if "variations" in item:
                for variant in item["variations"]:
                    concept_node = self._atomspace.add_node(types.ConceptNode, variant["displayName"])
                    repr_node = add_predicate(
                        self._atomspace,
                        "Represented in Minecraft by",
                        concept_node,
                        NumberNode(str(item["id"])),
                        NumberNode(str(variant["metadata"])),
                    )
                    inh_node = add_predicate(self._atomspace, "be", item_type_root_atom, concept_node)
    def _build_block_nodes(self, block, map_handle):

        # hack to make static object No. variable in class method
        if not hasattr(self._build_block_nodes.__func__, "objNo"):
            self._build_block_nodes.__func__.objNo = 0
        # Note: in 3DSpaceMap using structure node to represent block,
        # entity node to represent entity

        obj_node = self._atomspace.add_node(types.StructureNode, "obj%s" % (self._build_block_nodes.__func__.objNo))
        self._build_block_nodes.__func__.objNo += 1
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, obj_node, map_handle, [block.x, block.y, block.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(
            types.ConceptNode, blocks.get_block(block.blockid, block.metadata).display_name
        )
        material_link = add_predicate(self._atomspace, "material", obj_node, type_node)
        updated_eval_links.append(material_link)

        new_appeared_link = add_predicate(self._atomspace, "new_block", obj_node)
        updated_eval_links.append(new_appeared_link)

        return obj_node, updated_eval_links
Ejemplo n.º 6
0
    def _build_block_nodes(self, block, map_handle):

        # hack to make static object No. variable in class method
        if not hasattr(self._build_block_nodes.__func__, "objNo"):
            self._build_block_nodes.__func__.objNo = 0
        # Note: in 3DSpaceMap using structure node to represent block,
        # entity node to represent entity

        obj_node = self._atomspace.add_node(
            types.StructureNode,
            "obj%s" % (self._build_block_nodes.__func__.objNo))
        self._build_block_nodes.__func__.objNo += 1
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, obj_node, map_handle,
                                        [block.x, block.y, block.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(
            types.ConceptNode,
            blocks.get_block(block.blockid, block.metadata).display_name)
        material_link = add_predicate(self._atomspace, "material", obj_node,
                                      type_node)
        updated_eval_links.append(material_link)

        new_appeared_link = add_predicate(self._atomspace, "new_block",
                                          obj_node)
        updated_eval_links.append(new_appeared_link)

        return obj_node, updated_eval_links
Ejemplo n.º 7
0
    def load_entity_knowledge(self, knowledge_level):
        """ Creates atoms representing the different kinds of entities that can
        be encountered in the minecraft world.  Entities are things like the
        small dropped versions of mined blocks which fall on the ground after
        mining, or other creatures like animals or enemies, etc.
        """

        print "\nLoading grounded knowledge: entities"

        # This root atom is the atom that all entity types are a subtype of.
        entity_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "ENTITY_TYPE")

        # Loop over the entities in the spock bot library and load each one
        # into the atomspace.
        for entity in entities_list:
            atom = self._atomspace.add_node(types.ConceptNode,
                                            entity["displayName"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by", atom,
                                      NumberNode(str(entity["id"])))
            inh_node = add_predicate(self._atomspace, "be",
                                     entity_type_root_atom, atom)
            # print repr_node
            # print inh_node

            if "type" in entity:
                type_node = add_predicate(self._atomspace,
                                          "Minecraft entity type", atom,
                                          ConceptNode(str(entity["type"])))
Ejemplo n.º 8
0
    def load_item_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the items and their
        various properties
        """

        print "\nLoading grounded knowledge: items"

        # This root atom is the atom that all item types are a subtype of.
        item_type_root_atom = self._atomspace.add_node(types.ConceptNode,
                                                       "ITEM_TYPE")

        # Loop over the items in the spock bot library and load each one into
        # the atomspace.
        for item in items_list:
            atom = self._atomspace.add_node(types.ConceptNode,
                                            item["displayName"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by", atom,
                                      NumberNode(str(item["id"])))
            inh_node = add_predicate(self._atomspace, "be",
                                     item_type_root_atom, atom)
            # print repr_node
            # print inh_node

            if "variations" in item:
                for variant in item["variations"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, variant["displayName"])
                    repr_node = add_predicate(
                        self._atomspace, "Represented in Minecraft by",
                        concept_node, NumberNode(str(item["id"])),
                        NumberNode(str(variant["metadata"])))
                    inh_node = add_predicate(self._atomspace, "be",
                                             item_type_root_atom, concept_node)
    def _build_entity_node(self, entity, map_handle):
        entity_node = self._atomspace.add_node(types.EntityNode, str(entity.eid))
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, entity_node, map_handle, [entity.x, entity.y, entity.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(types.ConceptNode, str(entity.mob_type))
        type_link = add_predicate(self._atomspace, "entitytype", entity_node, type_node)
        updated_eval_links.append(type_link)

        yaw_node = self._atomspace.add_node(types.NumberNode, str(entity.head_yaw))
        pitch_node = self._atomspace.add_node(types.NumberNode, str(entity.head_pitch))
        look_link = add_predicate(self._atomspace, "look", entity_node, yaw_node, pitch_node)
        updated_eval_links.append(look_link)

        length_node = self._atomspace.add_node(types.NumberNode, str(entity.length))
        width_node = self._atomspace.add_node(types.NumberNode, str(entity.width))
        height_node = self._atomspace.add_node(types.NumberNode, str(entity.height))
        sizelink = add_predicate(self._atomspace, "size", entity_node, length_node, width_node, height_node)
        updated_eval_links.append(sizelink)

        v_x_node = self._atomspace.add_node(types.NumberNode, str(entity.velocity_x))
        v_y_node = self._atomspace.add_node(types.NumberNode, str(entity.velocity_y))
        v_z_node = self._atomspace.add_node(types.NumberNode, str(entity.velocity_z))
        velocitylink = add_predicate(self._atomspace, "velocity", entity_node, v_x_node, v_y_node, v_z_node)
        updated_eval_links.append(velocitylink)
        return entity_node, updated_eval_links
    def load_entity_knowledge(self, knowledge_level):
        """ Creates atoms representing the different kinds of entities that can
        be encountered in the minecraft world.  Entities are things like the
        small dropped versions of mined blocks which fall on the ground after
        mining, or other creatures like animals or enemies, etc.
        """

        print "\nLoading grounded knowledge: entities"

        entity_type_root_atom = self._atomspace.add_node(types.ConceptNode, "ENTITY_TYPE")

        for entity in entities_list:
            # print entity
            atom = self._atomspace.add_node(types.ConceptNode, entity["displayName"])
            repr_node = add_predicate(
                self._atomspace, "Represented in Minecraft by", atom, NumberNode(str(entity["id"]))
            )
            inh_node = add_predicate(self._atomspace, "be", entity_type_root_atom, atom)
            # print repr_node
            # print inh_node

            if "type" in entity:
                type_node = add_predicate(
                    self._atomspace, "Minecraft entity type", atom, ConceptNode(str(entity["type"]))
                )
    def load_window_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the windows and their
        various properties
        """
        print "\nLoading grounded knowledge: windows"

        # This root atom is the atom that all windows types are a subtype of.
        window_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "WINDOW_TYPE")

        # Loop over the windows in the spock bot library and load each one into
        # the atomspace.
        for window in windows_list:
            atom = self._atomspace.add_node(types.ConceptNode, window["name"])
            id_concept_node = self._atomspace.add_node(
                types.ConceptNode, window["id"])
            repr_node = add_predicate(
                self._atomspace,
                "Represented in Minecraft by",
                atom,
                id_concept_node)
            inh_node = add_predicate(
                self._atomspace, "be", window_type_root_atom, atom)
            # print "repr_node", repr_node
            # print "inh_node", inh_node

            if "slots" in window:
                for slot in window["slots"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, slot["name"])
                    index_node = add_predicate(
                        self._atomspace, "Slot index", concept_node, NumberNode(str(slot["index"])))

                    if "size" in slot:
                        size_node = add_predicate(
                            self._atomspace, "Slot index", concept_node, NumberNode(str(slot["size"])))
                        # print "size_node", size_node
                    slot_node = add_predicate(
                        self._atomspace, "Slot", atom, concept_node)
                    # print "index_node", index_node
                    # print "slot_node", slot_node

            if "properties" in window:
                for property in window["properties"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, property)
                    property_node = add_predicate(
                        self._atomspace, "Property", atom, concept_node)
                    # print "property_node", property_node

            if "openedWith" in window:
                for opened_with in window["openedWith"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, opened_with["type"])
                    id_node = add_predicate(self._atomspace,
                                            "Opened with ID",
                                            concept_node,
                                            NumberNode(str(opened_with["id"])))
                    opened_with_node = add_predicate(
                        self._atomspace, "Opened with", atom, concept_node)
Ejemplo n.º 12
0
    def load_window_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the windows and their
        various properties
        """
        print "\nLoading grounded knowledge: windows"

        # This root atom is the atom that all windows types are a subtype of.
        window_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "WINDOW_TYPE")

        # Loop over the windows in the spock bot library and load each one into
        # the atomspace.
        for window in windows_list:
            atom = self._atomspace.add_node(types.ConceptNode, window["name"])
            id_concept_node = self._atomspace.add_node(types.ConceptNode,
                                                       window["id"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by", atom,
                                      id_concept_node)
            inh_node = add_predicate(self._atomspace, "be",
                                     window_type_root_atom, atom)
            # print "repr_node", repr_node
            # print "inh_node", inh_node

            if "slots" in window:
                for slot in window["slots"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, slot["name"])
                    index_node = add_predicate(self._atomspace, "Slot index",
                                               concept_node,
                                               NumberNode(str(slot["index"])))

                    if "size" in slot:
                        size_node = add_predicate(
                            self._atomspace, "Slot index", concept_node,
                            NumberNode(str(slot["size"])))
                        # print "size_node", size_node
                    slot_node = add_predicate(self._atomspace, "Slot", atom,
                                              concept_node)
                    # print "index_node", index_node
                    # print "slot_node", slot_node

            if "properties" in window:
                for property in window["properties"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, property)
                    property_node = add_predicate(self._atomspace, "Property",
                                                  atom, concept_node)
                    # print "property_node", property_node

            if "openedWith" in window:
                for opened_with in window["openedWith"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, opened_with["type"])
                    id_node = add_predicate(self._atomspace, "Opened with ID",
                                            concept_node,
                                            NumberNode(str(opened_with["id"])))
                    opened_with_node = add_predicate(self._atomspace,
                                                     "Opened with", atom,
                                                     concept_node)
    def load_category_knowledge(self, knowledge_level):
        """ Creates inheritance links for a bunch of manually defined
        "convenience categories" which are useful for humans to interact with
        the bot, both in the python code and in chat communication.  These are
        also useful in rule learning because rules learned about something
        which is in a category with other things might also apply to those
        other things.  Having some basic categories to nudge the pattern mining
        algorithms in the right direction should make learning initial things
        about the world a bit easier.
        """

        print "\nLoading grounded knowledge: categories"

        categories_dict = {
            "WOOD_BLOCK" : (
                "Wood",
                "Oak wood facing up/down",
                "Spruce wood facing up/down",
                "Birch wood facing up/down",
                "Jungle wood facing up/down",
                "Oak wood facing East/West",
                "Spruce wood facing East/West",
                "Birch wood facing East/West",
                "Jungle wood facing East/West",
                "Oak wood facing North/South",
                "Spruce wood facing North/South",
                "Birch wood facing North/South",
                "Jungle wood facing North/South",
                "Oak wood with only bark",
                "Spruce wood with only bark",
                "Birch wood with only bark",
                "Jungle wood with only bark",

                "Wood (Acacia/Dark Oak)", 
                "Acacia wood facing up/down", 
                "Dark Oak wood facing up/down", 
                "Acacia wood facing East/West", 
                "Dark Oak wood facing East/West", 
                "Acacia wood facing North/South", 
                "Dark Oak wood facing North/South", 
                "Acacia wood with only bark", 
                "Dark Oak wood with only bark"),

            "STONE_BLOCK" : ("STONE", "COBBLESTONE"),
            "ORE_BLOCK" : ("COAL_ORE", "IRON_ORE", "GOLD_ORE", "DIAMOND_ORE", "LAPIS_ORE", "REDSTONE_ORE", "GLOWSTONE"),
            "PHYSICS_BLOCK" : ("WATER", "LAVA", "SAND", "GRAVEL"),
            "FLOWING_BLOCK" : ("WATER", "LAVA"),
            "FALLING_BLOCK" : ("SAND", "GRAVEL"),
        }

        # Loop over all the categories.
        for cat_base in categories_dict.keys():
            # Within each category, loop over all of the objects that are in that category.
            for subclass_object in categories_dict[cat_base]:
                base_atom = self._atomspace.add_node(types.ConceptNode, cat_base)
                subclass_atom = self._atomspace.add_node(types.ConceptNode, subclass_object)
                #TODO: Maybe delete this permanantly, for now just store as a predicate, not as an InheritanceLink
                #inh_atom = self._atomspace.add_link(types.InheritanceLink, [subclass_atom, base_atom])
                pred_atom = add_predicate(self._atomspace, "be", subclass_atom, base_atom)
    def _build_self_pos_node(self, client, map_handle):
        # TODO: for now because we only input self client so we define node name as "self"
        # but this should be included in the attribute
        client_node = self._atomspace.add_node(types.EntityNode, "self")
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, client_node, map_handle, [client.x, client.y, client.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(types.ConceptNode, "client")
        type_link = add_predicate(self._atomspace, "clienttype", client_node, type_node)
        updated_eval_links.append(type_link)

        yaw_node = self._atomspace.add_node(types.NumberNode, str(client.yaw))
        pitch_node = self._atomspace.add_node(types.NumberNode, str(client.pitch))
        look_link = add_predicate(self._atomspace, "look", client_node, yaw_node, pitch_node)
        updated_eval_links.append(look_link)
        return client_node, updated_eval_links
Ejemplo n.º 15
0
    def _build_entity_node(self, entity, map_handle):
        entity_node = self._atomspace.add_node(types.EntityNode,
                                               str(entity.eid))
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, entity_node,
                                        map_handle,
                                        [entity.x, entity.y, entity.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(types.ConceptNode,
                                             str(entity.mob_type))
        type_link = add_predicate(self._atomspace, "entitytype", entity_node,
                                  type_node)
        updated_eval_links.append(type_link)

        yaw_node = self._atomspace.add_node(types.NumberNode,
                                            str(entity.head_yaw))
        pitch_node = self._atomspace.add_node(types.NumberNode,
                                              str(entity.head_pitch))
        look_link = add_predicate(self._atomspace, "look", entity_node,
                                  yaw_node, pitch_node)
        updated_eval_links.append(look_link)

        length_node = self._atomspace.add_node(types.NumberNode,
                                               str(entity.length))
        width_node = self._atomspace.add_node(types.NumberNode,
                                              str(entity.width))
        height_node = self._atomspace.add_node(types.NumberNode,
                                               str(entity.height))
        sizelink = add_predicate(self._atomspace, "size", entity_node,
                                 length_node, width_node, height_node)
        updated_eval_links.append(sizelink)

        v_x_node = self._atomspace.add_node(types.NumberNode,
                                            str(entity.velocity_x))
        v_y_node = self._atomspace.add_node(types.NumberNode,
                                            str(entity.velocity_y))
        v_z_node = self._atomspace.add_node(types.NumberNode,
                                            str(entity.velocity_z))
        velocitylink = add_predicate(self._atomspace, "velocity", entity_node,
                                     v_x_node, v_y_node, v_z_node)
        updated_eval_links.append(velocitylink)
        return entity_node, updated_eval_links
    def load_goal_knowledge(self, knowledge_level):
        """ Creates atoms for a bunch of different goals to achieve.  The
        satisfaction of these goals leads to the overall happiness of the bot.
        """

        print "\nLoading grounded knowledge: goals"

        goal_root_node = self._atomspace.add_node(types.ConceptNode, "GOAL")

        goal_dict = {
            "Gather resources": {
                "description": "Gather resources like wood, stone, ore, etc. \
                                The base resources which are needed to craft \
                                tools and other items.",
                "init_need": 1,
                "init_desire": 10,
            },

            "Rest": {
                "description": "Stand around doing nothing.",
                "init_need": 0,
                "init_desire": 0.01,
            },

            "Explore": {
                "description": "Discover new blocks.",
                "init_need": 1,
                "init_desire": 2,
            },

            "Discover": {
                "description": "Discover new kinds of blocks.",
                "init_need": 0,
                "init_desire": 100,
            },

            "Look around": {
                "description": "Patrol the already explored area to look at \
                                blocks that have not been seen in a long time.",
                "init_need": 0,
                "init_desire": 0.1,
            },
        }

        for goal in goal_dict:
            concept_node = self._atomspace.add_node(types.ConceptNode, goal)
            inh_node = add_predicate(
                self._atomspace, "be", goal_root_node, concept_node)
            # print inh_node

        current_goal = self._atomspace.add_node(
            types.ConceptNode, "CURRENT_GOAL")
        goal_link = self._atomspace.add_link(
            types.Link, (current_goal, ConceptNode("Look around")))
Ejemplo n.º 17
0
    def load_category_knowledge(self, knowledge_level):
        """ Creates inheritance links for a bunch of manually defined
        "convenience categories" which are useful for humans to interact with
        the bot, both in the python code and in chat communication.  These are
        also useful in rule learning because rules learned about something
        which is in a category with other things might also apply to those
        other things.  Having some basic categories to nudge the pattern mining
        algorithms in the right direction should make learning initial things
        about the world a bit easier.
        """

        print "\nLoading grounded knowledge: categories"

        categories_dict = {
            "WOOD_BLOCK":
            ("Wood", "Oak wood facing up/down", "Spruce wood facing up/down",
             "Birch wood facing up/down", "Jungle wood facing up/down",
             "Oak wood facing East/West", "Spruce wood facing East/West",
             "Birch wood facing East/West", "Jungle wood facing East/West",
             "Oak wood facing North/South", "Spruce wood facing North/South",
             "Birch wood facing North/South", "Jungle wood facing North/South",
             "Oak wood with only bark", "Spruce wood with only bark",
             "Birch wood with only bark", "Jungle wood with only bark",
             "Wood (Acacia/Dark Oak)", "Acacia wood facing up/down",
             "Dark Oak wood facing up/down", "Acacia wood facing East/West",
             "Dark Oak wood facing East/West",
             "Acacia wood facing North/South",
             "Dark Oak wood facing North/South", "Acacia wood with only bark",
             "Dark Oak wood with only bark"),
            "STONE_BLOCK": ("STONE", "COBBLESTONE"),
            "ORE_BLOCK": ("COAL_ORE", "IRON_ORE", "GOLD_ORE", "DIAMOND_ORE",
                          "LAPIS_ORE", "REDSTONE_ORE", "GLOWSTONE"),
            "PHYSICS_BLOCK": ("WATER", "LAVA", "SAND", "GRAVEL"),
            "FLOWING_BLOCK": ("WATER", "LAVA"),
            "FALLING_BLOCK": ("SAND", "GRAVEL"),
        }

        # Loop over all the categories.
        for cat_base in categories_dict.keys():
            # Within each category, loop over all of the objects that are in
            # that category.
            for subclass_object in categories_dict[cat_base]:
                base_atom = self._atomspace.add_node(types.ConceptNode,
                                                     cat_base)
                subclass_atom = self._atomspace.add_node(
                    types.ConceptNode, subclass_object)

                # TODO: Maybe delete this permanantly, for now just store as
                #  a predicate, not as an InheritanceLink
                #inh_atom = self._atomspace.add_link(types.InheritanceLink,
                # [subclass_atom, base_atom])

                pred_atom = add_predicate(self._atomspace, "be", subclass_atom,
                                          base_atom)
    def handle_vision_message(self,data):
        #print "handle_visiion_message"
        #TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            block_material = blocks.get_block(block.blockid, block.metadata).display_name
            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            if old_block_handle.is_undefined():
                blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
            else:
                old_block_type_node = get_predicate(self._atomspace, "material",
                                                    Atom(old_block_handle, self._atomspace), 1)
                old_block_type = self._atomspace.get_name(old_block_type_node.h)
                if old_block_type == block_material:
                    continue
                elif block.blockid == 0:
                    blocknode, updated_eval_links = Atom(Handle(-1), self._atomspace), []
                else:
                    blocknode, updated_eval_links = self._build_block_nodes(block,
                                                                            map_handle)

                
                #TODO: not sure if we should add disappeared predicate here,
                #It looks reasonable but make the code more messy..
                disappeared_link = add_predicate(self._atomspace, "disappeared", Atom(old_block_handle, self._atomspace))
                updated_eval_links.append(disappeared_link)
            self._space_server.add_map_info(blocknode.h, map_handle, False, False,
                                            block.ROStimestamp,
                                            block.x, block.y, block.z)
            if old_block_handle.is_undefined():
                self._time_server.add_time_info(blocknode.h, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode.h, block.MCtimestamp, "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link.h,block.ROStimestamp, "ROS")
                self._time_server.add_time_info(link.h,block.MCtimestamp, "MC")
            #print blocknode
            #print updated_eval_links

        #TODO: The code below stores the number of blocks of each type seen in the current field of view into the atomspace.  It is commented out as it should probably not store this until the code to erase old values is also added otherwise this data just piles up as new links from the same root node and it becomes a jumbled mess.
        #print "\nBlock material summary:  saw %s kinds of blocks" % len(material_dict)
        """
Ejemplo n.º 19
0
    def load_block_knowledge(self, knowledge_level):
        """ Creates a number of atoms in atomspace which represent grounded
        knowledge about what kinds of blocks drop what resource when mined with
        a given tool.  The info is hardcoded into this python routine as a
        dictionary and then the dictionary info is converted into atomese by
        some for loops which loop over this dictionary.
        """

        print "\nLoading grounded knowledge: blocks and mining"

        # This root atom is the atom that all block types are a subtype of.
        block_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "BLOCK_TYPE")

        # Loop over the block types in the spock bot library and load each one
        # into the atomspace.
        for block in blocks_list:
            concept_node = self._atomspace.add_node(types.ConceptNode,
                                                    block["displayName"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by",
                                      concept_node,
                                      NumberNode(str(block["id"])))
            inh_node = add_predicate(self._atomspace, "be",
                                     block_type_root_atom, concept_node)
            # print inh_node
            # print repr_node

            # If this block type has a recorded hardness
            hard_node = 0
            if "hardness" in block and block["hardness"] >= 0:
                hard_node = add_predicate(self._atomspace, "Block hardness",
                                          concept_node,
                                          NumberNode(str(block["hardness"])))
                # print hard_node

            # Some block id's use a second 'metadata' value to store a subtype
            # of a particular block type.  If this block type has variations,
            # load them all.
            if "variations" in block:
                for variant in block["variations"]:
                    concept_node = self._atomspace.add_node(
                        types.ConceptNode, variant["displayName"])
                    repr_node = add_predicate(
                        self._atomspace, "Represented in Minecraft by",
                        concept_node, NumberNode(str(block["id"])),
                        NumberNode(str(variant["metadata"])))
                    inh_node = add_predicate(self._atomspace, "be",
                                             block_type_root_atom,
                                             concept_node)
                    # print inh_node
                    # print repr_node

                    # If the main block type had a hardness then set the same
                    # hardness for this variation as well.
                    if hard_node != 0:
                        hard_node = add_predicate(
                            self._atomspace, "Block hardness", concept_node,
                            NumberNode(str(block["hardness"])))
Ejemplo n.º 20
0
    def load_instrument_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the instruments and their
        various properties
        """
        print "\nLoading grounded knowledge: instruments"

        # This root atom is the atom that all instrument types are a subtype
        # of.
        instrument_type_root_atom = self._atomspace.add_node(
            types.ConceptNode, "INSTRUMENT_TYPE")

        # Loop over the instrument types in the spock bot library and load each
        # one into the atomspace.
        for instrument in instruments_list:
            concept_node = self._atomspace.add_node(types.ConceptNode,
                                                    instrument["name"])
            repr_node = add_predicate(self._atomspace,
                                      "Represented in Minecraft by",
                                      concept_node,
                                      NumberNode(str(instrument["id"])))
            inh_node = add_predicate(self._atomspace, "be",
                                     instrument_type_root_atom, concept_node)
    def load_item_knowledge(self, knowledge_level):
        """ Creates nodes in the atomspace for each of the items and their
        various properties
        """

        print "\nLoading grounded knowledge: items"

        # This root atom is the atom that all item types are a subtype of.
        item_type_root_atom = self._atomspace.add_node(types.ConceptNode, "ITEM_TYPE")

        # Loop over the items in the spock bot library and load each one into the atomspace.
        for item in items_list:
            atom = self._atomspace.add_node(types.ConceptNode, item["displayName"])
            repr_node = add_predicate(self._atomspace, "Represented in Minecraft by", atom, NumberNode(str(item["id"])))
            inh_node = add_predicate(self._atomspace, "be", item_type_root_atom, atom)
            #print repr_node
            #print inh_node

            if "variations" in item:
                for variant in item["variations"]:
                    concept_node = self._atomspace.add_node(types.ConceptNode, variant["displayName"])
                    repr_node = add_predicate(self._atomspace, "Represented in Minecraft by", concept_node, NumberNode(str(item["id"])), NumberNode(str(variant["metadata"])))
                    inh_node = add_predicate(self._atomspace, "be", item_type_root_atom, concept_node)
Ejemplo n.º 22
0
    def load_goal_knowledge(self, knowledge_level):
        """ Creates atoms for a bunch of different goals to achieve.  The
        satisfaction of these goals leads to the overall happiness of the bot.
        """

        print "\nLoading grounded knowledge: goals"

        goal_root_node = self._atomspace.add_node(types.ConceptNode, "GOAL")

        goal_dict = {
            "Gather resources": {
                "description": "Gather resources like wood, stone, ore, etc. \
                                The base resources which are needed to craft \
                                tools and other items.",
                "init_need": 1,
                "init_desire": 10,
            },
            "Rest": {
                "description": "Stand around doing nothing.",
                "init_need": 0,
                "init_desire": 0.01,
            },
            "Explore": {
                "description": "Discover new blocks.",
                "init_need": 1,
                "init_desire": 2,
            },
            "Discover": {
                "description": "Discover new kinds of blocks.",
                "init_need": 0,
                "init_desire": 100,
            },
            "Look around": {
                "description": "Patrol the already explored area to look at \
                                blocks that have not been seen in a long time.",
                "init_need": 0,
                "init_desire": 0.1,
            },
        }

        for goal in goal_dict:
            concept_node = self._atomspace.add_node(types.ConceptNode, goal)
            inh_node = add_predicate(self._atomspace, "be", goal_root_node,
                                     concept_node)
            # print inh_node

        current_goal = self._atomspace.add_node(types.ConceptNode,
                                                "CURRENT_GOAL")
        goal_link = self._atomspace.add_link(
            types.Link, (current_goal, ConceptNode("Look around")))
Ejemplo n.º 23
0
    def _build_self_pos_node(self, client, map_handle):
        # TODO: for now because we only input self client so we define node name as "self"
        # but this should be included in the attribute
        client_node = self._atomspace.add_node(types.EntityNode, "self")
        updated_eval_links = []

        at_location_link = add_location(self._atomspace, client_node,
                                        map_handle,
                                        [client.x, client.y, client.z])
        updated_eval_links.append(at_location_link)

        type_node = self._atomspace.add_node(types.ConceptNode, "client")
        type_link = add_predicate(self._atomspace, "clienttype", client_node,
                                  type_node)
        updated_eval_links.append(type_link)

        yaw_node = self._atomspace.add_node(types.NumberNode, str(client.yaw))
        pitch_node = self._atomspace.add_node(types.NumberNode,
                                              str(client.pitch))
        look_link = add_predicate(self._atomspace, "look", client_node,
                                  yaw_node, pitch_node)
        updated_eval_links.append(look_link)
        return client_node, updated_eval_links
Ejemplo n.º 24
0
 def handle_vision_message(self, data):
     print "handle_visiion_message"
     #TODO: In Minecraft the up/down direction is y coord
     # but we should swap y and z in ros node, not here..
     for block in data.blocks:
         swap_y_and_z(block)
     map_handle, cur_map = self._get_map()
     for block in data.blocks:
         old_block_handle = cur_map.get_block((block.x, block.y, block.z))
         updated_eval_links = []
         if old_block_handle.is_undefined():
             blocknode, updated_eval_links = self._build_block_nodes(
                 block, map_handle)
         else:
             old_block_type_node = get_predicate(
                 self._atomspace, "material",
                 Atom(old_block_handle, self._atomspace), 1)
             old_block_type = self._atomspace.get_name(
                 old_block_type_node.h)
             if old_block_type == str(block.blockid):
                 continue
             elif block.blockid == 0:
                 blocknode, updated_eval_links = Atom(
                     Handle(-1), self._atomspace), []
             else:
                 blocknode, updated_eval_links = self._build_block_nodes(
                     block, map_handle)
             #TODO: not sure if we should add disappeared predicate here,
             #It looks reasonable but make the code more messy..
             disappeared_link = add_predicate(
                 self._atomspace, "disappeared",
                 Atom(old_block_handle, self._atomspace))
             updated_eval_links.append(disappeared_link)
         self._space_server.add_map_info(blocknode.h, map_handle, False,
                                         False, block.ROStimestamp, block.x,
                                         block.y, block.z)
         if old_block_handle.is_undefined():
             self._time_server.add_time_info(blocknode.h,
                                             block.ROStimestamp, "ROS")
             self._time_server.add_time_info(blocknode.h, block.MCtimestamp,
                                             "MC")
         for link in updated_eval_links:
             self._time_server.add_time_info(link.h, block.ROStimestamp,
                                             "ROS")
             self._time_server.add_time_info(link.h, block.MCtimestamp,
                                             "MC")
         #print blocknode
         #print updated_eval_links
     print "handle_vision_message end"
    def load_block_knowledge(self, knowledge_level):
        """ Creates a number of atoms in atomspace which represent grounded
        knowledge about what kinds of blocks drop what resource when mined with
        a given tool.  The info is hardcoded into this python routine as a
        dictionary and then the dictionary info is converted into atomese by
        some for loops which loop over this dictionary.
        """

        print "\nLoading grounded knowledge: blocks and mining"

        block_type_root_atom = self._atomspace.add_node(types.ConceptNode, "BLOCK_TYPE")
        # print block_type_root_atom

        # Loop over the list of all the block types in the minecraft world
        for block in blocks_list:
            # print "\n", block
            concept_node = self._atomspace.add_node(types.ConceptNode, block["displayName"])
            repr_node = add_predicate(
                self._atomspace, "Represented in Minecraft by", concept_node, NumberNode(str(block["id"]))
            )
            inh_node = add_predicate(self._atomspace, "be", block_type_root_atom, concept_node)
            # print inh_node
            # print repr_node

            # If this block type has a recorded hardness
            hard_node = 0
            if "hardness" in block and block["hardness"] >= 0:
                hard_node = add_predicate(
                    self._atomspace, "Block hardness", concept_node, NumberNode(str(block["hardness"]))
                )
                # print hard_node

            # Some block id's use a second 'metadata' value to store a subtype of a particular block type.  If this block type has variations, load them all.
            if "variations" in block:
                for variant in block["variations"]:
                    concept_node = self._atomspace.add_node(types.ConceptNode, variant["displayName"])
                    repr_node = add_predicate(
                        self._atomspace,
                        "Represented in Minecraft by",
                        concept_node,
                        NumberNode(str(block["id"])),
                        NumberNode(str(variant["metadata"])),
                    )
                    inh_node = add_predicate(self._atomspace, "be", block_type_root_atom, concept_node)
                    # print inh_node
                    # print repr_node

                    if hard_node != 0:
                        hard_node = add_predicate(
                            self._atomspace, "Block hardness", concept_node, NumberNode(str(block["hardness"]))
                        )
Ejemplo n.º 26
0
 def handle_vision_message(self,data):
     print "handle_visiion_message"
     #TODO: In Minecraft the up/down direction is y coord
     # but we should swap y and z in ros node, not here..
     for block in data.blocks:
         swap_y_and_z(block)
     map_handle, cur_map = self._get_map()
     for block in data.blocks:
         old_block_handle = cur_map.get_block((block.x, block.y, block.z))
         updated_eval_links = []
         if old_block_handle.is_undefined():
             blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
         else:
             old_block_type_node = get_predicate(self._atomspace, "material",
                                                 Atom(old_block_handle, self._atomspace), 1)
             old_block_type = self._atomspace.get_name(old_block_type_node.h)
             if old_block_type == str(block.blockid):
                 continue
             elif block.blockid == 0:
                 blocknode, updated_eval_links = Atom(Handle(-1), self._atomspace), []
             else:
                 blocknode, updated_eval_links = self._build_block_nodes(block,
                                                                         map_handle)
             #TODO: not sure if we should add disappeared predicate here,
             #It looks reasonable but make the code more messy..
             disappeared_link = add_predicate(self._atomspace, "disappeared", Atom(old_block_handle, self._atomspace))
             updated_eval_links.append(disappeared_link)
         self._space_server.add_map_info(blocknode.h, map_handle, False, False,
                                         block.ROStimestamp,
                                         block.x, block.y, block.z)
         if old_block_handle.is_undefined():
             self._time_server.add_time_info(blocknode.h, block.ROStimestamp, "ROS")
             self._time_server.add_time_info(blocknode.h, block.MCtimestamp, "MC")
         for link in updated_eval_links:
             self._time_server.add_time_info(link.h,block.ROStimestamp, "ROS")
             self._time_server.add_time_info(link.h,block.MCtimestamp, "MC")
         #print blocknode
         #print updated_eval_links
     print "handle_vision_message end"
Ejemplo n.º 27
0
    def handle_vision_message(self, data):
        # print "handle_visiion_message"
        # TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            # Also store the new block material in case it differs from the existing material.
            # TODO: Use this dict for something or it can be removed, currently
            # it is created and filled up but not used by anything else.
            block_material = blocks.get_block(block.blockid,
                                              block.metadata).display_name

            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            # If this is the first time this block has been seen
            if old_block_handle.is_undefined():
                # Create the block in atomspace and set its initial attention
                # value.
                blocknode, updated_eval_links = self._build_block_nodes(
                    block, map_handle)
                # TODO: Make the 200 a constant, this occurs one other place.
                self._atomspace.set_av(blocknode.h, 200)
            else:
                # Block already exists, check to see if it is still the same
                # type.
                old_block_type_node = get_predicate(self._atomspace,
                                                    "material",
                                                    old_block_handle, 1)
                old_block_type = self._atomspace.get_name(
                    old_block_type_node.h)
                if old_block_type == block_material:
                    # Add short term importance to this block since it is in
                    # the field of view.
                    cur_sti = self._atomspace.get_av(old_block_handle)['sti']
                    # TODO: Make these numbers constants.
                    # TODO: Make the amount added be dependendant on the
                    # distance to the block.
                    cur_sti = min(cur_sti + 20, 500)
                    self._atomspace.set_av(old_block_handle, cur_sti)
                    continue
                elif block.blockid == 0:
                    # Block used to be solid and is now an air block, remove it
                    # from the atomspace and mark the old block as being
                    # disappeared for attention allocation routine to look at.

                    blocknode, updated_eval_links = Atom(-1), []
                    disappeared_link = add_predicate(self._atomspace,
                                                     "disappeared",
                                                     old_block_handle)
                    updated_eval_links.append(disappeared_link)
                else:
                    # NOTE: There is a bit of a bug here since the attention
                    # value does not increase here, but that is ok because this
                    # is rare anyway so skipping an increase is no big deal.
                    blocknode, updated_eval_links = self._build_block_nodes(
                        block, map_handle)

                disappeared_link = add_predicate(self._atomspace,
                                                 "disappeared",
                                                 old_block_handle)
                updated_eval_links.append(disappeared_link)

            # Add the block to the spaceserver and the timeserver.
            self._space_server.add_map_info(blocknode.h, map_handle, False,
                                            False, block.ROStimestamp, block.x,
                                            block.y, block.z)
            if old_block_handle.is_undefined():
                self._time_server.add_time_info(blocknode.h,
                                                block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode.h, block.MCtimestamp,
                                                "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link.h, block.ROStimestamp,
                                                "ROS")
                self._time_server.add_time_info(link.h, block.MCtimestamp,
                                                "MC")
                # print blocknode
                # print updated_eval_links

        # TODO: The code below stores the number of blocks of each type seen in
        # the current field of view into the atomspace.  It is commented out as
        # it should probably not store this until the code to erase old values
        # is also added otherwise this data just piles up as new links from the
        # same root node and it becomes a jumbled mess.

        # print "\nBlock material summary:  saw %s kinds of blocks" %
        # len(material_dict)
        """
    def handle_vision_message(self, data):
        # print "handle_visiion_message"
        # TODO: In Minecraft the up/down direction is y coord
        # but we should swap y and z in ros node, not here..
        for block in data.blocks:
            swap_y_and_z(block)
        material_dict = {}
        map_handle, cur_map = self._get_map()
        for block in data.blocks:
            old_block_handle = cur_map.get_block((block.x, block.y, block.z))
            updated_eval_links = []

            # Count how many of each block type we have seen during this vision frame.
            # Also store the new block material in case it differs from the existing material.
            # TODO: Use this dict for something or it can be removed, currently
            # it is created and filled up but not used by anything else.
            block_material = blocks.get_block(block.blockid, block.metadata).display_name

            if block_material in material_dict:
                material_dict[block_material] += 1
            else:
                material_dict[block_material] = 1

            # If this is the first time this block has been seen
            if old_block_handle == None:
                # Create the block in atomspace and set its initial attention
                # value.
                blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)
                # TODO: Make the 200 a constant, this occurs one other place.

                blocknode.av["sti"] = 200
            else:
                # Block already exists, check to see if it is still the same
                # type.
                old_block_type_node = get_predicate(self._atomspace, "material", old_block_handle, 1)
                old_block_type = old_block_type_node.name
                if old_block_type == block_material:
                    # Add short term importance to this block since it is in
                    # the field of view.
                    cur_sti = old_block_handle.av["sti"]
                    # TODO: Make these numbers constants.
                    # TODO: Make the amount added be dependendant on the
                    # distance to the block.
                    cur_sti = min(cur_sti + 20, 500)
                    old_block_handle.av["sti"] = cur_sti
                    continue
                elif block.blockid == 0:
                    # Block used to be solid and is now an air block, remove it
                    # from the atomspace and mark the old block as being
                    # disappeared for attention allocation routine to look at.

                    blocknode, updated_eval_links = Atom(-1), []
                    disappeared_link = add_predicate(self._atomspace, "disappeared", old_block_handle)
                    updated_eval_links.append(disappeared_link)
                else:
                    # NOTE: There is a bit of a bug here since the attention
                    # value does not increase here, but that is ok because this
                    # is rare anyway so skipping an increase is no big deal.
                    blocknode, updated_eval_links = self._build_block_nodes(block, map_handle)

                disappeared_link = add_predicate(self._atomspace, "disappeared", old_block_handle)
                updated_eval_links.append(disappeared_link)

            # Add the block to the spaceserver and the timeserver.
            self._space_server.add_map_info(
                blocknode, map_handle, False, False, block.ROStimestamp, block.x, block.y, block.z
            )
            if old_block_handle == None:
                self._time_server.add_time_info(blocknode, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(blocknode, block.MCtimestamp, "MC")
            for link in updated_eval_links:
                self._time_server.add_time_info(link, block.ROStimestamp, "ROS")
                self._time_server.add_time_info(link, block.MCtimestamp, "MC")
                # print blocknode
                # print updated_eval_links

        # TODO: The code below stores the number of blocks of each type seen in
        # the current field of view into the atomspace.  It is commented out as
        # it should probably not store this until the code to erase old values
        # is also added otherwise this data just piles up as new links from the
        # same root node and it becomes a jumbled mess.

        # print "\nBlock material summary:  saw %s kinds of blocks" %
        # len(material_dict)
        """