Skip to content

Commit

Permalink
Merge pull request #36 from goodmami/v0.7.2
Browse files Browse the repository at this point in the history
V0.7.2
  • Loading branch information
goodmami authored Nov 25, 2019
2 parents 0aa8dca + 9e1eda1 commit 721ea8a
Show file tree
Hide file tree
Showing 15 changed files with 248 additions and 49 deletions.
88 changes: 69 additions & 19 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,32 @@

## [Unreleased][unreleased]

(no unreleased changes yet)
(No unreleased changes)

## [v0.7.2][v0.7.2]

### Added

* `-q` / `--quiet` command line option
* `-v` / `--verbose` command line option
* Loggers that print some diagnostic information at the DEBUG and INFO
levels

### Fixed

* Remove superfluous `POP` layout markers when graphs have duplicated
triples ([#34][])
* Avoid `KeyError` on edge and attribute reification when graphs have
duplicated triples ([#35][])

### Changed

* `Model.reify()` no longer inverts the incoming triple


## [v0.7.1][v0.7.1]

The [v0.7.0][v070] release was missing a declaration for the new
The [v0.7.0](#v070) release was missing a declaration for the new
`penman.models` sub-package, so it was not available for new
installs. This release fixes that.

Expand All @@ -17,6 +38,7 @@ installs. This release fixes that.
"in case", as I think the missing package problem was the real
culprit for faulty documentation builds.)


## [v0.7.0][v0.7.0]

This release comprises a major restructuring from previous
Expand Down Expand Up @@ -101,24 +123,24 @@ modules.
* `penman.models.amr.normalizations`
* `penman.models.amr.reifications`
* `penman.models.amr.model`
* `penman.surface` (#19)
* `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_edges()` ([#27][])
* `penman.transform.reify_attributes()`
* `penman.transform.indicate_branches()`
* `penman.tree` (#16)
* `penman.tree` ([#16][])
* `penman.tree.Tree`
* `penman.tree.is_atomic()`

### Removed

* [docopt](https://github.com/docopt/docopt) dependency (#20)
* [docopt](https://github.com/docopt/docopt) dependency ([#20][])
* `penman.EncodeError`
* `penman.AMRCodec`
* `penman.Triple.inverted`
Expand All @@ -132,11 +154,11 @@ modules.

### Fixed

* Graphs can no longer be encoded with attributes as the top (#15)
* 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)
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)
without modifying the pure graph's triples ([#25][])

### Changed

Expand All @@ -151,10 +173,10 @@ modules.
parameters
* `penman.PENMANCodec.encode()` now takes `indent` and `compact`
parameters
* `penman.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)
* `penman.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 a `model`
parameter for the semantic model:
Expand All @@ -170,21 +192,22 @@ modules.
- `penman.dumps()`
- `penman.dump()`
* `penman.Graph.triples` is now a member variable instead of a method
* `penman.Graph` class is mutable (#32)
* `penman.Graph` class is mutable ([#32][])
* Concepts (node labels) in `penman.Graph` now have a special role
known to the `penman.graph` module, which can help avoid some
reentrancy issues (#29)
reentrancy issues ([#29][])


## [v0.6.2][v0.6.2]

### Fixed

* Value-cast patterns terminated with `$` to invalid casts (#9)
* Raise EncodeError when attempting to encode empty graphs (#14)
* Redefine NODETYPE_RE for AMRCodec (#17)
* 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)
default parser (the numeric values are still parses as atoms) ([#17][])


## [v0.6.1][v0.6.1]

Expand All @@ -203,6 +226,7 @@ modules.
* Grammar in README now more accurately reflect parsing behavior (and
vice versa)


## [v0.6.0][]

### Fixed
Expand Down Expand Up @@ -323,6 +347,7 @@ subclassed to customize behavior.
parameter for a serialization codec, and any additional `**kwargs`
are passed to its constructor.


## [v0.3.0][]

### Added
Expand All @@ -347,6 +372,7 @@ subclassed to customize behavior.
* `load()`, `loads()`, `dump()`, and `dumps()` can now take a `triples=...`
parameter (default: False); if True, read/write as triples


## [v0.2.0][]

### Changed
Expand All @@ -359,6 +385,7 @@ subclassed to customize behavior.
of triples (e.g. `instance-of(b, bark-01) ^ ARG0(b, d) ^
instance-of(d, dog)`).


## [v0.1.0][]

First release with very basic functionality.
Expand All @@ -370,6 +397,7 @@ First release with very basic functionality.
* `load()`/`loads()` reads Penman files/strings
* `dump()`/`dumps()` writes Penman files/strings


[unreleased]: ../../tree/develop
[v0.1.0]: ../../releases/tag/v0.1.0
[v0.2.0]: ../../releases/tag/v0.2.0
Expand All @@ -382,4 +410,26 @@ First release with very basic functionality.
[v0.6.2]: ../../releases/tag/v0.6.2
[v0.7.0]: ../../releases/tag/v0.7.0
[v0.7.1]: ../../releases/tag/v0.7.1
[v0.7.2]: ../../releases/tag/v0.7.2
[README]: README.md

[#4]: https://github.com/goodmami/penman/issues/4
[#6]: https://github.com/goodmami/penman/issues/6
[#9]: https://github.com/goodmami/penman/issues/9
[#13]: https://github.com/goodmami/penman/issues/13
[#14]: https://github.com/goodmami/penman/issues/14
[#15]: https://github.com/goodmami/penman/issues/15
[#16]: https://github.com/goodmami/penman/issues/16
[#17]: https://github.com/goodmami/penman/issues/17
[#19]: https://github.com/goodmami/penman/issues/19
[#20]: https://github.com/goodmami/penman/issues/20
[#21]: https://github.com/goodmami/penman/issues/21
[#22]: https://github.com/goodmami/penman/issues/22
[#23]: https://github.com/goodmami/penman/issues/23
[#25]: https://github.com/goodmami/penman/issues/25
[#26]: https://github.com/goodmami/penman/issues/26
[#27]: https://github.com/goodmami/penman/issues/27
[#29]: https://github.com/goodmami/penman/issues/29
[#32]: https://github.com/goodmami/penman/issues/32
[#34]: https://github.com/goodmami/penman/issues/34
[#35]: https://github.com/goodmami/penman/issues/35
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# The short X.Y version
version = 'v0.7'
# The full version, including alpha/beta/rc tags
release = 'v0.7.1'
release = 'v0.7.2'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion penman/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

__version__ = '0.7.1'
__version__ = '0.7.2'
__version_info__ = [
int(x) if x.isdigit() else x
for x in __version__.replace('.', ' ').replace('-', ' ').split()
Expand Down
15 changes: 11 additions & 4 deletions penman/codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from typing import Optional, Union, Type, Iterable, Iterator, List
import re
import logging

from penman.types import (
Variable,
Expand All @@ -29,6 +30,9 @@
from penman import layout


logger = logging.getLogger(__name__)


class PENMANCodec(object):
"""
An encoder/decoder for PENMAN-serialized graphs.
Expand Down Expand Up @@ -102,9 +106,7 @@ def iterparse(self, lines: Union[Iterable[str], str]) -> Iterator[Tree]:
"""
tokens = lex(lines, pattern=PENMAN_RE)
while tokens and tokens.peek().type in ('COMMENT', 'LPAREN'):
metadata = self._parse_comments(tokens)
node = self._parse_node(tokens)
yield Tree(node, metadata=metadata)
yield self._parse(tokens)

def parse(self, s: str) -> Tree:
"""
Expand All @@ -120,9 +122,14 @@ def parse(self, s: str) -> Tree:
Tree(('b', [('/', 'bark', []), ('ARG1', ('d', [('/', 'dog', [])]), [])]))
"""
tokens = lex(s, pattern=PENMAN_RE)
return self._parse(tokens)

def _parse(self, tokens: TokenIterator) -> Tree:
metadata = self._parse_comments(tokens)
node = self._parse_node(tokens)
return Tree(node, metadata=metadata)
tree = Tree(node, metadata=metadata)
logger.debug('Parsed: %s', tree)
return tree

def _parse_comments(self, tokens: TokenIterator):
"""
Expand Down
6 changes: 6 additions & 0 deletions penman/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ def __repr__(self):
id(self)
)

def __str__(self):
triples = '[{}]'.format(',\n '.join(map(repr, self.triples)))
epidata = '{{{}}}'.format(',\n '.join(
map('{0[0]!r}: {0[1]!r}'.format, self.epidata.items())))
return 'Graph(\n {},\n epidata={})'.format(triples, epidata)

def __eq__(self, other):
if not isinstance(other, Graph):
return NotImplemented
Expand Down
15 changes: 13 additions & 2 deletions penman/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

from typing import Union, Mapping
import copy
import logging

from penman.exceptions import LayoutError
from penman.types import Variable
Expand All @@ -61,6 +62,9 @@
from penman.model import Model


logger = logging.getLogger(__name__)


_Nodemap = Mapping[Variable, Union[Node, None]]


Expand Down Expand Up @@ -104,7 +108,9 @@ def interpret(t: Tree, model: Model = None) -> Graph:
if model is None:
model = Model()
top, triples, epidata = _interpret_node(t.node, model)
return Graph(triples, top=top, epidata=epidata, metadata=t.metadata)
g = Graph(triples, top=top, epidata=epidata, metadata=t.metadata)
logger.info('Interpreted: %s', g)
return g


def _interpret_node(t: Node, model: Model):
Expand Down Expand Up @@ -158,7 +164,12 @@ def configure(g: Graph,
if len(data) >= data_count:
raise LayoutError('possible cycle in configuration')
data = skipped + data
return Tree(node, metadata=g.metadata)
# remove any superfluous POPs
while data and data[-1] is POP:
data.pop()
tree = Tree(node, metadata=g.metadata)
logger.debug('Configured: %s', tree)
return tree


def _configure(g, top, model, strict):
Expand Down
18 changes: 14 additions & 4 deletions penman/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
from penman.exceptions import DecodeError


logger = logging.getLogger(__name__)


# These are the regex patterns for parsing. They must not have any
# capturing groups. They are used during lexing and will be
# checked by name during parsing.
Expand Down Expand Up @@ -200,17 +203,24 @@ def lex(lines: Union[Iterable[str], str],
else:
regex = PENMAN_RE

logging.debug('Lexing with pattern:\n{}'.format(regex.pattern))

tokens = _lex(lines, regex)
return TokenIterator(tokens)


def _lex(lines: Iterable[str], regex: Pattern[str]) -> Iterator[Token]:
for i, line in enumerate(lines, 1):
for m in regex.finditer(line):
logger.debug('Line %d: %r', i, line)
matches = list(regex.finditer(line))
tokens = []
for m in matches:
if m.lastgroup is None:
raise ValueError(
'Lexer pattern generated a match without a named '
'capturing group:\n{}'.format(regex.pattern))
yield Token(m.lastgroup, m.group(), i, m.start(), line)
tokens.append(Token(m.lastgroup, m.group(), i, m.start(), line))

if logger.isEnabledFor(logging.DEBUG):
for token in tokens:
logger.debug(token)

yield from tokens
Loading

0 comments on commit 721ea8a

Please sign in to comment.