示例#1
0
    valid_subtrees = example_valid_subtrees()
    invalid_subtrees = example_invalid_subtrees()
    for valid_subtree in valid_subtrees:
        assert is_subtree(tree, valid_subtree) == True
    for invalid_subtree in invalid_subtrees:
        assert is_subtree(tree, invalid_subtree) == False


# Example trees

## Jeff ate cookies

tree_jeff_ate_cookies = nx.DiGraph()
tree_jeff_ate_cookies.add_nodes_from(label_nodes([
    (1, 'S'),
    (2, 'NP'), (3, 'N'), (4, 'Jeff'),
    (5, 'VP'), (6, 'V'), (7, 'ate'),
    (8, 'NP'), (9, 'N'), (10, 'cookies')]))
tree_jeff_ate_cookies.add_edges_from([
    (1, 2), # S NP
    (1, 5), # S VP
    (2, 3), # NP N
    (3, 4), # N Jeff
    (5, 6), # VP V
    (6, 7), # V ate
    (5, 8), # VP NP
    (8, 9), # NP N
    (9, 10), # N cookies
])

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author: Arne Neumann <*****@*****.**>

import networkx as nx
from discoursekernels.util import label_nodes, label_edges

# Example dependency graphs

## the man saw the woman with the telescope

the_man_saw_the_woman_with_the_telescope = nx.DiGraph()
the_man_saw_the_woman_with_the_telescope.add_nodes_from(label_nodes(
    [(1, '*'), (2, 'saw'), (3, 'man'), (4, 'the'),
     (5, 'woman'), (6, 'the'), (7, 'with'),
     (8, 'telescope'), (9, 'the')]))
the_man_saw_the_woman_with_the_telescope.add_edges_from(label_edges(
    [(1, 2, 'root'), (2, 3, 'sbj'), (3, 4, 'dt'),
     (2, 5, 'obj'), (5, 6, 'dt'),
     (2, 7, 'pp'), (7, 8, 'pp-obj'), (8, 9, 'dt')]
))

## the man

the_man = nx.DiGraph()
the_man.add_nodes_from(label_nodes([(1, 'man'), (2, 'the')]))
the_man.add_edges_from(label_edges([(1, 2, 'dt')]))

## with the telescope

with_the_telescope = nx.DiGraph()