text_extensions_for_pandas/io/watson/nlu.py
def make_span_from_entities(char_span: SpanArray,
                            entities_frame: pd.DataFrame,
                            entity_col: str = "text") -> TokenSpanArray:
    """
    Create a token span array for entity text from the entities DataFrame, and an existing
    char span array with tokens from the entire analyzed text.

    :param char_span: Parsed tokens
    :param entities_frame: Entities DataFrame from `parse_response`
    :param entity_col: Column name for the entity text
    :return: TokenSpanArray for matching entities
    """
    entities = entities_frame[entity_col]
    entities_len = entities.str.len()
    begins = []
    ends = []

    i = 0
    while i < len(char_span):
        span = char_span[i]
        text = span.covered_text
        end = i
        num_tokens = 1
        stop = False
        while not stop:
            stop = True
            starts_with = entities.str.startswith(text)
            if any(starts_with):
                # Have a complete match, advance the end index
                if any(entities_len[starts_with] == len(text)):
                    end = i + num_tokens
                # Try the next token
                if i + num_tokens < len(char_span):
                    span = char_span[i + num_tokens]
                    text = text + " " + span.covered_text
                    num_tokens += 1
                    stop = False

        if i != end:
            begins.append(i)
            ends.append(end)
            i += (end - i)
        else:
            i += 1

    return TokenSpanArray(char_span, begins, ends)

    Create a token span array for entity text from the entities DataFrame, and an existing
    char span array with tokens from the entire analyzed text.

    :param char_span: Parsed tokens
    :param entities_frame: Entities DataFrame from `parse_response`
    :param entity_col: Column name for the entity text
    :return: TokenSpanArray for matching entities
    
Create a token span array for entity text from the entities DataFrame, and an existing
char span array with tokens from the entire analyzed text.
Create a token span array for entity text from the entities DataFrame and an existing char span array with tokens from the entire analyzed text .
def make_span_from_entities(char_span: SpanArray,
                            entities_frame: pd.DataFrame,
                            entity_col: str = "text") -> TokenSpanArray:
    entities = entities_frame[entity_col]
    entities_len = entities.str.len()
    begins = []
    ends = []
    i = 0
    while i < len(char_span):
        span = char_span[i]
        text = span.covered_text
        end = i
        num_tokens = 1
        stop = False
        while not stop:
            stop = True
            starts_with = entities.str.startswith(text)
            if any(starts_with):
                if any(entities_len[starts_with] == len(text)):
                    end = i + num_tokens
                if i + num_tokens < len(char_span):
                    span = char_span[i + num_tokens]
                    text = text + " " + span.covered_text
                    num_tokens += 1
                    stop = False
        if i != end:
            begins.append(i)
            ends.append(end)
            i += (end - i)
        else:
            i += 1
    return TokenSpanArray(char_span, begins, ends)
def make_span_from_entities ( char_span : SpanArray , entities_frame : pd . DataFrame , entity_col : str = "text" ) -> TokenSpanArray : entities = entities_frame [ entity_col ] entities_len = entities . str . len ( ) begins = [ ] ends = [ ] i = 0 while i < len ( char_span ) : span = char_span [ i ] text = span . covered_text end = i num_tokens = 1 stop = False while not stop : stop = True starts_with = entities . str . startswith ( text ) if any ( starts_with ) : if any ( entities_len [ starts_with ] == len ( text ) ) : end = i + num_tokens if i + num_tokens < len ( char_span ) : span = char_span [ i + num_tokens ] text = text + " " + span . covered_text num_tokens += 1 stop = False if i != end : begins . append ( i ) ends . append ( end ) i += ( end - i ) else : i += 1 return TokenSpanArray ( char_span , begins , ends )
Create a token span array for entity text from the entities DataFrame, and an existing
char span array with tokens from the entire analyzed text.
Create a token span array for entity text from the entities DataFrame and an existing char span array with tokens from the entire analyzed text .
"""
    Create a token span array for entity text from the entities DataFrame, and an existing
    char span array with tokens from the entire analyzed text.

    :param char_span: Parsed tokens
    :param entities_frame: Entities DataFrame from `parse_response`
    :param entity_col: Column name for the entity text
    :return: TokenSpanArray for matching entities
    """ # Have a complete match, advance the end index # Try the next token
TokenSpanArray for matching entities
TokenSpanArray for matching entities
char_span
SpanArray
None
entities_frame
pd.DataFrame
Entities DataFrame from `parse_response`
Entities DataFrame from ` parse_response `
entity_col
str
Column name for the entity text
Column name for the entity text