示例#1
0
def generate_entity_path_files(
    entity_storage: AbstractEntityStorage,
    entities_by_type: Dict[str, Dictionary],
    relation_type_storage: AbstractRelationTypeStorage,
    relation_types: Dictionary,
    dynamic_relations: bool,
) -> None:
    print(
        f"Preparing counts and dictionaries for entities and relation types:")
    entity_storage.prepare()
    relation_type_storage.prepare()

    for entity_name, entities in entities_by_type.items():
        for part in range(entities.num_parts):
            print(f"- Writing count of entity type {entity_name} "
                  f"and partition {part}")
            entity_storage.save_count(entity_name, part,
                                      entities.part_size(part))
            entity_storage.save_names(entity_name, part,
                                      entities.get_part_list(part))

    if dynamic_relations:
        print("- Writing count of dynamic relations")
        relation_type_storage.save_count(relation_types.size())
        relation_type_storage.save_names(relation_types.get_list())
示例#2
0
def generate_entity_path_files(
    entity_path: str,
    entities_by_type: Dict[str, Dictionary],
    relation_types: Dictionary,
    dynamic_relations: bool,
) -> None:

    print("Preparing entity path %s:" % entity_path)
    for entity_name, entities in entities_by_type.items():
        for part in range(entities.num_parts):
            print("- Writing count of entity type %s and partition %d" %
                  (entity_name, part))
            with open(
                    os.path.join(
                        entity_path,
                        "entity_count_%s_%d.txt" % (entity_name, part)),
                    "wt") as tf:
                tf.write("%d" % entities.part_size(part))

    if dynamic_relations:
        print("- Writing count of dynamic relations")
        with open(os.path.join(entity_path, "dynamic_rel_count.txt"),
                  "wt") as tf:
            tf.write("%d" % relation_types.size())