python 項目編號 2025821 有關于中英文數據的收集、處理

python專欄記錄:



前言

批量讀取單詞 JSON 文件 → 解析出單詞、釋義、例句、短語 → 數據清洗(去掉特殊符號) → 同步更新到 MySQL 數據庫。

內容

import json
import pymysql
import re
import time
from pymysql.converters import escape_string
coon = pymysql.connect(host='1.116.27.26', port=3306, user='root', passwd='LzyLyy', charset='utf8mb4', autocommit=True)
coon.select_db('rookie_word')
cur = coon.cursor()
def replaceFran(str):fr_en = [['é', 'e'], ['ê', 'e'], ['è', 'e'], ['?', 'e'], ['à', 'a'], ['a', 'a'], ['?', 'c'], ['?', 'i'], ['?', 'i'],['?', 'o'], ['ù', 'u'], ['?', 'u'], ['ü', 'u'], ['?', 'y']]for i in fr_en:str = str.replace(i[0], i[1])return str
file = open('初高中詞匯/GaoZhongluan_2.json','r',encoding='utf-8')
word_list = []
for line in file.readlines():words = line.strip()word_json = json.loads(words)#單詞word = word_json['headWord']try:sentence = word_json['content']['word']['content']['sentence']['sentences']  # 例句sentence_list = []for se in sentence:enSe = se['sContent']enTrans = se['sCn']sen = str(enSe) + str(enTrans)sentence_list.append(sen)# 例句資源sentence_ressentence_res = ''if(len(sentence_list)>=3):for i in range(3):sentence_res += str(sentence_list[i]) + ' | ' if(i < 2) else str(sentence_list[i])else:for l in range(len(sentence_list)):sentence_res += str(sentence_list[l])+ ' | ' if(l == len(sentence_list)) else str(sentence_list[l])except:sentence_res = ''# try:#     usphone = '美[' + word_json['content']['word']['content']['usphone']+']'  # 美式音標#     usphone_er = usphone.find('(for')#     if (usphone_er != -1):#         usphone = ''# except:#     usphone = ''# try:#     ukphone = '英[' + word_json['content']['word']['content']['ukphone']+']'  # 英式音標#     ukphone_er = ukphone.find('(for')#     if (ukphone_er != -1):#         ukphone = ''# except:#     ukphone = ''# #音標pronounce# pronounce = (usphone + '|' + ukphone).replace('?', '\'')   # .replace('\'', '-').replace('?', '-')try:phrase = word_json['content']['word']['content']['phrase']['phrases']# 短語資源pharse_rephrase_re = ''if(len(phrase)>=4):for ph in range(4):ph_content = phrase[ph]['pContent']ph_cn = phrase[ph]['pCn']phrase_re += (str(ph_content) + ' ' + str(ph_cn))+' | ' if ph < 3 else (str(ph_content) + ' ' + str(ph_cn))else:for ph in range(len(phrase)):ph_content = phrase[ph]['pContent']ph_cn = phrase[ph]['pCn']phrase_re += (str(ph_content) + ' ' + str(ph_cn)) if ph < len(phrase) - 1 else (str(ph_content) + ' ' + str(ph_cn) + ' | ')except:phrase_re = ''trans = word_json['content']['word']['content']['trans']  # 釋義# 釋義資源trans_re = ''for tr in range(len(trans)):try:pos = trans[tr]['pos']except:pos = ''tranCn = trans[tr]['tranCn']try:tranOther = trans[tr]['tranOther']except:tranOther = ''trans_re += (str(pos) + ' ' + str(tranCn) + ' ' + str(tranOther)) if tr < len(trans) - 1 else (str(pos) + ' ' + str(tranCn) + ' ' + str(tranOther) + ' | ')#釋義trans_re = replaceFran(trans_re)#例句sentence_res = replaceFran(sentence_res)#短語phrase_re = replaceFran(phrase_re)# print(word_json['wordRank'])# print('單詞:'+word)# print('例句:' + sentence_res)# print('音標:' + str(pronounce))# print('短語:' + phrase_re)# print('釋義:' + trans_re)sql = 'select * from word where word=%s'word_res = cur.execute(sql, word)if(word_res!=0):print(str(word) + '已存在')sql_l = 'select * from word_label where word=%s and label_id=%s'label_res = cur.execute(sql_l, [word, 18])if(label_res==0):sql_word_label = 'insert into word_label values(%s,%s)'cur.execute(sql_word_label, [word, 18])coon.commit()print(str(word + '已加入新標簽'))time.sleep(0.5)else:print(str(word) + '標簽已經滿')else:sql_word = 'UPDATE word SET explain_word= %s,sentence= %s,other= %s WHERE word= %s'cur.execute(sql_word, [trans_re, sentence_res, phrase_re, word])# sql_word = 'insert into word(word, pronounce, explain_word, sentence, other, word_source) values(%s,%s,%s,%s,%s,%s)'# cur.execute(sql_word, [word, pronounce, trans_re, sentence_res, phrase_re, 0])coon.commit()# sql_label = 'insert into word_label values(%s,%s)'# cur.execute(sql_label, [word, 18])# coon.commit()time.sleep(0.1)print('單詞:' + word + ' 已更新')

知識內容

數據庫
文本清洗
json數據處理


總結

阿巴。。。今天又水了一天

需要json文件的聯系我


致謝

靠咖啡續命的牛馬,👍點贊 📁 關注 💬評論 💰打賞。


參考

[1] deepseek等ai


往期回顧

  • 無,新手上車

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/919635.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/919635.shtml
英文地址,請注明出處:http://en.pswp.cn/news/919635.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Document Solutions .NET Bundle 8.2.0

Document Solutions .NET Bundle 8.2.0MESCIUS 的 Document Solutions .NET Bundle 是一套完整的 API 和查看工具&#xff0c;可增強文檔處理并提高效率。它包含 Excel、Word、PDF 和圖像文檔&#xff0c;以及 PDF 查看器、數據查看器和圖像查看器的標準許可證。它將強大的 .NE…

在職老D滲透日記day20:sqli-labs靶場通關(第27關)get報錯注入 過濾select和union ‘閉合

5.27.第27關 get報錯注入 過濾select和union 閉合function blacklist($id) { $id preg_replace(/[\/\*]/,"", $id); //strip out /* $id preg_replace(/[--]/,"", $id); //Strip out --. $id preg_replace(/[#]/,"", $id); //Strip out #. $…

Go 并發編程-channel

channel 文章目錄channel簡介基本概念類型表示法值表示法操作的特性初始化通道接收元素值Happens before發送值例1核心組件關鍵執行順序輸出示例&#xff08;可能順序&#xff09;設計要點例2例3關閉通道長度與容量單向通道主要用途增強代碼表達性和安全性&#xff08;最重要的…

開源和免費一樣嗎?以商城系統為例為您分析~

開源和免費并不完全一樣&#xff0c;二者在核心定義、權利范圍和實際應用中存在顯著區別&#xff0c;具體可以從以下幾個方面理解&#xff1a; 1. 核心定義不同開源&#xff08;Open Source&#xff09;&#xff1a; 指軟件的源代碼是公開可獲取的&#xff0c;任何人都可以查看…

CMOS知識點 MOS管飽和區電流公式

知識點16&#xff1a;同上篇一樣&#xff0c;MOS管主要有3個工作區域&#xff1a;截止區&#xff08;Cut-off Region&#xff09;&#xff1a; < &#xff0c;沒有溝道形成&#xff0c;幾乎沒有電流。線性區/三極管區&#xff08;Triode Region&#xff09;&#xff1a; &g…

【集合框架LinkedList底層添加元素機制】

在 Java 集合框架中&#xff0c;LinkedList 與 ArrayList 是兩種截然不同的線性表實現。如果說 ArrayList 像一個可以伸縮的“盒子陣列”&#xff0c;那么 LinkedList 就像一條由“節點”串聯而成的“雙向鏈條”。今天&#xff0c;我們將深入 LinkedList 的源碼&#xff0c;一步…

《P2700 逐個擊破》

題目背景三大戰役的平津戰場上&#xff0c;傅作義集團在以北平、天津為中心&#xff0c;東起唐山西至張家口的鐵路線上擺起了一字長蛇陣&#xff0c;并企圖在潰敗時從海上南逃或向西逃竄。為了就地殲敵不讓其逃走&#xff0c;指揮官制定了先切斷敵人東西兩頭退路然后再逐個殲滅…

C6.0:晶體管放大器的原理與應用(基極偏置篇)

將晶體管Q點偏置在負載線中點附近后&#xff0c;如果將一個小的交流信號耦合到基極上&#xff0c;便會產生一個交流的集電極電壓&#xff0c;交流集電極電壓與交流基極電壓波形相似&#xff0c;但是幅度要大了很多&#xff0c;即交流集電極電壓是對交流基極電壓的放大。本篇學習…

Oracle: cannot decrease column length because some value is too big

1.背景今天項目上查不到數據,查庫發現默認20位的字段被改為了200,用的還是char類型&#xff0c;填充了一堆空格 2.知識LENGTH() 函數用于計算字符串字段 長度TRIM() 函數用于去除字符串字段 column 前后的空格&#xff08;默認&#xff09;或指定字符&#xff1a;SUBSTR() 用于…

Elasticsearch 寫入全鏈路:從單機到集群

0. 先把術語擺正 Index&#xff08;索引&#xff09;&#xff1a;邏輯數據集合&#xff0c;≈ MySQL 的庫。Document&#xff08;文檔&#xff09;&#xff1a;一條 JSON 數據&#xff0c;≈ MySQL 的行。Field&#xff08;字段&#xff09;&#xff1a;文檔里的鍵值&#xff0…

Java多線程編程——基礎篇

目錄 前言 一、進程與線程 1、進程 2、線程 二、并發與并行 1、并發 2、并行 三、線程調度 1、CPU時間片 2、調度方式 ①時間片輪轉 ②搶占式調度 四、線程實現方式 1、繼承 Thread 類 Thread的多種構造函數&#xff1a; 2、實現 Runnable 接口 五、線程的核心方法 1、start() …

阿里云的centos8 服務器安裝MySQL 8.0

在 CentOS 8 上安裝 MySQL 8.0 可以通過添加 MySQL 官方 YUM 倉庫并使用 dnf 命令安裝。以下是具體步驟&#xff1a; 步驟如下&#xff1a; 下載并添加 MySQL 官方 YUM 倉庫 運行以下命令下載 MySQL 8.0 的 YUM 倉庫配置文件&#xff1a; sudo dnf install https://dev.mysql.…

【運維進階】Linux 正則表達式

Linux 正則表達式定義&#xff1a;正則表達式是一種pattern&#xff08;模式&#xff09;&#xff0c;用于與待搜索字符串匹配&#xff0c;以查找一個或多個目標字符串。組成&#xff1a;自成體系&#xff0c;由兩類字符構成普通字符&#xff1a;未被顯式指定為元字符的所有可打…

STM32輸入捕獲相位差測量技術詳解(基于TIM1復位模式)

本文將深入解析基于STM32定時器輸入捕獲功能的方波相位差測量技術&#xff0c;通過復位模式實現高精度相位檢測。以下是完整的代碼實現與詳細原理分析。一、相位差測量原理相位差測量基于兩個同頻方波信號下降沿時間差計算。核心原理&#xff1a;?復位模式?&#xff1a;將TIM…

什么是股指期貨可轉移阿爾法策略?

阿爾法&#xff08;Alpha&#xff09;是投資領域的一個術語&#xff0c;用來衡量投資組合的超額收益。簡單來說&#xff0c;阿爾法就是你在市場上賺的比平均水平多出來的那部分錢。比如&#xff0c;市場平均收益率是5%&#xff0c;但你的投資組合收益率是10%&#xff0c;那你的…

AXI GPIO S——ZYNQ學習筆記10

AXI GPIO 同意通道混合輸入輸出中斷控制#KEY set_property IOSTANDARD LVCMOS18 [get_ports {AXI_GPIO_KEY_tri_io[0]}] set_property PACKAGE_PIN J13 [get_ports {AXI_GPIO_KEY_tri_io[0]}] set_property IOSTANDARD LVCMOS18 [get_ports {AXI_GPIO_KEY_tri_io[1]}] set_pro…

如何通過傳感器選型優化,為設備壽命 “續航”?

在當今競爭激烈的工業領域&#xff0c;企業就像在一場沒有硝煙的戰爭中角逐&#xff0c;設備便是企業的“秘密武器”。設備的使用壽命&#xff0c;如同武器的耐用程度&#xff0c;直接決定了企業在生產戰場上的“戰斗力”。延長設備壽命&#xff0c;已然成為眾多企業降低生產成…

WebSocket連接的例子

// 初始化WebSocket連接 const initWebSocket () > {console.log("初始化鏈接中...")const websocketUrl ws://61.54.84.16:9090/;// WebSocket服務器地址websocket new WebSocket(websocketUrl)//使用真實的webscket// websocket new MockWebSocket(websocket…

c++之指針和引用

一 使用場景 C++ 什么時候使用指針?什么時候使用引用?什么時候應該按值傳遞?_引用什么時候用比較好-CSDN博客 只使用傳遞過來的值,而不對值進行修改 需要修改傳遞過來的值 內置數據類型 按值傳遞(小型結構) 指針傳遞 數組 指針傳遞 指針傳遞 結構 指針或引用(較大的結構…

pytorch學習筆記-模型訓練、利用GPU加速訓練(兩種方法)、使用模型完成任務

應該算是完結啦~再次感謝土堆老師&#xff01; 模型訓練 模型訓練基本可以分為以下幾個步驟按序執行&#xff1a; 引入數據集-使用dataloader加載數據集-建立模型-設置損失函數-設置優化器-進行訓練-訓練中計算損失&#xff0c;并使用優化器更新參數-模型測試-模型存儲 習慣上會…