Skip to content

Commit

Permalink
multilang fixes for default/non localised annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesamcl committed Mar 8, 2022
1 parent 6b26b5e commit 388ac3e
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public Pair<JsonElement, JsonElement> check(String filenameToSave, String path)
Pair<JsonElement, JsonElement> 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);
Expand All @@ -240,7 +240,7 @@ public Pair<JsonElement, JsonElement> 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");
}
Expand All @@ -260,7 +260,11 @@ public Pair<JsonElement, JsonElement> 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);
Expand Down
121 changes: 121 additions & 0 deletions ols-apps/ols-config-importer/src/main/resources/obo-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: [email protected]
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: [email protected]
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

Original file line number Diff line number Diff line change
Expand Up @@ -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<String> enValues = annotationValues.getStrings("en");
if(enValues != null) {
String label = annotationLabels.getFirstString("en");
String[] values = enValues.toArray(new String[0]);
List<String> 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<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,24 @@ public Map<String, Object> getAnnotationByLang(String lang) {

Map<String, Object> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,21 @@ public Map<String, Object> getAnnotationByLang(String lang) {

Map<String, Object> 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;
Expand Down
16 changes: 12 additions & 4 deletions ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Term.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,19 +286,27 @@ public Map<String, Object> getAnnotationByLang(String lang) {

Map<String, Object> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public LocalizedStrings() {

public LocalizedStrings(Map<String,String> strings) {
for(String lang : strings.keySet()) {
addString(lang, strings.get(lang));
addString(lang, strings.get(lang.toLowerCase()));
}
}

Expand All @@ -27,19 +27,22 @@ public Set<String> getLanguages() {
public Set<String> getNonEnLanguages() {
Set<String> 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<String> getStrings(String language) {
public List<String> getStrings(String... languages) {

List<String> strings = localizations.get(language);
for(String lang : languages) {

if(strings != null) {
return strings;
List<String> strings = localizations.get(lang.toLowerCase());

if(strings != null) {
return strings;
}
}

List<String> defaults = localizations.get("");
Expand All @@ -59,12 +62,15 @@ public Map<String, List<String>> getStrings() {
return localizations;
}

public String getFirstString(String language) {
public String getFirstString(String... languages) {

List<String> strings = localizations.get(language);
for(String lang : languages) {

if(strings != null && strings.size() > 0) {
return strings.get(0);
List<String> strings = localizations.get(lang.toLowerCase());

if(strings != null && strings.size() > 0) {
return strings.get(0);
}
}

List<String> defaults = localizations.get("");
Expand All @@ -78,11 +84,11 @@ public String getFirstString(String language) {

public void addString(String language, String value) {

List<String> strings = localizations.get(language);
List<String> strings = localizations.get(language.toLowerCase());

if(strings == null) {
strings = new ArrayList<>();
localizations.put(language, strings);
localizations.put(language.toLowerCase(), strings);
}

if(!strings.contains(value)) {
Expand Down

0 comments on commit 388ac3e

Please sign in to comment.