Skip to main content

PENMAN notation for graphs (e.g., AMR)

Project description

Penman — a Python library for PENMAN graph notation

PyPI Version Python Support Build Status Documentation Status

This package models graphs encoded in PENMAN notation (e.g., AMR), such as the following for the boy wants to go:

(w / want-01
   :ARG0 (b / boy)
   :ARG1 (g / go
            :ARG0 b))

The Penman package may be used as a Python library or as a script.

Features

  • Read and write PENMAN-serialized graphs or triple conjunctions
  • Read metadata in comments (e.g., # ::id 1234)
  • Read surface alignments (e.g., foo~e.1,2)
  • Inspect and manipulate the graph or tree structures
  • Customize graphs for writing:
    • Adjust indentation and compactness
    • Select a new top node
    • Rearrange edges
    • Restructure the tree shape
    • Relabel node variables
  • Transform the graph
    • Canonicalize roles
    • Reify and dereify edges
    • Reify attributes
    • Embed the tree structure with additional TOP triples
  • AMR model: role inventory and transformations
  • Tested (but not yet 100% coverage)
  • Documented (see the documentation)

Library Usage

>>> import penman
>>> g = penman.decode('(b / bark-01 :ARG0 (d / dog))')
>>> g.triples
[('b', ':instance', 'bark-01'), ('b', ':ARG0', 'd'), ('d', ':instance', 'dog')]
>>> print(penman.encode(g))
(b / bark-01
   :ARG0 (d / dog))
>>> print(penman.encode(g, top='d', indent=6))
(d / dog
      :ARG0-of (b / bark-01))
>>> print(penman.encode(g, indent=False))
(b / bark-01 :ARG0 (d / dog))

(more information)

Script Usage

$ penman --help
usage: penman [-h] [-V] [-v] [-q] [--model FILE | --amr] [--indent N]
              [--compact] [--triples] [--make-variables FMT] [--rearrange KEY]
              [--reconfigure KEY] [--canonicalize-roles] [--reify-edges]
              [--dereify-edges] [--reify-attributes] [--indicate-branches]
              [FILE [FILE ...]]

Read and write graphs in the PENMAN notation.

positional arguments:
  FILE                  read graphs from FILEs instead of stdin

optional arguments:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -v, --verbose         increase verbosity
  -q, --quiet           suppress output on <stdout> and <stderr>
  --model FILE          JSON model file describing the semantic model
  --amr                 use the AMR model

formatting options:
  --indent N            indent N spaces per level ("no" for no newlines)
  --compact             compactly print node attributes on one line
  --triples             print graphs as triple conjunctions

normalization options:
  --make-variables FMT  recreate node variables with FMT (e.g.: '{prefix}{j}')
  --rearrange KEY       reorder the branches of the tree
  --reconfigure KEY     reconfigure the graph layout with reordered triples
  --canonicalize-roles  canonicalize role forms
  --reify-edges         reify all eligible edges
  --dereify-edges       dereify all eligible edges
  --reify-attributes    reify all attributes
  --indicate-branches   insert triples to indicate tree structure

$ penman <<< "(w / want-01 :ARG0 (b / boy) :ARG1 (g / go :ARG0 b))"
(w / want-01
   :ARG0 (b / boy)
   :ARG1 (g / go
            :ARG0 b))

(more information)

PENMAN Notation

A description of the PENMAN notation can be found in the documentation. See also Nathan Schneider's PEG for AMR.

This module expands the notation slightly to allow for untyped nodes (e.g., (x)) and anonymous relations (e.g., (x : (y))). It also accommodates slightly malformed graphs as well as surface alignments.

Citation

There is not (yet) a canonical citation for the Penman library, so putting https://github.com/goodmami/penman in a footnote is sufficient. If you are referring to the graph transformation/normalization work or prefer an academic citation, please use the following:

@inproceedings{Goodman:2019,
  title     = "{AMR} Normalization for Fairer Evaluation",
  author    = "Goodman, Michael Wayne",
  booktitle = "Proceedings of the 33rd Pacific Asia Conference on Language, Information, and Computation",
  year      = "2019",
  pages     = "47--56",
  address   = "Hakodate"
}

Disclaimer

This project is not affiliated with ISI, the PENMAN project, or the AMR project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Penman-0.10.0.tar.gz (31.2 kB view details)

Uploaded Source

Built Distribution

Penman-0.10.0-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file Penman-0.10.0.tar.gz.

File metadata

  • Download URL: Penman-0.10.0.tar.gz
  • Upload date:
  • Size: 31.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for Penman-0.10.0.tar.gz
Algorithm Hash digest
SHA256 13d00c8f616381d66a96bc7d381e7c6f5b7d6bd8c49573255e62c071805c7597
MD5 2b3dd0c8e250c480235cd86f340e0bf2
BLAKE2b-256 e4fbb399cc2c420f0822cbfcefda0e5b4c99eb40b0dff9d5bf100c682773dae2

See more details on using hashes here.

Provenance

File details

Details for the file Penman-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: Penman-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 36.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for Penman-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 feeab3edc79b451c6f24165edafb7219bc11df3773e78ddbd2351fe4769ed771
MD5 24aa64076cd582b445be93693a347b52
BLAKE2b-256 da315abf5f3cfad12b83571d8b1ac4f5ac9ea6b1ea5852e9efc6cc69d9ab1c3d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page