text_extensions_for_pandas/spanner/extract.py
def extract_split(
    doc_text: str, split_points: Union[Sequence[int], np.ndarray, SpanArray]
) -> SpanArray:
    """
    Split a document into spans along a specified set of split points.

    :param doc_text: Text of the document; will be the target text of the returned spans.

    :param split_points: A series of offsets into ``doc_text``, expressed as either:
      * A sequence of integers (split at certain locations and return a set of splits that
        covers every character in the document) as a list or 1-d Numpy array
      * A sequence of spans (split around the indicated locations, but discard the parts
        of the document that are within a split point)

    :returns: An ``SpanArray``  that splits the document in the specified way.
    """
    if isinstance(split_points, (collections.abc.Sequence, np.ndarray)):
        # Single-integer split points ==> zero-length spans
        split_points = SpanArray(doc_text, split_points, split_points)
    elif not isinstance(split_points, SpanArray):
        raise TypeError(f"Split points are of type {type(split_points)}. Expected a "
                        f"sequence of integers or a SpanArray.")

    # Make sure split points are in order
    sorted_indices = split_points.argsort()
    sorted_split_points = split_points[sorted_indices]

    # Break out the split points.
    split_begins = sorted_split_points.begin.tolist()  # type: List[int]
    split_ends = sorted_split_points.end.tolist()  # type: List[int]

    # Tack on an additional split point at the very end to simplify the logic below.
    split_begins.append(len(doc_text))
    split_ends.append(len(doc_text))

    # Walk through the document, generating the begin and end offsets of spans
    begins = []
    ends = []
    begin = 0
    for split_begin, split_end in zip(split_begins, split_ends):
        end = split_begin
        if end > begin:  # Ignore zero-length and negative-length chunks
            begins.append(begin)
            ends.append(end)
        begin = split_end

    return SpanArray(doc_text, begins, ends)

    Split a document into spans along a specified set of split points.

    :param doc_text: Text of the document; will be the target text of the returned spans.

    :param split_points: A series of offsets into ``doc_text``, expressed as either:
      * A sequence of integers (split at certain locations and return a set of splits that
        covers every character in the document) as a list or 1-d Numpy array
      * A sequence of spans (split around the indicated locations, but discard the parts
        of the document that are within a split point)

    :returns: An ``SpanArray``  that splits the document in the specified way.
    
Split a document into spans along a specified set of split points.
Split a document into spans along a specified set of split points .
def extract_split(
    doc_text: str, split_points: Union[Sequence[int], np.ndarray, SpanArray]
) -> SpanArray:
    if isinstance(split_points, (collections.abc.Sequence, np.ndarray)):
        split_points = SpanArray(doc_text, split_points, split_points)
    elif not isinstance(split_points, SpanArray):
        raise TypeError(f"Split points are of type {type(split_points)}. Expected a "
                        f"sequence of integers or a SpanArray.")
    sorted_indices = split_points.argsort()
    sorted_split_points = split_points[sorted_indices]
    split_begins = sorted_split_points.begin.tolist()  
    split_ends = sorted_split_points.end.tolist()  
    split_begins.append(len(doc_text))
    split_ends.append(len(doc_text))
    begins = []
    ends = []
    begin = 0
    for split_begin, split_end in zip(split_begins, split_ends):
        end = split_begin
        if end > begin:  
            begins.append(begin)
            ends.append(end)
        begin = split_end
    return SpanArray(doc_text, begins, ends)
def extract_split ( doc_text : str , split_points : Union [ Sequence [ int ] , np . ndarray , SpanArray ] ) -> SpanArray : if isinstance ( split_points , ( collections . abc . Sequence , np . ndarray ) ) : split_points = SpanArray ( doc_text , split_points , split_points ) elif not isinstance ( split_points , SpanArray ) : raise TypeError ( f"Split points are of type {type(split_points)}. Expected a " f"sequence of integers or a SpanArray." ) sorted_indices = split_points . argsort ( ) sorted_split_points = split_points [ sorted_indices ] split_begins = sorted_split_points . begin . tolist ( ) split_ends = sorted_split_points . end . tolist ( ) split_begins . append ( len ( doc_text ) ) split_ends . append ( len ( doc_text ) ) begins = [ ] ends = [ ] begin = 0 for split_begin , split_end in zip ( split_begins , split_ends ) : end = split_begin if end > begin : begins . append ( begin ) ends . append ( end ) begin = split_end return SpanArray ( doc_text , begins , ends )
Split a document into spans along a specified set of split points.
Split a document into spans along a specified set of split points .
"""
    Split a document into spans along a specified set of split points.

    :param doc_text: Text of the document; will be the target text of the returned spans.

    :param split_points: A series of offsets into ``doc_text``, expressed as either:
      * A sequence of integers (split at certain locations and return a set of splits that
        covers every character in the document) as a list or 1-d Numpy array
      * A sequence of spans (split around the indicated locations, but discard the parts
        of the document that are within a split point)

    :returns: An ``SpanArray``  that splits the document in the specified way.
    """ # Single-integer split points ==> zero-length spans # Make sure split points are in order # Break out the split points. # type: List[int] # type: List[int] # Tack on an additional split point at the very end to simplify the logic below. # Walk through the document, generating the begin and end offsets of spans # Ignore zero-length and negative-length chunks
An ``SpanArray``  that splits the document in the specified way.
An ` ` SpanArray ` ` that splits the document in the specified way .
doc_text
str
Text of the document; will be the target text of the returned spans.
Text of the document ; will be the target text of the returned spans .
split_points
Union[Sequence[int], np.ndarray, SpanArray]
A series of offsets into ``doc_text``, expressed as either:
A sequence of integers (split at certain locations and return a set of splits that
covers every character in the document) as a list or 1-d Numpy array
A sequence of spans (split around the indicated locations, but discard the parts
of the document that are within a split point)
A series of offsets into ` ` doc_text ` ` expressed as either : A sequence of integers ( split at certain locations and return a set of splits that covers every character in the document ) as a list or 1 - d Numpy array A sequence of spans ( split around the indicated locations but discard the parts of the document that are within a split point )