示例#1
0
    def test_post_paraphrase_cleanup_exclude_unrend(self):
        fake_graph = graph.WikiMap()
        fake_graph.add_mapping("foo", "A", "B", False)
        fake_graph.add_mapping("foo", "B", "C", False)
        fake_graph.add_mapping("foo", "B", "D", False)
        fake_graph.add_mapping("junk", "B", "C", False)

        self.assertItemsEqual(
            synonyms.post_paraphrase_cleanup(["A", "B", "C"], True,
                                             fake_graph), ["B", "C"])
示例#2
0
    def setUp(self):
        self.G = graph.WikiMap()

        # four node group
        self.G.add_edge("A", "B")
        self.G.add_edge("A", "C")
        self.G.add_edge("D", "C")

        # three node group
        self.G.add_edge("Y", "X")
        self.G.add_edge("Z", "X")

        # three node group (another)
        self.G.add_edge("alpha", "beta")
        self.G.add_edge("alpha", "gamma")

        # two node group
        self.G.add_edge("M", "N")

        # EXPECTED:
        # three node group
        self.expected_three1 = graph.WikiMap()
        self.expected_three1.add_edge("Y", "X")
        self.expected_three1.add_edge("X", "Y")
        self.expected_three1.add_edge("Z", "X")
        self.expected_three1.add_edge("X", "Z")

        # three node group (another)
        self.expected_three2 = graph.WikiMap()
        self.expected_three2.add_edge("alpha", "beta")
        self.expected_three2.add_edge("beta", "alpha")
        self.expected_three2.add_edge("alpha", "gamma")
        self.expected_three2.add_edge("gamma", "alpha")

        # four node group
        self.expected_four = graph.WikiMap()
        self.expected_four.add_edge("A", "B")
        self.expected_four.add_edge("B", "A")
        self.expected_four.add_edge("A", "C")
        self.expected_four.add_edge("C", "A")
        self.expected_four.add_edge("D", "C")
        self.expected_four.add_edge("C", "D")
示例#3
0
def create_graph(infoboxes, clean):
    """Creates and saves a graph to [graph_path] from excel file located at
    [excel_path], optionally [clean]ing (boolean) the graph
    """
    G = graph.WikiMap()

    for infobox in infoboxes:
        for unrend, rend in data.get_single_mappings(infobox).iteritems():
            G.add_mapping(infobox, unrend, rend, clean)

    return G
示例#4
0
    def setUp(self):
        self.fake_graph = graph.WikiMap()
        self.fake_graph.add_mapping("random", "A", "X", False)
        self.fake_graph.add_mapping("bar", "F", "A", False)
        self.fake_graph.add_mapping("bar", "E", "A", False)
        self.fake_graph.add_mapping("foo", "E", "A", False)
        self.fake_graph.add_mapping("foo", "A", "B", False)
        self.fake_graph.add_mapping("bar", "E", "D", False)
        self.fake_graph.add_mapping("junk", "E", "D", False)
        self.fake_graph.add_mapping("foo", "B", "D", False)
        self.fake_graph.add_mapping("foo", "B", "C", False)
        self.fake_graph.add_mapping("junk", "B", "C", False)

        patcher = mock.patch('wikimap.synonyms.similar_enough')
        self.mock = patcher.start(
        )  # patcher.start() RETURNS the mocked object
        self.mock.side_effect = lambda x, y: x == y
        self.addCleanup(patcher.stop)
示例#5
0
    def setUp(self):
        self.G = graph.WikiMap()
        self.G.add_edge('unrend', 'hybrid')
        self.G.add_edge('hybrid', 'rend')

        self.G.node['unrend']['was'] = ['_unrend_']
        self.G.node['hybrid']['was'] = ['#hybrid#', '_hybrid_']
        self.G.node['rend']['was'] = ['_rend_']

        self.G.node['unrend']['infobox'] = {'Infobox foo bar': ['unrend']}
        self.G.node['hybrid']['infobox'] = {
            'Infobox foo bar': ['rend'],
            'Infobox baz bang': ['unrend', 'rend']
        }
        self.G.node['rend']['infobox'] = {'Infobox baz bang': ['rend']}

        self.G.edge['unrend']['hybrid']['infobox'] = ['Infobox foo bar']
        self.G.edge['hybrid']['rend']['infobox'] = [
            'Infobox baz bang', 'Infobox aba zaba'
        ]
示例#6
0
    def test_connected_component_nodes_with_size(self):
        G = graph.WikiMap()

        # four node group
        G.add_edge("A", "B")
        G.add_edge("A", "C")
        G.add_edge("D", "C")

        # three node group
        G.add_edge("Y", "X")
        G.add_edge("Z", "X")

        # three node group (another)
        G.add_edge("alpha", "beta")
        G.add_edge("alpha", "gamma")

        # two node group
        G.add_edge("M", "N")

        self.assertItemsEqual(G.connected_component_nodes_with_size(3),
                              [["Y", "X", "Z"], ["alpha", "beta", "gamma"]])
示例#7
0
 def setUp(self):
     self.G = graph.WikiMap()