def _get_arguments(arguments: list, holes: list):
     arguments = list(deepcopy(arguments))
     relevant_arguments = []
     mass = 0
     primitives = False
     idle = False
     fine = 1
     while not (idle and primitives) and len(holes) > 0 and len(arguments) > 0:
         primitives = True
         idle = True
         for i, argument in enumerate(arguments):
             if not argument.type.isprimitive(): primitives = False
             if argument.type == holes[0]:
                 del holes[0]
                 del arguments[i]
                 relevant_arguments.append(argument)
                 mass += (i + 1) * fine
                 idle = False
                 break
         if idle:
             arguments = [argument.simplify() for argument in arguments]
             fine += 4
         IO.debug("primitives = {}", primitives)
         IO.debug("idle = {}", idle)
         IO.debug("holes = {}", holes)
         IO.debug("arguments = {}", arguments)
         IO.debug("---------------------------")
     return relevant_arguments, mass
 def _build(self, node: NounPhrase, args: list) -> list:
     if isinstance(node, LeafNounPhrase):
         string = node.nn.text
         noun = Simplifier.simplify_word(string)
         adjectives = Simplifier.simplify_adjectives(node.jjs)
         type_names = [str(type) for type in Types.Type.extract(adjectives)]
         if len(type_names) == 1 and type_names[0] in self._builders and noun not in self._builders:
             adjectives.remove(type_names[0])
             adjectives.append(string)
             noun = type_names[0]
         constructed_object = None
         function = NullFunction()
         shell = self._get_relevant_shell(noun, adjectives)
         if shell is not None:
             adjectives = shell.difference(adjectives)
             function = self._get_relevant_function(noun, adjectives, shell.functions, args)
             if function.mass < float("inf"): constructed_object = self._execute(function, function.relevant_args)
         if constructed_object is None: constructed_object = Object.valueOf(string)
         IO.debug("relevant_function = {}", function)
         IO.debug("===========================")
         return [constructed_object]
     else:
         _args = [arg.mark(pp.pretext) for pp in node.pps for np in pp.nps for arg in self._build(np, [])]
         return [arg for np in node.nps for arg in self._build(np, args + _args)]
 def _get_relevant_function(self, noun: str, adjectives: list, functions: list, arguments: list) -> WFunction:
     relevant_function = NullFunction()
     for function in functions:
         holes = list(deepcopy(function.args))
         IO.debug(holes)
         IO.debug(arguments)
         IO.debug(adjectives)
         IO.debug(list(reversed([Object.valueOf(jj) for jj in adjectives])))
         relevant_arguments, mass = self._get_arguments(arguments, holes)
         if noun in self._type_builders and len(holes) == 1 and len(function.args) == 1:
             temp_function = self._type_builders[noun]
             if holes == list(temp_function.args): function = temp_function
         pair = self._get_arguments(list(reversed([Object.valueOf(jj) for jj in adjectives])), holes)
         relevant_arguments.extend(pair[0])
         mass += pair[1] - 2 * len(function.args)
         IO.debug("function = {}", function)
         IO.debug("relevant_arguments = {}", relevant_arguments)
         IO.debug("relevant_function = {}", relevant_function)
         IO.debug("mass = {}", mass if len(holes) == 0 else float("inf"))
         IO.debug("+++++++++++++++++++++++++++")
         if len(holes) == 0 and relevant_function.mass > mass:
             relevant_function = WFunction(mass, relevant_arguments, function)
     return relevant_function