Ejemplo n.º 1
0
def Error_Test(test):
    try:
        stats_word.stats_text_en(test, print_text=False)
    except ValueError as VE:
        print('Error =>', VE)
        return False
    else:
        return True
Ejemplo n.º 2
0
# his wisdom. When he saw their back-breaking labour, he ridiculed
# Yugong saying,”Aren’t you foolish, my friend? You are very old now,
# and with whatever remains of your waning strength, you won’t be able
# to remove even a corner of the mountain.”
# Yugong uttered a sigh and said,”A biased person like you will never
# understand. You can’t even compare with the widow’s little boy!”
# “Even if I were dead, there will still be my children, my
# grandchildren, my great grandchildren, my great great grandchildren.
# They descendants will go on forever. But these mountains will not
# grow any taler. We shall level them one day!” he declared with
# confidence.
# The wise old man was totally silenced.
# When the guardian gods of the mountains saw how determined Yugong and
# his crew were, they were struck with fear and reported the incident
# to the Emperor of Heavens.
# Filled with admiration for Yugong, the Emperor of Heavens ordered two
# mighty gods to carry the mountains away.

# '''

text = ["a", "b"]

# 任务2. 运行 python main.py,查看功能是否生效
# stats_word.stats_text_en(text)

if __name__ == "__main__":
    try:
        stats_word.stats_text_en(text)
    except ValueError as err:
        print(err)
Ejemplo n.º 3
0
def main():
    a = 123
    #if Error_Test(text):
    #    stats_word.stats_text_en(text,print_text=True)
    if Error_Test(a):
        stats_word.stats_text_en(a, print_text=True)
Ejemplo n.º 4
0
of Bohai.
Now Yugong’s neighbour was a widow who had an only child eight years
old. Evening the young boy offered his help eagerly.
Summer went by and winter came. It took Yugong and his crew a full
year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected
for his wisdom. When he saw their back-breaking labour, he ridiculed
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong
and his crew were, they were struck with fear and reported the
incident to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered
two mighty gods to carry the mountains away.
'''

stats_word.stats_text(100)
stats_word.stats_text(True)
stats_word.stats_text_cn(230)
stats_word.stats_text_cn(False)
stats_word.stats_text_en(300)
stats_word.stats_text_en(False)
Ejemplo n.º 5
0
year to travel back and forth once.
On the bank of the Yellow River dwelled an old man much respected
for his wisdom. When he saw their back-breaking labour, he ridiculed
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong
and his crew were, they were struck with fear and reported the
incident to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered
two mighty gods to carry the mountains away.
'''

import stats_word as sw 
sw.stats_text(text, 30)
sw.stats_text_cn(text,30)
sw.stats_text_en(text,30)

import json
with open('tang300.json', 'r', encoding='utf-8') as f:
    data = json.load(f)
data = str(data)
sw.stats_text_cn(data,100)
Ejemplo n.º 6
0
his crew were, they were struck with fear and reported the incident
to the Emperor of Heavens.

Filled with admiration for Yugong, the Emperor of Heavens ordered two
mighty gods to carry the mountains away.
'''
text1 = []  # 'list'列表
text2 = {}  # 'dict'字典
text3 = ()  # 'tuple'元组

import stats_word 

try:  
    stats_word.stats_text(text1)    # 检查中英文词频异常
except Exception as e:  
    print('ValueError =>', e)
    
try:  
    stats_word.stats_text_cn(text2)  # 检查中文字频异常     
except Exception as e:  
    print('ValueError =>', e)

try:  
    stats_word.stats_text_en(text3)  # 检查英文词频异常
except Exception as e:  
    print('ValueError =>', e)

try:  
    stats_word.stats_text(text) # 验证参数检查是否生效
except Exception as e:  
    print('ValueError =>', e)    
Ejemplo n.º 7
0
import stats_word
text = 89  #一个非字符串
try:  #执行正常的代码
    text_list = stats_word.stats_text_en(text)
    print(text_list)
except ValueError as identifier:  #如果检测到ValueError打印出来
    print('请输入字符串', identifier)
Ejemplo n.º 8
0
One day yugong gathered his family together and said,’’Let's do our best to level these two mountains. We shall open a road that leads to Yuzhou. What do you think?"

All but his wife agreed with him.
"You don't have the strength to cut even a small mound,” muttered his wife. "How on earth do you suppose you can level Mount Taixin and Mount Wanwu? Moreover, where will all the earth and rubble go?"
"Dump them into the Sea of Bohaii" said everyone.

So Yugong, his sons, and his grandsons started to break up rocks and remove the earth. They transported the earth and rubble to the Sea of Bohai.

Now Yugong's neighbour was a widow who had an only child eight years old. Evening the young boy offered his help eagerly.

Summer went by and winter came. It took Yugong and his crew a full year to travel back and forth once.

On the bank of the Yellow River dwelled an old man much respected for his wisdom. When he saw their back-breaking labour, he ridiculed Yugong sayingr"Aren't you foolish, my friend? You are very old now, and with whatever remains of your waning strength, you won't be able to remove even a corner of the mountain."

Yugong uttered a sigh and said,〃A biased person like you will never understand. You can't even compare with the widow's little boyl"

"Even if I were dead, there will still be my children, my grandchildren, my great grandchildren, my great great grandchildren. They descendants will go on forever. But these mountains will not grow any taler. We shall level them one day!” he declared with confidence.

The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and his crew were, they were struck with fear and reported the incident to the Emperor of Heavens.

Filled with admiration for Yugong, the Emperor of Heavens ordered two mighty gods to carry the mountains away.
'''
#在模块里调用指定函数(第三个合并的),参数是上头text文章。
print('合并词频统计结果: ', stats_word.stats_text(text))

try:
    stats_word.stats_text_en(123)
except ValueError:
    print('VALUEERROR')
Ejemplo n.º 9
0
def a(text):
    try:
        stats_word.stats_text_en(text)
    except ValueError:
        raise ValueError('请确认输入英文')
    return
Ejemplo n.º 10
0
Yugong was a ninety-year-old man who lived at the north of two high mountains, Mount Taixing and Mount Wangwu.

Stretching over a wide expanse of land, the mountains blocked yugong's way making it inconvenient for him and his family to get around.
One day yugong gathered his family together and said,’’Let's do our best to level these two mountains. We shall open a road that leads to Yuzhou. What do you think?"

All but his wife agreed with him.
"You don't have the strength to cut even a small mound,” muttered his wife. "How on earth do you suppose you can level Mount Taixin and Mount Wanwu? Moreover, where will all the earth and rubble go?"
"Dump them into the Sea of Bohaii" said everyone.

So Yugong, his sons, and his grandsons started to break up rocks and remove the earth. They transported the earth and rubble to the Sea of Bohai.

Now Yugong's neighbour was a widow who had an only child eight years old. Evening the young boy offered his help eagerly.

Summer went by and winter came. It took Yugong and his crew a full year to travel back and forth once.

On the bank of the Yellow River dwelled an old man much respected for his wisdom. When he saw their back-breaking labour, he ridiculed Yugong sayingr"Aren't you foolish, my friend? You are very old now, and with whatever remains of your waning strength, you won't be able to remove even a corner of the mountain."

Yugong uttered a sigh and said,〃A biased person like you will never understand. You can't even compare with the widow's little boyl"

"Even if I were dead, there will still be my children, my grandchildren, my great grandchildren, my great great grandchildren. They descendants will go on forever. But these mountains will not grow any taler. We shall level them one day!” he declared with confidence.

The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and his crew were, they were struck with fear and reported the incident to the Emperor of Heavens.

Filled with admiration for Yugong, the Emperor of Heavens ordered two mighty gods to carry the mountains away.
'''
#在模块里调用指定函数(第三个合并的),参数是上头text文章。
print('合并词频统计结果: ', stats_word.stats_text(text))

print(stats_word.stats_text_en(123))
Ejemplo n.º 11
0
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
安徽,简称“皖”,是中华人民共和国省级行政区。省会合肥。
位于中国华东,安徽界于东经114°54′-119°37′,北纬29°41′-34°38′之间,东连江苏、浙江,西接河南、湖北, 南邻江西,北靠山东,安徽省总面积14.01万平方千米。
安徽省居中靠东,沿江通海,有八百里的沿江城市群和皖江经济带,内拥长江水道,外承沿海地区经济辐射。地势由平原、丘陵、山地构成;地跨淮河、长江、钱塘江三大水系。
安徽省地处暖温带与亚热带过渡地区。淮河以北属暖温带半湿润季风气候,淮河以南为亚热带湿润季风气候。
安徽省是长三角的重要组成部分,处于全国经济发展的战略要冲和国内几大经济板块的对接地带,经济、文化和长江三角洲其他地区有着历史和天然的联系。
安徽文化发展源远流长,由徽州文化、淮河文化、皖江文化、庐州文化四个文化圈组成。截至2017年底,安徽省下辖16个省辖市,7个县级市,54个县,44个市辖区。
截至2018年末,安徽省常住人口6323.6万人,实现地区生产总值30006.8亿元,第一产业增加值2638亿元;第二产业增加值13842.1亿元;第三产业增加值13526.7亿元.
安徽省平原、台地(岗地)、丘陵、山地等类型齐全,可将全省分成淮河平原区、江淮台地丘陵区、皖西丘陵山地区、沿江平原区、皖南丘陵山地五个地貌区,
分别占全省面积的30.48%、17.56%、9.99%、24.91%和16.70%。安徽有天目-白际、黄山和九华山,三大山脉之间为新安江、水阳江、青弋江谷地,地势由山地核心向谷地渐次下降,
分别由中山、低山、丘陵、台地和平原组成层状地貌格局。山地多呈北东向和近东西向展布,其中最高峰为黄山莲花峰海拔1873米。山间大小盆地镶嵌其间,其中以休歙盆地为最大。'''

import stats_word

try:
    stats = stats_word.stats_text_cn(string1)
except ValueError:
    print("ValueError: You have an input that is not a string.")
else:
    print(stats)

try:
    stats = stats_word.stats_text_en(string1)
except ValueError:
    print("ValueError: You have an input that is not a string.")
else:
    print(stats)
Ejemplo n.º 12
0
#encoding=utf-8
import stats_word

text = ['人生苦短,我用python']

try:
    print(stats_word.stats_text_en(text))
except ValueError:
    print('输入对象必须为字符串类型')
Ejemplo n.º 13
0
    import stats_word
except :
	print('stats_word.py模块不在当前目录,程序出错退出')
	exit()

#####################
# 以下为测试程序
#####################
print('\n\n以下采用错误数据测试')
text_num=123456789

# 分别采用错误数据测试
print('测试stats_text =========')
print(stats_word.stats_text(text_num))
print('测试stats_text_en =========')
print(stats_word.stats_text_en(text_num))
print('测试stats_text_cn =========')
print(stats_word.stats_text_cn(text_num))

print('\n\n以下采用正确数据测试')
text_chr=' 严雨 and 风随心动 自学学习很有成就感 is very good'

# 分别采用正确数据测试
print('stats_text==========')
print('测试stats_text =========')
print(stats_word.stats_text(text_chr))
print('测试stats_text_en =========')
print(stats_word.stats_text_en(text_chr))
print('测试stats_text_cn =========')
print(stats_word.stats_text_cn(text_chr))
Ejemplo n.º 14
0
Yugong saying,”Aren’t you foolish, my friend? You are very old now,
and with whatever remains of your waning strength, you won’t be able
to remove even a corner of the mountain.”
Yugong uttered a sigh and said,”A biased person like you will never
understand. You can’t even compare with the widow’s little boy!”
“Even if I were dead, there will still be my children, my
grandchildren, my great grandchildren, my great great grandchildren.
They descendants will go on forever. But these mountains will not
grow any taler. We shall level them one day!” he declared with
confidence.
The wise old man was totally silenced.
When the guardian gods of the mountains saw how determined Yugong and
his crew were, they were struck with fear and reported the incident
to the Emperor of Heavens.
Filled with admiration for Yugong, the Emperor of Heavens ordered two
mighty gods to carry the mountains away.
'''
mdict = {}
mdict = stats_word.stats_text(text)
print(mdict)
print(sorted(mdict.items(), key=lambda d: d[1], reverse=True))

try:  #通过try…except捕获异常
    frequency = stats_word.stats_text(text)
    print(frequency)
    frequency1 = stats_word.stats_text_en(text)
    print(frequency1)
    frequency2 = stats_word.stats_text_ch(text)
    print(frequency2)
except ValueError as e:
    print(e)
Ejemplo n.º 15
0
int_a = 1234567890
list_b = ['the', '0', '李', '哈', '哈']
str_c = 'The work of lihaotian007 , 看起来不错哦'
dict_d = {'李': '0', 'the': '2', '哈': '3'}

print('''please choose the topy of Argument :
[0] int \t[1] list \t[2] string \t[3] dict
''')

a = input()
if a == '0':
    print('Above is the result of stats_text ', sw.stats_text(int_a), '\n')
    print('Above is the result of stats_text_cn ',
          sw.stats_text_cn(int_a, int_a), '\n')
    print('Above is the result of stats_text_en ',
          sw.stats_text_en(int_a, int_a), '\n')
elif a == '2':
    print('Above is the result of stats_text ', sw.stats_text(str_c), '\n')
    print('Above is the result of stats_text_cn ',
          sw.stats_text_cn(str_c, str_c), '\n')
    print('Above is the result of stats_text_en ',
          sw.stats_text_en(str_c, str_c), '\n')
elif a == '1':
    print('Above is the result of stats_text ', sw.stats_text(list_b), '\n')
    print('Above is the result of stats_text_cn ',
          sw.stats_text_cn(list_b, list_b), '\n')
    print('Above is the result of stats_text_en ',
          sw.stats_text_en(list_b, list_b), '\n')
elif a == '3':
    print('Above is the result of stats_text ', sw.stats_text(dict_d), '\n')
    print('Above is the result of stats_text_cn ',