NLP100
-
문제 11. 탭을 공백으로 변환NLP/NLP100 2021. 1. 4. 18:25
모든 탭을 공백 문자로 변환하시오. 확인을 위해 sed명령어, tr명령어, expand명령어를 사용하시오. datapath = "/Users/p1zz4/Downloads/popular-names.txt" with open(datapath) as p: f = [line.replace("\t", " ").rstrip() for line in p] print(f[:10]) # 전체 출력하느라 오래걸리므로 일부만 출력해서 확인 [확인] - sed (base) P1ZZ4:Downloads p1zz4$ sed "s/\t/ /g" re_popular-names.txt - tr (base) P1ZZ4:Downloads p1zz4$ tr '\tr' ' ' < re_popular-names.txt - expand (bas..
-
문제 06. 집합NLP/NLP100 2021. 1. 4. 18:17
"paraparaparadise"와 "paragraph"에 포함되는 문자 Bigram의 집합을 각각, X와 Y로 구하고, X와 Y의 합집합, 곱집합, 차집합을 구하시오. 그리고, "se"라는 Bigram이 X와 Y 중 어느 집합에 포함되는지 확인하시오. Xs = "paraparaparadise" Ys = "paragraph" def ngram(idx, n): return [idx[i:i+n] for i in range(len(idx)-n+1)] X = set(ngram(Xs,2)) Y = set(ngram(Ys,2)) print(f'union: {X | Y}') #합집합 print(f'intersection: {X & Y}') #교집합 print(f'difference of sets: {X - Y}') ..
-
문제 04. 원소 기호NLP/NLP100 2021. 1. 4. 18:09
Hi He Lied Because Boron Could Not Oxidize Fluorine. New Nations Might Also Sign Peace Security Clause. Arthur King Can 라는 문장을 단어 단위로 분할하고, 1,5,6,7,8,9,15,16,19 번째 단어는 앞글자, 그 밖의 단어는 앞에서 두 글자씩 추출하여 꺼낸 문자열에서 단어의 위치순으로 나열한 배열을 만드시오. def sol(i, word): if i in [1, 5, 6, 7, 8, 9, 15, 16, 19]: return (word[0], i) else: return (word[:2], i) text = 'Hi He Lied Because Boron Could Not Oxidize Fluorine. Ne..