本文整理汇总了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
示例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)
示例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))
示例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
示例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
示例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
示例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
示例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)
示例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
示例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()
示例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
示例12: __init__
def __init__(self):
self.user = User()
self.course = Course()
self.category = Category()
self.quiz = Quiz()
self.announcement = Announcement()
self.discussion = Discussion()
示例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)
示例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)
示例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)