def is_empty(self): """ >>> r = Output() >>> r.is_empty() True """ return is_empty_dictionary(self.dictionary)
def to_string(self, dictionary = None): """to_string for output object We can't use the parent's to_string, because output's element is list, when inputout's element is Context """ if dictionary is None: dictionary = self.dictionary else: dictionary = self.actual_sent_dictionary if is_empty_dictionary(dictionary): return "{}" return "%s" % dictionary
def set_dictionary(self, dictionary): """ >>> o = Output() >>> o.set_dictionary({1:[[],[]]}) >>> o.get_dictionary() == {} True >>> o.set_dictionary({}) >>> o.get_dictionary() == {} True >>> o.set_dictionary({1:[[1],[]]}) >>> o.get_dictionary() == {1:[[1],[]]} True """ # You can set {} to the output dictionary, but as long as it's not empty the input should be in standard form if dictionary != {}: assert is_dictionary_standard(dictionary), "dictionary is not in standard form %s" % dictionary # When dictionary is empty, make it explicitly null if is_empty_dictionary(dictionary): dictionary = {} self.dictionary = dictionary self.actual_sent_dictionary = {}
def to_string(self): result = {} for i, value in self.dictionary.items(): result[i] = contexts_to_standard(value) if is_empty_dictionary(result): return "{}" return str(result)