text_extensions_for_pandas/jupyter/widget/span.py
def DataFrameDocumentContainerComponent(widget): # -> ipw.Widget
    """A Component that separates a dataframe by document and generates their components."""

    dataframe = widget._df

    target_texts = []
    spans_by_text = {}

    span_columns = []
    # Check if any of the columns are of dtype SpanArray or TokenSpanArray
    for column_name in dataframe.columns:
        column = dataframe[column_name]

        if str(column.dtype) == "SpanDtype" or str(column.dtype) == "TokenSpanDtype":
            span_columns.append(column.name)

    if len(span_columns) > 0:
        # Iterate over all rows in the dataframe and add that span's text
        for span_column in span_columns:
            for i_loc in range(len(dataframe[span_column])):
                item = dataframe[span_column][i_loc]
                target_text = item.target_text
                if target_text not in target_texts:
                    target_texts.append(target_text)
                    spans_by_text[target_text] = []

                spans_by_text[target_text].append(
                    {"span": item, "i_loc": i_loc, "column": span_column,}
                )

        # Add the document display controls
        controls = DataFrameDocumentControlsComponent(
            widget=widget, span_columns=span_columns
        )

        # Generate a widget component for each document
        documents = []
        for text in target_texts:
            documents.append(
                DataFrameDocumentComponent(
                    widget=widget, text=text, spans=spans_by_text[text]
                )
            )

        documents_widget = ipw.VBox(children=[controls, *documents])
        documents_widget.add_class("tep--spanvis")
        return documents_widget
A Component that separates a dataframe by document and generates their components.
A Component that separates a dataframe by document and generates their components.
A Component that separates a dataframe by document and generates their components .
def DataFrameDocumentContainerComponent(widget): 
    dataframe = widget._df
    target_texts = []
    spans_by_text = {}
    span_columns = []
    for column_name in dataframe.columns:
        column = dataframe[column_name]
        if str(column.dtype) == "SpanDtype" or str(column.dtype) == "TokenSpanDtype":
            span_columns.append(column.name)
    if len(span_columns) > 0:
        for span_column in span_columns:
            for i_loc in range(len(dataframe[span_column])):
                item = dataframe[span_column][i_loc]
                target_text = item.target_text
                if target_text not in target_texts:
                    target_texts.append(target_text)
                    spans_by_text[target_text] = []
                spans_by_text[target_text].append(
                    {"span": item, "i_loc": i_loc, "column": span_column,}
                )
        controls = DataFrameDocumentControlsComponent(
            widget=widget, span_columns=span_columns
        )
        documents = []
        for text in target_texts:
            documents.append(
                DataFrameDocumentComponent(
                    widget=widget, text=text, spans=spans_by_text[text]
                )
            )
        documents_widget = ipw.VBox(children=[controls, *documents])
        documents_widget.add_class("tep--spanvis")
        return documents_widget
def DataFrameDocumentContainerComponent ( widget ) : dataframe = widget . _df target_texts = [ ] spans_by_text = { } span_columns = [ ] for column_name in dataframe . columns : column = dataframe [ column_name ] if str ( column . dtype ) == "SpanDtype" or str ( column . dtype ) == "TokenSpanDtype" : span_columns . append ( column . name ) if len ( span_columns ) > 0 : for span_column in span_columns : for i_loc in range ( len ( dataframe [ span_column ] ) ) : item = dataframe [ span_column ] [ i_loc ] target_text = item . target_text if target_text not in target_texts : target_texts . append ( target_text ) spans_by_text [ target_text ] = [ ] spans_by_text [ target_text ] . append ( { "span" : item , "i_loc" : i_loc , "column" : span_column , } ) controls = DataFrameDocumentControlsComponent ( widget = widget , span_columns = span_columns ) documents = [ ] for text in target_texts : documents . append ( DataFrameDocumentComponent ( widget = widget , text = text , spans = spans_by_text [ text ] ) ) documents_widget = ipw . VBox ( children = [ controls , * documents ] ) documents_widget . add_class ( "tep--spanvis" ) return documents_widget
A Component that separates a dataframe by document and generates their components.
A Component that separates a dataframe by document and generates their components .
# -> ipw.Widget """A Component that separates a dataframe by document and generates their components.""" # Check if any of the columns are of dtype SpanArray or TokenSpanArray # Iterate over all rows in the dataframe and add that span's text # Add the document display controls # Generate a widget component for each document
widget