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


Python category.Category类代码示例

本文整理汇总了Python中category.Category的典型用法代码示例。如果您正苦于以下问题:Python Category类的具体用法?Python Category怎么用?Python Category使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: categories_edit

def categories_edit(category_id):
    try:
        category = Category.find_by_id(category_id)
        if category:
            if request.method == 'GET':
                category_dict = category.__dict__
                form = Form(category_dict, form_fields)
                return render_template('category/edit.html', form=form, category_id=category_id, success=True)
            elif request.method == 'POST':
                form = Form(request.form, form_fields)
                if form.validate():
                    values = form.named_values()
                    category.from_dict(values)
                    category.save()
                    miner = miner_cls(category)
                    miners[category_id] = miner
                    miner.start()
                    return redirect(url_for('categories'))
                else:
                    return render_template('category/edit.html', form=form, category_id=category_id, success=True)
            elif request.method == 'DELETE':
                miner = miners[category_id]
                miner.stop()
                del miners[category_id]
                Category.delete(category_id)
                return 'Category {} deleted.'.format(category_id), 200
            else:
                return 'Unsupported request method.', 400
        else:
            return 'Category {} not found.'.format(category_id), 400
    except ValueError, e:
        print e
        return '{} is not a valid category id.'.format(category_id), 400
开发者ID:tirami,项目名称:udadisi-google-scholar,代码行数:33,代码来源:views.py

示例2: _add_category

 def _add_category(self, cate_name, post):
     cate = self.categories.get(cate_name)
     if not cate:
         url = os.path.join('categories', cate_name)
         cate = Category(self, cate_name, url)
         self.categories[cate_name] = cate
     cate.add_post(post)
开发者ID:youngtrips,项目名称:zephyr,代码行数:7,代码来源:site.py

示例3: test_basic

    def test_basic(self):
        name = 'music'
        c = Category(name)

        self.assertEqual(name, c.name)
        self.assertEqual(0, len(c.descriptions))
        self.assertEqual(0, c.fn(1))
开发者ID:mattdeluco,项目名称:problemtwo,代码行数:7,代码来源:test_category.py

示例4: load_categories

    def load_categories(self):
        for filename in os.listdir(self.database):
            category_name = os.path.splitext(filename)[0]

            category = Category(self.database, category_name, self.stop_list)
            if category.load():
                self.total_articles += category.article_count
                self.categories[category_name] = category
开发者ID:beeblook,项目名称:20-newsgroups,代码行数:8,代码来源:nb-classifier.py

示例5: category_relationships

 def category_relationships():
     response = None
     if request.method == 'POST':
         response = Category.create_relationships(id, related_collection_name, eval(request.data))
     elif request.method == 'PATCH':
         response = Category.update_relationship(id, related_collection_name, json.loads(request.data))
     elif request.method == 'DELETE':
         response = Category.disconnect_relationship(id, related_collection_name, eval(request.data))
     elif request.method == 'GET':
         response = Category.get_relationship(request.args, id, related_collection_name)
     return response
开发者ID:buckmaxwell,项目名称:planit-api,代码行数:11,代码来源:api.py

示例6: get_category

 def get_category(self, id, name=None):
     """
     Returns a Category for the passed ID, associated with this API object.
     """
     id = int(id)
     if id in self.cached_categories.keys():
         cat = self.cached_categories[id]
     else:
         cat = Category(id, self)
     if name:
         cat.name = name
     return cat
开发者ID:mustbenice,项目名称:pygazelle,代码行数:12,代码来源:api.py

示例7: categories

def categories():
    if request.method == 'GET':
        # return an html list of all the categories
        return render_template('category/index.html', categories=Category.all(), success=True)
    elif request.method == 'POST':
        # create new category based on the posted id
        params = request.get_json()
        new_category_id = int(params['id'])
        fields = {key: "" for key, value in form_fields.iteritems()}
        new_category = Category(new_category_id, fields)
        new_category.save()
        return 'OK', 200
    else:
        return 'error', 400
开发者ID:tirami,项目名称:udadisi-google-scholar,代码行数:14,代码来源:views.py

示例8: category_append

 def category_append(self, category, description=None, parent=None, slug=None, ordering=99999):
     category = Category(name=category, description=description, slug=slug, ordering=ordering)
     # get parent
     if parent is not None:
         for cat in self.categories:
             if isinstance(parent, int) and cat.id == parent:
                 category.parent = cat
                 break
             elif isinstance(parent, str) and cat.name == parent:
                 category.parent = cat
             else:
                 category.parent = None
     if category not in self.categories:
         self.categories.append(category)
开发者ID:Schturmfogel,项目名称:virtenviro,代码行数:14,代码来源:yml.py

示例9: recognize

def recognize(img, category, surf, centroids, linear_clf, ids):
    keypoints, descriptors = surf.detectAndCompute(img, None)

    category = Category(label=category)
    category.add_feature(descriptors)
    category.calc_bagofwords(centroids)

    bow = category.bagofwords[0]
    id = int(linear_clf.predict(bow)[0])
    for i in ids:
        if ids[i] == id:
            label = i
    print category.label, ":", label
    del category
开发者ID:vinaysrao,项目名称:ml-project,代码行数:14,代码来源:svm_recognize.py

示例10: learn

    def learn(self):
        # for each directory in the document root...
        for category_name in os.listdir(self.docroot):
            category_path = os.path.join(self.docroot, category_name)

            # if the category is a file (not a directory), then skip it
            if os.path.isfile(category_path):
                continue

            category = Category(self.database, category_name, self.stop_list)
            self.categories[category_name] = category

            # call the function to handle the directory/category
            category.categorize(category_path)
            category.save()
开发者ID:beeblook,项目名称:20-newsgroups,代码行数:15,代码来源:nb-classifier.py

示例11: build_default_template

def build_default_template(rule_pattern, ccg_tree):
    category = rule_pattern.category
    if len(ccg_tree) == 0:
        num_arguments = category.get_num_args()
    elif len(ccg_tree) == 1:
        category2 = Category(ccg_tree.get('category'))
        num_arguments = category.get_num_args() - category2.get_num_args()
    variable_names = ['x' + str(i) for i in range(num_arguments)]
    if not variable_names:
        template_string = r'\P.P'
    else:
        template_string =  r'\P ' + ' '.join(variable_names) \
                          + '.P(' + ', '.join(reversed(variable_names)) + ')'
    template = lexpr(template_string)
    return template
开发者ID:mynlp,项目名称:ccg2lambda,代码行数:15,代码来源:semantic_index.py

示例12: __init__

 def __init__(self):        
     self.user = User()
     self.course = Course()
     self.category = Category()
     self.quiz = Quiz()
     self.announcement = Announcement()
     self.discussion = Discussion()
开发者ID:dmellosnehal23,项目名称:Projects,代码行数:7,代码来源:admin.py

示例13: construct_compound_tense_subjunctive

def construct_compound_tense_subjunctive(infinitive, tense):
    past_participle = _construct_past_participle(infinitive)
    inflection = [("qu'" if f(aux)[0] in _VOWELS else 'que',
                   f(aux), aux, past_participle)
                  for f, aux in zip(_PRONOUNS,
                                    _COMPOUND_TENSE[tense])]
    return Category._make(inflection)
开发者ID:wmealem,项目名称:VerbTrainer,代码行数:7,代码来源:french.py

示例14: __init__

    def __init__(self, base, name=None):
        r"""
        Initialize ``self``.

        EXAMPLES::

            sage: S = Spec(ZZ)
            sage: C = Schemes(S); C
            Category of schemes over Integer Ring
            sage: C.__class__.__init__ == sage.categories.category_types.Category_over_base.__init__
            True
            sage: C.base() is S
            True
            sage: TestSuite(C).run()
        """
        self.__base = base
        Category.__init__(self, name)
开发者ID:Etn40ff,项目名称:sage,代码行数:17,代码来源:category_types.py

示例15: __init__

 def __init__(self, *args, **kwargs):
     self.__categories = kwargs.pop('categories')
     self.__filterOnlyWhenAllCategoriesMatch = \
         kwargs.pop('filterOnlyWhenAllCategoriesMatch', False)
     for eventType in (self.__categories.addItemEventType(),
                       self.__categories.removeItemEventType()):
         patterns.Publisher().registerObserver(self.onCategoryChanged,
                                               eventType=eventType, 
                                               eventSource=self.__categories)
     eventTypes = (Category.categorizableAddedEventType(),
                   Category.categorizableRemovedEventType(),
                   Category.filterChangedEventType())
     for eventType in eventTypes:
         patterns.Publisher().registerObserver(self.onCategoryChanged,
                                               eventType=eventType)
     pub.subscribe(self.onFilterMatchingChanged, 'settings.view.categoryfiltermatchall')
     super(CategoryFilter, self).__init__(*args, **kwargs)
开发者ID:HieronymusCH,项目名称:TaskCoach,代码行数:17,代码来源:filter.py


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