当前位置: 首页>>代码示例>>Python>>正文


Python Rule.t方法代码示例

本文整理汇总了Python中Rule.Rule.t方法的典型用法代码示例。如果您正苦于以下问题:Python Rule.t方法的具体用法?Python Rule.t怎么用?Python Rule.t使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rule.Rule的用法示例。


在下文中一共展示了Rule.t方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: topDownInduction

# 需要导入模块: from Rule import Rule [as 别名]
# 或者: from Rule.Rule import t [as 别名]
def topDownInduction(tree, s, split=False, LabelDict=None):
    """
    Rule Generation
    """
    global INVALIDS, DELETES, EXCEPTIONS

    logging.info("string: {}".format(s))
    logging.info("tree: {}".format(tree))
    
    rules = set()
    treeBuffer = [(tree,'S!')]
    try:
        while treeBuffer:
        
            r = Rule()
            node, label = treeBuffer.pop()
            
            arguments = ['X'] * len(node.childNodes) if not split else [LabelDict[child.name] for child in node.childNodes]
            
            for idx,child in enumerate(node.childNodes):
                treeBuffer.append((child,arguments[idx]))
            #
            # create rule label
            #
            r.label = getLabel(label, node.idx, arguments)
            #
            # create string representation
            #
            logging.debug("node.interval:".format(node.interval))
            interval = node.interval
            for child in node.childNodes:
                interval = interval.without(child.interval)
            logging.debug("Interval:".format(interval))
            r.s = getStringRule(interval, s)
            #print r.s
            #
            # create meaning representation
            #
            r.t = getMeaningRule(node.name,len(node.childNodes))
            
            if len(node.childNodes) != interval.flatten().count(-1):
                logging.debug("Invalid number of arguments: child({}) interval({})".format(
                    len(node.childNodes),
                    interval.flatten().count(-1))
                )
                INVALIDS += 1
                return set()
            if r.s in ("?1", "*(?1,?2)"):
                logging.debug("Deleting homorphism: {}".format(r.s))
                DELETES += 1
                return set()
            
            rules.add(r)

    except Exception as e:
        logging.error(e)
        EXCEPTIONS += 1
        return set()

    return rules
开发者ID:Rene90,项目名称:grammar_induction,代码行数:62,代码来源:inductionMethods.py

示例2: bottomUpInduction

# 需要导入模块: from Rule import Rule [as 别名]
# 或者: from Rule.Rule import t [as 别名]
def bottomUpInduction(tree, s, split=False, LabelDict=None):
    """
    Rule Generation
    """
    global INVALIDS, DELETES, EXCEPTIONS

    logging.info("string: {}".format(s))
    logging.info("tree: {}".format(tree))
    
    rules = set()
    treeBuffer = [(tree,tree.interval,'S!')]

    try:
        while treeBuffer:
            r = Rule()
            node, nodeInterval, label = treeBuffer.pop()
            arguments = ['X'] * len(node.childNodes) if not split else [LabelDict[child.name] for child in node.childNodes]
            if len(node.alignment) == 1:
                alignedWord = node.alignment[0]
                tmpInterval = Interval(nodeInterval.first(), alignedWord)
            else:
                minWord, maxWord = min(node.alignment), max(node.alignment)
                tmpInterval = Interval(minWord-1, maxWord)
            
            childsInterval = nodeInterval.without(tmpInterval)
            interval = tmpInterval
            
            if node.childNodes:
                splitIdx = node.childNodes[0].interval.last()
                tmpInterval = Interval(childsInterval.first(),splitIdx+1)
                
                treeBuffer.append((node.childNodes[0],tmpInterval,arguments[0]))
                for idx,child in enumerate(node.childNodes[1:]):
                    oldSplit = splitIdx
                    splitIdx = child.interval.last()
                    tmpInterval = Interval(oldSplit+1,splitIdx+1)
                    treeBuffer.append((child,tmpInterval,arguments[idx+1]))
            
            for _ in range(len(node.childNodes)): interval.addPlaceholder()
            
            #
            # create rule label
            #
            r.label = getLabel(label, node.idx, arguments)
            #
            # create string representation
            #
            r.s = getStringRule(interval, s)
            #
            # create meaning representation
            #
            r.t = getMeaningRule(node.name,len(node.childNodes))
            
            if len(node.childNodes) != interval.flatten().count(-1):
                logging.debug("Invalid number of arguments: child({}) interval({})".format(
                    len(node.childNodes),
                    interval.flatten().count(-1))
                )
                INVALIDS += 1
                return set()
            if r.s in ("?1", "*(?1,?2)"):
                logging.debug("Deleting homorphism: {}".format(r.s))
                DELETES += 1
                return set()
            
            rules.add(r)

    except Exception as e:
        logging.error(e)
        EXCEPTIONS += 1
        return set()

    return rules
开发者ID:Rene90,项目名称:grammar_induction,代码行数:75,代码来源:inductionMethods.py


注:本文中的Rule.Rule.t方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。