Ejemplo n.º 1
0
    def candMatchesRef(cls, hyp):
        """Checks whether the candidate hypothesis matches at least one given reference"""

        if hyp.startswith("<s>"):
            hyp = hyp[4:]
        if hyp.endswith("</s>"):
            hyp = hyp[:-5]
        return RefPhrases.isValidRefPhrNSent(cls.sent_id, hyp)
Ejemplo n.º 2
0
    def tgtMatchesRefSent(cls, tgt_phr, sent_id):
        '''Check whether phrases in the target rules match the current set of reference sentence(s)'''

        tgtToks = tgt_phr.split()
        tgt_i = 0
        beg_pos = 0
        for tgt_tok in tgtToks:
            if tgt_tok == "S__1" or tgt_tok == "X__1" or tgt_tok == "X__2":
                if tgt_i > 0 and tgt_i > beg_pos:
                    rule_phr = ' '.join(tgtToks[beg_pos:tgt_i])
                    if not RefPhrases.isValidRefPhrNSent(sent_id, rule_phr):
                        return False
                beg_pos = tgt_i + 1
            tgt_i += 1

        if tgt_i > beg_pos:
            rule_phr = ' '.join(tgtToks[beg_pos:tgt_i])
            if not RefPhrases.isValidRefPhrNSent(sent_id, rule_phr):
                return False
        return True
Ejemplo n.º 3
0
def main():

    global refFiles
    sent_count = settings.opts.sentindex * settings.opts.sent_per_file

    if settings.opts.force_decode:
        getRefFiles()
        RefPhrases(sent_count, refFiles)
    PhraseTable()

    readNParse(sent_count)  # Parse the sentences
Ejemplo n.º 4
0
    def tgtMatchesRefSent(cls, tgt_phr, sent_id):
        '''Check whether phrases in the target rules match the current set of reference sentence(s)'''

        tgtToks = tgt_phr.split()
        tgt_i = 0
        beg_pos = 0
        for tgt_tok in tgtToks:
            if tgt_tok == "S__1" or tgt_tok == "X__1" or tgt_tok == "X__2":
                if tgt_i > 0 and tgt_i > beg_pos:
                    rule_phr = ' '.join( tgtToks[beg_pos:tgt_i] )
                    if not RefPhrases.isValidRefPhrNSent(sent_id, rule_phr):
                        return False
                beg_pos = tgt_i + 1
            tgt_i += 1

        if tgt_i > beg_pos:
            rule_phr = ' '.join( tgtToks[beg_pos:tgt_i] )
            if not RefPhrases.isValidRefPhrNSent(sent_id, rule_phr):
                return False
        return True
Ejemplo n.º 5
0
    def candMatchesRef(cls, hyp):
        '''Checks whether the candidate hypothesis matches at least one given reference'''

        if hyp.startswith("<s>"): hyp = hyp[4:]
        if hyp.endswith("</s>"): hyp = hyp[:-5]
        return RefPhrases.isValidRefPhrNSent(cls.sent_id, hyp)