# Path: pyramids/categorization.py
# CATEGORY_WILDCARD = _CATEGORY_WILDCARD


from typing import NamedTuple, Sequence, Set, FrozenSet, List, Tuple, Optional, Iterator, Union, \
    Dict
    from graphviz import Digraph
from pyramids.categorization import Category, LinkLabel
        from pyramids.grammar import GrammarParser
        from pyramids.grammar import GrammarParser
    Digraph = None


__author__ = 'Aaron Hosford'
__all__ = [
    'Token',
    'ParseGraph',
    'BuildGraph'
]


Token = NamedTuple('Token', [('index', int), ('spelling', str), ('span', Optional[Tuple[int, int]]),
                             ('category', Category)])


class ParseGraph:
    """A simple class for representing language content as a semantic graph."""

    @classmethod
    def from_json(cls, json_data: Dict[str, List]) -> 'ParseGraph':
        """Constructs a ParseGraph from a JSON-serializable data structure produced by
        ParseGraph.to_json()."""
        root = json_data['roots'][-1]
        tokens = [Token(token.get('index', index), token['spelling'], token['span'],
                        GrammarParser.parse_category(token['category']))
                  for index, token in enumerate(json_data['tokens'])]
        links = [{} for _ in tokens]
        for link in json_data['links']:
            source = link['source']
            sink = link['sink']

# Path: pyramids/categorization.py
# CATEGORY_WILDCARD = _CATEGORY_WILDCARD


# Path: pyramids/graphs.py
from typing import NamedTuple, Sequence, Set, FrozenSet, List, Tuple, Optional, Iterator, Union, \
    Dict
    from graphviz import Digraph
from pyramids.categorization import Category, LinkLabel
        from pyramids.grammar import GrammarParser
        from pyramids.grammar import GrammarParser

    Digraph = None


__author__ = 'Aaron Hosford'
__all__ = [
    'Token',
    'ParseGraph',
    'BuildGraph'
]


Token = NamedTuple('Token', [('index', int), ('spelling', str), ('span', Optional[Tuple[int, int]]),
                             ('category', Category)])


class ParseGraph:
    """A simple class for representing language content as a semantic graph."""

    @classmethod
    def from_json(cls, json_data: Dict[str, List]) -> 'ParseGraph':
        """Constructs a ParseGraph from a JSON-serializable data structure produced by
        ParseGraph.to_json()."""
        root = json_data['roots'][-1]
        tokens = [Token(token.get('index', index), token['spelling'], token['span'],
                        GrammarParser.parse_category(token['category']))
                  for index, token in enumerate(json_data['tokens'])]
        links = [{} for _ in tokens]
        for link in json_data['links']:
            source = link['source']
            sink = link['sink']

            label = LinkLabel.get(link['label'])