From 388ac3eada53dd5a8042f0e0ed95eb1931a5b6ad Mon Sep 17 00:00:00 2001 From: James McLaughlin Date: Tue, 8 Mar 2022 17:53:03 +0000 Subject: [PATCH] multilang fixes for default/non localised annotations --- .../uk/ac/ebi/ols/apitester/OlsApiTester.java | 10 +- .../src/main/resources/obo-config.yaml | 121 ++++++++++++++++++ .../ac/ebi/spot/ols/loader/NodeCreator.java | 15 ++- .../ebi/spot/ols/neo4j/model/Individual.java | 16 ++- .../ac/ebi/spot/ols/neo4j/model/Property.java | 15 ++- .../uk/ac/ebi/spot/ols/neo4j/model/Term.java | 16 ++- .../ebi/spot/ols/util/LocalizedStrings.java | 30 +++-- 7 files changed, 190 insertions(+), 33 deletions(-) diff --git a/apitester/src/main/java/uk/ac/ebi/ols/apitester/OlsApiTester.java b/apitester/src/main/java/uk/ac/ebi/ols/apitester/OlsApiTester.java index 09979aae..a56d92ea 100644 --- a/apitester/src/main/java/uk/ac/ebi/ols/apitester/OlsApiTester.java +++ b/apitester/src/main/java/uk/ac/ebi/ols/apitester/OlsApiTester.java @@ -231,7 +231,7 @@ public Pair check(String filenameToSave, String path) Pair results = getBoth(path); JsonElement result1 = results.getLeft(); - JsonElement result2 = results.getLeft(); + JsonElement result2 = results.getRight(); String result1Json = gson.toJson(result1); String result2Json = gson.toJson(result2); @@ -240,7 +240,7 @@ public Pair check(String filenameToSave, String path) save(filenameToSave + "_2.json", result2Json); if(!result1Json.equals(result2Json)) { - System.out.println("⚠️ Response did not match"); + System.out.println("❌ Response did not match"); } else { System.out.println("✅ Response matched"); } @@ -260,7 +260,11 @@ public Pair getBoth(String path) throws IOException, M public JsonElement get(String baseUrl, String path) throws IOException, MalformedURLException { - URLConnection conn = new URL(baseUrl + path).openConnection(); + String finalUrl = baseUrl + path; + + System.out.println("GET " + finalUrl); + + URLConnection conn = new URL(finalUrl).openConnection(); InputStream is = conn.getInputStream(); Reader reader = new InputStreamReader(is, "UTF-8"); JsonElement result = JsonParser.parseReader(reader); diff --git a/ols-apps/ols-config-importer/src/main/resources/obo-config.yaml b/ols-apps/ols-config-importer/src/main/resources/obo-config.yaml index f4c020cf..7101883a 100644 --- a/ols-apps/ols-config-importer/src/main/resources/obo-config.yaml +++ b/ols-apps/ols-config-importer/src/main/resources/obo-config.yaml @@ -67,4 +67,125 @@ ontologies: repository: https://github.com/Superraptor/GSSO title: Gender, Sex, and Sexual Orientation (GSSO) ontology tracker: https://github.com/Superraptor/GSSO/issues + - activity_status: active + contact: + email: davidos@ebi.ac.uk + github: dosumis + label: David Osumi-Sutherland + orcid: 0000-0002-7073-9172 + dependencies: + - id: pr + - id: go + - id: uberon + - id: ro + - id: pato + - id: ncbitaxon + - id: bfo + - id: cl + - id: omo + - id: nbo + - id: chebi + - id: so + description: Cell types that are provisionally defined by experimental techniques + such as single cell or single nucleus transcriptomics rather than a straightforward + & coherent set of properties. + domain: phenotype + homepage: https://github.com/obophenotype/provisional_cell_ontology + id: pcl + layout: ontology_detail + license: + label: CC BY 4.0 + logo: http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by.png + url: http://creativecommons.org/licenses/by/4.0/ + ontology_purl: http://purl.obolibrary.org/obo/pcl.owl + preferredPrefix: PCL + products: + - id: pcl.owl + ontology_purl: http://purl.obolibrary.org/obo/pcl.owl + - id: pcl.obo + ontology_purl: http://purl.obolibrary.org/obo/pcl.obo + - id: pcl.json + ontology_purl: http://purl.obolibrary.org/obo/pcl.json + - id: pcl-base.owl + ontology_purl: http://purl.obolibrary.org/obo/pcl-base.owl + - id: pcl-base.obo + ontology_purl: http://purl.obolibrary.org/obo/pcl-base.obo + - id: pcl-base.json + ontology_purl: http://purl.obolibrary.org/obo/pcl-base.json + - id: pcl-full.owl + ontology_purl: http://purl.obolibrary.org/obo/pcl-full.owl + - id: pcl-full.obo + ontology_purl: http://purl.obolibrary.org/obo/pcl-full.obo + - id: pcl-full.json + ontology_purl: http://purl.obolibrary.org/obo/pcl-full.json + - id: pcl-simple.owl + ontology_purl: http://purl.obolibrary.org/obo/pcl-simple.owl + - id: pcl-simple.obo + ontology_purl: http://purl.obolibrary.org/obo/pcl-simple.obo + - id: pcl-simple.json + ontology_purl: http://purl.obolibrary.org/obo/pcl-simple.json + repository: https://github.com/obophenotype/provisional_cell_ontology + title: Provisional Cell Ontology + tracker: https://github.com/obophenotype/provisional_cell_ontology/issues + - activity_status: active + build: + checkout: git clone https://github.com/scdodev/scdo-ontology.git + path: . + system: git + contact: + email: giant.plankton@gmail.com + github: JadeHotchkiss + label: Jade Hotchkiss + orcid: 0000-0002-2193-0704 + dependencies: + - id: apollo_sv + - id: aro + - id: chebi + - id: chmo + - id: cmo + - id: doid + - id: dron + - id: duo + - id: envo + - id: eupath + - id: exo + - id: gaz + - id: gsso + - id: hp + - id: hsapdv + - id: ico + - id: ido + - id: idomal + - id: mp + - id: nbo + - id: ncit + - id: obi + - id: ogms + - id: opmi + - id: pr + - id: sbo + - id: stato + - id: symp + - id: uo + - id: vo + - id: vt + description: An ontology for the standardization of terminology and integration + of knowledge about Sickle Cell Disease. + domain: disease + homepage: https://scdontology.h3abionet.org/ + id: scdo + layout: ontology_detail + license: + label: GPL-3.0 + url: https://www.gnu.org/licenses/gpl-3.0.en.html + ontology_purl: https://github.com/scdodev/scdo-ontology/blob/master/scdo_fr-t-en.owl + preferredPrefix: SCDO + products: + - id: scdo.owl + ontology_purl: http://purl.obolibrary.org/obo/scdo.owl + - id: scdo.obo + ontology_purl: http://purl.obolibrary.org/obo/scdo.obo + repository: https://github.com/scdodev/scdo-ontology + title: Sickle Cell Disease Ontology + tracker: https://github.com/scdodev/scdo-ontology/issues diff --git a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/loader/NodeCreator.java b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/loader/NodeCreator.java index da53c413..463c56b5 100644 --- a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/loader/NodeCreator.java +++ b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/loader/NodeCreator.java @@ -184,16 +184,19 @@ protected static void addAnnotationPropertiesConditionally(OntologyLoader loader for (IRI property : annotations.keySet()) { LocalizedStrings annotationLabels = loader.getTermLabels().get(property); LocalizedStrings annotationValues = annotations.get(property); - List enValues = annotationValues.getStrings("en"); - if(enValues != null) { - String label = annotationLabels.getFirstString("en"); - String[] values = enValues.toArray(new String[0]); + List defaultValues = annotationValues.getStrings("en", "en-US"); + if(defaultValues != null) { + String label = annotationLabels.getFirstString("en", "en-US"); + String[] values = defaultValues.toArray(new String[0]); nodeProperties.put(ANNOTATION_DESIGNATION + label, values); } - for (String language : annotationLabels.getNonEnLanguages()) { + for (String language : annotationLabels.getLanguages()) { + if(language.equals("")) { + continue; + } List localizedValues = annotationValues.getStrings(language); if(localizedValues == null || localizedValues.size() == 0) { - localizedValues = annotationValues.getStrings("en"); + localizedValues = annotationValues.getStrings("en", "en-US"); } if (localizedValues != null) { String label = annotationLabels.getFirstString(language); diff --git a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Individual.java b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Individual.java index a1575e54..4de6ddff 100644 --- a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Individual.java +++ b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Individual.java @@ -204,16 +204,24 @@ public Map getAnnotationByLang(String lang) { Map res = new TreeMap<>(); - if (lang.equals("en") && annotation != null) { + if ( (lang.equals("en") || lang.startsWith("en-")) && annotation != null) { res.putAll(annotation.asMap()); } for (String k : localizedAnnotations.keySet()) { - if (k.indexOf(lang + "-") == 0) { - res.put(k.substring(lang.length() + 1), localizedAnnotations.get(k)); - } + + int n = lang.lastIndexOf('-'); + + if(n != -1) { + String annoLang = lang.substring(0, n); + + if (annoLang.equalsIgnoreCase(lang)) { + res.put(k.substring(n + 1), localizedAnnotations.get(k)); + } + } } return res; } + } diff --git a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Property.java b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Property.java index 74629d8c..89b1b010 100644 --- a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Property.java +++ b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Property.java @@ -203,14 +203,21 @@ public Map getAnnotationByLang(String lang) { Map res = new TreeMap<>(); - if (lang.equals("en") && annotation != null) { + if ( (lang.equals("en") || lang.startsWith("en-")) && annotation != null) { res.putAll(annotation.asMap()); } for (String k : localizedAnnotations.keySet()) { - if (k.indexOf(lang + "-") == 0) { - res.put(k.substring(lang.length() + 1), localizedAnnotations.get(k)); - } + + int n = lang.lastIndexOf('-'); + + if(n != -1) { + String annoLang = lang.substring(0, n); + + if (annoLang.equalsIgnoreCase(lang)) { + res.put(k.substring(n + 1), localizedAnnotations.get(k)); + } + } } return res; diff --git a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Term.java b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Term.java index ce5cf2f0..9c0e1167 100644 --- a/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Term.java +++ b/ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Term.java @@ -286,19 +286,27 @@ public Map getAnnotationByLang(String lang) { Map res = new TreeMap<>(); - if (lang.equals("en") && annotation != null) { + if ( (lang.equals("en") || lang.startsWith("en-")) && annotation != null) { res.putAll(annotation.asMap()); } for (String k : localizedAnnotations.keySet()) { - if (k.indexOf(lang + "-") == 0) { - res.put(k.substring(lang.length() + 1), localizedAnnotations.get(k)); - } + + int n = lang.lastIndexOf('-'); + + if(n != -1) { + String annoLang = lang.substring(0, n); + + if (annoLang.equalsIgnoreCase(lang)) { + res.put(k.substring(n + 1), localizedAnnotations.get(k)); + } + } } return res; } + @JsonProperty(value = IS_DEFINING_ONTOLOGY) public boolean isLocal() { return isLocal; diff --git a/ontology-tools/src/main/java/uk/ac/ebi/spot/ols/util/LocalizedStrings.java b/ontology-tools/src/main/java/uk/ac/ebi/spot/ols/util/LocalizedStrings.java index 4003dcfe..fdadb6ae 100644 --- a/ontology-tools/src/main/java/uk/ac/ebi/spot/ols/util/LocalizedStrings.java +++ b/ontology-tools/src/main/java/uk/ac/ebi/spot/ols/util/LocalizedStrings.java @@ -16,7 +16,7 @@ public LocalizedStrings() { public LocalizedStrings(Map strings) { for(String lang : strings.keySet()) { - addString(lang, strings.get(lang)); + addString(lang, strings.get(lang.toLowerCase())); } } @@ -27,19 +27,22 @@ public Set getLanguages() { public Set getNonEnLanguages() { Set langs = new HashSet<>(); for(String lang : localizations.keySet()) { - if(lang.compareTo("en") != 0 && lang.compareTo("") != 0) { + if(lang.compareTo("en") != 0 && (!lang.startsWith("en-")) && lang.compareTo("") != 0) { langs.add(lang); } } return langs; } - public List getStrings(String language) { + public List getStrings(String... languages) { - List strings = localizations.get(language); + for(String lang : languages) { - if(strings != null) { - return strings; + List strings = localizations.get(lang.toLowerCase()); + + if(strings != null) { + return strings; + } } List defaults = localizations.get(""); @@ -59,12 +62,15 @@ public Map> getStrings() { return localizations; } - public String getFirstString(String language) { + public String getFirstString(String... languages) { - List strings = localizations.get(language); + for(String lang : languages) { - if(strings != null && strings.size() > 0) { - return strings.get(0); + List strings = localizations.get(lang.toLowerCase()); + + if(strings != null && strings.size() > 0) { + return strings.get(0); + } } List defaults = localizations.get(""); @@ -78,11 +84,11 @@ public String getFirstString(String language) { public void addString(String language, String value) { - List strings = localizations.get(language); + List strings = localizations.get(language.toLowerCase()); if(strings == null) { strings = new ArrayList<>(); - localizations.put(language, strings); + localizations.put(language.toLowerCase(), strings); } if(!strings.contains(value)) {