question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to reverse the order for argument?

See original GitHub issue

Hi,

I got one example and I want to modify the amr graph to get the reverse version of the reverse sentence for that. The original sentence:

# ::snt If you can use a computer, you have keyboarding skills.
(z0 / have-condition-91
      :ARG1 (z1 / have-03
            :ARG0 (z2 / you)
            :ARG1 (z3 / skill
                  :topic (z4 / keyboard-01)))
      :ARG2 (z5 / possible-01
            :ARG1 (z6 / use-01
                  :ARG0 z2
                  :ARG1 (z7 / computer))))

The reverse sentence would be

# ::snt If you have keyboardin skills, you can use a computer.

How can I do that? Many thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
goodmamicommented, Feb 2, 2022

You can use the other graph methods to find things, but it depends on what kinds of patterns you are looking for. For instance:

>>> def swappable_conditions(g):
...     for inst in g.instances():
...         if (inst.target == 'have-condition-91'
...                 and len(g.edges(source=inst.source, role=':ARG1')) == 1
...                 and len(g.edges(source=inst.source, role=':ARG2')) == 1):
...             yield inst.source
... 
>>> list(swappable_conditions(g))
['z0']
>>> g.edges(source='z0', role=':ARG1')
[Edge(source='z0', role=':ARG1', target='z1')]
>>> g.edges(source='z0', role=':ARG1')[0].target
'z1'
>>> g.edges(source='z0', role=':ARG2')[0].target
'z5'
1reaction
goodmamicommented, Jan 26, 2022

Firstly, to be clear, the ::snt metadata is not modeled beyond simply being stored along with the graph, so if you want to change that you simply reassign it. But if you are using that to illustrate that you want to swap the arguments in the graph, then you’ll need to replace two triples: ('z0', ':ARG1', 'z1') and ('z0', ':ARG2', 'z5').

>>> import penman
>>> g = penman.decode('''
... # ::snt If you can use a computer, you have keyboarding skills.
... (z0 / have-condition-91
...       :ARG1 (z1 / have-03
...             :ARG0 (z2 / you)
...             :ARG1 (z3 / skill
...                   :topic (z4 / keyboard-01)))
...       :ARG2 (z5 / possible-01
...             :ARG1 (z6 / use-01
...                   :ARG0 z2
...                   :ARG1 (z7 / computer))))
... ''')
>>> g.triples.remove(('z0', ':ARG1', 'z1'))  # remove the triples
>>> g.triples.remove(('z0', ':ARG2', 'z5'))
>>> g.triples.append(('z0', ':ARG1', 'z5'))  # add the replacements
>>> g.triples.append(('z0', ':ARG2', 'z1'))
>>> g.metadata['snt'] = 'If you have keyboarding skills, you can use a computer.'
>>> print(penman.encode(g))
# ::snt If you have keyboarding skills, you can use a computer.
(z0 / have-condition-91
    :ARG1 (z5 / possible-01
              :ARG1 (z6 / use-01
                        :ARG0 z2
                        :ARG1 (z7 / computer)))
    :ARG2 (z1 / have-03
              :ARG0 (z2 / you)
              :ARG1 (z3 / skill
                        :topic (z4 / keyboard-01))))

Does that help?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use reverse() in Python - Educative.io
The reversed() function takes any sequence as an argument and returns a reversed iterator object. The iterator object accesses the objects of the...
Read more >
Assembly Parameter Passing in Reverse Order?
Pushing the right-most first means that the left-most (of the non-register args) is right above the return address, i.e. at a known position ......
Read more >
REVERSE - IBM
The REVERSE function returns a character string of exactly the same length as the argument, whose characters are exactly the same as those...
Read more >
cursor motions - Change or reverse order of arguments
Go back to beginning and delete unnecessary commas and spaces from beginning of arglist with x. Obviously, this is kind of tedious. What...
Read more >
The reverse Parameter - Real Python
00:45 then you'll see that the names are returned in alphabetical order, so 'A' , 'H' , 'M' , and 'S' . Now...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found