0

I want to use a public function defined in the python script. This script contains multiple functions and I want to use one specific function. Next I want to check some visual output while importing this script and the function in jupyter notebook. I need some help with jupyter notebook. ( How to import and use this function in jupyter notebook ?)

Here is the function I want to use and check its output visually in jupyter notebook:

 def merge_boxes_horizontally(boxes: Iterable[TextBox]) -> list[TextBoxCluster]:
    """
    Merge boxes that belong to one line.

    The algorithm does the following:
    1. Sort boxes by x-coordinate.
    2. Iterate through them and merge those that are close in x- and have
       overlap in y-direction to clusters.
    3. If the current box does not belong to a previously seen cluster,
       start a new cluster from the box.

    Parameters
    ----------
    boxes
        The boxes that shall be clustered.

    Returns
    -------
    List[TextBoxCluster]
        A list of the line segments that were found, sorted by y-coordinate.
    """
    boxes_sorted = sorted(boxes, key=lambda box: box.left)
    reference, *remainder = boxes_sorted
    clusters: dict[TextBox, list[TextBox]] = {reference: [reference]}
    for box in remainder:
        is_matched = False
        for reference, cluster in clusters.items():
            if has_sufficient_y_overlap(reference, box):
                *_, last_in_row = cluster
                if in_x_proximity(last_in_row, box):
                    cluster.append(box)
                    is_matched = True
                    break
        if not is_matched:
            clusters[box] = [box]
    return sorted(
        (TextBoxCluster(cluster) for cluster in clusters.values()),
        key=lambda box: box.top,
    )  
aarya
  • 83
  • 1
  • 8
  • @edornd could you please help ? – aarya Aug 04 '22 at 09:59
  • You aren't providing critical information to best guide you. You don't say the source of this function, for example. If you said the file or package that has it, those looking to help you could advise much better. Alternatively, if you read how to [save a python script into a local directory and call it with an import statement](https://stackoverflow.com/a/72019554/8508004), it may give you an idea how to proceed yourself. Another option: You could just put that code block in a cell in your notebook run it, and then call it. If it is self-contained it will work. – Wayne Aug 04 '22 at 15:40

0 Answers0