本文整理汇总了Python中aleph.model.Collection.create方法的典型用法代码示例。如果您正苦于以下问题:Python Collection.create方法的具体用法?Python Collection.create怎么用?Python Collection.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Collection
的用法示例。
在下文中一共展示了Collection.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_collections
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def test_update_collections(self):
url = '/api/1/documents/1000/collections'
ores = self.client.get(url)
user = self.login()
can_write = Collection.create({'label': "Write"}, user)
no_write = Collection.create({'label': "No-write"})
db.session.commit()
data = list(ores.json)
data.append(can_write.id)
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 200, res
assert can_write.id in res.json, res.json
data = list(ores.json)
data = [no_write.id]
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 200, res
assert no_write.id not in res.json, res.json
assert 1000 in res.json, res.json
data = list(ores.json)
data = ['foo']
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 400, res
示例2: test_update_collections_via_doc_update
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def test_update_collections_via_doc_update(self):
url = '/api/1/documents/1000'
ores = self.client.get(url)
user = self.login()
Permission.grant_collection(1000, user, True, True)
can_write = Collection.create({'label': "Write"}, user)
no_write = Collection.create({'label': "No-write"})
db.session.commit()
data = ores.json.copy()
data['collection_id'].append(can_write.id)
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 200, res
assert can_write.id in res.json['collection_id'], res.json
data = ores.json.copy()
data['collection_id'] = [no_write.id]
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 200, res
assert no_write.id not in res.json['collection_id'], res.json
assert 1000 in res.json['collection_id'], res.json
data = ores.json.copy()
data['collection_id'] = ['foo']
res = self.client.post(url, data=json.dumps(data),
content_type='application/json')
assert res.status_code == 400, res
示例3: create
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def create():
authz.require(authz.logged_in())
collection = Collection.create(request_data(), request.auth_role)
db.session.commit()
update_collection(collection)
log_event(request)
return view(collection.id)
示例4: crawl
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def crawl(self, directory=None, collection=None, meta={}):
collection = collection or directory
collection = Collection.create({
'foreign_id': 'directory:%s' % slugify(collection),
'label': collection
})
db.session.commit()
collection_id = collection.id
if os.path.isfile(directory):
self.crawl_file(collection_id, directory, meta)
directory = directory or os.getcwd()
directory = directory.encode('utf-8')
for (dirname, dirs, files) in os.walk(directory):
dirparts = [d for d in dirname.split(os.path.sep)
if d in SKIP_DIRECTORIES]
if len(dirparts):
continue
log.info("Descending: %r", dirname)
for file_name in files:
dirname = string_value(dirname)
file_name = string_value(file_name)
if file_name in SKIP_FILES:
continue
file_path = os.path.join(dirname, file_name)
self.crawl_file(collection_id, file_path, meta)
示例5: load_collection
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def load_collection(self, data):
foreign_id = data.get('foreign_id')
collection = Collection.by_foreign_id(foreign_id)
if collection is None:
collection = Collection.create(data)
db.session.commit()
update_collection(collection)
return collection
示例6: crawl_collection
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def crawl_collection(self, engine, foreign_id, data):
collection = Collection.create({
'foreign_id': foreign_id,
'label': data.get('label')
})
db.session.commit()
meta_base = data.get('meta', {})
for name, query in data.get('queries', {}).items():
self.crawl_query(engine, collection, meta_base, name, query)
示例7: collection
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def collection(self):
if not hasattr(self, '_collection'):
self._collection = Collection.create({
'foreign_id': self.COLLECTION_ID,
'label': self.COLLECTION_LABEL or self.COLLECTION_ID
})
db.session.commit()
db.session.add(self._collection)
return self._collection
示例8: create_collection
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def create_collection(self, graph):
collection = Collection.create({
'foreign_id': self.config.get('collection'),
'label': self.config.get('collection'),
'managed': True
})
db.session.commit()
coll_type = NodeType.get('Collection')
return coll_type.merge(graph, name=collection.label,
fingerprint=collection.foreign_id,
alephCollection=collection.id)
示例9: collection
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def collection(self):
if not hasattr(self, "_collection"):
self._collection = Collection.create(
{
"foreign_id": self.COLLECTION_ID,
"label": self.COLLECTION_LABEL or self.COLLECTION_ID,
"managed": True,
}
)
db.session.commit()
db.session.add(self._collection)
return self._collection
示例10: create_collection
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def create_collection(data, role=None, sync=False):
role = role or Role.load_cli_user()
created_at = datetime.utcnow()
collection = Collection.create(data, role=role, created_at=created_at)
if collection.created_at == created_at:
publish(Events.CREATE_COLLECTION,
actor_id=role.id,
params={'collection': collection})
db.session.commit()
Authz.flush()
refresh_collection(collection.id)
return index.index_collection(collection, sync=sync)
示例11: crawl
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def crawl(self, directory=None, collection=None, meta={}):
directory = string_value(directory)
if directory is None or not os.path.exists(directory):
log.error("Invalid directory: %r", directory)
return
directory = os.path.abspath(os.path.normpath(directory))
collection = collection or directory
collection = Collection.create({
'foreign_id': 'directory:%s' % slugify(collection),
'label': collection
})
db.session.commit()
meta = self.make_meta(meta)
meta.source_path = directory
ingest_directory(collection.id, meta, directory)
示例12: __init__
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def __init__(self, config):
validate(config, 'mapping.json#')
self.config = config
uri = os.path.expandvars(self.config.get('database'))
self.engine = create_engine(uri)
self.meta = MetaData()
self.meta.bind = self.engine
self.nodes = [NodeMapping(self, n, c) for (n, c)
in config.get('nodes').items()]
self.edges = [EdgeMapping(self, c) for c in config.get('edges', [])]
self.collection = Collection.create({
'foreign_id': config.get('collection'),
'label': config.get('collection'),
'managed': True
})
db.session.add(self.collection)
db.session.commit()
示例13: crawl_item
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def crawl_item(self, item):
coll_data = item.meta.get('source', {})
coll_fk = coll_data.pop('foreign_id')
if coll_fk is None:
raise ValueError("No foreign_id for collection given: %r" % item)
if coll_fk not in self.collections:
label = coll_data.get('label', coll_fk)
self.collections[coll_fk] = Collection.create({
'foreign_id': coll_fk,
'label': label
})
if coll_data.get('public'):
Permission.grant_foreign(self.collections[coll_fk],
Role.SYSTEM_GUEST,
True, False)
db.session.commit()
log.info('Import: %r', item.identifier)
meta = self.normalize_metadata(item)
ingest_file(self.collections[coll_fk].id, meta,
item.data_path, move=False)
示例14: crawl
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def crawl(self):
for base_url in SITES:
print 'Working on base_url: {}'.format(base_url)
self.attributes = SITES[base_url]
self.label = self.attributes['label']
collection = Collection.create({
'label': self.label,
'foreign_id': 'blacklight'
})
db.session.commit()
self.failed_articles = 0
page_count = self.get_page_count(base_url)
print "Pages: {}".format(page_count)
page_number = 1
while (page_number <= page_count):
if self.failed_articles >= FAILED_LIMIT:
log.warning('Failure limit reach: {}'.format(FAILED_LIMIT))
break
self.crawl_page(base_url, page_number, page_count)
page_number += 1
示例15: load
# 需要导入模块: from aleph.model import Collection [as 别名]
# 或者: from aleph.model.Collection import create [as 别名]
def load(self):
"""Generate query rows and load them into the graph."""
collection = Collection.create({
'foreign_id': self.config.get('collection'),
'label': self.config.get('collection'),
'managed': True
})
db.session.commit()
graph = get_graph()
coll_type = NodeType.get('Collection')
collection = coll_type.merge(graph, name=collection.label,
fingerprint=collection.foreign_id,
alephCollection=collection.id)
begin_time = time()
rp = self.engine.execute(self.query)
log.debug("Query time: %.5fms", (time() - begin_time) * 1000)
stats = {'rows': 0, 'nodes': 0, 'rels': 0}
while True:
graphtx = graph.begin()
rows = rp.fetchmany(10000)
if not len(rows):
break
for row in rows:
stats['rows'] += 1
self.update(graphtx, collection, dict(row.items()), stats)
if stats['rows'] % 1000 == 0:
elapsed = (time() - begin_time)
stats['per_node'] = max(stats['nodes'], 1) / elapsed
log.info("Loaded: %(rows)s [%(nodes)s nodes, "
"%(rels)s edges], %(per_node).5f n/s", stats)
graphtx.commit()
log.info("Done. Loaded %(rows)s rows, %(nodes)s nodes, "
"%(rels)s edges.", stats)