Example #1
0
    def __getRulesFromPT(self, s_rule, span):
        ''' Get the rules from the Phrase table and create new entry object for each rule returned by phrase table '''

        tgtLst = PhraseTable.getRuleEntries(s_rule, self.sent_indx)
        newTgtLst = []
        for r_item in tgtLst:
            new_entry = Hypothesis.createFromRule(r_item, span)
            newTgtLst.append(new_entry)

        return newTgtLst
Example #2
0
    def __getRulesFromPT(self, s_rule, span):
        ''' Get the rules from the Phrase table and create new entry object for each rule returned by phrase table '''

        tgtLst = PhraseTable.getRuleEntries(s_rule, self.sent_indx)
        newTgtLst = []
        for r_item in tgtLst:
            new_entry = Hypothesis.createFromRule(r_item, span)
            newTgtLst.append(new_entry)

        return newTgtLst
Example #3
0
    def __reduceCell(self, span, cell_type, rule_nt, final_cell):
        '''Reduce the cell entries to merge products and build translations'''

        global consObjsLst  # Consequent Rules are to be processed in order: check 'X' rules and then 'S' rules

        src_side = ' '.join(
            self.wordsLst[span[0]:span[1] +
                          1])  # Get the source side of the span
        merge_obj = Lazy(self.sent_indx, span, cell_type, final_cell)
        cube_indx = 0
        cell_max_X_depth = 0
        for conseq_obj in consObjsLst:
            rule = conseq_obj.rule
            cube_depth_hier = 0 if (not conseq_obj.spanTup or cell_type
                                    == 'S') else conseq_obj.top_X_level + 1
            ruleRHSLst = PhraseTable.getRuleEntries(rule, self.sent_indx)
            if not ruleRHSLst: continue

            # Set the maximum depth of the current Cell
            if cell_type == 'X' and cube_depth_hier > cell_max_X_depth:
                cell_max_X_depth = cube_depth_hier

            # set the source side rule and span for the current cube
            merge_obj.setSourceInfo(cube_indx, rule, conseq_obj.spanTup,
                                    cube_depth_hier, self.refsLst)
            # add the consequent item to the cube as its first dimension
            merge_obj.add2Cube(cube_indx, ruleRHSLst)

            # add the rules for the sub-spans
            if rule.find('X__1') != -1 or rule.startswith(
                    'S__1'):  # process the rules having a non-terminal
                s_indx = 0
                for rterm in rule.split():
                    if rterm.startswith('X__'): left_side = 'X'
                    elif rterm.startswith('S__'): left_side = 'S'
                    else: continue

                    # add the antecedent item(s) of the sub-spans in the derivation
                    s_span = conseq_obj.spanTup[s_indx]
                    s_depth = conseq_obj.depth1 if s_indx == 0 else conseq_obj.depth2
                    merge_obj.add2Cube(
                        cube_indx, Parse.chartDict[s_span].getTupLst4NT(
                            left_side, s_depth))
                    s_indx += 1
            cube_indx += 1

        tgtLst = merge_obj.mergeProducts()
        self.__flush2Cell(span, (rule_nt, src_side), cell_max_X_depth,
                          tgtLst)  # Flush the entries to the cell
        merge_obj = ''  # Important: This clears the mem-obj and calls the garbage collector on Lazy()
        del consObjsLst[:]
Example #4
0
    def __reduceCell(self, span, cell_type, rule_nt, final_cell):
        '''Reduce the cell entries to merge products and build translations'''

        global consObjsLst          # Consequent Rules are to be processed in order: check 'X' rules and then 'S' rules

        src_side = ' '.join( self.wordsLst[span[0]:span[1]+1] ) # Get the source side of the span
        merge_obj = Lazy(self.sent_indx, span, cell_type, final_cell)
        cube_indx = 0
        cell_max_X_depth = 0
        for conseq_obj in consObjsLst:
            rule = conseq_obj.rule
            cube_depth_hier = 0 if (not conseq_obj.spanTup or cell_type == 'S') else conseq_obj.top_X_level + 1
            ruleRHSLst = PhraseTable.getRuleEntries(rule, self.sent_indx)
            if not ruleRHSLst: continue

            # Set the maximum depth of the current Cell
            if cell_type == 'X' and cube_depth_hier > cell_max_X_depth: cell_max_X_depth = cube_depth_hier

            # set the source side rule and span for the current cube
            merge_obj.setSourceInfo( cube_indx, rule, conseq_obj.spanTup, cube_depth_hier, self.refsLst )
            # add the consequent item to the cube as its first dimension
            merge_obj.add2Cube( cube_indx, ruleRHSLst )

            # add the rules for the sub-spans
            if rule.find('X__1') != -1 or rule.startswith('S__1'):  # process the rules having a non-terminal
                s_indx = 0
                for rterm in rule.split():
                    if rterm.startswith('X__'): left_side = 'X'
                    elif rterm.startswith('S__'): left_side = 'S'
                    else: continue
              
                    # add the antecedent item(s) of the sub-spans in the derivation
                    s_span = conseq_obj.spanTup[s_indx]
                    s_depth = conseq_obj.depth1 if s_indx == 0 else conseq_obj.depth2
                    merge_obj.add2Cube( cube_indx, Parse.chartDict[s_span].getTupLst4NT(left_side, s_depth) )
                    s_indx += 1
            cube_indx += 1

        tgtLst = merge_obj.mergeProducts()
        self.__flush2Cell( span, (rule_nt, src_side), cell_max_X_depth, tgtLst)   # Flush the entries to the cell
        merge_obj = ''  # Important: This clears the mem-obj and calls the garbage collector on Lazy()
        del consObjsLst[:]