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

Commit

Permalink
Fix for non-localized annotations not visible when viewing another la…
Browse files Browse the repository at this point in the history
…nguage
  • Loading branch information
jamesamcl committed Apr 14, 2022
1 parent 7d7456f commit a39f6ff
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ ontologies:
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
ontology_purl: https://raw.githubusercontent.com/scdodev/scdo-ontology/master/scdo_fr-t-en.owl
preferredPrefix: SCDO
products:
- id: scdo.owl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ public Map<String, Object> getAnnotationByLang(String lang) {

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

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

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

if (annoLang.equalsIgnoreCase(lang)) {
res.put(k.substring(n + 1), localizedAnnotations.get(k));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ public Map<String, Object> getAnnotationByLang(String lang) {

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

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

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

if (annoLang.equalsIgnoreCase(lang)) {
res.put(k.substring(n + 1), localizedAnnotations.get(k));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,10 @@ public Map<String, Object> getAnnotationByLang(String lang) {

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

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

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

if (annoLang.equalsIgnoreCase(lang)) {
res.put(k.substring(n + 1), localizedAnnotations.get(k));
Expand Down
3 changes: 1 addition & 2 deletions ols-web/src/main/resources/static/css/new_ols.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions ols-web/src/main/resources/static/css/new_ols.css.map

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.ac.ebi.spot.ols.loader;

import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;

import org.mockito.internal.debugging.Localized;
import org.semanticweb.owlapi.apibinding.OWLManager;
Expand Down Expand Up @@ -325,6 +326,27 @@ private void initializeVocabularyToIgnore() throws OntologyLoadingException {
owlVocabulary.add(factory.getOWLBottomObjectProperty().getIRI());
}


private void populateOntologyLanguages(Collection<OWLEntity> allEntities) {

for (OWLEntity owlEntity: allEntities) {
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())){
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {

OWLAnnotationValue value = annotationAssertionAxiom.getValue();

if(value.isLiteral()) {
if(((OWLLiteral) value).hasLang()) {
ontologyLanguages.add( ((OWLLiteral) value).getLang() );
}
}

});
}
}
}


@Override
public String getShortForm(IRI ontologyTermIRI) {

Expand Down Expand Up @@ -440,6 +462,8 @@ protected OWLOntology loadOntology() throws OWLOntologyCreationException {
ResourceUsage.logUsage(getLogger(), "#### Monitoring ", getOntologyName() +
":After copying of entities", ":");

populateOntologyLanguages(allEntities);

indexTerms(allEntities);
ResourceUsage.logUsage(getLogger(), "#### Monitoring ", getOntologyName() +
":After index terms", ":");
Expand Down Expand Up @@ -1242,11 +1266,18 @@ protected Optional<String> evaluateLabelAnnotationValue(OWLEntity entity, OWLAnn

private boolean isEnglishLabel(OWLAnnotationValue value) {
return value instanceof OWLLiteral && ((OWLLiteral) value).getLang().equalsIgnoreCase("en");
}

protected void evaluateAnnotationValue(OWLEntity entity, OWLAnnotationProperty annotationProperty, IRI annotationPropertyIRI, OWLAnnotationValue value, String lang) {



}

protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {

IRI owlEntityIRI = owlEntity.getIRI();

Set<String> slims = new HashSet<>();

LocalizedStrings definitions = new LocalizedStrings();
Expand All @@ -1261,7 +1292,21 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
Collection<OBOSynonym> oboSynonyms = new HashSet<>();
Collection<OBOXref> oboEntityXrefs = new HashSet<>();

// loop through other annotations in the imports closure
Set<IRI> annotationProperties = new HashSet<>();

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

OWLAnnotationProperty annotationProperty = annotationAssertionAxiom.getProperty();
IRI annotationPropertyIRI = annotationProperty.getIRI();

annotationProperties.add(annotationPropertyIRI);
});
}


// pass 2: read the annotations
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())){
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {
OWLAnnotationProperty annotationProperty = annotationAssertionAxiom.getProperty();
Expand All @@ -1275,11 +1320,9 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
if(value.isLiteral()) {
if(((OWLLiteral) value).hasLang()) {
lang = ((OWLLiteral) value).getLang();
ontologyLanguages.add(lang);
}
}


if (getLabelIRI().equals(annotationPropertyIRI)) {
classLabels.addString(lang, evaluateLabelAnnotationValue(
owlEntity, value).get());
Expand Down Expand Up @@ -1390,9 +1433,41 @@ else if (annotationPropertyIRI.equals(Namespaces.OWL.createIRI("deprecated"))) {
}
oboEntityXrefs.add(oboXrefs);
}

});
}


// cross reference the set of all ontologies properties with the set of
// languages in the ontology. Any missing languages are added with the English strings.
// Otherwise, if you switch language in the webapp to a language into which the ontology
// is not localised, the annotations will not appear!
//
if (termAnnotations.containsKey(owlEntityIRI)) {

Map<IRI, LocalizedStrings> annotations = termAnnotations.get(owlEntityIRI);

for(IRI annotationPropertyIri : annotations.keySet()) {

LocalizedStrings annos = annotations.get(annotationPropertyIri);

for(String ontologyLang : ontologyLanguages) {

if(!annos.getLanguages().contains(ontologyLang)) {
annos.setStrings(ontologyLang, annos.getStrings("", "en", "en-US"));
}
}

}
}

for (String ontologyLang : ontologyLanguages) {
if (!classLabels.getLanguages().contains(ontologyLang)) {
classLabels.setStrings(ontologyLang, classLabels.getStrings("", "en", "en-US"));
}
}


setClassLabels(owlEntityIRI, classLabels);

if (definitionCitations.size() > 0) {
Expand All @@ -1416,6 +1491,7 @@ else if (annotationPropertyIRI.equals(Namespaces.OWL.createIRI("deprecated"))) {
if (slims.size() >0) {
setSlims(owlEntityIRI, slims);
}

}

private OBOXref extractOBOXrefs (OWLAnnotation annotation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public void addDefaultString(String value) {

}


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

}

public void setStrings(String language, List<String> strings) {

localizations.put(language, new ArrayList<String>(strings));

}

}

0 comments on commit a39f6ff

Please sign in to comment.