def main(params: Parameters):
    # List of the six ACE corpus /adj/ folders (one for each type: bc, bn, cts, nw, un, wl)
    corpus_paths = params.arbitrary_list("corpus_paths")
    # Path to the project config file template (json file)
    json_template_path = params.existing_file("json_template_path")
    # Path to the cached_annotation_ser directory
    annotation_ser_path = params.existing_directory("annotation_ser_path")

    # Path to the cached_xmi directory
    cached_xmi_path = params.existing_directory("cached_xmi_path")

    # Path to target corpus (narrowed ACE-Corpus)
    cached_ace_data_path = params.creatable_directory("cached_ace_data_path")

    # List of users (strings)
    user_list = params.arbitrary_list("user_list")
    # List of event type (Format: "EVENT_TYPE.SUBTYPE" strings)
    event_list = params.arbitrary_list("event_list")

    # Output Directory Path where configured projects are moved to (use an empty directory)
    output_dir_path = params.creatable_directory("output_dir_path")

    flatten_ace_data(corpus_paths, cached_ace_data_path)

    complete_map = get_complete_project_to_doc_mapping(cached_ace_data_path)

    for user in user_list:
        for event_type in event_list:
            # For All events to be printed
            if event_type == "All":
                for event in complete_map:
                    configure_and_generate_project(
                        json_template_path=json_template_path,
                        event_name=event,
                        user_name=user,
                        event_doc_map=complete_map,
                        cached_ser_path=annotation_ser_path,
                        cached_xmi_path=cached_xmi_path,
                        output_dir_path=output_dir_path)
            else:
                configure_and_generate_project(
                    json_template_path=json_template_path,
                    event_name=event_type,
                    user_name=user,
                    event_doc_map=complete_map,
                    cached_ser_path=annotation_ser_path,
                    cached_xmi_path=cached_xmi_path,
                    output_dir_path=output_dir_path)
示例#2
0
def main(params: Parameters):
    # create_cas_from_apf(TEST_APF_PATH, TEST_SGM_PATH, OUTPUT_DIR_PATH)
    corpus_paths = params.arbitrary_list("corpus_paths")
    output_xmi_dir_path = params.creatable_directory("cached_xmi_path")
    type_system_path = params.existing_file("type_system_path")
    cas_xmi_template_path = params.existing_file("cas_xmi_template_path")

    # Load Typesystem
    with type_system_path.open('rb') as file:
        typesystem = load_typesystem(file)

    # Load xmi_template
    with cas_xmi_template_path.open('rb') as cas_xmi_file:
        cas_template = load_cas_from_xmi(cas_xmi_file, typesystem=typesystem)

    for ace_corpus_path in corpus_paths:
        print('Processing apf files from: ' + ace_corpus_path)
        start_time = time.perf_counter()
        for filename in os.listdir(ace_corpus_path):
            if filename.endswith(".apf.xml"):
                print("Processing " + filename)
                create_cas_from_apf(apf_filename=filename,
                                    apf_path=ace_corpus_path + filename,
                                    source_sgm_path=ace_corpus_path + filename.replace(
                                        ".apf.xml", ".sgm"),
                                    output_dir_path=output_xmi_dir_path, typesystem=typesystem,
                                    cas_template=cas_template)
        elapsed_time = time.perf_counter() - start_time
        print(f"Processing Completed. Time elapsed: {elapsed_time:0.4f} seconds")
示例#3
0
 def from_parameters(params: Parameters) -> Optional["SpackConfiguration"]:
     if SpackConfiguration.SPACK_ENVIRONMENT_PARAM in params:
         if SpackConfiguration.SPACK_PACKAGES_PARAM in params:
             raise RuntimeError(
                 f"{SpackConfiguration.SPACK_ENVIRONMENT_PARAM} "
                 f"and {SpackConfiguration.SPACK_PACKAGES_PARAM} are mutually exclusive"
             )
         return SpackConfiguration(
             spack_root=params.existing_directory(
                 SpackConfiguration.SPACK_ROOT_PARAM),
             spack_environment=params.string(
                 SpackConfiguration.SPACK_ENVIRONMENT_PARAM),
         )
     elif SpackConfiguration.SPACK_PACKAGES_PARAM in params:
         if SpackConfiguration.SPACK_ENVIRONMENT_PARAM in params:
             raise RuntimeError(
                 f"{SpackConfiguration.SPACK_ENVIRONMENT_PARAM} "
                 f"and {SpackConfiguration.SPACK_PACKAGES_PARAM} are mutually exclusive"
             )
         return SpackConfiguration(
             spack_root=params.existing_directory(
                 SpackConfiguration.SPACK_ROOT_PARAM),
             spack_packages=[
                 SpackPackage.parse(package_specifier)
                 for package_specifier in params.arbitrary_list(
                     SpackConfiguration.SPACK_PACKAGES_PARAM)
             ],
         )
     else:
         return None