Skip to main content

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

Project description

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
  • Transform the graph
    • Canonicalize roles
    • Reify 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 :ARG0 (d / dog))')
>>> g.triples
[('b', ':instance', 'bark'), ('b', ':ARG0', 'd'), ('d', ':instance', 'dog')]
>>> print(penman.encode(g))
(b / bark
   :ARG0 (d / dog))
>>> print(penman.encode(g, top='d', indent=6))
(d / dog
      :ARG0-of (b / bark))
>>> print(penman.encode(g, indent=False))
(b / bark :ARG0 (d / dog))

Script Usage

$ penman --help
usage: penman [-h] [-V] [--model FILE | --amr] [--indent N] [--compact]
              [--triples] [--canonicalize-roles] [--reify-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
  --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:
  --canonicalize-roles  canonicalize role forms
  --reify-edges         reify 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))

Requirements

  • Python 3.6+

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.

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.8.0.tar.gz (26.5 kB view details)

Uploaded Source

Built Distribution

Penman-0.8.0-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Penman-0.8.0.tar.gz
  • Upload date:
  • Size: 26.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5

File hashes

Hashes for Penman-0.8.0.tar.gz
Algorithm Hash digest
SHA256 b5bf9326435495d6e7abcef04cf6e410d9d5e7a18b0859bda2ef5f98dd35db21
MD5 39896306c710497ee74aaeee7be9b689
BLAKE2b-256 9ef7d15b2bb3dac98f182d6822775a982904a21cddf112806a7172cfbcb8d75b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Penman-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.5

File hashes

Hashes for Penman-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 128f82896a451964c08ebab71b67aaf2156804886f1f8edf33a4ba47ddd1b9d5
MD5 c88678b353afe7db383b5d9a8462de51
BLAKE2b-256 4d59ab0bd9c7a00c6d8199252ed24ff4c86f938c86830128388d0a45b681c16f

See more details on using hashes here.

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