#!/usr/bin/env python3
# -*- coding: utf-8 -*-

""" 단어 sequence를 위한 class 생성
    
    pages 499~503; 한글 기준
"""
import re
import reprlib

RE_WORD = re.compile('\w+')

class Sentence:
    
    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)
        
    def __getitem__(self, index):
        return self.words[index]
    
    def __len__(self):
        return len(self.words)
    
    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)
    
s = Sentence('"The winter is coming," the KDH said,')
print(s)  # Sentence('"The winter ...the KDH said,')
          # 실제로는 reprlib.repr()이 생성한 것

for word in s:
    print(word)
list(s)  # ['The', 'winter', 'is', 'coming', 'the', 'KDH', 'said']
38934d389f2df3181aa7b2adca1d140ffe9964fc
<mask token>


class Sentence:

    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)

    def __getitem__(self, index):
        return self.words[index]

    def __len__(self):
        return len(self.words)

    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)


<mask token>

<mask token>


class Sentence:

    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)

    def __getitem__(self, index):
        return self.words[index]

    def __len__(self):
        return len(self.words)

    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)


<mask token>
print(s)
for word in s:
    print(word)
list(s)

<mask token>
RE_WORD = re.compile('\\w+')


class Sentence:

    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)

    def __getitem__(self, index):
        return self.words[index]

    def __len__(self):
        return len(self.words)

    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)


s = Sentence('"The winter is coming," the KDH said,')
print(s)
for word in s:
    print(word)
list(s)

<mask token>
import re
import reprlib
RE_WORD = re.compile('\\w+')


class Sentence:

    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)

    def __getitem__(self, index):
        return self.words[index]

    def __len__(self):
        return len(self.words)

    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)


s = Sentence('"The winter is coming," the KDH said,')
print(s)
for word in s:
    print(word)
list(s)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

""" 단어 sequence를 위한 class 생성
    
    pages 499~503; 한글 기준
"""
import re
import reprlib

RE_WORD = re.compile('\w+')

class Sentence:
    
    def __init__(self, text):
        self.text = text
        self.words = RE_WORD.findall(text)
        
    def __getitem__(self, index):
        return self.words[index]
    
    def __len__(self):
        return len(self.words)
    
    def __repr__(self):
        return 'Sentence(%s)' % reprlib.repr(self.text)
    
s = Sentence('"The winter is coming," the KDH said,')
print(s)  # Sentence('"The winter ...the KDH said,')
          # 실제로는 reprlib.repr()이 생성한 것

for word in s:
    print(word)
list(s)  # ['The', 'winter', 'is', 'coming', 'the', 'KDH', 'said']