Пример #1
0
    x = label(s)
    if x is None:
        x = label_word(s)
        
        if x is not None: 
            print '  '*depth+x
        return
    print '  '*depth+label(s)
    print_tree(s*vocab.parse('~L_'+x), depth+1)
    print_tree(s*vocab.parse('~R_'+x), depth+1)
        
    
    
vocab = Vocabulary(D)    

NEXT = vocab.parse('NEXT')

for category, items in words.items():
    for item in items:
        rules.append((category, [item]))
print rules    
    
sp_goal = vocab.parse('S')

sp_tree = None
    
for input in input_sentence:
    print 'parsing text:', input
    
    sp_lex = vocab.parse(input)
    
Пример #2
0
    ('S', ['NP', 'VP']),
    ('VP', ['V']),
    ('NP', ['DET', 'N']),
    ]
    
words = {
    'N': 'man dog'.split(),
    'DET': 'a the'.split(),
    'V': 'ran saw'.split(),
    }
    
vocab = Vocabulary(D)    

for category, items in words.items():
    for item in items:
        vocab.add(item, vocab.parse('CATEGORY*%s+TEXT*text_%s'%(category, item)))
    
sp_goal = vocab.parse('S')

    
for input in input_sentence:
    print 'parsing text:', input
    sp_lex = vocab.parse(input)
    
    category = sp_lex*vocab.parse('~CATEGORY')
    
    while True:
        print 'looking for rules with LC=', vocab.text(category, include_pairs=False, maximum_count=1)
        for LHS, RHS in rules:
            c = category.dot(vocab.parse(RHS[0]))
            if c>0.7: