2ronwalf def create_ontology(internal_iri, name: internal_iri) 2ronwalf basepath: determine_path(internal_iri, :basepath), 2ronwalf file_extension: determine_path(internal_iri, :extension), 2ronwalf externally_generated_locid: determine_locid(internal_iri), 2ronwalf ontology = SingleOntology.create!(options, without_protection: true) 2ronwalf Repository.where(name: Settings.external_repository_name).first_or_create 2ronwalf def add_to_repository(iri, message, user, location: iri) 2ronwalf tmp_path = download_iri(location) 2ronwalf repository.save_file_only(tmp_path, determine_path(iri, :fullpath), 2ronwalf def determine_locid(external_iri) 2ronwalf "/#{repository.path}/#{determine_path(external_iri, :fullpath)}" 2ronwalf def determine_iri(external_iri) 2ronwalf "#{Hostname.url_authority}#{determine_locid(external_iri)}" 2ronwalf def determine_path(external_iri, symbol) when :fullpath then determine_filepath(external_iri) when :dirpath then determine_filepath(external_iri, false) when :basepath then determine_basepath(external_iri, false) when :basename then determine_basename(external_iri, false) when :extension then determine_extension(external_iri) def determine_filepath(external_iri, with_file=true) fullpath = iri_split(external_iri) with_file ? fullpath : fullpath.sub(determine_basename(external_iri), '') def determine_basepath(external_iri, with_extension=true) basepath = iri_split(external_iri) with_extension ? basepath : basepath.sub(determine_extension(external_iri), '') def determine_basename(external_iri, with_extension=true) File.basename(determine_basepath(external_iri, with_extension)) def determine_extension(external_iri) File.extname(determine_basepath(external_iri)) # split iri into wget -r style match = URI::regexp(['http','https']).match(iri) elsif URI::regexp(['file']).match(iri) def download_iri(external_iri) dir = Pathname.new('/tmp/reference_ontologies/'). join(determine_path(external_iri, :dirpath)) ensure_path_existence(dir) filepath = dir.join(determine_basename(external_iri)) fetch_uri_content(external_iri, write_file: filepath) def ensure_path_existence(directory)