V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  superychen  ›  全部回复第 2 页 / 共 4 页
回复总数  77
1  2  3  4  
我当分子吧😄
<iframe
src="https://carbon.now.sh/embed?bg=rgba%2874%2C74%2C74%2C1%29&t=vscode&wt=none&l=python&width=680&ds=true&dsyoff=20px&dsblur=68px&wc=true&wa=true&pv=56px&ph=56px&ln=false&fl=1&fm=Hack&fs=14px&lh=133%25&si=false&es=2x&wm=false&code=import%2520opencc%250Aimport%2520re%250Afrom%2520difflib%2520import%2520SequenceMatcher%250A%250APATTERN_CHINESE%2520%253D%2520re.compile%28r%27%255B%255Cu4e00-%255Cu9fa5%255D%27%29%250ACONVERTER%2520%253D%2520opencc.OpenCC%28%2522t2s%2522%29%250A%250A%2523%2520%25E5%258F%25AA%25E4%25BF%259D%25E7%2595%2599%25E4%25B8%25AD%25E6%2596%2587%250Adef%2520clean%28text%29%253A%250A%2520%2520%2520%2520return%2520%27%27.join%28PATTERN_CHINESE.findall%28text%29%29%250A%250A%2523%2520%25E7%25B9%2581%25E4%25BD%2593%25E8%25BD%25AC%25E7%25AE%2580%25E4%25BD%2593%250Adef%2520simplify%28text%29%253A%250A%2520%2520%2520%2520return%2520CONVERTER.convert%28text%29%250A%250A%2523%2520%25E6%25AF%2594%25E8%25BE%2583%25E6%2596%2587%25E6%259C%25AC%250Adef%2520compare_text%28text1%252C%2520text2%29%253A%250A%2520%2520%2520%2520text1%2520%253D%2520clean%28text1%29%250A%2520%2520%2520%2520text2%2520%253D%2520clean%28text2%29%250A%2520%2520%2520%2520text1a%2520%253D%2520simplify%28text1%29%250A%2520%2520%2520%2520text2a%2520%253D%2520simplify%28text2%29%250A%2520%2520%2520%2520matcher%2520%253D%2520SequenceMatcher%28None%252C%2520text1a%252C%2520text2a%29%250A%2520%2520%2520%2520diffs%2520%253D%2520matcher.get_opcodes%28%29%250A%2520%2520%2520%2520index%2520%253D%25200%250A%2520%2520%2520%2520for%2520tag%252C%2520i1%252C%2520i2%252C%2520j1%252C%2520j2%2520in%2520diffs%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520if%2520tag%2520%253D%253D%2520%27replace%27%253A%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520index%2520%252B%253D%25201%250A%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520%2520print%28f%27%257Bindex%257D.%2520%257Btext1%255Bi1%253Ai2%255D%257D%2520%253C-%253E%2520%257Btext2%255Bj1%253Aj2%255D%257D%27%29%250A%250A%2523%2520%25E7%25AE%2580%25E4%25BD%2593%25E8%25BD%25AC%25E7%25B9%2581%25E4%25BD%2593%250Asimplified_text%2520%253D%2520%27%27%27%25E5%25BA%258A%2520%25E5%2589%258D%2520%25E7%259C%258B%2520%25E6%259C%2588%2520%25E5%2585%2589%250A%250A%25E7%2596%2591%2520%25E6%2598%25AF%2520%25E5%259C%25B0%2520%25E4%25B8%258A%2520%25E9%259C%259C%250A%250A%25E4%25B8%25BE%2520%25E5%25A4%25B4%2520%25E6%259C%259B%2520%25E5%25B1%25B1%2520%25E6%259C%2588%250A%250A%25E4%25BD%258E%2520%25E5%25A4%25B4%2520%25E6%2580%259D%2520%25E6%2595%2585%2520%25E4%25B9%25A1%27%27%27%250Atraditional_text%2520%253D%2520%27%27%27%25E7%2589%2580%25E5%2589%258D%25E6%2598%258E%25E6%259C%2588%25E5%2585%2589%25EF%25BC%258C%25E7%2596%2591%25E6%2598%25AF%25E5%259C%25B0%25E4%25B8%258A%25E9%259C%259C%25E3%2580%2582%250A%250A%25E8%2588%2589%25E9%25A0%25AD%25E6%259C%259B%25E6%2598%258E%25E6%259C%2588%25EF%25BC%258C%25E4%25BD%258E%25E9%25A0%25AD%25E6%2580%259D%25E6%2595%2585%25E9%2584%2589%25E3%2580%2582%27%27%27%250A%250Acompare_text%28simplified_text%252Ctraditional_text%29"
style="width: 673px; height: 951px; border:0; transform: scale(1); overflow:hidden;"
sandbox="allow-scripts allow-same-origin">
</iframe>
```python
import opencc
import re
from difflib import SequenceMatcher

PATTERN_CHINESE = re.compile(r'[\u4e00-\u9fa5]')
CONVERTER = opencc.OpenCC("t2s")

# 只保留中文
def clean(text):
return ''.join(PATTERN_CHINESE.findall(text))

# 繁体转简体
def simplify(text):
return CONVERTER.convert(text)

# 比较文本
def compare_text(text1, text2):
text1 = clean(text1)
text2 = clean(text2)
text1a = simplify(text1)
text2a = simplify(text2)
matcher = SequenceMatcher(None, text1a, text2a)
diffs = matcher.get_opcodes()
index = 0
for tag, i1, i2, j1, j2 in diffs:
if tag == 'replace':
index += 1
print(f'{index}. {text1[i1:i2]} <-> {text2[j1:j2]}')

# 简体转繁体
simplified_text = '''床 前 看 月 光

疑 是 地 上 霜

举 头 望 山 月

低 头 思 故 乡'''
traditional_text = '''牀前明月光,疑是地上霜。

舉頭望明月,低頭思故鄉。'''

compare_text(simplified_text,traditional_text)
```
字数都一样么?问问 gpt 就能用 python 给你生成个代码
2023-12-08 15:13:19 +08:00
回复了 yzqdm 创建的主题 Java 请教一下 Java 写物联网项目监控设备上下线方案
2023-10-07 11:34:09 +08:00
回复了 sloknyyz 创建的主题 Google Google 真是臉都不要了
我前三条也是赞助商广告。。。
2023-09-25 14:48:45 +08:00
回复了 dingwen07 创建的主题 Android 已经确认淘宝正在刻意访问用户全部图库
@shijingshijing 菜鸟的和这个差不多,文案 是进行运单号扫描查件等功能,恶心的就是每次都弹这个框
2023-09-25 09:06:35 +08:00
回复了 dingwen07 创建的主题 Android 已经确认淘宝正在刻意访问用户全部图库
我在 iOS 上的菜鸟裹裹最近每次打开扫码都会提示 菜鸟想访问你的照片,并提供了选择更多照片和保留当前所选内容两个选项,我每次都选择保留当前所选内容,但下次扫码还是会弹出这个框
2023-09-22 13:10:08 +08:00
回复了 jiejianshiwa 创建的主题 Android 手機帶殼的防摔能力是不帶殼的 100 倍
没带壳的话我的手机可能已经摔坏 10 次了😂
2023-09-13 09:38:25 +08:00
回复了 Socrazy 创建的主题 推广 猫主食罐头半价优惠,免费送 20 罐,欢迎盖楼抽免单
凑个热闹,家里三只😀
2023-09-13 08:58:07 +08:00
回复了 zhangsimon 创建的主题 推广 中秋来送秋月梨😋, V 站福利回帖抽奖!🔥
分母+10086
2023-07-13 10:16:40 +08:00
回复了 JasonLaw 创建的主题 程序员 Java - 如果根据参数类型调用不同的方法?
@JasonLaw 那感觉只能为每个 class 类型指定 toString 方法,最后根据 class 类型直接找对应方法进行转换


private static final Map<Class<?>, Function<Object, String>> FUNCTIONS = Map.of(
String.class, String::valueOf,
Integer.class, String::valueOf,
Instant.class, Object::toString
);

public void put(String key, Object v) {
map.put(key, null == v ? null : FUNCTIONS.get(v.getClass()).apply(v));
}
2023-07-13 09:27:14 +08:00
回复了 JasonLaw 创建的主题 程序员 Java - 如果根据参数类型调用不同的方法?
```java
class DataContainer {

private final Map<String, String> map = new HashMap<>();

public void put(String key, Object v) {
map.put(key, null == v ? null : String.valueOf(v));
}

public String get(String k) {
return map.get(k);
}

}
```
2023-07-13 09:24:37 +08:00
回复了 JasonLaw 创建的主题 程序员 Java - 如果根据参数类型调用不同的方法?
按照你这个代码,为啥还要区分 String 和 Integer ?直接一个 put(String k, Object v),里面 map.put(k, String.valueOf(v))不可以吗,如果 v 是 String ,调用一次 String.valueOf(v)也没啥问题
2023-07-13 09:01:13 +08:00
回复了 cncmmdwl 创建的主题 设计 有谁知道为什么 m.baidu 特别喜欢给用户放视频?
为什么我手机每次 chrome 打开百度网页都要定位权限。。
2023-07-12 15:26:45 +08:00
回复了 hobbyliu 创建的主题 分享发现 帮运维同学撸了个 crontab 表达式在线生成器的轮子
@hteen 😲😲😲
站里刚看到一个找 php 的 /t/954829
2023-07-07 13:38:42 +08:00
回复了 ARslince 创建的主题 问与答 老哥你们的头发还好吗?发量咋样
已经好几年没听理发师说我头发厚了
2023-07-07 10:51:02 +08:00
回复了 iaoiand 创建的主题 问与答 最近针对 iPhone 用户的垃圾信息骚扰手段升级了?
共享的我也收到好几次了
1  2  3  4  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5331 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 31ms · UTC 06:58 · PVG 14:58 · LAX 22:58 · JFK 01:58
Developed with CodeLauncher
♥ Do have faith in what you're doing.