コード例 #1
0
 def test_fit_transform(self):
     np.testing.assert_array_equal(
         RDF2VecTransformer().fit_transform(KNOWLEDGE_GRAPH,
                                            ENTITIES_SUBSET),
         RDF2VecTransformer().fit(
             KNOWLEDGE_GRAPH, ENTITIES_SUBSET).transform(ENTITIES_SUBSET),
     )
コード例 #2
0
 def test_load_save_transformer(self):
     RDF2VecTransformer(
         walkers=[RandomWalker(2, None),
                  WeisfeilerLehmanWalker(2, 2)]).save()
     transformer = RDF2VecTransformer.load()
     assert len(transformer.walkers) == 2
     assert isinstance(transformer.walkers[0], RandomWalker)
     assert isinstance(transformer.walkers[1], WeisfeilerLehmanWalker)
     os.remove("transformer_data")
コード例 #3
0
 def test_transform(self):
     transformer = RDF2VecTransformer()
     with pytest.raises(NotFittedError):
         transformer.transform(ENTITIES_SUBSET)
     transformer.fit(KNOWLEDGE_GRAPH, ENTITIES_SUBSET)
     features = transformer.transform(ENTITIES_SUBSET)
     assert type(features) == list
コード例 #4
0
    def test_fit_transform(self, setup, kg, walker, sampler, is_inverse,
                           is_split):
        if "UniformSampler" in str(sampler):
            sampler = sampler()
        else:
            sampler = sampler(is_inverse, is_split)

        assert RDF2VecTransformer(
            walkers=[walker(2, 5, sampler, random_state=42)]).fit_transform(
                kg, [f"{URL}#{entity}" for entity in ROOTS_WITHOUT_URL])
コード例 #5
0
 def test_fit(self):
     transformer = RDF2VecTransformer()
     with pytest.raises(ValueError):
         transformer.fit(KNOWLEDGE_GRAPH, ["does", "not", "exist"])
     transformer.fit(KNOWLEDGE_GRAPH, ENTITIES_SUBSET)
コード例 #6
0
 def test_fit_transform(self, walker, sampler):
     transformer = RDF2VecTransformer(walkers=[walker(2, 5, sampler())])
     assert transformer.fit_transform(KNOWLEDGE_GRAPH, ENTITIES_SUBSET)
コード例 #7
0
 def test_fail_load_transformer(self):
     pickle.dump([0, 1, 2], open("tmp", "wb"))
     with pytest.raises(ValueError):
         RDF2VecTransformer.load("tmp")
     os.remove("tmp")