org.monarchinitiative.phenol.io.utils.CurieUtilBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of phenol-io Show documentation
Show all versions of phenol-io Show documentation
phenol-io contains the generic I/O functionality for ontologies
package org.monarchinitiative.phenol.io.utils;
import com.google.common.collect.ImmutableMap;
import org.prefixcommons.CurieUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
import java.io.InputStream;
import java.util.Map;
/**
* Wrapper class to help build a {@link CurieUtil} using the default mappings and / or just a subset.
*
* @author Jules Jacobsen
*/
public class CurieUtilBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(CurieUtilBuilder.class);
private static final Map DEFAULT_CURIE_MAP = ImmutableMap.copyOf(generate());
private static final CurieUtil DEFAULT_CURIE_UTIL = new CurieUtil(DEFAULT_CURIE_MAP);
private CurieUtilBuilder() {
}
public static Map defaultCurieMap() {
return DEFAULT_CURIE_MAP;
}
public static CurieUtil defaultCurieUtil() {
return DEFAULT_CURIE_UTIL;
}
public static CurieUtil withDefaultsAnd(Map additionalCuries) {
ImmutableMap.Builder merged = new ImmutableMap.Builder<>();
merged.putAll(DEFAULT_CURIE_MAP);
merged.putAll(additionalCuries);
return new CurieUtil(merged.build());
}
public static CurieUtil just(Map curies) {
return new CurieUtil(ImmutableMap.copyOf(curies));
}
/**
* Reads curie_map.yaml and put the k-v entries into curieMap, which will be used for initialization of
* CurieUtil. The original curie_map.yaml is available at Dipper's Github:
* https://github.com/monarch-initiative/dipper/blob/master/dipper/curie_map.yaml.
*/
private static Map generate() {
try {
InputStream inputStream = CurieUtilBuilder.class.getClassLoader().getResourceAsStream("curie_map.yaml");
Yaml yaml = new Yaml();
return yaml.load(inputStream);
} catch (Exception e) {
LOGGER.error(e.getMessage(), e);
}
return ImmutableMap.of();
}
}