def get_db(): db = SessionLocal() try: yield db finally: db.close()
def test_callback(a, b): pass @nb.jit(nopython=True) def calculate(doc_x, doc_y): euclidean_distance = np.linalg.norm(doc_x - doc_y) if np.argmax(doc_x) == np.argmax(doc_y): return euclidean_distance * 0.4 return euclidean_distance session = SessionLocal() comments = crud.get_bilibili_video_comments_by_vid(4, session) session.close() docs = [comment.text for comment in comments] text_preprocessing = TextPreprocessing(CorpusLanguage.Chinese, docs) text_preprocessing.start() if False: ss_nmf = SSNMFTopicModel(test_callback, text_preprocessing.tfidfWD, 10, 20, 1000, 1e-4, 2020) time_start = time.time() ss_nmf.fit_original_nmf_cjlin_nnls() time_end = time.time() print(f'花费{time_end - time_start}秒') # 获取主题摘要 bag_words = text_preprocessing.bagWords
from crud import create_user, create_blogpost from database import SessionLocal from models import BlogPost, User faker = Faker() db = SessionLocal() for _ in range(100): name = faker.name() address = faker.address() phone = faker.msisdn() email = f'{name.replace(" ", "_")}@email.com' new_user = User(name=name, address=address, phone=phone, email=email) create_user(db=db, user=new_user) for _ in range(100): title = faker.sentence(5) body = faker.paragraph(190) date = faker.date_time() user_id = randrange(1, 100) new_post = BlogPost(title=title, body=body, date=date) create_blogpost(db=db, blogpost=new_post, user_id=user_id) db.close() #TODO: Add rich library to get visual feedback
async def get_db(): try: db = SessionLocal() yield db finally: db.close()
def hw_get_voo(id): session = SessionLocal() voo = session.query(Voo).filter_by(id=id).all() voo_json = populate_voo(voo) session.close() return voo_json
def hw_get_voos_aeroportos(): session = SessionLocal() voos = session.query(Voo).order_by(Voo.data.asc()).all() voos_json = populate_voo_aeroporto(voos) session.close() return voos_json
def get_db(): try: db = SessionLocal() # 本地会话 yield db finally: db.close()