本文整理汇总了Python中nomenklatura.model.Dataset.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.by_name方法的具体用法?Python Dataset.by_name怎么用?Python Dataset.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nomenklatura.model.Dataset
的用法示例。
在下文中一共展示了Dataset.by_name方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reconcile
# 需要导入模块: from nomenklatura.model import Dataset [as 别名]
# 或者: from nomenklatura.model.Dataset import by_name [as 别名]
def reconcile(dataset=None):
"""
Reconciliation API, emulates Google Refine API. See:
http://code.google.com/p/google-refine/wiki/ReconciliationServiceApi
"""
if dataset is not None:
dataset = Dataset.by_name(dataset)
# TODO: Add proper support for types and namespacing.
data = request.args.copy()
data.update(request.form.copy())
if 'query' in data:
# single
q = data.get('query')
if q.startswith('{'):
try:
q = json.loads(q)
except ValueError:
raise BadRequest()
else:
q = data
return jsonify(reconcile_op(dataset, q))
elif 'queries' in data:
# multiple requests in one query
qs = data.get('queries')
try:
qs = json.loads(qs)
except ValueError:
raise BadRequest()
queries = {}
for k, q in qs.items():
queries[k] = reconcile_op(dataset, q)
return jsonify(queries)
else:
return reconcile_index(dataset)
示例2: suggest
# 需要导入模块: from nomenklatura.model import Dataset [as 别名]
# 或者: from nomenklatura.model.Dataset import by_name [as 别名]
def suggest(dataset):
"""
Suggest API, emulates Google Refine API. See:
http://code.google.com/p/google-refine/wiki/SuggestApi
"""
dataset = Dataset.by_name(dataset)
entities = Entity.all().filter(Entity.invalid!=True)
query = request.args.get('prefix', '').strip()
entities = entities.filter(Entity.name.ilike('%s%%' % query))
entities = entities.offset(get_offset(field='start'))
entities = entities.limit(get_limit(default=20))
matches = []
for entity in entities:
matches.append({
'name': entity.name,
'n:type': {
'id': '/' + dataset.name,
'name': dataset.label
},
'id': entity.id
})
return jsonify({
"code" : "/api/status/ok",
"status" : "200 OK",
"prefix" : query,
"result" : matches
})
示例3: type_to_dataset
# 需要导入模块: from nomenklatura.model import Dataset [as 别名]
# 或者: from nomenklatura.model.Dataset import by_name [as 别名]
def type_to_dataset(type_name):
dataset_name = type_name.strip().strip('/')
dataset = Dataset.by_name(dataset_name)
if dataset is None:
raise BadRequest('No type (or invalid type) specified!')
return dataset