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


Python Inventory.unit方法代码示例

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


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

示例1: decodeInventoryEntry_level1

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import unit [as 别名]
def decodeInventoryEntry_level1(document):
    """
    Decodes a basic entry such as: '6 lobster cake' or '6' cakes
    @param document : NLP Doc object
    :return: Status if decoded correctly (true, false), and Inventory object
    """
    count = Inventory(str(document))
    for token in document:
        if token.pos_ == (u'NOUN' or u'NNS' or u'NN'):
            item = str(token)

            for child in token.children:
                if child.dep_ == u'compound' or child.dep_ == u'ad':
                    item = str(child) + str(item)
                elif child.dep_ == u'nummod':
                    count.amount = str(child).strip()
                    for numerical_child in child.children:
                        # this isn't arithmetic rather than treating it such as a string
                        count.amount = str(numerical_child) + str(count.amount).strip()
                else:
                    print "WARNING: unknown child: " + str(child) + ':'+str(child.dep_)

            count.item = item
            count.unit = item

    return count
开发者ID:Arttii,项目名称:spaCy,代码行数:28,代码来源:inventoryCount.py

示例2: decodeInventoryEntry_level2

# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import unit [as 别名]
def decodeInventoryEntry_level2(document):
    """
    Entry level 2, a more complicated parsing scheme that covers examples such as
    'i have 80 boxes of freshly baked pies'

    @document @param document : NLP Doc object
    :return: Status if decoded correctly (true, false), and Inventory object-
    """

    count = Inventory(str(document))

    for token in document:
        #  Look for a preposition object that is a noun (this is the item we are counting).
        #  If found, look at its' dependency (if a preposition that is not indicative of
        #  inventory location, the dependency of the preposition must be a noun

        if token.dep_ == (u'pobj' or u'meta') and token.pos_ == (u'NOUN' or u'NNS' or u'NN'):
            item = ''

            #  Go through all the token's children, these are possible adjectives and other add-ons
            #  this deals with cases such as 'hollow rounded waffle pancakes"
            for i in token.children:
                item += ' ' + str(i)

            item += ' ' + str(token)
            count.item = item

            # Get the head of the item:
            if token.head.dep_ != u'prep':
                #  Break out of the loop, this is a confusing entry
                break
            else:
                amountUnit = token.head.head
                count.unit = str(amountUnit)

                for inner in amountUnit.children:
                    if inner.pos_ == u'NUM':
                        count.amount += str(inner)
    return count
开发者ID:Arttii,项目名称:spaCy,代码行数:41,代码来源:inventoryCount.py


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