예제 #1
0
def test_word_region_first():
    text = createMockContent('INT. GERMAN BEER HALL. NIGHT. 1868.')
    assert isHeading(text) == True
예제 #2
0
def test_time_2_dashes():
    text = createMockContent('INT. DON DRAPER’S OFFICE -- LATER')
    assert isHeading(text) == True
예제 #3
0
def test_word_before_region():
    text = createMockContent('RIGHT IN THE STINT.')
    assert isHeading(text) == False
예제 #4
0
def test_region_location():
    text = createMockContent('INT. ELEVATOR')
    assert isHeading(text) == True
예제 #5
0
def test_ext_int_combo():
    text1 = createMockContent('EXT/INT. WATERFORD HOUSE - CONTINUOUS')
    text2 = createMockContent('INT/EXT. WATERFORD HOUSE - CONTINUOUS')
    assert isHeading(text1) == True
    assert isHeading(text2) == True
예제 #6
0
def test_region_location_time():
    text = createMockContent('EXT. WATERFORD HOUSE - CONTINUOUS')
    assert isHeading(text) == True
예제 #7
0
def test_word_before_region():
    text = createMockContent(
        'THE PAST. INT. CONCORD. MARCH HOUSE. JO & MEG’S ROOM. 1861.')
    assert isHeading(text) == True
예제 #8
0
def categorizeSections(topTrends, script, pageStart, includeSceneNumber):
    """categorize lines into types"""

    finalSections = []
    sceneNumber = 0
    for page in script:
        if page["page"] < pageStart:
            continue
        finalSections.append({"page": page["page"], "content": []})

        finalSections[-1]["content"].append({
            # "scene_number": sceneNumber,
            "scene_info": finalSections[LAST_SCENE]["content"][-1]["scene_info"] if len(finalSections) >= 2 else None,
            "scene": []
        })

        characterOccurred = False
        for i, content in enumerate(page["content"]):
            if "character2" in content:
                finalSections[-1]["content"][-1]["scene"].append({
                    "type": "DUAL_DIALOGUE",
                    "content": {
                        "character1": content["segment"],
                        "character2": content["character2"],
                    }
                })
                characterOccurred = False
                continue

            previousY = page["content"][i -
                                        1]["segment"][-1]["y"] if i > 0 else 0
            x = content["segment"][0]["x"]
            y = content["segment"][0]["y"]
            text = content["segment"][0]["text"]

            # booleans
            isAction = abs(x - topTrends[0][0]) <= 15
            isTransition = content["segment"][0]["x"] >= 420 or "FADE" in text or ("CUT" in text and not isAction) or "TO:" in text

            if isHeading(content["segment"][0]):
                sceneNumber += 1
                if len(finalSections[-1]["content"][-1]["scene"]) == 0:
                    finalSections[-1]["content"][-1] = {
                        # "scene_number": sceneNumber,
                        "scene_info": extractHeading(content["segment"][0]["text"]),
                        "scene": []
                    }
                else:
                    finalSections[-1]["content"].append({
                        # "scene_number": sceneNumber,
                        "scene_info": extractHeading(content["segment"][0]["text"]),
                        "scene": []
                    })
                characterOccurred = False
            elif isTransition:
                finalSections[-1]["content"][-1]["scene"].append({
                    "type": "TRANSITION",
                    "content": {
                        "text": text,
                        "metadata": {
                            "x": x,
                            "y": y
                        }
                    }
                })
                characterOccurred = False
            elif isAction:
                # if Heading is multi-line
                if i > 0 and len(finalSections[-1]["content"][-1]["scene"]) == 0 and y - page["content"][i-1]["segment"][-1]["y"] < 24:
                    finalSections[-1]["content"][-1]["scene_info"]["location"] += " " + text
                else:
                    finalSections[-1]["content"][-1]["scene"].append({
                        "type": "ACTION",
                        "content": [{"text": text, "x": x, "y": y}]
                    })
                    characterOccurred = False

            elif isCharacter(content["segment"][0]):
                finalSections[-1]["content"][-1]["scene"].append({
                    "type": "CHARACTER",
                    "text": extractCharacter(content["segment"][0]),
                    "metadata": {
                        "x": x,
                        "y": y
                    }
                })
                characterOccurred = True
            else:
                currentScene = finalSections[-1]["content"][-1]["scene"]

                # first line of page is never a dialogue
                if len(currentScene) == 0 or not characterOccurred:
                    finalSections[-1]["content"][-1]["scene"].append({
                        "type": "ACTION",
                        "content": [{"text": text, "x": x, "y": y}]
                    })

                else:
                    finalSections[-1]["content"][-1]["scene"].append({
                        "type": "DIALOGUE",
                        "text": text,
                        "metadata": {
                            "x": x,
                            "y": y
                        }
                    })

    return finalSections