Skip to content

Commit

Permalink
Fix #424
Browse files Browse the repository at this point in the history
  • Loading branch information
henrietteharmse committed Jul 20, 2023
1 parent f4b369f commit 3ce067b
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,12 @@ public void search(
if (fieldList.contains("id")) outDoc.put("id", JsonHelper.getString(json, "id"));
if (fieldList.contains("iri")) outDoc.put("iri", JsonHelper.getString(json, "iri"));
if (fieldList.contains("ontology_name")) outDoc.put("ontology_name", JsonHelper.getString(json, "ontologyId"));
if (fieldList.contains("label")) outDoc.put("label", JsonHelper.getStrings(json, "label"));
if (fieldList.contains("label")) {
var label = outDoc.put("label", JsonHelper.getStrings(json, "label"));
if(label!=null) {
outDoc.put("label", label);
}
}
if (fieldList.contains("description")) outDoc.put("description", JsonHelper.getStrings(json, "definition"));
if (fieldList.contains("short_form")) outDoc.put("short_form", JsonHelper.getStrings(json, "shortForm"));
if (fieldList.contains("obo_id")) outDoc.put("obo_id", JsonHelper.getStrings(json, "curie"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ public static JsonObject localizeLinkedEntities(JsonObject linkedEntities, Strin
JsonObject entityProps = linkedEntities.getAsJsonObject(entityIri);
JsonObject entityPropsRes = new JsonObject();
for(String k : entityProps.keySet()) {
entityPropsRes.add(k, localizeValueWithFallbacks(entityProps.get(k), lang));
var val = localizeValueWithFallbacks(entityProps.get(k), lang);
if(val!=null)
entityPropsRes.add(k, val);
}
res.add(entityIri, entityPropsRes);
}
Expand Down
50 changes: 50 additions & 0 deletions dataload/configs/ado.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "OBO Foundry",
"title": "The OBO Foundry",
"markdown": "kramdown",
"highlighter": "rouge",
"baseurl": "/",
"imgurl": "/images",
"repo": "https://github.com/OBOFoundry/OBOFoundry.github.io/",
"repo_src": "https://github.com/OBOFoundry/OBOFoundry.github.io/blob/master/",
"author": {
"name": "OBO Technical WG"
},
"ontologies": [
{
"activity_status": "active",
"contact": {
"email": "alpha.tom.kodamullil@scai.fraunhofer.de",
"github": "akodamullil",
"label": "Alpha Tom Kodamullil",
"orcid": "0000-0001-9896-3531"
},
"dependencies": [
{
"id": "bfo"
}
],
"description": "Alzheimer's Disease Ontology is a knowledge-based ontology that encompasses varieties of concepts related to Alzheimer'S Disease, structured by upper level Basic Formal Ontology(BFO). This Ontology is enriched by the interrelated entities that demonstrate the network of the understanding on Alzheimer's disease and can be readily applied for text mining.",
"domain": "health",
"homepage": "https://github.com/Fraunhofer-SCAI-Applied-Semantics/ADO",
"id": "ado",
"layout": "ontology_detail",
"license": {
"label": "CC BY 4.0",
"logo": "http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by.png",
"url": "https://creativecommons.org/licenses/by/4.0/"
},
"ontology_purl": "http://purl.obolibrary.org/obo/ado.owl",
"preferredPrefix": "ADO",
"products": [
{
"id": "ado.owl",
"ontology_purl": "http://purl.obolibrary.org/obo/ado.owl"
}
],
"repository": "https://github.com/Fraunhofer-SCAI-Applied-Semantics/ADO",
"title": "Alzheimer's Disease Ontology",
"tracker": "https://github.com/Fraunhofer-SCAI-Applied-Semantics/ADO/issues"
}
]
}
2 changes: 1 addition & 1 deletion dataload/extras/orcid2level/dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.ac.ebi.spot</groupId>
<artifactId>orcid-extractor</artifactId>
<artifactId>orcid2level</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import uk.ac.ebi.rdf2json.OntologyGraph;
import uk.ac.ebi.rdf2json.OntologyNode;
import uk.ac.ebi.rdf2json.annotators.helpers.PropertyCollator;
import uk.ac.ebi.rdf2json.properties.PropertyValue;

public class DefinitionAnnotator {

Expand All @@ -27,6 +28,27 @@ public static Set<String> getDefinitionProperties(OntologyGraph graph) {
}

public static void annotateDefinitions(OntologyGraph graph) {
PropertyCollator.collateProperties(graph, "definition", getDefinitionProperties(graph), List.of());
collateProperties(graph, "definition", getDefinitionProperties(graph));
}

private static void collateProperties(OntologyGraph graph, String destProp, Collection<String> sourceProps) {

for(String id : graph.nodes.keySet()) {
OntologyNode c = graph.nodes.get(id);

// skip bnodes
if(c.uri == null)
continue;

for(String prop : sourceProps) {
List<PropertyValue> values = c.properties.getPropertyValues(prop);
if(values != null) {
for(PropertyValue value : values) {
c.properties.addProperty(destProp, value);
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import uk.ac.ebi.rdf2json.OntologyGraph;
import uk.ac.ebi.rdf2json.OntologyNode;
import uk.ac.ebi.rdf2json.annotators.helpers.PropertyCollator;
import uk.ac.ebi.rdf2json.properties.PropertyValue;
import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral;

public class LabelAnnotator {

Expand All @@ -12,7 +14,8 @@ public static Set<String> getLabelProperties(OntologyGraph graph) {
List.of(
"http://www.w3.org/2000/01/rdf-schema#label",
"http://purl.org/dc/elements/1.1/title",
"http://purl.org/dc/terms/title"
"http://purl.org/dc/terms/title",
"http://www.w3.org/2004/02/skos/core#prefLabel"
)
);

Expand All @@ -26,6 +29,58 @@ public static Set<String> getLabelProperties(OntologyGraph graph) {
}

public static void annotateLabels(OntologyGraph graph) {
PropertyCollator.collateProperties(graph, "label", getLabelProperties(graph), List.of("shortForm"));
collateProperties(graph, "label", getLabelProperties(graph), List.of("shortForm"));
}

private static void collateProperties(OntologyGraph graph, String destProp, Collection<String> sourceProps, Collection<String> fallbackProps) {

long startTime3 = System.nanoTime();

for(String id : graph.nodes.keySet()) {
OntologyNode c = graph.nodes.get(id);

// skip bnodes
if(c.uri == null)
continue;

boolean hasEnglishValue = false;

for(String prop : sourceProps) {
List<PropertyValue> values = c.properties.getPropertyValues(prop);
if(values != null) {
for(PropertyValue value : values) {
c.properties.addProperty(destProp, value);
if(!isNonEnglishValue(graph, value))
hasEnglishValue = true;
}
}
}

if(!hasEnglishValue) {
for(String prop : fallbackProps) {
List<PropertyValue> values = c.properties.getPropertyValues(prop);
if (values != null) {
for (PropertyValue value : values) {
c.properties.addProperty(destProp, value);
}
}
}
}
}

long endTime3 = System.nanoTime();
System.out.println("collate properties from " + sourceProps + " and fallback " + fallbackProps + " into " + destProp + ": " + ((endTime3 - startTime3) / 1000 / 1000 / 1000));


}

private static boolean isNonEnglishValue(OntologyGraph graph, PropertyValue value) {
if(value.getType() == PropertyValue.Type.LITERAL) {
PropertyValueLiteral literal = (PropertyValueLiteral) value;
if( !literal.getLang().equals("") && !literal.getLang().equals("en")) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ public static Set<String> getSynonymProperties(OntologyGraph graph) {
}

public static void annotateSynonyms(OntologyGraph graph) {
PropertyCollator.collateProperties(graph, "synonym", getSynonymProperties(graph), List.of());
collateProperties(graph, "synonym", getSynonymProperties(graph));
}

private static void collateProperties(OntologyGraph graph, String destProp, Collection<String> sourceProps) {

for(String id : graph.nodes.keySet()) {
OntologyNode c = graph.nodes.get(id);

// skip bnodes
if(c.uri == null)
continue;

for(String prop : sourceProps) {
List<PropertyValue> values = c.properties.getPropertyValues(prop);
if(values != null) {
for(PropertyValue value : values) {
c.properties.addProperty(destProp, value);
}
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,14 @@
import uk.ac.ebi.rdf2json.OntologyNode;
import uk.ac.ebi.rdf2json.OntologyGraph;
import uk.ac.ebi.rdf2json.properties.PropertyValue;
import uk.ac.ebi.rdf2json.properties.PropertyValueBNode;
import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral;

import java.util.Collection;
import java.util.List;

public class PropertyCollator {

public static void collateProperties(OntologyGraph graph, String destProp, Collection<String> sourceProps, Collection<String> fallbackProps) {

long startTime3 = System.nanoTime();

for(String id : graph.nodes.keySet()) {
OntologyNode c = graph.nodes.get(id);

// skip bnodes
if(c.uri == null)
continue;

boolean annotated = false;

for(String prop : sourceProps) {
List<PropertyValue> values = c.properties.getPropertyValues(prop);
if(values != null) {
for(PropertyValue value : values) {
c.properties.addProperty(destProp, value);
annotated = true;
}
}
}

if(!annotated) {
for(String prop : fallbackProps) {
List<PropertyValue> values = c.properties.getPropertyValues(prop);
if (values != null) {
for (PropertyValue value : values) {
c.properties.addProperty(destProp, value);
}
}
}
}
}

long endTime3 = System.nanoTime();
System.out.println("collate properties from " + sourceProps + " and fallback " + fallbackProps + " into " + destProp + ": " + ((endTime3 - startTime3) / 1000 / 1000 / 1000));


}
}


9 changes: 9 additions & 0 deletions testcases/localized-labels/label.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"ontologies": [
{
"id": "label",
"preferredPrefix": "label",
"ontology_purl": "./testcases/localized-labels/label.rdf"
}
]
}
100 changes: 100 additions & 0 deletions testcases/localized-labels/label.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.ebi.ac.uk/ols4/testcase/label/"
xml:base="http://www.ebi.ac.uk/ols4/testcase/label/"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<owl:Ontology rdf:about="http://www.ebi.ac.uk/ols4/testcase/label">
<owl:versionIRI rdf:resource="http://www.ebi.ac.uk/ols4/testcase/label/v.0.0.1"/>
</owl:Ontology>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Object Properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://www.ebi.ac.uk/ols4/testcase/label#deProperty -->

<owl:ObjectProperty rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#deProperty">
<rdfs:label xml:lang="de">de Lang</rdfs:label>
</owl:ObjectProperty>



<!-- http://www.ebi.ac.uk/ols4/testcase/label#enProperty -->

<owl:ObjectProperty rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#enProperty">
<rdfs:label xml:lang="en">en label</rdfs:label>
</owl:ObjectProperty>



<!-- http://www.ebi.ac.uk/ols4/testcase/label#noLabelProperty -->

<owl:ObjectProperty rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#noLabelProperty"/>



<!-- http://www.ebi.ac.uk/ols4/testcase/label#property -->

<owl:ObjectProperty rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#property">
<rdfs:label>noLangProperty</rdfs:label>
</owl:ObjectProperty>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- http://www.ebi.ac.uk/ols4/testcase/label#deLangClass -->

<owl:Class rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#deLangClass">
<rdfs:label xml:lang="de">de lang class</rdfs:label>
</owl:Class>



<!-- http://www.ebi.ac.uk/ols4/testcase/label#enLabelClass -->

<owl:Class rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#enLabelClass">
<rdfs:label xml:lang="en">en label class</rdfs:label>
</owl:Class>



<!-- http://www.ebi.ac.uk/ols4/testcase/label#noLabelClass -->

<owl:Class rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#noLabelClass"/>



<!-- http://www.ebi.ac.uk/ols4/testcase/label#noLangClass -->

<owl:Class rdf:about="http://www.ebi.ac.uk/ols4/testcase/label#noLangClass">
<rdfs:comment></rdfs:comment>
<rdfs:label>no lang label class</rdfs:label>
</owl:Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.24.2023-01-14T21:28:32Z) https://github.com/owlcs/owlapi -->

0 comments on commit 3ce067b

Please sign in to comment.