def verify_ambiguity(self, mingp, minlp, minsen, duration=None): print "==> verify grammar %s with minimiser %s \n" % \ (mingp, self._sin.minp) self._sin.lex = Lexer.parse(open(self._sin.lp, 'r').read()) self._sin.cfg = CFG.parse(self._sin.lex, open(self._sin.gp, "r").read()) self._sin.parser = Accent.compile(self._sin.gp, self._sin.lp) minlex = Lexer.parse(open(minlp, 'r').read()) mincfg = CFG.parse(minlex, open(mingp, 'r').read()) seq = mincfg.get_rule('root').seqs[0] # check if the root rule of minimised cfg == root of original cfg if (len(seq) == 1) and (str(seq[0]) == self._sin.cfg.start_rulen): out = Accent.run(self._sin.parser, minsen) if Accent.was_ambiguous(out): print "** verified **" minbend = "%sm" % self._sin.backend if minbend in Backends.BACKENDS: bend = Backends.BACKENDS[minbend](self._sin, mincfg, minsen) else: bend = Backends.WGTBACKENDS[minbend](self._sin, mincfg, minsen) # we keep trying until we hit the subseq while not bend.found: bend.run(self._sin.t_depth, self._sin.wgt, duration) print "** verified **"
def run_accent(self, sen, gp, lp): """ build parser in td using gp+lp, and parse sentence sen.""" parser = Accent.compile(gp, lp) ptrees = Accent.run(parser, sen) ambi_parse = AmbiParse.parse(lp, self._sin.lex_ws, ptrees) _gp = tempfile.mktemp('.acc', dir=self._sin.td) _lp = tempfile.mktemp('.lex', dir=self._sin.td) self.write_cfg_lex(ambi_parse, _gp, _lp) return _gp, _lp, ambi_parse
def run_accent(self, sen, gp, lp, td): """ build parser in td using gp+lp, and parse sentence sen.""" parser = Accent.compile(gp, lp) out = Accent.run(parser, sen) ambiparse = AmbiParse.parse(self, out) _gp = tempfile.mktemp('.acc', dir=td) _lp = tempfile.mktemp('.lex', dir=td) MiniUtils.write_cfg_lex(ambiparse.min_cfg, _gp, lp, _lp) return _gp, _lp
def run_accent(self, sen, gf, lf): """ build parser in td using gf+lf, and parse sentence sen.""" parser = Accent.compile(gf, lf) ptrees = Accent.run(parser, sen) ambi_parse = AmbiParse.parse(lf, self._sin.lex_ws, ptrees, sen) #_gp = tempfile.mktemp('.acc', dir=self._sin.td) #_lp = tempfile.mktemp('.lex', dir=self._sin.td) #_ambstrp = os.path.join(self._sin.td, "%s.ambs" % 'accent') #self.write_cfg_lex(ambi_parse, _gp, _lp, _ambstrp) return ambi_parse