Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 1b98c2a

Browse files
committed
Merge branch 'multilang-fix' into dev
2 parents 568cab7 + a39f6ff commit 1b98c2a

File tree

8 files changed

+125
-60
lines changed

8 files changed

+125
-60
lines changed

ols-apps/ols-config-importer/src/main/resources/obo-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ ontologies:
178178
license:
179179
label: GPL-3.0
180180
url: https://www.gnu.org/licenses/gpl-3.0.en.html
181-
ontology_purl: https://github.com/scdodev/scdo-ontology/blob/master/scdo_fr-t-en.owl
181+
ontology_purl: https://raw.githubusercontent.com/scdodev/scdo-ontology/master/scdo_fr-t-en.owl
182182
preferredPrefix: SCDO
183183
products:
184184
- id: scdo.owl

ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Individual.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ public Map<String, Object> getAnnotationByLang(String lang) {
217217

218218
for (String k : localizedAnnotations.keySet()) {
219219

220-
int n = lang.lastIndexOf('-');
220+
int n = k.lastIndexOf('-');
221221

222222
if(n != -1) {
223-
String annoLang = lang.substring(0, n);
223+
String annoLang = k.substring(0, n);
224224

225225
if (annoLang.equalsIgnoreCase(lang)) {
226226
res.put(k.substring(n + 1), localizedAnnotations.get(k));

ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Property.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,10 @@ public Map<String, Object> getAnnotationByLang(String lang) {
209209

210210
for (String k : localizedAnnotations.keySet()) {
211211

212-
int n = lang.lastIndexOf('-');
212+
int n = k.lastIndexOf('-');
213213

214214
if(n != -1) {
215-
String annoLang = lang.substring(0, n);
215+
String annoLang = k.substring(0, n);
216216

217217
if (annoLang.equalsIgnoreCase(lang)) {
218218
res.put(k.substring(n + 1), localizedAnnotations.get(k));

ols-neo4j/src/main/java/uk/ac/ebi/spot/ols/neo4j/model/Term.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,10 @@ public Map<String, Object> getAnnotationByLang(String lang) {
292292

293293
for (String k : localizedAnnotations.keySet()) {
294294

295-
int n = lang.lastIndexOf('-');
295+
int n = k.lastIndexOf('-');
296296

297297
if(n != -1) {
298-
String annoLang = lang.substring(0, n);
298+
String annoLang = k.substring(0, n);
299299

300300
if (annoLang.equalsIgnoreCase(lang)) {
301301
res.put(k.substring(n + 1), localizedAnnotations.get(k));

ols-web/src/main/resources/static/css/new_ols.css

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ols-web/src/main/resources/static/css/new_ols.css.map

Lines changed: 5 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ontology-tools/src/main/java/uk/ac/ebi/spot/ols/loader/AbstractOWLOntologyLoader.java

Lines changed: 105 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package uk.ac.ebi.spot.ols.loader;
22

33
import com.google.common.collect.Multimap;
4+
import com.google.common.collect.SetMultimap;
5+
46
import org.semanticweb.owlapi.apibinding.OWLManager;
57
import org.semanticweb.owlapi.io.OWLObjectRenderer;
68
import org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterOWLSyntaxOWLObjectRendererImpl;
@@ -324,6 +326,27 @@ private void initializeVocabularyToIgnore() throws OntologyLoadingException {
324326
owlVocabulary.add(factory.getOWLBottomObjectProperty().getIRI());
325327
}
326328

329+
330+
private void populateOntologyLanguages(Collection<OWLEntity> allEntities) {
331+
332+
for (OWLEntity owlEntity: allEntities) {
333+
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())){
334+
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {
335+
336+
OWLAnnotationValue value = annotationAssertionAxiom.getValue();
337+
338+
if(value.isLiteral()) {
339+
if(((OWLLiteral) value).hasLang()) {
340+
ontologyLanguages.add( ((OWLLiteral) value).getLang() );
341+
}
342+
}
343+
344+
});
345+
}
346+
}
347+
}
348+
349+
327350
@Override
328351
public String getShortForm(IRI ontologyTermIRI) {
329352

@@ -436,6 +459,8 @@ protected OWLOntology loadOntology() throws OWLOntologyCreationException {
436459
ResourceUsage.logUsage(getLogger(), "#### Monitoring ", getOntologyName() +
437460
":After copying of entities", ":");
438461

462+
populateOntologyLanguages(allEntities);
463+
439464
indexTerms(allEntities);
440465
ResourceUsage.logUsage(getLogger(), "#### Monitoring ", getOntologyName() +
441466
":After index terms", ":");
@@ -1231,11 +1256,18 @@ protected Optional<String> evaluateLabelAnnotationValue(OWLEntity entity, OWLAnn
12311256

12321257
private boolean isEnglishLabel(OWLAnnotationValue value) {
12331258
return value instanceof OWLLiteral && ((OWLLiteral) value).getLang().equalsIgnoreCase("en");
1259+
}
1260+
1261+
protected void evaluateAnnotationValue(OWLEntity entity, OWLAnnotationProperty annotationProperty, IRI annotationPropertyIRI, OWLAnnotationValue value, String lang) {
1262+
1263+
1264+
12341265
}
12351266

12361267
protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
12371268

12381269
IRI owlEntityIRI = owlEntity.getIRI();
1270+
12391271
Set<String> slims = new HashSet<>();
12401272

12411273
LocalizedStrings definitions = new LocalizedStrings();
@@ -1250,45 +1282,46 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
12501282
Collection<OBOSynonym> oboSynonyms = new HashSet<>();
12511283
Collection<OBOXref> oboEntityXrefs = new HashSet<>();
12521284

1253-
// loop through other annotations in the imports closure
1254-
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())) {
1255-
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {
1256-
OWLAnnotationProperty annotationProperty = annotationAssertionAxiom.getProperty();
1257-
IRI annotationPropertyIRI = annotationProperty.getIRI();
1258-
OWLAnnotationValue value = annotationAssertionAxiom.getValue();
1259-
1260-
// blank string = default lang
1261-
String lang = "";
1262-
1263-
// but take lang from the value if it is present
1264-
if (value.isLiteral()) {
1265-
if (((OWLLiteral) value).hasLang()) {
1266-
lang = ((OWLLiteral) value).getLang();
1267-
ontologyLanguages.add(lang);
1268-
}
1269-
}
1285+
Set<IRI> annotationProperties = new HashSet<>();
12701286

1287+
// pass 1: populate the set of all annotation properties used
1288+
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())){
1289+
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {
12711290

1272-
if (getLabelIRI().equals(annotationPropertyIRI)) {
1273-
classLabels.addString(lang, evaluateLabelAnnotationValue(
1274-
owlEntity, value).get());
1275-
} else if (getSynonymIRIs().contains(annotationPropertyIRI)) {
1276-
synonyms.addString(lang, getOWLAnnotationValueAsString(value).get());
1277-
} else if (getDefinitionIRIs().contains(annotationPropertyIRI)) {
1278-
definitions.addString(lang, getOWLAnnotationValueAsString(value).get());
1279-
} else if (annotationPropertyIRI.equals(Namespaces.OBOINOWL.createIRI("inSubset")) && value instanceof IRI) {
1280-
if (extractShortForm((IRI) value).isPresent()) {
1281-
slims.add(extractShortForm((IRI) value).get());
1282-
}
1283-
} else if (annotationPropertyIRI.equals(Namespaces.OWL.createIRI("deprecated"))) {
1284-
addObsoleteTerms(owlEntityIRI);
1285-
} else {
1286-
if (getOWLAnnotationValueAsString(value).isPresent()) {
1287-
// initialise maps if first time
1288-
if (!termAnnotations.containsKey(owlEntityIRI)) {
1289-
HashMap<IRI, LocalizedStrings> newMap = new HashMap<>();
1290-
newMap.put(annotationPropertyIRI, new LocalizedStrings());
1291-
termAnnotations.put(owlEntityIRI, newMap);
1291+
OWLAnnotationProperty annotationProperty = annotationAssertionAxiom.getProperty();
1292+
IRI annotationPropertyIRI = annotationProperty.getIRI();
1293+
1294+
annotationProperties.add(annotationPropertyIRI);
1295+
});
1296+
}
1297+
1298+
1299+
// pass 2: read the annotations
1300+
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())){
1301+
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {
1302+
OWLAnnotationProperty annotationProperty = annotationAssertionAxiom.getProperty();
1303+
IRI annotationPropertyIRI = annotationProperty.getIRI();
1304+
OWLAnnotationValue value = annotationAssertionAxiom.getValue();
1305+
1306+
// blank string = default lang
1307+
String lang = "";
1308+
1309+
// but take lang from the value if it is present
1310+
if(value.isLiteral()) {
1311+
if(((OWLLiteral) value).hasLang()) {
1312+
lang = ((OWLLiteral) value).getLang();
1313+
}
1314+
}
1315+
1316+
if (getLabelIRI().equals(annotationPropertyIRI)) {
1317+
classLabels.addString(lang, evaluateLabelAnnotationValue(
1318+
owlEntity, value).get());
1319+
}
1320+
else if (getSynonymIRIs().contains(annotationPropertyIRI)) {
1321+
synonyms.addString(lang, getOWLAnnotationValueAsString(value).get());
1322+
}
1323+
else if (getDefinitionIRIs().contains(annotationPropertyIRI)) {
1324+
definitions.addString(lang, getOWLAnnotationValueAsString(value).get());
12921325
}
12931326

12941327
if (!termAnnotations.get(owlEntityIRI).containsKey(annotationPropertyIRI)) {
@@ -1302,7 +1335,7 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
13021335
termAnnotations.get(owlEntityIRI).get(annotationPropertyIRI).addString(
13031336
lang, getOWLAnnotationValueAsString(value).get());
13041337
}
1305-
}
1338+
});
13061339
}
13071340

13081341
// pull out term replaced by
@@ -1370,13 +1403,41 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
13701403
String description = getOWLAnnotationValueAsString(axiomAnnotation.getValue()).get();
13711404
oboXrefs.setDescription(description);
13721405
}
1373-
}
1374-
oboEntityXrefs.add(oboXrefs);
1375-
}
1376-
});
1406+
});
13771407
}
13781408

1379-
setClassLabels(owlEntityIRI, classLabels);
1409+
1410+
// cross reference the set of all ontologies properties with the set of
1411+
// languages in the ontology. Any missing languages are added with the English strings.
1412+
// Otherwise, if you switch language in the webapp to a language into which the ontology
1413+
// is not localised, the annotations will not appear!
1414+
//
1415+
if (termAnnotations.containsKey(owlEntityIRI)) {
1416+
1417+
Map<IRI, LocalizedStrings> annotations = termAnnotations.get(owlEntityIRI);
1418+
1419+
for(IRI annotationPropertyIri : annotations.keySet()) {
1420+
1421+
LocalizedStrings annos = annotations.get(annotationPropertyIri);
1422+
1423+
for(String ontologyLang : ontologyLanguages) {
1424+
1425+
if(!annos.getLanguages().contains(ontologyLang)) {
1426+
annos.setStrings(ontologyLang, annos.getStrings("", "en", "en-US"));
1427+
}
1428+
}
1429+
1430+
}
1431+
}
1432+
1433+
for (String ontologyLang : ontologyLanguages) {
1434+
if (!classLabels.getLanguages().contains(ontologyLang)) {
1435+
classLabels.setStrings(ontologyLang, classLabels.getStrings("", "en", "en-US"));
1436+
}
1437+
}
1438+
1439+
1440+
setClassLabels(owlEntityIRI, classLabels);
13801441

13811442
if (definitionCitations.size() > 0) {
13821443
setOboDefinitionCitation(owlEntityIRI, definitionCitations);
@@ -1399,6 +1460,7 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
13991460
if (slims.size() > 0) {
14001461
setSlims(owlEntityIRI, slims);
14011462
}
1463+
14021464
}
14031465

14041466
private OBOXref extractOBOXrefs(OWLAnnotation annotation) {

ontology-tools/src/main/java/uk/ac/ebi/spot/ols/util/LocalizedStrings.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public void addDefaultString(String value) {
102102

103103
}
104104

105+
105106
public int size() {
106107
int n = 0;
107108
for(List<String> values : this.localizations.values()) {
@@ -119,5 +120,11 @@ public void addAll(LocalizedStrings other) {
119120
}
120121

121122
}
123+
124+
public void setStrings(String language, List<String> strings) {
125+
126+
localizations.put(language, new ArrayList<String>(strings));
127+
128+
}
122129

123130
}

0 commit comments

Comments
 (0)