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), )
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")
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
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])
def test_fit(self): transformer = RDF2VecTransformer() with pytest.raises(ValueError): transformer.fit(KNOWLEDGE_GRAPH, ["does", "not", "exist"]) transformer.fit(KNOWLEDGE_GRAPH, ENTITIES_SUBSET)
def test_fit_transform(self, walker, sampler): transformer = RDF2VecTransformer(walkers=[walker(2, 5, sampler())]) assert transformer.fit_transform(KNOWLEDGE_GRAPH, ENTITIES_SUBSET)
def test_fail_load_transformer(self): pickle.dump([0, 1, 2], open("tmp", "wb")) with pytest.raises(ValueError): RDF2VecTransformer.load("tmp") os.remove("tmp")