Spaces:
Runtime error
Runtime error
Delete count.py
Browse files
count.py
DELETED
|
@@ -1,35 +0,0 @@
|
|
| 1 |
-
import re
|
| 2 |
-
|
| 3 |
-
def count_chars_words(sentence):
|
| 4 |
-
# 使用正则表达式分割句子,其中中文按字分割,英文按词分割
|
| 5 |
-
segments = re.findall(r'[\u4e00-\u9fa5]+|\w+', sentence)
|
| 6 |
-
|
| 7 |
-
# 统计字符数和词数
|
| 8 |
-
char_count = 0
|
| 9 |
-
word_count = 0
|
| 10 |
-
for segment in segments:
|
| 11 |
-
# print(segment)
|
| 12 |
-
if re.match(r'[\u4e00-\u9fa5]+', segment): # 中文部分,每个汉字算一个字符
|
| 13 |
-
char_count += len(segment)
|
| 14 |
-
else: # 英文部分,每个单词算一个词
|
| 15 |
-
word_count += len(segment.split())
|
| 16 |
-
|
| 17 |
-
return char_count + word_count
|
| 18 |
-
|
| 19 |
-
sentence = "如果您 want to deploy the 模型并进行推理"
|
| 20 |
-
count = count_chars_words(sentence)
|
| 21 |
-
print(f"字符数:{count}")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
sentence = "今天天气真好,我们一起出去吃饭吧。"
|
| 25 |
-
count = count_chars_words(sentence)
|
| 26 |
-
print(f"字符数:{count}")
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
sentence = "我最近在学习machine learning,希望能够在未来的artificial intelligence领域有所建树。"
|
| 30 |
-
count = count_chars_words(sentence)
|
| 31 |
-
print(f"字符数:{count}")
|
| 32 |
-
|
| 33 |
-
sentence = "El resplandor del sol acaricia las olas, pintando el cielo con una paleta deslumbrante。"
|
| 34 |
-
count = count_chars_words(sentence)
|
| 35 |
-
print(f"字符数:{count}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|