# Path: pyramids/categorization.py
# CATEGORY_WILDCARD = _CATEGORY_WILDCARD
# 
# Path: pyramids/graphs.py
# class ParseGraph:
# class BuildGraph:
#     def from_json(cls, json_data: Dict[str, List]) -> 'ParseGraph':
#     def __init__(self, root: int, tokens: Sequence[Token], links: List[Dict[int, Set[str]]],
#                  phrases: List[List[Tuple[Category, List[Tuple[int, int]]]]]):
#     def root_index(self) -> int:
#     def root_category(self) -> Category:
#     def tokens(self) -> Tuple[Token, ...]:
#     def __str__(self) -> str:
#     def __getitem__(self, index: int) -> Token:
#     def __len__(self) -> int:
#     def to_json(self) -> Dict[str, List]:
#     def get_phrase_category(self, head: int) -> Category:
#     def get_phrase_stack(self, head: int) -> Category:
#     def get_sinks(self, source: int) -> Set[int]:
#     def get_sources(self, sink: int) -> Set[int]:
#     def get_labels(self, source: int, sink: int) -> FrozenSet[str]:
#     def _get_phrase_tokens(self, head: int, indices: Set[int]) -> None:
#     def get_phrase_tokens(self, head: int = None) -> List[Token]:
#     def get_phrase_text(self, head: int = None) -> str:
#     def visualize(self, gv_graph: Digraph) -> None:
#     def from_parse_graphs(cls, graphs: Sequence[Union[ParseGraph, 'BuildGraph']]) -> 'BuildGraph':
#     def from_json(cls, json_data: Dict[str, List]) -> 'BuildGraph':
#     def __init__(self):
#     def tokens(self) -> Tuple[Token, ...]:
#     def get_annotations(self) -> List[str]:
#     def find_roots(self) -> Set[int]:
#     def find_leaves(self) -> Set[int]:
#     def _is_forest(self, roots: Set[int]) -> bool:
#     def is_tree(self) -> bool:
#     def is_forest(self) -> bool:
#     def set_phrase_category(self, index: int, category: Category) -> None:
#     def append_token(self, spelling: str, category: Category = None,
#                      span: Tuple[int, int] = None) -> int:
#     def clear_token_category(self, index: int) -> None:
#     def add_link(self, source: int, label: str, sink: int) -> None:
#     def discard_link(self, source: int, label: str, sink: int) -> None:
#     def remove_link(self, source: int, label: str, sink: int) -> None:
#     def has_link(self, source: int, label: str, sink: int) -> bool:
#     def iter_links(self, source: int = None, label: str = None, sink: int = None) \
#             def sink_iterator_func(sinks):
#             def sink_iterator_func(sinks):
#             def label_iterator_func(labels):
#             def label_iterator_func(labels):
#     def __getitem__(self, index: int) -> Token:
#     def __len__(self) -> int:
#     def to_json(self) -> Dict[str, List]:
#     def get_phrase_category(self, head: int) -> Category:
#     def get_sinks(self, source: int) -> Set[int]:
#     def get_sources(self, sink: int) -> Set[int]:
#     def get_labels(self, source: int, sink: int) -> FrozenSet[LinkLabel]:
#     def _get_phrase_tokens(self, head: int, indices: Set[int]) -> None:
#     def get_phrase_tokens(self, head: int = None) -> List[Token]:
#     def visualize(self, gv_graph: Digraph) -> None:
# 
# Path: pyramids/traversal.py
# class LanguageContentHandler:
#     """A content handler for natural language, in the style of the
#     ContentHandler class of the xml.sax module."""
# 
#     def handle_tree_end(self) -> None:
#         """Called to indicate the token_end_index of a tree."""
# 
#     def handle_token(self, spelling: str, category: Category, index: int = None,
#                      span: Tuple[int, int] = None) -> None:
#         """Called to indicate the occurrence of a token."""
# 
#     def handle_root(self) -> None:
#         """Called to indicate that the next token is the root."""
# 
#     def handle_link(self, source_start_index: int, sink_start_index: int, label: str) -> None:
#         """Called to indicate the occurrence of a link between two tokens.
#         Note that this will not be called until handle_token() has been
#         called for both the source and sink."""
# 
#     def handle_phrase_start(self, category: Category, head_start_index: int = None) -> None:
#         """Called to indicate the token_start_index of a phrase."""
# 
#     def handle_phrase_end(self) -> None:
#         """Called to indicate the token_end_index of a phrase."""


from typing import List, Tuple
from pyramids.categorization import Category
from pyramids.graphs import ParseGraph, Token
from pyramids.traversal import LanguageContentHandler
        self._graphs = []
        return graphs

    def handle_tree_end(self) -> None:
        """Called to indicate the token_end_index of a tree."""
        assert self._root is not None
        assert not self._phrase_stack

        graph = ParseGraph(self._root, self._tokens, self._links, self._phrases)

        self._graphs.append(graph)

        self._counter = 0
        self._root = None
        self._tokens.clear()
        self._links.clear()
        self._phrases.clear()
        self._index_map.clear()
        self._phrase_stack.clear()

    def handle_token(self, spelling: str, category: Category, index: int = None,
                     span: Tuple[int, int] = None) -> int:
        """Called to indicate the occurrence of a token."""
        if index is None:
            index = self._counter
            self._counter += 1
        else:
            assert index not in self._index_map
            assert not self._counter
        self._index_map[index] = len(self._tokens)

# Path: pyramids/categorization.py
# CATEGORY_WILDCARD = _CATEGORY_WILDCARD
# 
# Path: pyramids/graphs.py
# class ParseGraph:
# class BuildGraph:
#     def from_json(cls, json_data: Dict[str, List]) -> 'ParseGraph':
#     def __init__(self, root: int, tokens: Sequence[Token], links: List[Dict[int, Set[str]]],
#                  phrases: List[List[Tuple[Category, List[Tuple[int, int]]]]]):
#     def root_index(self) -> int:
#     def root_category(self) -> Category:
#     def tokens(self) -> Tuple[Token, ...]:
#     def __str__(self) -> str:
#     def __getitem__(self, index: int) -> Token:
#     def __len__(self) -> int:
#     def to_json(self) -> Dict[str, List]:
#     def get_phrase_category(self, head: int) -> Category:
#     def get_phrase_stack(self, head: int) -> Category:
#     def get_sinks(self, source: int) -> Set[int]:
#     def get_sources(self, sink: int) -> Set[int]:
#     def get_labels(self, source: int, sink: int) -> FrozenSet[str]:
#     def _get_phrase_tokens(self, head: int, indices: Set[int]) -> None:
#     def get_phrase_tokens(self, head: int = None) -> List[Token]:
#     def get_phrase_text(self, head: int = None) -> str:
#     def visualize(self, gv_graph: Digraph) -> None:
#     def from_parse_graphs(cls, graphs: Sequence[Union[ParseGraph, 'BuildGraph']]) -> 'BuildGraph':
#     def from_json(cls, json_data: Dict[str, List]) -> 'BuildGraph':
#     def __init__(self):
#     def tokens(self) -> Tuple[Token, ...]:
#     def get_annotations(self) -> List[str]:
#     def find_roots(self) -> Set[int]:
#     def find_leaves(self) -> Set[int]:
#     def _is_forest(self, roots: Set[int]) -> bool:
#     def is_tree(self) -> bool:
#     def is_forest(self) -> bool:
#     def set_phrase_category(self, index: int, category: Category) -> None:
#     def append_token(self, spelling: str, category: Category = None,
#                      span: Tuple[int, int] = None) -> int:
#     def clear_token_category(self, index: int) -> None:
#     def add_link(self, source: int, label: str, sink: int) -> None:
#     def discard_link(self, source: int, label: str, sink: int) -> None:
#     def remove_link(self, source: int, label: str, sink: int) -> None:
#     def has_link(self, source: int, label: str, sink: int) -> bool:
#     def iter_links(self, source: int = None, label: str = None, sink: int = None) \
#             def sink_iterator_func(sinks):
#             def sink_iterator_func(sinks):
#             def label_iterator_func(labels):
#             def label_iterator_func(labels):
#     def __getitem__(self, index: int) -> Token:
#     def __len__(self) -> int:
#     def to_json(self) -> Dict[str, List]:
#     def get_phrase_category(self, head: int) -> Category:
#     def get_sinks(self, source: int) -> Set[int]:
#     def get_sources(self, sink: int) -> Set[int]:
#     def get_labels(self, source: int, sink: int) -> FrozenSet[LinkLabel]:
#     def _get_phrase_tokens(self, head: int, indices: Set[int]) -> None:
#     def get_phrase_tokens(self, head: int = None) -> List[Token]:
#     def visualize(self, gv_graph: Digraph) -> None:
# 
# Path: pyramids/traversal.py
# class LanguageContentHandler:
#     """A content handler for natural language, in the style of the
#     ContentHandler class of the xml.sax module."""
# 
#     def handle_tree_end(self) -> None:
#         """Called to indicate the token_end_index of a tree."""
# 
#     def handle_token(self, spelling: str, category: Category, index: int = None,
#                      span: Tuple[int, int] = None) -> None:
#         """Called to indicate the occurrence of a token."""
# 
#     def handle_root(self) -> None:
#         """Called to indicate that the next token is the root."""
# 
#     def handle_link(self, source_start_index: int, sink_start_index: int, label: str) -> None:
#         """Called to indicate the occurrence of a link between two tokens.
#         Note that this will not be called until handle_token() has been
#         called for both the source and sink."""
# 
#     def handle_phrase_start(self, category: Category, head_start_index: int = None) -> None:
#         """Called to indicate the token_start_index of a phrase."""
# 
#     def handle_phrase_end(self) -> None:
#         """Called to indicate the token_end_index of a phrase."""


# Path: pyramids/parse_graph_builder.py
from typing import List, Tuple
from pyramids.categorization import Category
from pyramids.graphs import ParseGraph, Token
from pyramids.traversal import LanguageContentHandler

        self._graphs = []
        return graphs

    def handle_tree_end(self) -> None:
        """Called to indicate the token_end_index of a tree."""
        assert self._root is not None
        assert not self._phrase_stack

        graph = ParseGraph(self._root, self._tokens, self._links, self._phrases)

        self._graphs.append(graph)

        self._counter = 0
        self._root = None
        self._tokens.clear()
        self._links.clear()
        self._phrases.clear()
        self._index_map.clear()
        self._phrase_stack.clear()

    def handle_token(self, spelling: str, category: Category, index: int = None,
                     span: Tuple[int, int] = None) -> int:
        """Called to indicate the occurrence of a token."""
        if index is None:
            index = self._counter
            self._counter += 1
        else:
            assert index not in self._index_map
            assert not self._counter
        self._index_map[index] = len(self._tokens)

        self._tokens.append(Token(index, spelling, span, category))