This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| def cipher(S): | |
| return ''.join(chr(219 - ord(c)) if c.islower() else c for c in S) | |
| S = "abcDe" | |
| print(cipher(S)) | |
| print(cipher(cipher(S))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| def n_gram(n, s): | |
| return [s[i:i+n] for i in range(0, len(s)-n+1)] | |
| print(n_gram(2, 'I am an NLPer')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| s = 'Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can.' | |
| target = 1, 5, 6, 7, 8, 9, 15, 16, 19 | |
| result = [w[: 1 if i in target else 2] for i, w in enumerate(s.split(), 1)] | |
| print(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| s = 'Now I need a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.' | |
| # 単語毎のリストに分解してから,.を除外し文字数をカウント | |
| result = [len(w.rstrip(',.')) for w in s.split()] | |
| print(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| s1 = 'パトカー' | |
| s2 = 'タクシー' | |
| s = ''.join(i+j for i, j in zip(s1, s2)) | |
| print(s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import numpy.random as rd | |
| def gen_typo(S): | |
| if len(S) <= 4: | |
| return S | |
| else: | |
| idx = [0] | |
| idx.extend(rd.choice(range(1, len(S)-1), len(S)-2, replace=False)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| def cipher(S): | |
| result = [] | |
| for i in range(len(S)): | |
| if(S[i].islower()): | |
| result.append(chr(219 - ord(S[i]))) | |
| else: | |
| result.append(S[i]) | |
| return ''.join(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| def gen_sentence(x, y, z): | |
| return "{}時の{}は{}".format(x, y, z) | |
| x = 12 | |
| y = '気温' | |
| z = 22.4 | |
| print(gen_sentence(x, y, z)) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| # 2つのバイグラムの和集合、積集合、差集合 | |
| def bi_gram(s): | |
| result = [] | |
| for i in range(0, len(s)-1): | |
| result.append(s[i:i+2]) | |
| return result | |
| s1 = 'paraparaparadise' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| def n_gram(n, s): | |
| result = [] | |
| for i in range(0, len(s)-n+1): | |
| result.append(s[i:i+n]) | |
| return result | |
| print(n_gram(2, 'I am an NLPer')) |