<jupyter_start><jupyter_text>__Exercise 1__<jupyter_code>import nltk, re, pprint
from nltk import load_parser
grammar8 = load_parser('file:chapter_9_ex1_a.fcfg')
sent = "I am happy".split()
trees = grammar8.parse(sent)
for tree in trees:
    print tree
sent = "she is happy".split()
trees = grammar8.parse(sent)
for tree in trees:
    print tree
sent = "you is happy".split()
trees = grammar8.parse(sent)
for tree in trees:
    print tree
sent = "they am happy".split()
trees = grammar8.parse(sent)
for tree in trees:
    print tree
grammar20 = load_parser('file:chapter_9_ex1_b.fcfg')
sent = "I am happy".split()
trees = grammar20.parse(sent)
for tree in trees:
    print tree
sent = "she is happy".split()
trees = grammar20.parse(sent)
for tree in trees:
    print tree
sent = "you is happy".split()
trees = grammar20.parse(sent)
for tree in trees:
    print tree
sent = "they am happy".split()
trees = grammar20.parse(sent)
for tree in trees:
    print tree<jupyter_output><empty_output><jupyter_text>__Exercise 2__<jupyter_code>grammar = load_parser('file:chapter_9_ex2.fcfg')
sent = "the boy sings".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "boy sings".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "the boys sing".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "boys sing".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "the water is precious".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "water is precious".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree<jupyter_output>(S[]
  (NP[NUM='sg'] (N[NUM='sg', -count] water))
  (VP[NUM='sg', TENSE='pres']
    (Cop[NUM='sg', TENSE='pres'] is)
    (Adj[] precious)))<jupyter_text>__Exercise 3__<jupyter_code>def subsumes(f1, f2):
    if len(f2.keys()) > len(f1.keys()):
        return False;
    for key in f2.keys():
        if (key not in f1.keys()) or (f1[key] != f2[key]):
            return False;
    return True

fs1 = nltk.FeatStruct(A='a')
fs2 = nltk.FeatStruct(A='a', B='b')
print subsumes(fs1, fs2)
print subsumes(fs2, fs1)<jupyter_output>False
True<jupyter_text>__Exercise 4__<jupyter_code># don't know what is expected here :/ see chapter_9_ex4.fcfg<jupyter_output><empty_output><jupyter_text>__Exercise 5__<jupyter_code>grammar = load_parser('file:chapter_9_ex5.fcfg')
sent = "ich sehe die Hunde".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "wir kommen".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree
sent = "ich komme die Hunde".split()
trees = grammar.parse(sent)
for tree in trees:
    print tree<jupyter_output><empty_output><jupyter_text>__Exercise 6__<jupyter_code>grammar = load_parser('file:chapter_9_ex6.fcfg')

def parse(sent, grammer):
    sent = sent.split()
    trees = grammar.parse(sent)
    for tree in trees:
        print tree

parse("un cuadro hermoso", grammar)
parse("unos cuadros hermosos", grammar)
parse("una cortina hermosa", grammar)
parse("unas cortinas hermosas", grammar)
parse("un cuadro hermosas", grammar)
parse("unos cortinas hermosas", grammar)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13212838890620132, 'fraction_numerical': 0.014646307260828918, 'mean_word_length': 4.783783783783784, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '600912', 'license': 'MIT', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1162, 'n_words': 316, 'path': 'chapter_9_exercises.ipynb', 'repo_name': 'JuliaNeumann/nltk_book_exercises', 'size': '3209'}