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


Python inflection.singularize方法代码示例

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


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

示例1: get_resource_type_from_included_serializer

# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import singularize [as 别名]
def get_resource_type_from_included_serializer(self):
        """
        Check to see it this resource has a different resource_name when
        included and return that name, or None
        """
        field_name = self.field_name or self.parent.field_name
        parent = self.get_parent_serializer()

        if parent is not None:
            # accept both singular and plural versions of field_name
            field_names = [
                inflection.singularize(field_name),
                inflection.pluralize(field_name)
            ]
            includes = get_included_serializers(parent)
            for field in field_names:
                if field in includes.keys():
                    return get_resource_type_from_serializer(includes[field])

        return None 
开发者ID:django-json-api,项目名称:django-rest-framework-json-api,代码行数:22,代码来源:relations.py

示例2: depluralise_string

# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import singularize [as 别名]
def depluralise_string(string):
        singular = inflection.singularize(string)
        return singular 
开发者ID:nocturnaltortoise,项目名称:recaptcha-cracker,代码行数:5,代码来源:preprocessors.py

示例3: singularize_rule

# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import singularize [as 别名]
def singularize_rule(self):
        """Singularize words
        """
        item = self.item
        if len(item['prioritized_docids']) < 1:
            claim_tokens = item['claim_tokens']
            # finded_keys  = item['prioritized_docids']
            claim_tokens = [inflection.singularize(c) for c in claim_tokens]
            claim = ' '.join(claim_tokens)
            fk_new = self._keyword_match(claim)
            # finded_keys = set(finded_keys) | set(fk_new)
            item['prioritized_docids'] = list(fk_new)
        return self 
开发者ID:easonnie,项目名称:combine-FEVER-NSMN,代码行数:15,代码来源:item_rules.py

示例4: generate_model_name

# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import singularize [as 别名]
def generate_model_name(raml_resource):
    """ Generate model name.

    :param raml_resource: Instance of ramlfications.raml.ResourceNode.
    """
    resource_uri = get_resource_uri(raml_resource).strip('/')
    resource_uri = re.sub('\W', ' ', resource_uri)
    model_name = inflection.titleize(resource_uri)
    return inflection.singularize(model_name).replace(' ', '') 
开发者ID:ramses-tech,项目名称:ramses,代码行数:11,代码来源:utils.py

示例5: get

# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import singularize [as 别名]
def get(self, primary_id, secondary_model_name=None, secondary_id=None):
    try:
        # patch __log
        self.__log = self._GRest__log

        (primary, secondary) = validate_models(self,
                                               primary_id,
                                               secondary_model_name,
                                               secondary_id)

        primary_selected_item = primary.model.nodes.get_or_none(
            **{primary.selection_field: primary.id})

        if all([primary_selected_item,
                secondary.model,
                secondary.id]):
            # user selected a nested model with 2 keys
            # (from the primary and secondary models)
            # /users/user_id/roles/role_id -> selected role of this user
            # /categories/cat_id/tags/tag_id -> selected tag of this category

            # In this example, the p variable of type Post
            # is the secondary_item
            # (u:User)-[:POSTED]-(p:Post)
            secondary_item = primary_selected_item.get_all(
                secondary.model_name,
                secondary.selection_field,
                secondary.id,
                retrieve_relations=True)

            return serialize({singularize(secondary.model_name):
                              secondary_item})
        elif all([primary_selected_item, secondary.model]):
            # user selected a nested model with primary key
            # (from the primary and the secondary models)
            # /users/user_1/roles -> all roles for this user
            relationships = primary_selected_item.get_all(
                secondary.model_name,
                retrieve_relations=True)
            return serialize({pluralize(secondary.model_name):
                              relationships})
        else:
            # user selected a single item (from the primary model)
            if primary_selected_item:
                return serialize({primary.model_name:
                                  primary_selected_item.to_dict()})
            else:
                raise HTTPException(msg.MODEL_DOES_NOT_EXIST.format(
                    model=primary.model_name), 404)
    except (DoesNotExist, AttributeError) as e:
        self.__log.exception(e)
        raise HTTPException(msg.ITEM_DOES_NOT_EXIST, 404) 
开发者ID:mostafa,项目名称:grest,代码行数:54,代码来源:get.py


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