Skip to content

Commit

Permalink
Merge pull request #68 from goodmami/v0.11.1
Browse files Browse the repository at this point in the history
V0.11.1
  • Loading branch information
goodmami authored Feb 6, 2020
2 parents 772932a + 594268b commit bc0b820
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
(no unreleased changes yet)


## [v0.11.1][]

**Release date: 2020-02-06**

### Fixed

* Avoid another source of concepts becoming nodes ([#61][])
* Only configure one tree branch for new triples ([#67][])


## [v0.11.0][]

**Release date: 2020-01-28**
Expand Down Expand Up @@ -574,6 +584,7 @@ First release with very basic functionality.
[v0.9.1]: ../../releases/tag/v0.9.1
[v0.10.0]: ../../releases/tag/v0.10.0
[v0.11.0]: ../../releases/tag/v0.11.0
[v0.11.1]: ../../releases/tag/v0.11.1
[README]: README.md

[#4]: https://github.com/goodmami/penman/issues/4
Expand Down Expand Up @@ -611,3 +622,5 @@ First release with very basic functionality.
[#52]: https://github.com/goodmami/penman/issues/52
[#53]: https://github.com/goodmami/penman/issues/53
[#55]: https://github.com/goodmami/penman/issues/55
[#61]: https://github.com/goodmami/penman/issues/61
[#67]: https://github.com/goodmami/penman/issues/67
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.11.0'
__version__ = '0.11.1'
__version_info__ = tuple(
int(x) if x.isdigit() else x
for x in __version__.replace('.', ' ').replace('-', ' ').split()
Expand Down
17 changes: 10 additions & 7 deletions penman/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,19 @@ def _preconfigure(g, strict):
push, pops = None, []
for epi in epidata.get(triple, []):
if isinstance(epi, Push):
if push is not None or epi.variable in pushed:
pvar = epi.variable
if push is not None or pvar in pushed:
if strict:
raise LayoutError(
f"multiple node contexts for '{epi.variable}'")
f"multiple node contexts for '{pvar}'")
pass # change to 'continue' to disallow multiple contexts
if epi.variable not in (triple[0], triple[2]):
if pvar not in (triple[0], triple[2]) or role == CONCEPT_ROLE:
if strict:
raise LayoutError(
f"node context '{epi.variable}' "
f"node context '{pvar}' "
f"invalid for triple: {triple!r}")
continue
pushed.add(epi.variable)
pushed.add(pvar)
push = epi
elif epi is POP:
pops.append(epi)
Expand Down Expand Up @@ -367,14 +368,15 @@ def _configure_node(var, data, nodemap, model):
continue # prefer (a) over (a /) when concept is missing
role = '/'
index = 0
push = None # never push on concept roles
else:
index = len(edges)

if push and push.variable == target:
nodemap[push.variable] = (push.variable, [])
target = _configure_node(
push.variable, data, nodemap, model)
elif target in nodemap and nodemap[target] is None:
elif role != '/' and target in nodemap and nodemap[target] is None:
# site of potential node context
nodemap[target] = node

Expand Down Expand Up @@ -416,10 +418,11 @@ def _get_or_establish_site(var, nodemap):
nodemap[var] = node
for i in range(len(edges)):
# replace the variable in the tree with the new node
if edges[i][1] == var:
if edges[i][1] == var and edges[i][0] != '/':
edge = list(edges[i])
edge[1] = node
edges[i] = tuple(edge)
break
else:
pass # otherwise the node already exists so we're good
return True
Expand Down
23 changes: 23 additions & 0 deletions tests/test_codec.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,29 @@ def test_encode_atoms(self):
g = penman.Graph([('one', 'instance', '"a string"')])
assert encode(g) == '(one / "a string")'

def test_encode_issue_61(self):
# https://github.com/goodmami/penman/issues/61
g = penman.Graph([('i2', ':instance', 'i'),
('i', ':instance', 'i'),
('i2', ':ARG0', 'i')],
top='i2')
assert encode(g, indent=None) == '(i2 / i :ARG0 (i / i))'

def test_encode_issue_67(self):
# https://github.com/goodmami/penman/issues/61
triples = [('h', ':instance', 'have-org-role-91'),
('a', ':instance', 'activist'),
('h', ':ARG0', 'a'),
('h', ':ARG2', 'a')]
assert encode(penman.Graph(triples, top='a')) == (
'(a / activist\n'
' :ARG0-of (h / have-org-role-91)\n'
' :ARG2-of h)')
assert encode(penman.Graph(triples, top='h')) == (
'(h / have-org-role-91\n'
' :ARG0 (a / activist)\n'
' :ARG2 a)')

def test_parse_triples(self):
assert codec.parse_triples('role(a,b)') == [
('a', 'role', 'b')]
Expand Down

0 comments on commit bc0b820

Please sign in to comment.