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

Commit

Permalink
Merge branch 'multilang-fix' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesamcl committed Apr 28, 2022
2 parents 568cab7 + a39f6ff commit 1b98c2a
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 60 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 @@ -217,10 +217,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,8 @@
package uk.ac.ebi.spot.ols.loader;

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

import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.OWLObjectRenderer;
import org.semanticweb.owlapi.manchestersyntax.renderer.ManchesterOWLSyntaxOWLObjectRendererImpl;
Expand Down Expand Up @@ -324,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 @@ -436,6 +459,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 @@ -1231,11 +1256,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 @@ -1250,45 +1282,46 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
Collection<OBOSynonym> oboSynonyms = new HashSet<>();
Collection<OBOXref> oboEntityXrefs = new HashSet<>();

// loop through other annotations in the imports closure
for (OWLOntology anOntology : getManager().ontologies().collect(Collectors.toSet())) {
EntitySearcher.getAnnotationAssertionAxioms(owlEntity, anOntology).forEach(annotationAssertionAxiom -> {
OWLAnnotationProperty annotationProperty = annotationAssertionAxiom.getProperty();
IRI annotationPropertyIRI = annotationProperty.getIRI();
OWLAnnotationValue value = annotationAssertionAxiom.getValue();

// blank string = default lang
String lang = "";

// but take lang from the value if it is present
if (value.isLiteral()) {
if (((OWLLiteral) value).hasLang()) {
lang = ((OWLLiteral) value).getLang();
ontologyLanguages.add(lang);
}
}
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 -> {

if (getLabelIRI().equals(annotationPropertyIRI)) {
classLabels.addString(lang, evaluateLabelAnnotationValue(
owlEntity, value).get());
} else if (getSynonymIRIs().contains(annotationPropertyIRI)) {
synonyms.addString(lang, getOWLAnnotationValueAsString(value).get());
} else if (getDefinitionIRIs().contains(annotationPropertyIRI)) {
definitions.addString(lang, getOWLAnnotationValueAsString(value).get());
} else if (annotationPropertyIRI.equals(Namespaces.OBOINOWL.createIRI("inSubset")) && value instanceof IRI) {
if (extractShortForm((IRI) value).isPresent()) {
slims.add(extractShortForm((IRI) value).get());
}
} else if (annotationPropertyIRI.equals(Namespaces.OWL.createIRI("deprecated"))) {
addObsoleteTerms(owlEntityIRI);
} else {
if (getOWLAnnotationValueAsString(value).isPresent()) {
// initialise maps if first time
if (!termAnnotations.containsKey(owlEntityIRI)) {
HashMap<IRI, LocalizedStrings> newMap = new HashMap<>();
newMap.put(annotationPropertyIRI, new LocalizedStrings());
termAnnotations.put(owlEntityIRI, newMap);
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();
IRI annotationPropertyIRI = annotationProperty.getIRI();
OWLAnnotationValue value = annotationAssertionAxiom.getValue();

// blank string = default lang
String lang = "";

// but take lang from the value if it is present
if(value.isLiteral()) {
if(((OWLLiteral) value).hasLang()) {
lang = ((OWLLiteral) value).getLang();
}
}

if (getLabelIRI().equals(annotationPropertyIRI)) {
classLabels.addString(lang, evaluateLabelAnnotationValue(
owlEntity, value).get());
}
else if (getSynonymIRIs().contains(annotationPropertyIRI)) {
synonyms.addString(lang, getOWLAnnotationValueAsString(value).get());
}
else if (getDefinitionIRIs().contains(annotationPropertyIRI)) {
definitions.addString(lang, getOWLAnnotationValueAsString(value).get());
}

if (!termAnnotations.get(owlEntityIRI).containsKey(annotationPropertyIRI)) {
Expand All @@ -1302,7 +1335,7 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
termAnnotations.get(owlEntityIRI).get(annotationPropertyIRI).addString(
lang, getOWLAnnotationValueAsString(value).get());
}
}
});
}

// pull out term replaced by
Expand Down Expand Up @@ -1370,13 +1403,41 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
String description = getOWLAnnotationValueAsString(axiomAnnotation.getValue()).get();
oboXrefs.setDescription(description);
}
}
oboEntityXrefs.add(oboXrefs);
}
});
});
}

setClassLabels(owlEntityIRI, classLabels);

// 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) {
setOboDefinitionCitation(owlEntityIRI, definitionCitations);
Expand All @@ -1399,6 +1460,7 @@ protected void evaluateAllAnnotationsValues(OWLEntity owlEntity) {
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 1b98c2a

Please sign in to comment.