Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Frame ID reset during looping #166

Closed
Jimmy-Mcnulty opened this issue Apr 17, 2018 · 12 comments
Closed

Frame ID reset during looping #166

Jimmy-Mcnulty opened this issue Apr 17, 2018 · 12 comments

Comments

@Jimmy-Mcnulty
Copy link

Is there a way to extract the Frame IDs at the document level? At any other level, the frame IDs start from 1. This makes it difficult to link the text.

@ringgaard
Copy link
Contributor

I am not sure what you mean by "frame id reset". Could you provide an example?

@Jimmy-Mcnulty
Copy link
Author

Jimmy-Mcnulty commented Apr 17, 2018 via email

@ringgaard
Copy link
Contributor

I assume you are doing this from Python. The "frame id" is just a reference that is added to anonymous frames so you can refer to them from other frames. These ids are generated by the frame serialization and is not a permanent part of the frame. The frames form a graph which you can traverse, and you can just compare the frames to see if they are the same (PyFrame supports "rich compare"). You don't need the ids for this.

@Jimmy-Mcnulty
Copy link
Author

Jimmy-Mcnulty commented Apr 27, 2018 via email

@ringgaard
Copy link
Contributor

The frames in a store basically form a graph so when you want to serialize some of these to text all the (anonymous) frames are numbered consecutively as they are output, and if there is a back pointer, it will just output a reference to the frame.

Here is a simple example of parsing some text and traversing the mentions and frames output:

import sling

parser = sling.Parser("local/sempar.flow")

n_isa = parser.commons['isa']
n_name = parser.commons['name']

while True:
  text = raw_input('Enter text: ')
  if text == 'quit': break;
  doc = parser.parse(text)

  print "Text:", doc.phrase(0, len(doc.tokens))

  for mention in doc.mentions:
    for e in mention.evokes():
      if n_name not in e:
        e.name = doc.phrase(mention.begin, mention.end)

  for mention in doc.mentions:
    print "mention", doc.phrase(mention.begin, mention.end)
    for e in mention.evokes():
      print "  evoke", e[n_isa].name, e
      for r,v in e:
        if 'description' in r:
          print "    role", r.description, v
  print

However, I am stil not sure what your problem is. Maybe you could provide an example of the problem you encounter.

@Jimmy-Mcnulty
Copy link
Author

Jimmy-Mcnulty commented Apr 29, 2018 via email

@ringgaard
Copy link
Contributor

A semantic frame can be viewed as a N-way relation between the role fillers. A (subject, predicate, object) triple is encoded as {:predicate subject: {...} object: {...}}.

@Jimmy-Mcnulty
Copy link
Author

Jimmy-Mcnulty commented May 4, 2018 via email

@ringgaard
Copy link
Contributor

The SLING output is a graph. The syntax is like JSON, but with a few extensions (see here).

Each frame is a node in the graph, and each frame slot is an edge in the graph. Here is a simple example of the SLING output from the parser:

{=#1 
  :/s/document
  /s/document/text: "John hit the ball with a bat."
  /s/document/tokens: [
    {=#2 /s/token/text: "John" }, 
    {=#3 /s/token/text: "hit" }, 
    {=#4 /s/token/text: "the"}, 
    {=#5 /s/token/text: "ball"}, 
    {=#6 /s/token/text: "with"}, 
    {=#7 /s/token/text: "a"}, 
    {=#8 /s/token/text: "bat"}, 
    {=#9 /s/token/text: "."}
  ]
  /s/document/mention: {=#10 
    :/s/phrase
    /s/phrase/begin: 0
    /s/phrase/evokes: {=#11 :/saft/person }
  }
  /s/document/mention: {=#12 
    :/s/phrase
    /s/phrase/begin: 1
    /s/phrase/evokes: {=#13 
      :/pb/hit-01
      /pb/arg0: #11
      /pb/arg1: {=#14 :/saft/consumer_good }
      /pb/argm-mnr: {=#15 :/saft/consumer_good  }
    }
  }
  /s/document/mention: {=#16 
    :/s/phrase
    /s/phrase/begin: 3
    /s/phrase/evokes: #14
  }
  /s/document/mention: {=#17 
    :/s/phrase
    /s/phrase/begin: 6
    /s/phrase/evokes: #15
  }
}

For example, frame 13 is a node in the graph:

{=#13 
  :/pb/hit-01
  /pb/arg0: #11
  /pb/arg1: {=#14 :/saft/consumer_good  }
  /pb/argm-mnr: {=#15  :/saft/consumer_good  }
}

The id if the frame is 13 (=#13) which can be used to refer to this frame from other frames. The type of the frame is the PropBank predicate hit.01 (:/pb/hit-01). The frame has three roles:

  • The /pb/arg0 role points to #11 (evoked by "John")
  • The /pb/arg1 role points to #14 (evoked by "ball")
  • The /pb/argm-mnr role points to #15 (evoked by "bat")

A SLING store is a semantic frame store, but this is basically equivalent to a graph. You can read and write frame graphs using the Python SLING API in either text or binary encoded form:

import sling
store = sling.Store()
f = store.parse("{...}")

@Jimmy-Mcnulty
Copy link
Author

Jimmy-Mcnulty commented Aug 31, 2018 via email

@ringgaard
Copy link
Contributor

We are planning to release version 2 of the semantic parser later this year, based on the caspar branch.

@Jimmy-Mcnulty
Copy link
Author

Jimmy-Mcnulty commented Aug 31, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants