首页 > 数据库 >数据库处理

数据库处理

时间:2024-07-10 20:31:03浏览次数:10  
标签:files pairs similarity 处理 数据库 results unmatched cursor


def store_results_to_db(results, db_dir):
    # 遍历每个子目录的结果
    for common_dir, data in results.items():
        # 跳过非字典类型的条目,如unmatched_files_A和unmatched_files_B
        if not isinstance(data, dict) or common_dir in ('unmatched_files_A', 'unmatched_files_B', 'high_similarity_pairs', 'low_similarity_pairs'):
            continue

        # 创建子目录对应的数据库文件
        db_path = os.path.join(db_dir, f'{common_dir}.db')
        conn = sqlite3.connect(db_path)
        cursor = conn.cursor()

        # 创建表
        cursor.execute('''CREATE TABLE IF NOT EXISTS unmatched_files_A (
                        file_name TEXT
                        )''')

        cursor.execute('''CREATE TABLE IF NOT EXISTS unmatched_files_B (
                        file_name TEXT
                        )''')

        cursor.execute('''CREATE TABLE IF NOT EXISTS high_similarity_pairs (
                        imgA TEXT,
                        imgB TEXT,
                        similarity REAL
                        )''')

        cursor.execute('''CREATE TABLE IF NOT EXISTS low_similarity_pairs (
                        imgA TEXT,
                        imgB TEXT,
                        similarity REAL
                        )''')

        # 插入 unmatched_files_A 和 unmatched_files_B 数据
        unmatched_files_A = results.get('unmatched_files_A', {}).get(common_dir, [])
        for file_name in unmatched_files_A:
            cursor.execute('INSERT INTO unmatched_files_A (file_name) VALUES (?)',
                           (file_name,))

        unmatched_files_B = results.get('unmatched_files_B', {}).get(common_dir, [])
        for file_name in unmatched_files_B:
            cursor.execute('INSERT INTO unmatched_files_B (file_name) VALUES (?)',
                           (file_name,))

        # 插入 high_similarity_pairs 和 low_similarity_pairs 数据
        high_similarity_pairs = results.get('high_similarity_pairs', [])
        for imgA, imgB, similarity in high_similarity_pairs:
            cursor.execute('INSERT INTO high_similarity_pairs (imgA, imgB, similarity) VALUES (?, ?, ?)',
                           (imgA, imgB, similarity))

        low_similarity_pairs = results.get('low_similarity_pairs', [])
        for imgA, imgB, similarity in low_similarity_pairs:
            cursor.execute('INSERT INTO low_similarity_pairs (imgA, imgB, similarity) VALUES (?, ?, ?)',
                           (imgA, imgB, similarity))

        conn.commit()
        conn.close()

# 使用函数
dirA = r'D:/Code/PDF_to_img/PDFCORE_PDF_IMG_BACKGROUND'
dirB = r'D:/Code/PDF_to_img/LIBHARU_PDF_IMG_BACKGROUND'
pixel_threshold = 50
sector_threshold = 5
sector=72
similarity_threshold = 70
not_similarity_threshold = 30
db_dir= r"Db_DIR"
# 使用函数
results = compare_directories(dirA, dirB, pixel_threshold, sector_threshold,similarity_threshold,not_similarity_threshold)

store_results_to_db(results, db_dir)

标签:files,pairs,similarity,处理,数据库,results,unmatched,cursor
From: https://www.cnblogs.com/DINGJINXING/p/18294940

相关文章

  • 【VMware vCenter】VMware vCenter Server(VCSA) 5.5 版本证书过期问题处理过程。
    之前帮客户处理了一个因证书过期导致vCenterServer无法登录的问题,在此记录一下,因为时间过去有点久了,可能会有些地方描述的不是很清楚,所以就当作参考就行。客户环境是一个非常老的vCenterServer5.5版本并基于Linux版本的VCSA(当时这个版本还有基于Windows的,注意区别),早......
  • "HIBERNATE_SEQUENCE" does not exist问题处理
    JavaWeb应用在MySQL环境下可以正常运行,数据迁移至Oracle或者人大金仓后应用运行爆出如下错误:严重:Servlet.service()forservlet[JeeCmsAdmin]incontextwithpath[/dhccms]threwexception[org.hibernate.exception.SQLGrammarException:couldnotgetnextsequence......
  • 如何通过SRA Tools处理从NCBI获得的SRA数据
    1.安装SRATools通过SRAToolkit可以方便的从NCBI下载SRA数据,但是速度较慢,Aspera虽然快,但是难点在于找NCBI的源文件地址,而且SRAToolkit好像可以调用Aspera(虽然还没找到方法)具体操作可以参考这个帖子,下载安装很容易,主要是配置环境要配置好,不然用不了https://blog.csdn.net/m0_6......
  • 【Python&RS】基于Python分块处理大型遥感影像的方法
    ​    RSer工作时不可避免会用到大型的遥感影像,由于分辨率过高、区域过大、波段信息过多等原因,都会导致数据非常的大。这个时候我们在进行一些简单的操作,如计算NDVI、二值化、分类等时,计算机的内存都会溢出。因此今天跟大家分享一下我平时分块的方法,中间如何计算就按照......
  • 常见数据库类型和选取详解
    数据库是用于存储、检索和管理数据的系统。它们可以根据数据模型的不同被分类为不同类型。以下是一些常见的数据库类型和它们的选取详解:1.关系型数据库(RDBMS)特点:使用表格(tables)来组织数据。基于严格定义的数据模型和关系。支持SQL(结构化查询语言)进行数据查询和操作。常......
  • laravel: 安装完后配置session使用文件而非使用数据库
    一,报错信息:laravel在安装完成后初次运行时会报错,InternalServerErrorIlluminate\Database\QueryExceptionSQLSTATE[HY000]:Generalerror:8attempttowriteareadonlydatabase(Connection:sqlite,SQL:update"sessions"set"payload"=YTozOntzOjY......
  • 你真的懂多线程吗?多线程 并行处理 CPU 操作系统
    了解多线程、并行处理首先需要了解什么CPU、CPU核数、操作系统CPU物理数即电脑拥有的物理CPU数量,普通电脑一般只有一个CPU插槽,也就是只有一个物理CPU。我们日常说的CPU,就是指封装好的一个物理CPU,作为商品进行售卖。但在编程讨论时,某些情况下,我们说的CPU含义又是指其中一个运算......
  • insert into....select从一个数据库的表中导入到另一个数据库的表中
    说明已知条件:有两台oracle数据库,ora1和ora2,ora1的表中有数据(ip:192.0.0.1,表名table1,用户名和密码:yth(有管理员的权限),数据库服务名:orcl),需要导入ora2中(ip:192.0.0.2,表名table2,用户名和密码:ythcj(有管理员的权限),数据库服务名:orcl)。1.在ora2中建立数据库的链接指向ora1(需要有管理员......
  • 基于单层LSTM模型的文本序列预测:从预处理到字符预测的完整流程
    数据集我的数据集就是重复的两句话,重复了几百次。引言在自然语言处理(NLP)领域,序列预测是一个非常重要的任务,它涉及到根据已有的文本序列来预测接下来的内容。近年来,循环神经网络(RNN)及其变体,如长短时记忆网络(LSTM),因其能够有效处理序列数据中的长期依赖关系而广受青睐。本博客......
  • Linux环境下安装DM8数据库
    文章目录一、安装包下载二、新建组和用户三、设置文件打开最大数四、创建目录及修改目录权限五、挂载镜像及数据库安装六、配置数据库实例七、注册服务八、运行数据库(启动,停止,重启,查看数据库状态和端口号等)总结一、安装包下载官方下载网址:https://eco.dameng.com......