示例#1
0
class BasicTest(unittest.TestCase):

    def setUp(self):
        self.db = DatabaseAPI()
        self.onto = self.db.get_onto()


    def test_add_and_remove_tools(self):
        with self.onto as onto:
            # populate the workspace
            self.db.add_object(onto.Screwdriver, x=1, y=2, color="red")
            self.db.add_object(onto.Screwdriver, x=3, y=1, color="blue")
            self.db.add_object(onto.Hammer, x=4, y=4, color="blue")
            self.db.add_object(onto.Pliers, x=3, y=3, color="green")

            # try a few queries about the workspace
            print("All objects in the workspace:")
            pp(self.db.get_all_tools())
            print()

            print("All screwdrivers in the workspace:")
            pp(self.db.get_class_objects(onto.Screwdriver))
            print()

            print("All blue objects in the workspace:")
            pp(self.db.get_objects_by_color("blue"))
            print()

            # # update position of the pliers
            # pliers = self.db.get_class_objects(onto.Pliers)[0]
            # self.db.update_object_position(pliers, x=5, y=4)
            # print("The pliers after updating its position:")
            # print(pliers)
            # print()

            # delete the nail
            print("Deleting the pliers...")
            self.db.delete_object(pliers)
            print("List of pliers:")
            pp(self.db.get_class_objects(onto.Pliers))
            print()

            # process a NL instruction
            nl_processor = NLProcessor()

            input_sentence = "Now take the screwdriver and put it in the right corner."
            robot_program = nl_processor.process_text(input_sentence)

            print()
            print("Program")
            print("--------")
            print(robot_program)
示例#2
0
class AreaDetector(CrowModule):
    namespace = db.onto

    def __init__(self):
        self.logger = logging.getLogger(__name__)
        self.db_api = DatabaseAPI()

    def detect_area(self,
                    tagged_text: TaggedText) -> db.onto.ObjectPlaceholder:
        area_list = self.db_api.get_class_objects(db.onto.Area)

        for area in area_list:
            if tagged_text.contains_text(area.name):
                self.logger.debug(
                    f"Area detected for \"{tagged_text.get_text()}\": {area}")

                return area

        return None