Ejemplo n.º 1
0
    def run(self, td):
        currgp, currlp = self.ambimin.gp, self.ambimin.lp
        n = 1

        while n <= self.ambimin.mincnt:
            amb, sen, trees = self.find_ambiguity(currgp, currlp)
            assert amb
            ambi_parse = AmbiParse.parse(self, trees)
            gp = os.path.join(td, "%s.acc" % n)
            lp = os.path.join(td, "%s.lex" % n)
            print "currgp: %s, gp: %s " % (currgp, gp)
            MiniUtils.write_cfg_lex(ambi_parse.min_cfg, gp, currlp, lp)
            self.write_stat(gp)

            currgp = gp
            currlp = lp
            n += 1

        # run ambidexter on the minimised grammar
        _gp = self.ambidxt.filter(currgp, str(self.ambimin.duration))
        self.write_stat(_gp)

        if _gp is not None:
            return _gp, currlp

        return currgp, currlp
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    def run(self, td):
        currgp, currlp = self.ambimin.gp, self.ambimin.lp
        n = 1

        while n <= self.ambimin.mincnt:
            amb, sen, trees = self.find_ambiguity(currgp, currlp)
            assert amb
            ambi_parse = AmbiParse.parse(self, trees)
            gp = os.path.join(td, "%s.acc" % n)
            lp = os.path.join(td, "%s.lex" % n)
            print "currgp: %s, gp: %s " % (currgp, gp)
            MiniUtils.write_cfg_lex(ambi_parse.min_cfg, gp, currlp, lp)
            self.write_stat(gp)

            currgp = gp
            currlp = lp
            n += 1

        # run ambidexter on the minimised grammar
        fltr = '-%s' % self.ambimin.fltr
        fltr_outg = '-%s' % self.ambimin.fltr_cfg_outfmt
        opts = ['-h', fltr, fltr_outg]
        t1 = time.time()
        _gp = self.ambidxt.filter(currgp, str(self.ambimin.ambi_duration), opts)
        t2 = time.time()
        self.write_stat(_gp)

        if _gp is None:
            return currgp, currlp 

        print "=> filtered grammar : " , _gp
        tp = self.fix_sym_tokens_bug(currgp, _gp, td)

        # run ambidexter on the minimised grammar
        opts = ['-pg', '-ik', '0']
        t = self.ambimin.ambi_duration - (t2 - t1)
        print "time remaining: " , t
        ambisen, accsen = self.ambidxt.ambiguous(tp, currlp, str(t), opts)
        print "accsen: " , accsen
        if accsen is not None:
            __gp, __lp = self.run_accent(accsen, tp, currlp, td)
            self.write_stat(__gp)
            return __gp, __lp

        # AmbiDexter didn't find anything
        self.write_stat(None)
        return tp, currlp
Ejemplo n.º 4
0
    def run(self, td):
        gp, lp = self.ambimin.gp, self.ambimin.lp
        amb, sen, trees = self.find_ambiguity(gp, lp)
        assert amb
        ambi_parse = AmbiParse.parse(self, trees)
        # save the minimised cfg, lex to target files
        _gp = os.path.join(td, "%s.acc" % 0)
        _lp = os.path.join(td, "%s.lex" % 0)
        print "gp: %s, _gp: %s " % (gp, _gp)
        MiniUtils.write_cfg_lex(ambi_parse.min_cfg, _gp, lp, _lp)

        # run ambidexter on the minimised grammar
        sen, r = self.ambidexter(_gp)
        if r != 0:
            return _gp, _lp, None

        return _gp, _gp, sen