1. Learn
  2. /
  3. कोर्स
  4. /
  5. Python में Software Engineering Principles

Connected

अभ्यास

अपनी class की functionality का उपयोग

अब आपने अपनी Document class के __init__ मेथड में अतिरिक्त functionality जोड़ दी है, जो आपके users के लिए text को अपने-आप प्रोसेस करती है. इस अभ्यास में, आप उन्हीं users में से एक की तरह काम करेंगे ताकि अपनी मेहनत के फायदे देख सकें.

Document class (नीचे कॉपी की गई) आपके environment में लोड कर दी गई है (आपके नए अपडेट्स सहित).

class Document:
  def __init__(self, text):
    self.text = text
    # pre tokenize the document with non-public tokenize method
    self.tokens = self._tokenize()
    # pre tokenize the document with non-public count_words
    self.word_counts = self._count_words()

  def _tokenize(self):
    return tokenize(self.text)

  # non-public method to tally document's word counts with Counter
  def _count_words(self):
    return Counter(self.tokens)

निर्देश

100 XP
  • अपने environment में लोड किए गए datacamp_tweets डेटा सेट से एक नया Document instance बनाएँ. datacamp_tweets ऑब्जेक्ट एक सिंगल string है जिसमें DataCamp और उसके users द्वारा लिखे गए सैकड़ों tweets हैं.
  • datacamp_doc के पहले 5 tokens प्रिंट करें.
  • Document.__init__ मेथड में non-public _count_words() मेथड द्वारा अपने-आप निकाले गए सबसे सामान्य 5 शब्द प्रिंट करें.