(no unreleased changes yet)
This release adds a handful of minor functions and expands the documentation.
penman.layout.appears_inverted()
(#37)- Tree branch sorting functions (#31)
penman.model.Model.original_order()
penman.model.Model.canonical_order()
penman.model.Model.random_order()
penman.layout.rearrange()
(#31)--rearrange=(canonical|random)
command-line option
-q
/--quiet
command line option-v
/--verbose
command line option- Loggers that print some diagnostic information at the DEBUG and INFO levels
- Remove superfluous
POP
layout markers when graphs have duplicated triples (#34) - Avoid
KeyError
on edge and attribute reification when graphs have duplicated triples (#35)
Model.reify()
no longer inverts the incoming triple
The v0.7.0 release was missing a declaration for the new
penman.models
sub-package, so it was not available for new
installs. This release fixes that.
- The
penman.models
package is now declared insetup.py
- The documentation now looks one level up when building (this is just "in case", as I think the missing package problem was the real culprit for faulty documentation builds.)
This release comprises a major restructuring from previous
versions. No longer is there a single penman.py
module, but the
penman
package, which has the following modules:
__about__
- package meta-informationcodec
- high-level parsing and formattingepigraph
- epigraphical markersexceptions
- exception classesgraph
- triple and graph classesinterface
-load()
,dump()
, etc.layout
- interpretation and configuration of treeslexer
- low-level parsingmain
- command-line interfacemodel
- semantic model classsurface
- surface alignment informationtransform
- tree and graph transformationstree
- tree classtypes
- static type checking definitions
In addition, there is a models
sub-package for provided semantic
models, although it currently only contains one: models.amr
.
While some of the original API is preserved through imports in
penman/__init__.py
, there are a number of backward-incompatible
changes in this release. Changes that affect the old API are listed
below, but otherwise the new functionality is under the added
modules.
- Removed support for Python 2.7
- Removed support for Python 3.3
- Removed support for Python 3.4
- Removed support for Python 3.5
- Added support for Python 3.6
- Added support for Python 3.7
- Added support for Python 3.8
penman.Graph.epidata
penman.Graph.metadata
penman.PENMANCodec.parse()
penman.PENMANCodec.parse_triples()
penman.PENMANCodec.iterparse()
penman.PENMANCodec.format()
penman.PENMANCodec.format_triples()
penman.codec
penman.epigraph
penman.epigraph.Epidatum
penman.exceptions
penman.exceptions.GraphError
penman.exceptions.LayoutError
penman.exceptions.SurfaceError
penman.exceptions.ModelError
penman.graph
penman.graph.CONCEPT_ROLE
penman.graph.Edge
penman.graph.Attribute
penman.layout
penman.layout.LayoutMarker
penman.layout.Push
penman.layout.POP
penman.layout.interpret()
penman.layout.configure()
penman.layout.reconfigure()
penman.layout.has_valid_layout()
penman.lexer
penman.lexer.PATTERNS
penman.lexer.PENMAN_RE
penman.lexer.TRIPLE_RE
penman.lexer.Token
penman.lexer.TokenIterator
penman.lexer.lex()
penman.model
penman.model.Model
penman.models
penman.models.amr
penman.models.amr.roles
penman.models.amr.normalizations
penman.models.amr.reifications
penman.models.amr.model
penman.surface
(#19)penman.surface.AlignmentMarker
penman.surface.Alignment
penman.surface.RoleAlignment
penman.surface.alignments()
penman.surface.role_alignments()
penman.transform
penman.transform.canonicalize_roles()
penman.transform.reify_edges()
(#27)penman.transform.reify_attributes()
penman.transform.indicate_branches()
penman.tree
(#16)penman.tree.Tree
penman.tree.is_atomic()
- docopt dependency (#20)
penman.EncodeError
penman.AMRCodec
penman.Triple.inverted
penman.PENMANCodec.is_relation_inverted()
penman.PENMANCodec.invert_relation()
penman.PENMANCodec.handle_triple()
penman.PENMANCodec.triples_to_graph()
penman.original_order()
penman.out_first_order()
penman.alphanum_order()
- Graphs can no longer be encoded with attributes as the top (#15)
- For AMR, both
:mod
and:domain
are for non-inverted relations, although their inverses can be canonicalized to the other (#26) - Epigraphical layout markers allow the tree structure to be preserved without modifying the pure graph's triples (#25)
- Restructured project as a package
- Use Sphinx-generated documentation
- Replaced "relation" with "role" when "role" is intended.
- Replaced "node type" and "node label" with "concept"
- Replaced "node identifier" with "variable"
- Roles now include the colon (
:ARG0
, notARG0
), following convention penman.PENMANCodec
no longer takes theindent
orrelation_sort
parameterspenman.PENMANCodec.encode()
now takesindent
andcompact
parameterspenman.PENMANCodec.iterdecode()
works on streams (#21)penman.PENMANCodec
now reads comments with metadata (#23)penman.PENMANCodec
no longer accepts non-symbol variables (#13)penman.dump()
now writes iteratively to a stream (#22)- The following no longer take the
cls
parameter for a codec class, nor**kwargs
to configure that class, but instead amodel
parameter for the semantic model:penman.decode()
penman.encode()
penman.loads()
penman.dumps()
penman.load()
penman.dump()
- The following now take the formatting parameters
indent
andcompact
:penman.encode()
penman.dumps()
penman.dump()
penman.Graph.triples
is now a member variable instead of a methodpenman.Graph
class is mutable (#32)- Concepts (node labels) in
penman.Graph
now have a special role known to thepenman.graph
module, which can help avoid some reentrancy issues (#29)
- Value-cast patterns terminated with
$
to invalid casts (#9) - Raise EncodeError when attempting to encode empty graphs (#14)
- Redefine NODETYPE_RE for AMRCodec (#17)
- Remove specific float and int parsing in variables/nodetypes for the default parser (the numeric values are still parses as atoms) (#17)
- Some additional regular expressions on
PENMANCodec
to influence parsing behavior CONTRIBUTING.md
- Allow numeric and string variables and node types
- Grammar in README now more accurately reflect parsing behavior (and vice versa)
- By default, always preserve relation order when given (fixes #6)
__version_info__
now gives integers for numeric parts
PenmanError
as a exception base classEncodeError
for errors during encoding; derived fromPenmanError
- Functions for ordering relations (these behave like
sorted()
, in that they take and return a list). Note that the type relation (given bycodec.TYPE_REL
), if present, always appears first, regardless of the sorting method.original_order
- the default; return the list as-isout_first_order
- sort all true orientations before inverted orientations; otherwise order is retainedalphanum_order
- former default; sort relations alphabetically with embedded integers sorted numerically (likesort -V
)
- Added disclaimer to
README.md
saying that this module is not affiliated with ISI, the PENMAN project, or the AMR project Triple
objects can now have aninverted
attribute that can be given as a fourth instantiation parameter. The object is still treated as a 3-tuple, sosrc, rel, tgt = triple
still works (andtriple[3]
will not get the inversion status; usetriple.inverted
). Valid values areFalse
(true orientation),True
(inverted orientation), andNone
(no orientation specified).--indent
option for commandline usageAMRCodec
with a more restrictive grammar and special inversions
DecodeError
now derives fromPenmanError
PENMANCodec
now takes arelation_sort
parameter whose value is a function that sortsTriple
objects (see Added above)- Updated the PEG definition in
README.md
, and accompanying prose.
- Numeric conversion in
PENMANCodec.handle_triple()
now happens to both sources and targets, andhandle_triple()
is now run on the top, as well. Fixes #4 Graph.__str__()
now initializes a default codec for serialization.- Incorrect script usage fixed in README.md and from
penman.py --help
- Updated documentation
- Properly trim off ^ in triple-conjunction parsing.
TOP_VAR
andTOP_REL
are added toPENMANCodec
(these were module-level variables prior to v0.4.0); they are only used for triple-conjunctions. If left asNone
, they will not be printed or interpreted.PENMANCodec.triples_to_graph
to instantiate a Graph with awareness of codec configuration (e.g.TOP_VAR
,TYPE_REL
, etc.)
PENMANCodec.handle_value()
- value conversion is now done inPENMANCodec.handle_triple()
, which has access to relation name, etc.
- Decoupled
Graph
from the codec by removing thecodec
parameter and its usage in the class methods. Graphs can be instantiated with awareness of the codec via the codec'striples_to_graph()
method. PENMANCodec
returns all node type triples before other edge triples.PENMANCodec
reads/writes TOP nodes in triple conjunctions ifTOP_VAR
andTOP_REL
are set (see above).- Default node types are no longer stored as triples. This means a graph
like
(a / a :ARG b)
cannot say ifb
is a node or just a symbol. Let's see how far this gets us before re-adding such support. PENMANCodec.handle_triple()
now manages value conversion- PENMAN serialization now sorts relations like
sort -V
This release is a major rewrite of the serialization mechanism. Now a serialization codec manages the interface between graphs and PENMAN or triple conjunctions, and it can be instantiated with parameters or subclassed to customize behavior.
PENMANCodec
class for managing serialization to/from PENMAN and triple conjunctionsGraph.attributes()
returns terminal relations
- Module-level
TOP
andTOP_RELATION
are no longer used for customizing serialization behavior (seePENMANCodec
) Graph.concepts()
Graph.constants()
Triple.is_inverted()
(usePENMANCodec.is_relation_inverted()
)
Graph.to_triples()
is nowGraph.triples()
and no longer has anormalize
parameter, but can now be filtered bysource
,relation
, andtarget
, as withGraph.edges()
andGraph.attributes()
Graph.edges()
only returns triples between nonterminal nodes- Default relation for node types is
instance
, sinceinstance-of
seems to not be used, documented, or intuitive. load()
,loads()
,dump()
, anddumps()
now take acls
parameter for a serialization codec, and any additional**kwargs
are passed to its constructor.
TOP
andTOP_RELATION
as module-level variablesis_relation_inverted()
invert_relation()
Graph.top
Graph.variables()
Graph.concepts()
Graph.constants()
Graph.edges()
Graph.from_triples()
can take an explicittop=...
parameter- The
indent
parameter toGraph.to_penman()
now takes a range of values:indent=True
is the default with adaptive indentationindent=False
andindent=None
do not insert newlines and use a single space to delimit fieldsindent=N
, whereN
is an integer, indents N spaces after a newline
load()
,loads()
,dump()
, anddumps()
can now take atriples=...
parameter (default: False); if True, read/write as triples
- PENMAN serialization uses slightly more sophisticated default weights for choosing when to invert edges, which prevents some ugly graphs.
Graph.to_triples()
takes anormalize=True
parameter (defaultFalse
) to uninvert inverted edges.- Running the script with
--triples
now prints the logical conjunction of triples (e.g.instance-of(b, bark-01) ^ ARG0(b, d) ^ instance-of(d, dog)
).
First release with very basic functionality.
Triple
namedtuple for edge information (source, relation, target)Graph
stores graph data and provides methods for accessload()
/loads()
reads Penman files/stringsdump()
/dumps()
writes Penman files/strings