In [ ]:
 
In [ ]:
 
In [2]:
cat_text = "The cat (Felis catus) is a small carnivorous mammal.[1][2] It is the only domesticated species in the family Felidae and often referred to as the domestic cat to distinguish it from wild members of the family.[4] The cat is either a house cat or a farm cat, which are pets, or a feral cat, which ranges freely and avoids human contact.[5] A house cat is valued by humans for companionship and for its ability to hunt rodents. About 60 cat breeds are recognized by various cat registries.[6] The cat is similar in anatomy to the other felid species, has a strong flexible body, quick reflexes, sharp teeth and retractable claws adapted to killing small prey. Its night vision and sense of smell are well developed. Cat communication includes vocalizations like meowing, purring, trilling, hissing, growling and grunting as well as cat-specific body language. It is a solitary hunter, but a social species. It can hear sounds too faint or too high in frequency for human ears, such as those made by mice and other small mammals. It is a predator that is most active at dawn and dusk.[7] It secretes and perceives pheromones.[8] Female domestic cats can have kittens from spring to late autumn, with litter sizes ranging from two to five kittens.[9] Domestic cats are bred and shown as registered pedigreed cats, a hobby known as cat fancy. Failure to control breeding of pet cats by spaying and neutering, as well as abandonment of pets, resulted in large numbers of feral cats worldwide, contributing to the extinction of entire bird species, and evoking population control.[10] It was long thought that cat domestication was initiated in Egypt, because cats in ancient Egypt were venerated since around 3100 BC.[11][12] However, the earliest indication for the taming of an African wildcat (F. lybica) was found in Cyprus, where a cat skeleton was excavated close by a human Neolithic grave dating to around 7500 BC.[13] African wildcats were probably first domesticated in the Near East.[14] As of 2017, the domestic cat was the second-most popular pet in the U.S. by number of pets owned, after freshwater fish,[15] with 95 million cats owned.[16][17] In the United Kingdom, around 7.3 million cats lived in more than 4.8 million households as of 2019.[18]"
cat_history = "Cats are common pets throughout the world, and their worldwide population exceeds 500 million as of 2007.[179] Although cat guardianship has commonly been associated with women, a 2007 Gallup poll reported that men and women in the United States of America were equally likely to own a cat.[180] As well as being kept as pets, cats are also used in the international fur[181] and leather industries for making coats, hats, blankets, and stuffed toys;[182] and shoes, gloves, and musical instruments respectively[183] (about 24 cats are needed to make a cat-fur coat).[184] This use has been outlawed in the United States, Australia, and the European Union in 2007.[185] Cat pelts have been used for superstitious purposes as part of the practise of witchcraft,[186] and are still made into blankets in Switzerland as folk remedies believed to help rheumatism.[187] In the Western intellectual tradition, the idea of cats as everyday objects have served to illustrate problems of quantum mechanics in the Schrödinger's cat thought experiment. A few attempts to build a cat census have been made over the years, both through associations or national and international organizations (such as the Canadian Federation of Humane Societies's one[188]) and over the Internet,[189][190] but such a task does not seem simple to achieve. General estimates for the global population of domestic cats range widely from anywhere between 200 million to 600 million.[191][192][193][194][195] Walter Chandoha made his career photographing cats after his 1949 images of Loco, an especially charming stray taken in, were published around the world. He is reported to have photographed 90,000 cats during his career and maintained an archive of 225,000 images that he drew from for publications during his lifetime.[196]"
In [13]:
import nltk
from nltk.tokenize import TreebankWordTokenizer
tokenizer = TreebankWordTokenizer()

cats_intro = cat_text.lower()
intro_tokens = tokenizer.tokenize(cats_intro)
intro_tokens = [token for token in intro_tokens if token.isalpha()]

cats_history = cat_history.lower()
history_tokens = tokenizer.tokenize(cats_history)
history_tokens = [token for token in history_tokens if token.isalpha()]

print(len(intro_tokens))
print(len(history_tokens))
346
260

Look at Term Frequency of "Cat" in each document

In [11]:
intro_tf = {}
history_tf = {}

intro_counts = Counter(intro_tokens)
history_counts = Counter(history_tokens)
Out[11]:
['the',
 'cat',
 'felis',
 'catus',
 'is',
 'a',
 'small',
 'carnivorous',
 'it',
 'is',
 'the',
 'only',
 'domesticated',
 'species',
 'in',
 'the',
 'family',
 'felidae',
 'and',
 'often',
 'referred',
 'to',
 'as',
 'the',
 'domestic',
 'cat',
 'to',
 'distinguish',
 'it',
 'from',
 'wild',
 'members',
 'of',
 'the',
 'the',
 'cat',
 'is',
 'either',
 'a',
 'house',
 'cat',
 'or',
 'a',
 'farm',
 'cat',
 'which',
 'are',
 'pets',
 'or',
 'a',
 'feral',
 'cat',
 'which',
 'ranges',
 'freely',
 'and',
 'avoids',
 'human',
 'a',
 'house',
 'cat',
 'is',
 'valued',
 'by',
 'humans',
 'for',
 'companionship',
 'and',
 'for',
 'its',
 'ability',
 'to',
 'hunt',
 'about',
 'cat',
 'breeds',
 'are',
 'recognized',
 'by',
 'various',
 'cat',
 'the',
 'cat',
 'is',
 'similar',
 'in',
 'anatomy',
 'to',
 'the',
 'other',
 'felid',
 'species',
 'has',
 'a',
 'strong',
 'flexible',
 'body',
 'quick',
 'reflexes',
 'sharp',
 'teeth',
 'and',
 'retractable',
 'claws',
 'adapted',
 'to',
 'killing',
 'small',
 'its',
 'night',
 'vision',
 'and',
 'sense',
 'of',
 'smell',
 'are',
 'well',
 'cat',
 'communication',
 'includes',
 'vocalizations',
 'like',
 'meowing',
 'purring',
 'trilling',
 'hissing',
 'growling',
 'and',
 'grunting',
 'as',
 'well',
 'as',
 'body',
 'it',
 'is',
 'a',
 'solitary',
 'hunter',
 'but',
 'a',
 'social',
 'it',
 'can',
 'hear',
 'sounds',
 'too',
 'faint',
 'or',
 'too',
 'high',
 'in',
 'frequency',
 'for',
 'human',
 'ears',
 'such',
 'as',
 'those',
 'made',
 'by',
 'mice',
 'and',
 'other',
 'small',
 'it',
 'is',
 'a',
 'predator',
 'that',
 'is',
 'most',
 'active',
 'at',
 'dawn',
 'and',
 'it',
 'secretes',
 'and',
 'perceives',
 'female',
 'domestic',
 'cats',
 'can',
 'have',
 'kittens',
 'from',
 'spring',
 'to',
 'late',
 'autumn',
 'with',
 'litter',
 'sizes',
 'ranging',
 'from',
 'two',
 'to',
 'five',
 'domestic',
 'cats',
 'are',
 'bred',
 'and',
 'shown',
 'as',
 'registered',
 'pedigreed',
 'cats',
 'a',
 'hobby',
 'known',
 'as',
 'cat',
 'failure',
 'to',
 'control',
 'breeding',
 'of',
 'pet',
 'cats',
 'by',
 'spaying',
 'and',
 'neutering',
 'as',
 'well',
 'as',
 'abandonment',
 'of',
 'pets',
 'resulted',
 'in',
 'large',
 'numbers',
 'of',
 'feral',
 'cats',
 'worldwide',
 'contributing',
 'to',
 'the',
 'extinction',
 'of',
 'entire',
 'bird',
 'species',
 'and',
 'evoking',
 'population',
 'it',
 'was',
 'long',
 'thought',
 'that',
 'cat',
 'domestication',
 'was',
 'initiated',
 'in',
 'egypt',
 'because',
 'cats',
 'in',
 'ancient',
 'egypt',
 'were',
 'venerated',
 'since',
 'around',
 'however',
 'the',
 'earliest',
 'indication',
 'for',
 'the',
 'taming',
 'of',
 'an',
 'african',
 'wildcat',
 'lybica',
 'was',
 'found',
 'in',
 'cyprus',
 'where',
 'a',
 'cat',
 'skeleton',
 'was',
 'excavated',
 'close',
 'by',
 'a',
 'human',
 'neolithic',
 'grave',
 'dating',
 'to',
 'around',
 'african',
 'wildcats',
 'were',
 'probably',
 'first',
 'domesticated',
 'in',
 'the',
 'near',
 'as',
 'of',
 'the',
 'domestic',
 'cat',
 'was',
 'the',
 'popular',
 'pet',
 'in',
 'the',
 'by',
 'number',
 'of',
 'pets',
 'owned',
 'after',
 'freshwater',
 'fish',
 'with',
 'million',
 'cats',
 'in',
 'the',
 'united',
 'kingdom',
 'around',
 'million',
 'cats',
 'lived',
 'in',
 'more',
 'than',
 'million',
 'households',
 'as',
 'of']
In [ ]: