Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibly disconnected graph #141

Closed
jkang1640 opened this issue May 7, 2024 · 2 comments
Closed

Possibly disconnected graph #141

jkang1640 opened this issue May 7, 2024 · 2 comments
Labels
question Further information is requested

Comments

@jkang1640
Copy link

jkang1640 commented May 7, 2024

Hello,

First of all, I'd like to thank the contributors of Penman!

I have an example which causes 'possibly disconnected graph' error and I can't wrap my head around the cause of the error.

import penman

triples = [('a3', ':ARG0', 'p2'), ('a2', ':ARG1', 'p2')]
graph = penman.Graph(triples)
print(penman.encode(graph))

# penman.exceptions.LayoutError: possibly disconnected graph  

I expected it to encode something like this:

(a3 :ARG0 p2 
        :ARG1-of a2)

Instead, I have a 'possibly disconnected graph' error when encoding. Is this an expected behavior of penman, and If so, could you please help me understand why the encoding is failing? Your assistance would be greatly appreciated.

Thank you very much.

@goodmami goodmami added bug Something isn't working question Further information is requested and removed bug Something isn't working labels May 9, 2024
@goodmami
Copy link
Owner

goodmami commented May 9, 2024

Hi, thanks for submitting this report. I initially agreed that this was a bug, but after probing a bit I think it's just an edge case. The short answer or workaround is: make sure your nodes/variables all have :instance triples, even if the concept is None. Below I'll give some more explanation of the underlying problem.

When configuring a tree for PENMAN output from a Graph, the Penman library identifies the variables (or node identifiers) as the set of symbols appearing as the source in one or more Graph triples. Since p2 in your example never appears as the source, it is not considered a variable:

>>> import penman
>>> penman.Graph([('a3', ':ARG0', 'p2'), ('a2', ':ARG1', 'p2')]).variables()
{'a2', 'a3'}

Penman therefore treats it like a constant. It is therefore similar to something like this, which is more clearly a disconnected graph in AMR:

>>> penman.Graph([('a3', ':polarity', '-'), ('a2', ':polarity', '-')])

Your example works if I give the conjunctive node p2 a concept triple (even with a None value):

>>> penman.encode(penman.Graph([('a3', ':ARG0', 'p2'), ('a2', ':ARG1', 'p2'), ('p2', ':instance', None)]))
'(a3 :ARG0 (p2 :ARG1-of a2))'

Another option is to use an explicit Push('p2') epigraphical marker to say that p2 should introduce a new node context in the tree representation, but I don't think this is easier:

>>> from penman.layout import Push
>>> penman.encode(
...     penman.Graph(
...         [('a3', ':ARG0', 'p2'), ('a2', ':ARG1', 'p2')],
...         epidata={('a3', ':ARG0', 'p2'): [Push('p2')]}
...     )
... )
'(a3 :ARG0 (p2 :ARG1-of a2))'

You could argue that symbols like a2 (single ASCII letter followed by an int) should always be variables, or that targets of roles like :ARG0 and :ARG1 are variables, but that's not part of the PENMAN notation as defined by this library. Even if we could say that were true for AMR graphs, that information would probably belong in the AMR Model.

Does that help at all?

@jkang1640
Copy link
Author

jkang1640 commented May 13, 2024

Thank you very much for your answer and the examples.

Does that help at all?

Yesss! it's crystal clear why it caused the error and now I see how to handle those cases. Thank you very much and I'll close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants