import json from typing import Dict, Any class BagOfWords: def __init__(self, **kwargs: Any) -> None: """ Initialize the component. """ self.name = 'BagOfWords' self.iife_script = '''''' self.div_id = 'BagOfWords-328cd234' self.props = [] self.markup = "" self.add_params(kwargs) def add_params(self, params: Dict[str, Any]) -> None: """ Add parameters to the component and serve in html. Parameters ---------- params : dict The parameters to add to the component. """ js_data = json.dumps(params, indent=0) self.markup = f"""
""" def _repr_html_(self) -> str: """ Return the component as an HTML string. """ return f""" {self.iife_script} {self.markup} """ def __call__(self, **kwargs: Any) -> "BagOfWords": """ Call the component with the given kwargs. Parameters ---------- kwargs : any The kwargs to pass to the component. Returns ------- PackagedComponent A python class representing the svelte component, renderable in Jupyter. """ # render with given arguments self.add_params(kwargs) return self