def walk(args, depth=0): "walk all trees concurrently and build result" if depth == n: return Expression(f, *args) else: dim = None for i, arg in enumerate(args): if not arg.has_form("List", None): raise MessageException("MapThread", "mptd", heads[i], i + 1, full_expr, depth, n) if dim is None: dim = len(arg.leaves) if dim != len(arg.leaves): raise MessageException( "MapThread", "mptc", 1, i + 1, full_expr, dim, len(arg.leaves), ) return Expression( "List", *[ walk([arg.leaves[i] for arg in args], depth + 1) for i in range(dim) ])
def parts(): for li in lists.leaves: head_name = li.get_head_name() if head_name == "System`List": yield li.leaves elif head_name != "System`Missing": raise MessageException("Catenate", "invrp", li)
def __init__(self, name, mode="r", encoding=None): if encoding is not None: encoding = to_python_encoding(encoding) if "b" in mode: # We should not specify an encoding for a binary mode encoding = None elif encoding is None: raise MessageException("General", "charcode", self.encoding) self.encoding = encoding super().__init__(name, mode, self.encoding) self.old_inputfile_var = None # Set in __enter__ and __exit__
def inflected_forms(self, syn, desc): try: word, pos, _ = desc if pos == 'Verb': from pattern.en import lexeme return [w for w in reversed(lexeme(word)) if w != word] elif pos == 'Noun': from pattern.en import pluralize return [pluralize(word)] elif pos == 'Adjective': from pattern.en import comparative, superlative return [comparative(word), superlative(word)] else: return [] except ImportError: raise MessageException('General', 'unavailable', 'WordData[_, "InflectedForms"]', 'pattern')