Пример #1
0
def test_userdefined_dataset():
    custom_dataset_path = os.path.join(
        os.path.dirname(os.path.abspath(__file__)), 'resource',
        'custom_dataset')
    knowledge_graph = KnowledgeGraph(dataset="userdefineddataset",
                                     custom_dataset_path=custom_dataset_path)
    knowledge_graph.prepare_data()
    knowledge_graph.dump()

    knowledge_graph.read_cache_data('triplets_train')
    knowledge_graph.read_cache_data('triplets_test')
    knowledge_graph.read_cache_data('triplets_valid')
    knowledge_graph.read_cache_data('hr_t')
    knowledge_graph.read_cache_data('tr_h')
    knowledge_graph.read_cache_data('idx2entity')
    knowledge_graph.read_cache_data('idx2relation')
    knowledge_graph.read_cache_data('entity2idx')
    knowledge_graph.read_cache_data('relation2idx')

    knowledge_graph.dataset.read_metadata()
    knowledge_graph.dataset.dump()

    assert knowledge_graph.kg_meta.tot_train_triples == 1
    assert knowledge_graph.kg_meta.tot_test_triples == 1
    assert knowledge_graph.kg_meta.tot_valid_triples == 1
    assert knowledge_graph.kg_meta.tot_entity == 6
    assert knowledge_graph.kg_meta.tot_relation == 3
Пример #2
0
def test_fb15k_meta():
    """Function to test the the knowledge graph parse for Freebase and basic operations."""
    knowledge_graph = KnowledgeGraph(dataset="freebase15k")
    knowledge_graph.force_prepare_data()
    knowledge_graph.dump()

    assert knowledge_graph.is_cache_exists()
    knowledge_graph.prepare_data()

    knowledge_graph.dataset.read_metadata()
    knowledge_graph.dataset.dump()
Пример #3
0
def test_fb15k_manipulate():
    """Function to test the the knowledge graph parse for Freebase and basic operations."""
    knowledge_graph = KnowledgeGraph(dataset="freebase15k")
    knowledge_graph.force_prepare_data()
    knowledge_graph.dump()

    knowledge_graph.read_cache_data('triplets_train')
    knowledge_graph.read_cache_data('triplets_test')
    knowledge_graph.read_cache_data('triplets_valid')
    knowledge_graph.read_cache_data('hr_t')
    knowledge_graph.read_cache_data('tr_h')
    knowledge_graph.read_cache_data('idx2entity')
    knowledge_graph.read_cache_data('idx2relation')
    knowledge_graph.read_cache_data('entity2idx')
    knowledge_graph.read_cache_data('relation2idx')
Пример #4
0
def test_known_datasets(dataset_name):
    """Function to test the the knowledge graph parse for Freebase."""
    knowledge_graph = KnowledgeGraph(dataset=dataset_name)
    knowledge_graph.force_prepare_data()

    assert len(knowledge_graph.dump()) == 9
    assert knowledge_graph.is_cache_exists()

    kg_metadata = knowledge_graph.dataset.read_metadata()

    assert kg_metadata.tot_triple > 0
    assert kg_metadata.tot_valid_triples > 0
    assert kg_metadata.tot_test_triples > 0
    assert kg_metadata.tot_train_triples > 0
    assert kg_metadata.tot_relation > 0
    assert kg_metadata.tot_entity > 0

    assert len(knowledge_graph.read_cache_data('triplets_train')) > 0
    assert len(knowledge_graph.read_cache_data('triplets_test')) > 0
    assert len(knowledge_graph.read_cache_data('triplets_valid')) > 0
    assert len(knowledge_graph.read_cache_data('hr_t')) > 0
    assert len(knowledge_graph.read_cache_data('tr_h')) > 0
    assert len(knowledge_graph.read_cache_data('idx2entity')) > 0
    assert len(knowledge_graph.read_cache_data('idx2relation')) > 0
    assert len(knowledge_graph.read_cache_data('entity2idx')) > 0
    assert len(knowledge_graph.read_cache_data('relation2idx')) > 0
Пример #5
0
def test_benchmarks(dataset_name):
    """Function to test the the knowledge graph parse for Freebase."""
    knowledge_graph = KnowledgeGraph(dataset=dataset_name)
    knowledge_graph.force_prepare_data()
    knowledge_graph.dump()