本文整理汇总了Python中aleph.model.Document.all方法的典型用法代码示例。如果您正苦于以下问题:Python Document.all方法的具体用法?Python Document.all怎么用?Python Document.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aleph.model.Document
的用法示例。
在下文中一共展示了Document.all方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_load_sample_directory
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def test_load_sample_directory(self):
samples_path = self.get_fixture_path('samples')
document = Document.by_keys(collection_id=self.collection.id,
foreign_id='samples')
db.session.commit()
db.session.refresh(document)
ingest_document(document, samples_path)
assert Document.all().count() == 5, Document.all().count()
示例2: test_load_pdf_file
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def test_load_pdf_file(self):
pdf_path = self.get_fixture_path('demo.pdf')
document = Document.by_keys(collection_id=self.collection.id,
foreign_id='demo.pdf')
db.session.commit()
db.session.refresh(document)
ingest_document(document, pdf_path)
assert Document.all().count() == 1, Document.all().count()
示例3: index
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def index():
sources_ids = match_ids('sources', authz.sources(authz.READ))
q = Document.all().filter(Document.source_id.in_(sources_ids))
hashes = request.args.getlist('content_hash')
if len(hashes):
q = q.filter(Document.content_hash.in_(hashes))
return jsonify(Pager(q))
示例4: load_fixtures
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def load_fixtures(self, file_name, process_documents=True):
filepath = self.get_fixture_path(file_name)
load_fixtures(db, loaders.load(filepath))
db.session.commit()
reindex_entities()
if process_documents:
for doc in Document.all():
analyze_document(doc)
optimize_search()
示例5: load_documents
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def load_documents():
graph = get_graph()
tx = graph.begin()
for i, document in enumerate(Document.all()):
load_document(tx, document)
if i > 0 and i % 1000 == 0:
tx.commit()
tx = graph.begin()
tx.commit()
示例6: index
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def index():
collection_ids = match_ids('collection', authz.collections(authz.READ))
q = Document.all()
clause = Collection.id.in_(collection_ids)
q = q.filter(Document.collections.any(clause))
hashes = request.args.getlist('content_hash')
if len(hashes):
q = q.filter(Document.content_hash.in_(hashes))
return jsonify(Pager(q))
示例7: load_documents
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def load_documents():
graph = get_graph()
tx = graph.begin()
for i, document in enumerate(Document.all()):
log.info("Load doc [%s]: %r", document.id, document.meta)
load_document(tx, document)
if i > 0 and i % 1000 == 0:
tx.commit()
tx = graph.begin()
tx.commit()
示例8: test_load_csv_file
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def test_load_csv_file(self):
csv_path = self.get_fixture_path('experts.csv')
document = Document.by_keys(collection_id=self.collection.id,
foreign_id='experts.csv')
document.file_name = 'experts.csv'
db.session.commit()
db.session.refresh(document)
ingest_document(document, csv_path)
assert Document.all().count() == 1, Document.all().count()
records = db.session.query(DocumentRecord).all()
assert len(records) == 14, len(records)
rec0 = records[0]
assert str(rec0.id) in repr(rec0), repr(rec0)
assert 'nationality' in rec0.data, rec0.data
assert 'name' in rec0.data, rec0.data
doc = rec0.document
doc.delete_records()
records = db.session.query(DocumentRecord).all()
assert len(records) == 0, len(records)
示例9: test_load_csv_file
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def test_load_csv_file(self):
csv_path = self.get_fixture_path('experts.csv')
crawler = DirectoryCrawler()
crawler.execute(directory=csv_path)
assert Document.all().count() == 1, Document.all().count()
records = db.session.query(DocumentRecord).all()
assert len(records) == 14, len(records)
rec0 = records[0]
assert str(rec0.id) in repr(rec0), repr(rec0)
assert 'experts.csv' in rec0.document.meta.file_name, \
rec0.document.meta
assert 'nationality' in rec0.data, rec0.data
assert 'name' in rec0.data, rec0.data
doc = rec0.document
assert 'experts' in repr(doc)
doc.delete_records()
records = db.session.query(DocumentRecord).all()
assert len(records) == 0, len(records)
示例10: index
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def index():
try:
authorized = authz.collections(authz.READ)
collection_ids = [int(f) for f in request.args.getlist('collection')]
collection_ids = collection_ids or authorized
collection_ids = [c for c in collection_ids if c in authorized]
except ValueError:
raise BadRequest()
q = Document.all()
clause = Collection.id.in_(collection_ids)
q = q.filter(Document.collections.any(clause))
hashes = request.args.getlist('content_hash')
if len(hashes):
q = q.filter(Document.content_hash.in_(hashes))
return jsonify(Pager(q))
示例11: create_document
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def create_document(self, meta, type=None):
if meta.content_hash:
q = Document.all()
if meta.foreign_id:
q = q.filter(Document.foreign_id == meta.foreign_id)
else:
q = q.filter(Document.content_hash == meta.content_hash)
q = q.filter(Document.source_id == self.source_id)
document = q.first()
if document is None:
document = Document()
document.source_id = self.source_id
document.meta = meta
document.type = type or self.DOCUMENT_TYPE
db.session.add(document)
db.session.flush()
return document
示例12: create_document
# 需要导入模块: from aleph.model import Document [as 别名]
# 或者: from aleph.model.Document import all [as 别名]
def create_document(self, meta, type=None):
if meta.content_hash:
q = Document.all()
if meta.foreign_id:
q = q.filter(Document.foreign_id == meta.foreign_id)
else:
q = q.filter(Document.content_hash == meta.content_hash)
clause = Collection.id == self.collection_id
q = q.filter(Document.collections.any(clause))
document = q.first()
if document is None:
document = Document()
document.collections = [Collection.by_id(self.collection_id)]
document.meta = meta
document.type = type or self.DOCUMENT_TYPE
db.session.add(document)
db.session.flush()
return document