예제 #1
0
 def __init__(self,
              source: Any = None,
              matcher=None,
              suggesters: List[Suggester] = None,
              choosers: List[Chooser] = None,
              exclude: DialogFieldValue = None):
     self._source = source
     self._matcher = matcher
     self._suggesters = suggesters if suggesters else []
     self._choosers = choosers if choosers else []
     self.__origin = FieldValue.empty()
     self.__matched = FieldValue.empty()
     self.__suggested = FieldValue.empty()
     self._exclude = exclude  # exclude is specially may be None
예제 #2
0
 def value(self):
     if not FieldValue.is_empty(self.__suggested):
         return self.__suggested
     elif not FieldValue.is_empty(self.__matched):
         return self.__matched
     else:
         return FieldValue.empty()
예제 #3
0
 def get_exclude(self, field_name) -> FieldValue:
     """
         For internal needs exclude could be None, but for external needs everything should be FieldValue
     """
     exclude = self._fields[field_name].exclude
     if not exclude:
         return FieldValue.empty()
     return exclude
예제 #4
0
 def suggest(self, form) -> DialogFieldValue:
     LOG.info("Suggest field %s" % self._source)
     for suggester in self._suggesters:
         suggester_name = suggester.__class__.__name__
         suggester_result = suggester(self, form)
         LOG.info("%s -> Suggested value for field %s is %s" %
                  (suggester_name, self._source, suggester_result))
         if suggester_result:
             suggester_result_fieldvalue = self._to_suggest_fieldvalue(
                 suggester_result)
             if FieldValue.is_suggested(suggester_result_fieldvalue):
                 choosers_result = self._choose(suggester_result)
                 result = suggester_result if not choosers_result else choosers_result
                 suggester_result_fieldvalue = self._to_suggest_fieldvalue(
                     result)
             self.__suggested = suggester_result_fieldvalue
             LOG.info("Suggested FieldValue for field %s is %s" %
                      (self._source, self.__suggested.__class__.__name__))
             return self.__suggested
     LOG.info("Suggested value for field %s is empty" % self._source)
     return FieldValue.empty()
예제 #5
0
 def suggested(self):
     if self.__selected_field:
         return self.__selected_field.suggested
     return FieldValue.empty()
예제 #6
0
 def matched(self):
     if self.__selected_field:
         return self.__selected_field.matched
     return FieldValue.empty()
예제 #7
0
 def origin(self):
     if self.__selected_field:
         return self.__selected_field.origin
     return FieldValue.empty()
예제 #8
0
 def value(self):
     if self.__selected_field:
         return self.__selected_field.value
     return FieldValue.empty()
예제 #9
0
 def suggest(self, form) -> DialogFieldValue:
     if self.__selected_field:
         return self.__selected_field.suggest(form)
     return FieldValue.empty()