def add_metadata()

in aristotle/aristotle.py [0:0]


    def add_metadata(self, sid, key, value):
        """ Update self.metadata_dict and self.keys_dict data structures for the
            given sid, adding the passed in key and value.

            :param sid: sid to update
            :type sid: int, required
            :param key: key to add or update
            :type key: string, required
            :param value: value corresponding to given key
            :type value: string, required
        """
        # key-value pairs are case insensitive; make everything lower case (needed for accurate matching
        # in filters) and strip leading and trailing whitespace.
        key = key.lower().strip()
        value = value.lower().strip()
        if sid not in self.metadata_dict.keys():
            print_error("add_metadata() called for sid '{}' but sid is invalid (does not exist).".format(sid))
            return
        # populate metadata_dict
        if key not in self.metadata_dict[sid]['metadata'].keys():
            self.metadata_dict[sid]['metadata'][key] = []
        if value not in self.metadata_dict[sid]['metadata'][key]:
            self.metadata_dict[sid]['metadata'][key].append(value)
        # populate keys_dict
        if key not in self.keys_dict.keys():
            self.keys_dict[key] = {}
        if value not in self.keys_dict[key].keys():
            self.keys_dict[key][value] = []
        if sid not in self.keys_dict[key][value]:
            self.keys_dict[key][value].append(sid)