# Path: penman/surface.py
# class Alignment(AlignmentMarker):
#     __slots__ = ()
#     mode = 2
# 
# class RoleAlignment(AlignmentMarker):
#     __slots__ = ()
#     mode = 1
# 
# def alignments(g: Graph) -> _Alignments:
#     """
#     Return a mapping of triples to alignments in graph *g*.
# 
#     Args:
#         g: a :class:`~penman.graph.Graph` containing alignment data
#     Returns:
#         A :class:`dict` mapping :class:`~penman.graph.Triple` objects
#         to their corresponding :class:`Alignment` objects, if any.
#     Example:
#         >>> from penman import decode
#         >>> from penman import surface
#         >>> g = decode(
#         ...   '(c / chase-01~4'
#         ...   '   :ARG0~5 (d / dog~7)'
#         ...   '   :ARG0~3 (c / cat~2))')
#         >>> surface.alignments(g)  # doctest: +NORMALIZE_WHITESPACE
#         {('c', ':instance', 'chase-01'): Alignment((4,)),
#          ('d', ':instance', 'dog'): Alignment((7,)),
#          ('c', ':instance', 'cat'): Alignment((2,))}
#     """
#     return _get_alignments(g, Alignment)
# 
# def role_alignments(g: Graph) -> _Alignments:
#     """
#     Return a mapping of triples to role alignments in graph *g*.
# 
#     Args:
#         g: a :class:`~penman.graph.Graph` containing role alignment
#         data
#     Returns:
#         A :class:`dict` mapping :class:`~penman.graph.Triple` objects
#         to their corresponding :class:`RoleAlignment` objects, if any.
#     Example:
#         >>> from penman import decode
#         >>> from penman import surface
#         >>> g = decode(
#         ...   '(c / chase-01~4'
#         ...   '   :ARG0~5 (d / dog~7)'
#         ...   '   :ARG0~3 (c / cat~2))')
#         >>> surface.role_alignments(g)  # doctest: +NORMALIZE_WHITESPACE
#         {('c', ':ARG0', 'd'): RoleAlignment((5,)),
#          ('c', ':ARG0', 'c'): RoleAlignment((3,))}
#     """
#     return _get_alignments(g, RoleAlignment)


import penman
from penman.surface import (
    Alignment,
    RoleAlignment,
    alignments,
    role_alignments,
)


codec = penman.PENMANCodec()


def test_alignments(isi_aligned):
    g = codec.decode('(a :ARG~1 (b / beta~2))')
    assert alignments(g) == {
        ('b', ':instance', 'beta'): Alignment((2,)),
    }
    assert role_alignments(g) == {
        ('a', ':ARG', 'b'): RoleAlignment((1,)),
    }
    assert codec.encode(g, indent=None) == '(a :ARG~1 (b / beta~2))'

    g = codec.decode(isi_aligned[0])
    assert alignments(g) == {
        ('d', ':instance', 'drive-01'): Alignment((2,), prefix='e.'),
        ('h', ':instance', 'he'): Alignment((1,), prefix='e.'),
        ('c', ':instance', 'care-04'): Alignment((3,), prefix='e.'),
    }

# Path: penman/surface.py
# class Alignment(AlignmentMarker):
#     __slots__ = ()
#     mode = 2
# 
# class RoleAlignment(AlignmentMarker):
#     __slots__ = ()
#     mode = 1
# 
# def alignments(g: Graph) -> _Alignments:
#     """
#     Return a mapping of triples to alignments in graph *g*.
# 
#     Args:
#         g: a :class:`~penman.graph.Graph` containing alignment data
#     Returns:
#         A :class:`dict` mapping :class:`~penman.graph.Triple` objects
#         to their corresponding :class:`Alignment` objects, if any.
#     Example:
#         >>> from penman import decode
#         >>> from penman import surface
#         >>> g = decode(
#         ...   '(c / chase-01~4'
#         ...   '   :ARG0~5 (d / dog~7)'
#         ...   '   :ARG0~3 (c / cat~2))')
#         >>> surface.alignments(g)  # doctest: +NORMALIZE_WHITESPACE
#         {('c', ':instance', 'chase-01'): Alignment((4,)),
#          ('d', ':instance', 'dog'): Alignment((7,)),
#          ('c', ':instance', 'cat'): Alignment((2,))}
#     """
#     return _get_alignments(g, Alignment)
# 
# def role_alignments(g: Graph) -> _Alignments:
#     """
#     Return a mapping of triples to role alignments in graph *g*.
# 
#     Args:
#         g: a :class:`~penman.graph.Graph` containing role alignment
#         data
#     Returns:
#         A :class:`dict` mapping :class:`~penman.graph.Triple` objects
#         to their corresponding :class:`RoleAlignment` objects, if any.
#     Example:
#         >>> from penman import decode
#         >>> from penman import surface
#         >>> g = decode(
#         ...   '(c / chase-01~4'
#         ...   '   :ARG0~5 (d / dog~7)'
#         ...   '   :ARG0~3 (c / cat~2))')
#         >>> surface.role_alignments(g)  # doctest: +NORMALIZE_WHITESPACE
#         {('c', ':ARG0', 'd'): RoleAlignment((5,)),
#          ('c', ':ARG0', 'c'): RoleAlignment((3,))}
#     """
#     return _get_alignments(g, RoleAlignment)


# Path: tests/test_surface.py
import penman
from penman.surface import (
    Alignment,
    RoleAlignment,
    alignments,
    role_alignments,
)



codec = penman.PENMANCodec()


def test_alignments(isi_aligned):
    g = codec.decode('(a :ARG~1 (b / beta~2))')
    assert alignments(g) == {
        ('b', ':instance', 'beta'): Alignment((2,)),
    }
    assert role_alignments(g) == {
        ('a', ':ARG', 'b'): RoleAlignment((1,)),
    }
    assert codec.encode(g, indent=None) == '(a :ARG~1 (b / beta~2))'

    g = codec.decode(isi_aligned[0])
    assert alignments(g) == {
        ('d', ':instance', 'drive-01'): Alignment((2,), prefix='e.'),
        ('h', ':instance', 'he'): Alignment((1,), prefix='e.'),
        ('c', ':instance', 'care-04'): Alignment((3,), prefix='e.'),
    }

    assert role_alignments(g) == {}