def _parse_validate_compile_intent(self): from lux.processor.Parser import Parser from lux.processor.Validator import Validator self._intent = Parser.parse(self._intent) Validator.validate_intent(self._intent, self) self.maintain_metadata() from lux.processor.Compiler import Compiler self.current_vis = Compiler.compile_intent(self, self._intent)
def refresh_source(self, ldf): """ Loading the source into the visualizations in the VisList, then populating each visualization based on the new source data, effectively "materializing" the visualization collection. Parameters ---------- ldf : LuxDataframe Input Dataframe to be attached to the VisList Returns ------- VisList Complete VisList with fully-specified fields See Also -------- lux.vis.Vis.refresh_source Note ---- Function derives a new _inferred_intent by instantiating the intent specification on the new data """ if ldf is not None: from lux.processor.Parser import Parser from lux.processor.Validator import Validator from lux.processor.Compiler import Compiler self._source = ldf self._source.maintain_metadata() if len(self._input_lst) > 0: approx = False if self._is_vis_input(): compiled_collection = [] for vis in self._collection: vis._inferred_intent = Parser.parse(vis._intent) Validator.validate_intent(vis._inferred_intent, ldf) Compiler.compile_vis(ldf, vis) compiled_collection.append(vis) self._collection = compiled_collection else: self._inferred_intent = Parser.parse(self._intent) Validator.validate_intent(self._inferred_intent, ldf) self._collection = Compiler.compile_intent( ldf, self._inferred_intent) # Early pruning determination criteria width_criteria = len(self._collection) > (lux.config.topk + 3) length_criteria = len( ldf) > lux.config.early_pruning_sample_start if lux.config.early_pruning and width_criteria and length_criteria: # print("Apply approx to this VisList") ldf._message.add_unique( "Large search space detected: Lux is approximating the interestingness of recommended visualizations.", priority=1, ) approx = True lux.config.executor.execute(self._collection, ldf, approx=approx)
def compile_intent(ldf: LuxDataFrame, _inferred_intent: List[Clause]) -> VisList: """ Compiles input specifications in the intent of the ldf into a collection of lux.vis objects for visualization. 1) Enumerate a collection of visualizations interested by the user to generate a vis list 2) Expand underspecified specifications(lux.Clause) for each of the generated visualizations. 3) Determine encoding properties for each vis Parameters ---------- ldf : lux.core.frame LuxDataFrame with underspecified intent. vis_collection : list[lux.vis.Vis] empty list that will be populated with specified lux.Vis objects. Returns ------- vis_collection: list[lux.Vis] vis list with compiled lux.Vis objects. """ valid_intent = _inferred_intent # ensures intent is non-empty if valid_intent and Validator.validate_intent(_inferred_intent, ldf, True): vis_collection = Compiler.enumerate_collection(_inferred_intent, ldf) # autofill data type/model information Compiler.populate_data_type_model(ldf, vis_collection) # remove invalid visualizations from collection if len(vis_collection) >= 1: vis_collection = Compiler.remove_all_invalid(vis_collection) for vis in vis_collection: # autofill viz related information Compiler.determine_encoding(ldf, vis) ldf._compiled = True return vis_collection elif _inferred_intent: return []
def refresh_source(self, ldf): # -> Vis: """ Loading the source data into the Vis by instantiating the specification and populating the Vis based on the source data, effectively "materializing" the Vis. Parameters ---------- ldf : LuxDataframe Input Dataframe to be attached to the Vis Returns ------- Vis Complete Vis with fully-specified fields See Also -------- lux.Vis.VisList.refresh_source Note ---- Function derives a new _inferred_intent by instantiating the intent specification on the new data """ if ldf is not None: from lux.processor.Parser import Parser from lux.processor.Validator import Validator from lux.processor.Compiler import Compiler from lux.executor.PandasExecutor import ( PandasExecutor, ) # TODO: temporary (generalize to executor) self.check_not_vislist_intent() ldf.maintain_metadata() self._source = ldf self._inferred_intent = Parser.parse(self._intent) Validator.validate_intent(self._inferred_intent, ldf) vlist = Compiler.compile_vis(ldf, self) ldf.executor.execute(vlist, ldf) # Copying properties over since we can not redefine `self` within class function if len(vlist) > 0: vis = vlist[0] self.title = vis.title self._mark = vis._mark self._inferred_intent = vis._inferred_intent self._vis_data = vis.data self._min_max = vis._min_max
def refresh_source(self, ldf): """ Loading the source into the visualizations in the VisList, then populating each visualization based on the new source data, effectively "materializing" the visualization collection. Parameters ---------- ldf : LuxDataframe Input Dataframe to be attached to the VisList Returns ------- VisList Complete VisList with fully-specified fields See Also -------- lux.vis.Vis.refresh_source Note ---- Function derives a new _inferred_intent by instantiating the intent specification on the new data """ if (ldf is not None): from lux.processor.Parser import Parser from lux.processor.Validator import Validator from lux.processor.Compiler import Compiler self._source = ldf self._source.maintain_metadata() if len(self._input_lst) > 0: if (self._is_vis_input()): compiled_collection = [] for vis in self._collection: vis._inferred_intent = Parser.parse(vis._intent) Validator.validate_intent(vis._inferred_intent, ldf) vislist = Compiler.compile_vis(ldf, vis) if (len(vislist) > 0): vis = vislist[0] compiled_collection.append(vis) self._collection = compiled_collection else: self._inferred_intent = Parser.parse(self._intent) Validator.validate_intent(self._inferred_intent, ldf) self._collection = Compiler.compile_intent( ldf, self._inferred_intent) ldf.executor.execute(self._collection, ldf)
def current_vis(self): from lux.processor.Validator import Validator # _parse_validate_compile_intent does not call executor, # we only attach data to current vis when user request current_vis valid_current_vis = (self._current_vis is not None and len(self._current_vis) > 0 and self._current_vis[0].data is None and self._current_vis[0].intent) if valid_current_vis and Validator.validate_intent( self._current_vis[0].intent, self): lux.config.executor.execute(self._current_vis, self) return self._current_vis
def refresh_source(self, ldf): # -> Vis: """ Loading the source data into the Vis by instantiating the specification and populating the Vis based on the source data, effectively "materializing" the Vis. Parameters ---------- ldf : LuxDataframe Input Dataframe to be attached to the Vis Returns ------- Vis Complete Vis with fully-specified fields See Also -------- lux.Vis.VisList.refresh_source Note ---- Function derives a new _inferred_intent by instantiating the intent specification on the new data """ if ldf is not None: from lux.processor.Parser import Parser from lux.processor.Validator import Validator from lux.processor.Compiler import Compiler self.check_not_vislist_intent() ldf.maintain_metadata() self._source = ldf self._inferred_intent = Parser.parse(self._intent) Validator.validate_intent(self._inferred_intent, ldf) Compiler.compile_vis(ldf, self) lux.config.executor.execute([self], ldf)