Best Python code snippet using localstack_python
testExtration.py
Source:testExtration.py
...11#代ç æ件夹å
å«æ件chinesenews.txtï¼å
容为ä¸ç¯ä¸ææ°é»#12'''13input_file = open('chinesenews.txt',encoding= 'utf8')14fileContent = input_file.read()15tags = ChineseDealing.extract_tags(fileContent, topK=5)16print ('1'+",".join(tags))17'''18str1 = 'è®°è
10æ¥ä»å
¬å®é¨è·æï¼å
¨å½å
¬å®äº¤é管çé¨é¨å°ä»10æ11æ¥è³12æ31æ¥å¼å±å
¬è·¯éç¹äº¤éè¿æ³è¡ä¸ºä¸é¡¹æ´æ²»å·¥ä½ï¼å¯¹é«éå
¬è·¯åéç¹å½ãçéä¸çè¶
éè¡é©¶ã客车è¶
åãç²å³é©¾é©¶3ç§ä¸¥éè¿æ³è¡ä¸ºè¿è¡éä¸æ´æ²»ã'19keystr1 = 'æ´æ²»äº¤éè¿æ³'20print(keystr1)21print(str1)22print(ChineseDealing.extractNewsTag(str1))2324str2 = '10æ¥10æ¶50åå·¦å³ï¼éåºç¶¦æ±å¿å¢å
åçä¸èµ·é大交éäºæ
ï¼ä¸è¾ä¸å客车ç±äºæ¹åççªç¶å¤±çµï¼å®¢è½¦ä»å±±é´å
¬è·¯ä¸ä¾§ç¿»æå
¥æ²³ä¸ï¼ç®å已确å®7人æ»äº¡ã15人å伤ã'25keystr2 = 'éåºé大车祸'26print(keystr2)27print(str2)28print(ChineseDealing.extractForumTag(str2))2930str3 = 'ä¸ä½ç³æ²¹ä¸å
ä¸å®¶è®¤ä¸ºï¼å½å
æåæ²¹ä»·æ ¼å¯è½åºç°â象å¾æ§âçä¸è°ã'31keystr3 = '油价'32print(keystr3)33print(str3)34print(ChineseDealing.extractNewsTag(str3))3536str4 = 'ééé¨å
¬å®å±æ¿å§å¼ åºåæ¨æ¥è¡¨ç¤ºï¼é¢è®¡æå¹´4ææå½å车å°å®ç°ç¬¬å
次大æéï¼å¨ä¸äºåºæ®µå®¢è½¦è¿è¡æ¶éå¯è¾¾200å
¬éã'37keystr4 = 'å车æé'38print(keystr4)39print(str4)40print(ChineseDealing.extract_tags(str4, topK=2))4142str5 = 'è®°è
10æ¥ä»é西çæ¸åå¸æ¿åºäºè§£å°ï¼å½å°å¤§é¢ç§¯æ»å¡ç¾å®³æåä¸åéé¾è
éä½å·²è¢«åç°ï¼æ¤æ¬¡ç¾å®³è¢«å13ä½ææ°ä¸æ1人è·æã12人æ»äº¡ã'43keystr5 = 'é西æ»å¡'44print(keystr5)45print(str5)46print(ChineseDealing.extract_tags(str5, topK=2))4748str6 = 'ç»æ¶æ害å
èå¤èªæ²»åºç¥åæ°è¥ä¼ä¸å®¶äºå
¨æ°ç两åå¶ææ½æ°¸å¿ ååå¿å¼ºï¼å¨10æ¥çä¸å®¡å®£å¤ä¸è¢«å¼å浩ç¹å¸ä¸çº§äººæ°æ³é¢å¤å¤æ»åï¼å¥å¤ºæ¿æ²»æå©ç»èº«ã'49keystr6 = 'å
èå¤ç»æ¶æ人æ¡'50print(keystr6)51print(str6)52print(ChineseDealing.extract_tags(str6, topK=2))5354str7 = 'æ¨æ¥ï¼åæ¹å§ãæè²é¨çä¸é¨å§èåååºéç¥ï¼å³å®ä»10æä¸æ¬å¼å§è³11æåºï¼å¨å
¨å½èå´å
å¼å±æè²æ¶è´¹ä¸é¡¹æ£æ¥ãæ®è®°è
äºè§£ï¼æå½55ä¸æä¸å°å¦ä¸ï¼æ¯å¹´æ©æ ¡è´¹æ¶å
¥è³å°ç¾äº¿å
以ä¸ã'55keystr7 = 'æ©æ ¡è´¹'56print(keystr7)57print(str7)58print(ChineseDealing.extract_tags(str7, topK=2))5960str8 = 'å»å¹´åçå¨äºåæå±±â10·18âçæ ¡åæ¨æ¡ä¸ï¼ä¸åæªæ»¡18å¨å²çä¸å¦çå ææ¨åæåå¦ï¼æ·±å¤æææ½å
¥å®¿èï¼ææ»çç¡çåå¦ãå°±å¨ä»èµ°åºå¶æ¡ç°åºæ¶ï¼éè§äºå¦å¤ä¸¤ä¸ªåå¦ï¼ç¬¬äºå¤©æä¸ï¼å¶æå次è¿å
¥å®¿èæ人çå£ãæ¤æ¡éæå
¨å½ãè®°è
æ¨æ¥è·æï¼äºåçé«é¢å¯¹è¿èµ·å¶ææ¡ä½åºç»å®¡å¤å³ï¼ç»´æä¸å®¡æ³é¢å¤å¤å¶ææ æå¾åï¼å¹¶ç±è¢«å人家å±åå
¶æå¨å¦æ ¡å
±åèµå¿æ»è
家å±15ä¸å
ã'61keystr8 = 'äºåæ ¡åæ¨æ¡è¿½è¸ª'62print(keystr8)63print(str8)64print(ChineseDealing.extract_tags(str8, topK=2))6566str9 = 'è¿æ¥ï¼ä¸ä½é³å
åçåæªå©å¦å¦å´ç¨å¥¹çå强åä¹è§ææäºèº«è¾¹çæåå许å¤ç½æ°ãå°ççª(blog)ââå京ææ¥ä¸åæåè®°è
ï¼å¨å 个æåçªéææ
åæ
ï¼å´æ¯
ç¶å³å®çä¸èéçå©åï¼äº²åå°ç§°è¿ä¸ªå©å为âçªå¨âï¼å¹¶å¨å客ä¸ç¨è½»æ¾ãè°ä¾çè¯è¨è®°å½ä¸æåæé´çç¹ç¹æ»´æ»´ï¼è¯¥å客çç¹å»çå¨ä¸å¨å
çªç ´30ä¸ã'67keystr9 = 'æªå©å¦å¦å¼å客'68print(keystr9)69print(str9)
...
test.py
Source:test.py
...11class ExtractIpv4Test(unittest.TestCase):12 def do_extract(self, expected, text, tag='ipv4'):13 self.assertEqual(14 expected,15 extract_tags(text).get(tag, []))16 def test_all_zeroes(self):17 self.do_extract(['0.0.0.0'], '#0.0.0.0#')18 19 def test_multiple(self):20 self.do_extract(['0.0.0.0', '1.1.1.1'], '#0.0.0.0#1.1.1.1#')21 22 def test_all_ff(self):23 self.do_extract(['255.255.255.255'], '#255.255.255.255#')24 def test_out_of_range(self):25 self.do_extract([], '#256.256.256.256#')26 27 def test_short_formats(self):28 "Although these are valid IPs we only want to match full 4-octet IPs"29 self.do_extract([], '#192.168.1#')30 self.do_extract([], '#192.168#')31 self.do_extract([], '#192#')32class ExtractIpv6Test(unittest.TestCase):33 def do_extract(self, expected, text, tag='ipv6'):34 self.assertEqual(35 expected,36 extract_tags(text).get(tag, []))37 def test_full_address(self):38 self.maxDiff = None39 self.do_extract(40 ['fe80:0000:0000:0000:0204:61ff:fe9d:f156'], 41 '#fe80:0000:0000:0000:0204:61ff:fe9d:f156#')42 43 def test_drop_leading_zeroes(self):44 self.do_extract(45 ['fe80:0:0:0:204:61ff:fe9d:f156'], 46 '#fe80:0:0:0:204:61ff:fe9d:f156#')47 def test_collapse_multiple_zeroes(self):48 self.do_extract(49 ['fe80::204:61ff:fe9d:f156'], 50 '#fe80::204:61ff:fe9d:f156#')51 def test_localhost(self):52 self.do_extract(53 ['::1'], 54 '#::1#')55 56 def test_link_local_prefix(self):57 self.do_extract(58 ['fe80::'], 59 '#fe80::#')60 def test_global_unicast_prefix(self):61 self.do_extract(62 ['2001::'], 63 '#2001::#')64class ExtractEmailTest(unittest.TestCase):65 def do_extract(self, expected, text, tag='email'):66 self.assertEqual(67 expected,68 extract_tags(text).get(tag, []))69 def test_plain_email(self):70 self.do_extract(['test@test.com'], '#test@test.com#')71class ExtractMd5Test(unittest.TestCase):72 def do_extract(self, expected, text, tag='md5'):73 self.assertEqual(74 expected,75 extract_tags(text).get(tag, []))76 def test_plain_md5(self):77 self.do_extract(78 ['0123456789abcdef0123456789abcdef'],79 '#0123456789abcdef0123456789abcdef#')80 def test_uppercase(self):81 self.do_extract(82 ['0123456789ABCDEF0123456789ABCDEF'],83 '#0123456789ABCDEF0123456789ABCDEF#')84 85 def test_invalid_letters(self):86 self.do_extract(87 [],88 '#G123456789ABCDEF0123456789ABCDEF#')89 def test_md5_no_match_inside_longer(self):90 self.do_extract(91 [],92 '#0123456789abcdef0123456789abcdef00000000#')93class ExtractUrlTest(unittest.TestCase):94 def do_extract(self, expected, text, tag='url'):95 self.assertEqual(96 expected,97 extract_tags(text).get(tag, []))98 def test_http_url(self):99 self.do_extract(['http://www.example.com'], '#http://www.example.com ')100 def test_ftp_url(self):101 self.do_extract(['ftp://www.example.com'], '#ftp://www.example.com ')102class ExtractBaseDomainTest(unittest.TestCase):103 def do_extract(self, expected, text, tag='domain'):104 self.assertEqual(105 expected,106 extract_tags(text).get(tag, []))107 def test_dot_com(self):108 self.do_extract(['domain.com'], 'http://sub.domain.com/foo')109 def test_dot_co_dot_uk(self):110 self.do_extract(['domain.co.uk'], 'http://sub.domain.co.uk/foo')111 def test_multi_subdomains(self):112 self.do_extract(['domain.com'], 'http://sub1.sub2.domain.com/foo')113class ExtractHostnameTest(unittest.TestCase):114 def do_extract(self, expected, text, tag='hostname'):115 self.assertEqual(116 expected,117 extract_tags(text).get(tag, []))118 def test_dot_com(self):119 self.do_extract(['sub.domain.com'], 'http://sub.domain.com/foo')120 def test_dot_co_dot_uk(self):121 self.do_extract(['sub.domain.co.uk'], 'http://sub.domain.co.uk/foo')122 def test_multi_subdomains(self):123 self.do_extract(124 ['sub1.sub2.domain.com'],125 'http://sub1.sub2.domain.com/foo')126if __name__ == '__main__':...
__init__.py
Source:__init__.py
1from __future__ import absolute_import2from .tfidf import TFIDF3from .textrank import TextRank4try:5 from .analyzer import ChineseAnalyzer6except ImportError:7 pass8default_tfidf = TFIDF()9default_textrank = TextRank()10extract_tags = tfidf = default_tfidf.extract_tags11set_idf_path = default_tfidf.set_idf_path12textrank = default_textrank.extract_tags13def set_stop_words(stop_words_path):14 default_tfidf.set_stop_words(stop_words_path)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!