diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/SolrFieldMapper.java b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/SolrFieldMapper.java index fba40164b..9f0ae9f47 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/SolrFieldMapper.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/SolrFieldMapper.java @@ -5,6 +5,8 @@ import java.util.List; import java.util.stream.Collectors; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + public class SolrFieldMapper { // Maps OLS3 field names to the OLS4 schema @@ -36,23 +38,23 @@ public static List mapFieldsList(Collection ols3FieldNames) { continue; } - if (legacyFieldName.equals("label")) { - newFields.add(prefix + "label" + suffix); + if (legacyFieldName.equals(LABEL.getText())) { + newFields.add(prefix + LABEL.getText() + suffix); continue; } - if (legacyFieldName.equals("synonym")) { - newFields.add(prefix + "synonym" + suffix); + if (legacyFieldName.equals(SYNONYM.getText())) { + newFields.add(prefix + SYNONYM.getText() + suffix); continue; } - if (legacyFieldName.equals("definition")) { - newFields.add(prefix + "definition" + suffix); + if (legacyFieldName.equals(DEFINITION.getText())) { + newFields.add(prefix + DEFINITION.getText() + suffix); continue; } - if (legacyFieldName.equals("description")) { - newFields.add(prefix + "definition" + suffix); + if (legacyFieldName.equals(DEFINITION.getOls3Text())) { + newFields.add(prefix + DEFINITION.getText() + suffix); continue; } diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1PreferredRootTermAssembler.java b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1PreferredRootTermAssembler.java index 2e941caef..21fe94634 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1PreferredRootTermAssembler.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1PreferredRootTermAssembler.java @@ -9,6 +9,7 @@ import org.springframework.web.util.UriUtils; import uk.ac.ebi.spot.ols.model.v1.V1Related; import uk.ac.ebi.spot.ols.model.v1.V1Term; +import static uk.ac.ebi.ols.shared.DefinedFields.*; import java.util.Collection; import java.util.HashSet; diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SearchController.java b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SearchController.java index c8e846896..55896fb00 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SearchController.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SearchController.java @@ -130,7 +130,7 @@ public void search( solrQuery.set("defType", "edismax"); solrQuery.setQuery(query.toLowerCase()); // Specify the query fields with boosting - String[] fields = {"label_s^5", "synonym_s^3", "short_form_s^2", "obo_id_s^2", "iri_s", "annotations_trimmed"}; + String[] fields = {LABEL.getText()+"_s^5", SYNONYM.getText()+"_s^3", "short_form_s^2", "obo_id_s^2", "iri_s", "annotations_trimmed"}; solrQuery.set("qf", String.join(" ", SolrFieldMapper.mapFieldsList(List.of(fields)))); // Boost exact phrase matches in label and synonym fields solrQuery.set("pf", "lowercase_label^10 lowercase_synonym^5"); @@ -142,7 +142,7 @@ public void search( solrQuery.set("defType", "edismax"); solrQuery.setQuery(query); - String[] fields = {"label^5", "synonym^3", "definition", "short_form^2", "obo_id^2", "iri", "annotations_trimmed"}; + String[] fields = {LABEL.getText()+"^5", SYNONYM.getText()+"^3", DEFINITION.getText(), "short_form^2", "obo_id^2", "iri", "annotations_trimmed"}; solrQuery.set("qf", String.join(" ", SolrFieldMapper.mapFieldsList(List.of(fields)))); @@ -206,9 +206,10 @@ public void search( .collect(Collectors.joining(" OR ")); if (inclusive) { - solrQuery.addFilterQuery("filter( iri: (" + result + ")) filter(hierarchicalAncestor: (" + result + "))"); + solrQuery.addFilterQuery("filter( iri: (" + result + ")) filter(" + HIERARCHICAL_ANCESTOR.getText()+ + ": (" + result + "))"); } else { - solrQuery.addFilterQuery("hierarchicalAncestor: (" + result + ")"); + solrQuery.addFilterQuery(HIERARCHICAL_ANCESTOR.getText() + ": (" + result + ")"); } } @@ -219,9 +220,10 @@ public void search( .collect(Collectors.joining(" OR ")); if (inclusive) { - solrQuery.addFilterQuery("filter( iri: (" + result + ")) filter(hierarchicalAncestor: (" + result + "))"); + solrQuery.addFilterQuery("filter( iri: (" + result + ")) filter("+ HIERARCHICAL_ANCESTOR.getText()+ + ": (" + result + "))"); } else { - solrQuery.addFilterQuery("hierarchicalAncestor: (" + result + ")"); + solrQuery.addFilterQuery(HIERARCHICAL_ANCESTOR.getText()+": (" + result + ")"); } } @@ -281,8 +283,8 @@ public void search( fieldList.add("id"); fieldList.add("iri"); fieldList.add("ontology_name"); - fieldList.add("label"); - fieldList.add("description"); + fieldList.add(LABEL.getText()); + fieldList.add(DEFINITION.getOls3Text()); fieldList.add("short_form"); fieldList.add("obo_id"); fieldList.add("type"); @@ -292,13 +294,14 @@ 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")) { - var label = outDoc.put("label", JsonHelper.getString(json, "label")); + if (fieldList.contains(LABEL.getText())) { + var label = outDoc.put(LABEL.getText(), JsonHelper.getString(json, LABEL.getText())); if(label!=null) { - outDoc.put("label", label); + outDoc.put(LABEL.getText(), label); } } - if (fieldList.contains("description")) outDoc.put("description", JsonHelper.getStrings(json, "definition")); + if (fieldList.contains(DEFINITION.getOls3Text())) outDoc.put(DEFINITION.getOls3Text(), + JsonHelper.getStrings(json, DEFINITION.getText())); if (fieldList.contains("short_form")) outDoc.put("short_form", JsonHelper.getString(json, "shortForm")); if (fieldList.contains("obo_id")) outDoc.put("obo_id", JsonHelper.getString(json, "curie")); if (fieldList.contains(IS_DEFINING_ONTOLOGY.getOls3Text())) outDoc.put(IS_DEFINING_ONTOLOGY.getOls3Text(), @@ -307,7 +310,7 @@ public void search( if (fieldList.contains("type")) { outDoc.put("type", JsonHelper.getType(json, "type")); } - if (fieldList.contains("synonym")) outDoc.put("synonym", JsonHelper.getStrings(json, "synonym")); + if (fieldList.contains(SYNONYM.getText())) outDoc.put(SYNONYM.getText(), JsonHelper.getStrings(json, SYNONYM.getText())); if (fieldList.contains("ontology_prefix")) outDoc.put("ontology_prefix", JsonHelper.getString(json, "ontologyPreferredPrefix")); if (fieldList.contains("subset")) outDoc.put("subset", JsonHelper.getStrings(json, "http://www.geneontology.org/formats/oboInOwl#inSubset")); if (fieldList.contains("ontology_iri")) outDoc.put("ontology_iri", JsonHelper.getStrings(json, "ontologyIri").get(0)); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SelectController.java b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SelectController.java index c7833650b..8aad57cba 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SelectController.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SelectController.java @@ -97,7 +97,7 @@ public void select( } solrQuery.setQuery(query); solrQuery.set("defType", "edismax"); - solrQuery.set("qf", "label whitespace_edge_label synonym whitespace_edge_synonym shortForm whitespace_edge_shortForm curie iri"); + solrQuery.set("qf", LABEL.getText()+" whitespace_edge_label synonym whitespace_edge_synonym shortForm whitespace_edge_shortForm curie iri"); solrQuery.set("bq", "type:ontology^10.0 " + IS_DEFINING_ONTOLOGY.getText() +":true^100.0 str_label:\"" + queryLc + "\"^1000 edge_label:\"" + queryLc + "\"^500 str_synonym:\"" + queryLc + "\" edge_synonym:\"" + queryLc + "\"^100"); @@ -129,14 +129,14 @@ public void select( String result = childrenOf.stream() .map(addQuotes) .collect(Collectors.joining(" OR ")); - solrQuery.addFilterQuery("directAncestor: (" + result + ")"); + solrQuery.addFilterQuery(DIRECT_ANCESTOR.getText() + ": (" + result + ")"); } if (allChildrenOf != null) { String result = allChildrenOf.stream() .map(addQuotes) .collect(Collectors.joining(" OR ")); - solrQuery.addFilterQuery("hierarchicalAncestor: (" + result + ")"); + solrQuery.addFilterQuery(HIERARCHICAL_ANCESTOR.getText() + ": (" + result + ")"); } solrQuery.addFilterQuery(IS_OBSOLETE.getText() + ":" + queryObsoletes); @@ -146,9 +146,9 @@ public void select( solrQuery.add("hl.simple.pre", ""); solrQuery.add("hl.simple.post", ""); solrQuery.addHighlightField("whitespace_edge_label"); - solrQuery.addHighlightField("label"); + solrQuery.addHighlightField(LABEL.getText()); solrQuery.addHighlightField("whitespace_edge_synonym"); - solrQuery.addHighlightField("synonym"); + solrQuery.addHighlightField(SYNONYM.getText()); logger.debug("select: ()", solrQuery.toQueryString()); @@ -175,10 +175,10 @@ public void select( fieldList.add("iri"); fieldList.add("short_form"); fieldList.add("obo_id"); - fieldList.add("label"); + fieldList.add(LABEL.getText()); fieldList.add("ontology_name"); fieldList.add("ontology_prefix"); - fieldList.add("description"); + fieldList.add(DEFINITION.getOls3Text()); fieldList.add("type"); } @@ -187,8 +187,9 @@ public void select( if (fieldList.contains("id")) outDoc.put("id", res.get("id").toString().replace('+', ':')); 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.getString(json, "label")); - if (fieldList.contains("description")) outDoc.put("description", JsonHelper.getStrings(json, "definition")); + if (fieldList.contains(LABEL.getText())) outDoc.put(LABEL.getText(), JsonHelper.getString(json, LABEL.getText())); + if (fieldList.contains(DEFINITION.getOls3Text())) outDoc.put(DEFINITION.getOls3Text(), + JsonHelper.getStrings(json, DEFINITION.getText())); if (fieldList.contains("short_form")) outDoc.put("short_form", JsonHelper.getString(json, "shortForm")); if (fieldList.contains("obo_id")) outDoc.put("obo_id", JsonHelper.getString(json, "curie")); if (fieldList.contains(IS_DEFINING_ONTOLOGY.getOls3Text())) outDoc.put(IS_DEFINING_ONTOLOGY.getOls3Text(), @@ -197,7 +198,7 @@ public void select( if (fieldList.contains("type")) { outDoc.put("type", JsonHelper.getType(json, "type")); } - if (fieldList.contains("synonym")) outDoc.put("synonym", JsonHelper.getStrings(json, "synonym")); + if (fieldList.contains(SYNONYM.getText())) outDoc.put(SYNONYM.getText(), JsonHelper.getStrings(json, SYNONYM.getText())); if (fieldList.contains("ontology_prefix")) outDoc.put("ontology_prefix", JsonHelper.getString(json, "ontologyPreferredPrefix")); docs.add(outDoc); @@ -228,9 +229,9 @@ public void select( Map resHighlight = new LinkedHashMap<>(); for(var fieldName : highlight.keySet()) { if(fieldName.equals("whitespace_edge_label")) { - resHighlight.put("label_autosuggest", highlight.get(fieldName)); + resHighlight.put(LABEL.getText()+"_autosuggest", highlight.get(fieldName)); } else if(fieldName.equals("whitespace_edge_synonym")) { - resHighlight.put("synonym_autosuggest", highlight.get(fieldName)); + resHighlight.put(SYNONYM.getText()+"_autosuggest", highlight.get(fieldName)); } else { resHighlight.put(fieldName, highlight.get(fieldName)); } diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SuggestController.java b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SuggestController.java index a0ed42721..256fbbb7f 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SuggestController.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/controller/api/v1/V1SuggestController.java @@ -26,6 +26,8 @@ import java.nio.charset.StandardCharsets; import java.util.*; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + @Tag(name = "Suggest Controller") @RestController public class V1SuggestController { @@ -55,9 +57,9 @@ public void suggest( solrQuery.setQuery(query); solrQuery.set("defType", "edismax"); - solrQuery.set("qf", "label^10 edge_label^2 whitespace_edge_label^1"); + solrQuery.set("qf", LABEL.getText()+"^10 edge_label^2 whitespace_edge_label^1"); solrQuery.set("wt", "json"); - solrQuery.setFields("label"); + solrQuery.setFields(LABEL.getText()); solrQuery.setSort("score", SolrQuery.ORDER.desc); @@ -73,7 +75,7 @@ public void suggest( solrQuery.setStart(start); solrQuery.setRows(rows); solrQuery.add("group", "true"); - solrQuery.add("group.field", "label"); + solrQuery.add("group.field", LABEL.getText()); solrQuery.add("group.main", "true"); @@ -90,7 +92,7 @@ public void suggest( for(SolrDocument res : qr.getResults()) { Map outDoc = new HashMap<>(); - outDoc.put("autosuggest", res.get("label")); + outDoc.put("autosuggest", res.get(LABEL.getText())); docs.add(outDoc); } diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1AncestorsJsTreeBuilder.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1AncestorsJsTreeBuilder.java index 1df8d7672..0b38ec415 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1AncestorsJsTreeBuilder.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1AncestorsJsTreeBuilder.java @@ -80,7 +80,7 @@ private void createJsTreeEntries(List> jstree, JsonObject ent } jstreeEntry.put("iri", entityIri); - jstreeEntry.put("text", JsonHelper.getString(entity, "label")); + jstreeEntry.put("text", JsonHelper.getString(entity, LABEL.getText())); Collection childIris = entityIriToChildIris.get(entityIri); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1ChildrenJsTreeBuilder.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1ChildrenJsTreeBuilder.java index fe8ff8434..f0ef2ce78 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1ChildrenJsTreeBuilder.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1ChildrenJsTreeBuilder.java @@ -32,11 +32,11 @@ List> buildJsTree() { jstreeEntry.put("id", base64Encode(thisEntityJsTreeIdDecoded + ";" + child.getAsJsonObject().get("iri").getAsString())); jstreeEntry.put("parent", base64Encode(thisEntityJsTreeIdDecoded)); jstreeEntry.put("iri", JsonHelper.getString(child.getAsJsonObject(), "iri")); - jstreeEntry.put("text", JsonHelper.getString(child.getAsJsonObject(), "label")); + jstreeEntry.put("text", JsonHelper.getString(child.getAsJsonObject(), LABEL.getText())); jstreeEntry.put("state", Map.of("opened", false)); jstreeEntry.put("children", JsonHelper.getString(child.getAsJsonObject(), HAS_DIRECT_CHILDREN.getText()).equals("true") - || JsonHelper.getString(child.getAsJsonObject(), "hasHierarchicalChildren").equals("true") + || JsonHelper.getString(child.getAsJsonObject(), HAS_HIERARCHICAL_CHILDREN.getText()).equals("true") ); Map attrObj = new LinkedHashMap<>(); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1GraphRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1GraphRepository.java index 9c7aa2ce8..7214e1a7f 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1GraphRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1GraphRepository.java @@ -12,6 +12,8 @@ import uk.ac.ebi.spot.ols.repository.transforms.RemoveLiteralDatatypesTransform; import uk.ac.ebi.spot.ols.service.Neo4jClient; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + import java.util.*; import java.util.stream.Collectors; @@ -76,13 +78,13 @@ private Map getGraphForEntity(String iri, String type, String ne for(String referencedIri : linkedEntities.keySet()) { JsonObject reference = linkedEntities.getAsJsonObject(referencedIri); if(!iriToLabel.containsKey(referencedIri)) - iriToLabel.put(referencedIri, JsonHelper.getString(reference, "label")); + iriToLabel.put(referencedIri, JsonHelper.getString(reference, LABEL.getText())); } } Map nodeRes = new LinkedHashMap<>(); nodeRes.put("iri", JsonHelper.getString(ontologyNodeObject, "iri")); - nodeRes.put("label", JsonHelper.getString(ontologyNodeObject, "label")); + nodeRes.put(LABEL.getText(), JsonHelper.getString(ontologyNodeObject, LABEL.getText())); return nodeRes; }).collect(Collectors.toList()); @@ -107,7 +109,7 @@ private Map getGraphForEntity(String iri, String type, String ne if(propertyLabel == null) propertyLabel = "is a"; - edgeRes.put("label", propertyLabel); + edgeRes.put(LABEL.getText(), propertyLabel); edgeRes.put("uri", uri); return edgeRes; diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1JsTreeRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1JsTreeRepository.java index 36d0618e6..e93c99a38 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1JsTreeRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1JsTreeRepository.java @@ -7,6 +7,8 @@ import uk.ac.ebi.spot.ols.repository.neo4j.OlsNeo4jClient; import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + import java.util.*; import java.util.stream.Collectors; @@ -30,7 +32,7 @@ public List> getJsTreeForIndividual(String iri, String ontolo private List> getJsTreeForEntity(String iri, String type, String neo4jType, String ontologyId, String lang) { - List parentRelationIRIs = List.of("directParent"); + List parentRelationIRIs = List.of(DIRECT_PARENT.getText()); String thisEntityId = ontologyId + "+" + type + "+" + iri; @@ -59,7 +61,7 @@ public List> getJsTreeChildrenForIndividual(String individual private List> getJsTreeChildrenForEntity(String iri, String jstreeId, String type, String neo4jType, String ontologyId, String lang) { - List parentRelationIRIs = List.of("directParent"); + List parentRelationIRIs = List.of(DIRECT_PARENT.getText()); String thisEntityId = ontologyId + "+" + type + "+" + iri; diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1PropertyRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1PropertyRepository.java index 3098f0860..c77b922bf 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1PropertyRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1PropertyRepository.java @@ -30,22 +30,26 @@ public class V1PropertyRepository { V1OntologyRepository ontologyRepository; public Page getParents(String ontologyId, String iri, String lang, Pageable pageable) { - return neo4jClient.traverseOutgoingEdges("OntologyProperty", ontologyId + "+property+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return neo4jClient.traverseOutgoingEdges("OntologyProperty", ontologyId + "+property+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1PropertyMapper.mapProperty(record, lang)); } public Page getChildren(String ontologyId, String iri, String lang, Pageable pageable) { - return this.neo4jClient.traverseIncomingEdges("OntologyProperty", ontologyId + "+property+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.traverseIncomingEdges("OntologyProperty", ontologyId + "+property+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1PropertyMapper.mapProperty(record, lang)); } public Page getDescendants(String ontologyId, String iri, String lang, Pageable pageable) { - return this.neo4jClient.recursivelyTraverseIncomingEdges("OntologyProperty", ontologyId + "+property+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseIncomingEdges("OntologyProperty", ontologyId + "+property+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1PropertyMapper.mapProperty(record, lang)); } public Page getAncestors(String ontologyId, String iri, String lang, Pageable pageable) { - return neo4jClient.recursivelyTraverseOutgoingEdges("OntologyProperty", ontologyId + "+property+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return neo4jClient.recursivelyTraverseOutgoingEdges("OntologyProperty", ontologyId + "+property+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1PropertyMapper.mapProperty(record, lang)); } diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1TermRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1TermRepository.java index cd03273b5..fa84de098 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1TermRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/V1TermRepository.java @@ -40,13 +40,14 @@ public class V1TermRepository { public Page getParents(String ontologyId, String iri, String lang, Pageable pageable) { - return this.neo4jClient.traverseOutgoingEdges("OntologyClass", ontologyId + "+class+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.traverseOutgoingEdges("OntologyClass", ontologyId + "+class+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(node -> V1TermMapper.mapTerm(node, lang)); } public Page getHierarchicalParents(String ontologyId, String iri, String lang, Pageable pageable) { - List relationIRIs = List.of("hierarchicalParent"); + List relationIRIs = List.of(HIERARCHICAL_PARENT.getText()); return this.neo4jClient.traverseOutgoingEdges("OntologyClass", ontologyId + "+class+" + iri, relationIRIs, Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); @@ -54,7 +55,7 @@ public Page getHierarchicalParents(String ontologyId, String iri, String public Page getHierarchicalAncestors(String ontologyId, String iri, String lang, Pageable pageable) { - List relationIRIs = List.of("hierarchicalParent"); + List relationIRIs = List.of(HIERARCHICAL_PARENT.getText()); return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", ontologyId + "+class+" + iri, relationIRIs, Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); @@ -63,13 +64,14 @@ public Page getHierarchicalAncestors(String ontologyId, String iri, Stri public Page getChildren(String ontologyId, String iri, String lang, Pageable pageable) { - return this.neo4jClient.traverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.traverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); } public Page getHierarchicalChildren(String ontologyId, String iri, String lang, Pageable pageable) { - List relationIRIs = List.of("hierarchicalParent"); + List relationIRIs = List.of(HIERARCHICAL_PARENT.getText()); return this.neo4jClient.traverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, relationIRIs, Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); @@ -78,16 +80,18 @@ public Page getHierarchicalChildren(String ontologyId, String iri, Strin public Page getHierarchicalDescendants(String ontologyId, String iri, String lang, Pageable pageable) { - List relationIRIs = List.of("hierarchicalParent"); + List relationIRIs = List.of(HIERARCHICAL_PARENT.getText()); - return this.neo4jClient.recursivelyTraverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, relationIRIs, Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, + relationIRIs, Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); } public Page getDescendants(String ontologyId, String iri, String lang, Pageable pageable) { - return this.neo4jClient.recursivelyTraverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseIncomingEdges("OntologyClass", ontologyId + "+class+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); } @@ -96,7 +100,8 @@ public Page getAncestors(String ontologyId, String iri, String lang, Pag V1Ontology ontology = ontologyRepository.get(ontologyId, lang); - return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", ontologyId + "+class+" + iri, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", ontologyId + "+class+" + iri, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); } @@ -105,7 +110,7 @@ public Page getRelated(String ontologyId, String iri, String lang, Strin return this.neo4jClient.traverseOutgoingEdges( "OntologyClass", ontologyId + "+class+" + iri, - Arrays.asList("relatedTo"), + Arrays.asList(RELATED_TO.getText()), Map.of("property", relation), pageable) .map(record -> V1TermMapper.mapTerm(record, lang)); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/AnnotationExtractor.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/AnnotationExtractor.java index bdb08290d..1859bf6a1 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/AnnotationExtractor.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/AnnotationExtractor.java @@ -10,6 +10,7 @@ import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; +import static uk.ac.ebi.ols.shared.DefinedFields.*; public class AnnotationExtractor { @@ -95,7 +96,7 @@ public static Map extractAnnotations(JsonObject json) { if(linkedEntityObj != null) { - String definedLabel = JsonHelper.getString(linkedEntityObj.getAsJsonObject(), "label"); + String definedLabel = JsonHelper.getString(linkedEntityObj.getAsJsonObject(), LABEL.getText()); if(definedLabel != null) { label = definedLabel; diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1IndividualMapper.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1IndividualMapper.java index 389823083..16fec1466 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1IndividualMapper.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1IndividualMapper.java @@ -5,6 +5,7 @@ import uk.ac.ebi.spot.ols.model.v1.V1Individual; import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform; import uk.ac.ebi.spot.ols.repository.v1.JsonHelper; +import static uk.ac.ebi.ols.shared.DefinedFields.*; import java.util.Objects; @@ -25,9 +26,9 @@ public static V1Individual mapIndividual(JsonElement json, String lang) { individual.ontologyPrefix = JsonHelper.getString(localizedJson, "ontologyPreferredPrefix"); individual.ontologyIri = JsonHelper.getString(localizedJson, "ontologyIri"); - individual.label = JsonHelper.getString(localizedJson, "label"); - individual.description = JsonHelper.getStrings(localizedJson, "definition").toArray(new String[0]); - individual.synonyms = JsonHelper.getStrings(localizedJson, "synonym").toArray(new String[0]); + individual.label = JsonHelper.getString(localizedJson, LABEL.getText()); + individual.description = JsonHelper.getStrings(localizedJson, DEFINITION.getText()).toArray(new String[0]); + individual.synonyms = JsonHelper.getStrings(localizedJson, SYNONYM.getText()).toArray(new String[0]); individual.annotation = AnnotationExtractor.extractAnnotations(localizedJson); individual.inSubsets = AnnotationExtractor.extractSubsets(localizedJson); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OboDefinitionCitationExtractor.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OboDefinitionCitationExtractor.java index 041172bf1..05ebbb9ff 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OboDefinitionCitationExtractor.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OboDefinitionCitationExtractor.java @@ -6,6 +6,8 @@ import uk.ac.ebi.spot.ols.model.v1.V1OboXref; import uk.ac.ebi.spot.ols.repository.v1.JsonHelper; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -16,7 +18,7 @@ public static List extractFromJson(JsonObject json) { JsonObject linkedEntities = json.get("linkedEntities").getAsJsonObject(); - List definitions = JsonHelper.getValues(json, "definition"); + List definitions = JsonHelper.getValues(json, DEFINITION.getText()); List res = new ArrayList<>(); for(JsonElement def : definitions) { diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OntologyMapper.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OntologyMapper.java index 22f62e4db..d74a1e7d7 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OntologyMapper.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1OntologyMapper.java @@ -8,9 +8,13 @@ import uk.ac.ebi.spot.ols.repository.transforms.LocalizationTransform; import uk.ac.ebi.spot.ols.repository.v1.JsonHelper; +import uk.ac.ebi.ols.shared.DefinedFields; + import java.util.Map; import java.util.Objects; +import static uk.ac.ebi.ols.shared.DefinedFields.LANGUAGE; + public class V1OntologyMapper { private static final Gson gson = new Gson(); @@ -26,7 +30,7 @@ public static V1Ontology mapOntology(JsonElement json, String lang) { ontology.ontologyId = JsonHelper.getString(localizedJson, "ontologyId"); ontology.fileHash = JsonHelper.getString(localizedJson, "fileHash"); - ontology.languages = JsonHelper.getStrings(localizedJson, "language"); + ontology.languages = JsonHelper.getStrings(localizedJson, LANGUAGE.getText()); ontology.config = new V1OntologyConfig(); @@ -56,7 +60,7 @@ public static V1Ontology mapOntology(JsonElement json, String lang) { ontology.config.definitionProperties = JsonHelper.getStrings(localizedJson, "definition_property"); ontology.config.synonymProperties = JsonHelper.getStrings(localizedJson, "synonym_property"); ontology.config.hierarchicalProperties = JsonHelper.getStrings(localizedJson, "hierarchical_property"); - ontology.config.baseUris = JsonHelper.getStrings(localizedJson, "base_uri"); + ontology.config.baseUris = JsonHelper.getStrings(localizedJson, DefinedFields.BASE_URI.getText()); ontology.config.hiddenProperties = JsonHelper.getStrings(localizedJson, "hidden_property"); ontology.config.preferredRootTerms = JsonHelper.getStrings(localizedJson, "preferredRootTerms"); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1PropertyMapper.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1PropertyMapper.java index 19153f65b..bacc22958 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1PropertyMapper.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1PropertyMapper.java @@ -27,9 +27,9 @@ public static V1Property mapProperty(JsonElement json, String lang) { property.ontologyPrefix = JsonHelper.getString(localizedJson, "ontologyPreferredPrefix"); property.ontologyIri = JsonHelper.getString(localizedJson, "ontologyIri"); - property.label = JsonHelper.getString(localizedJson, "label"); - property.description = JsonHelper.getStrings(localizedJson, "definition").toArray(new String[0]); - property.synonyms = JsonHelper.getStrings(localizedJson, "synonym").toArray(new String[0]); + property.label = JsonHelper.getString(localizedJson, LABEL.getText()); + property.description = JsonHelper.getStrings(localizedJson, DEFINITION.getText()).toArray(new String[0]); + property.synonyms = JsonHelper.getStrings(localizedJson, SYNONYM.getText()).toArray(new String[0]); property.annotation = AnnotationExtractor.extractAnnotations(localizedJson); //property.inSubsets = AnnotationExtractor.extractSubsets(localizedJson); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1TermMapper.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1TermMapper.java index 9509ec7ea..fdb9853a1 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1TermMapper.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v1/mappers/V1TermMapper.java @@ -34,9 +34,9 @@ public static V1Term mapTerm(JsonElement json, String lang) { term.oboId = term.shortForm; } - term.label = JsonHelper.getString(localizedJson, "label"); - term.description = JsonHelper.getStrings(localizedJson, "definition").toArray(new String[0]); - term.synonyms = JsonHelper.getStrings(localizedJson, "synonym").toArray(new String[0]); + term.label = JsonHelper.getString(localizedJson, LABEL.getText()); + term.description = JsonHelper.getStrings(localizedJson, DEFINITION.getText()).toArray(new String[0]); + term.synonyms = JsonHelper.getStrings(localizedJson, SYNONYM.getText()).toArray(new String[0]); term.annotation = AnnotationExtractor.extractAnnotations(localizedJson); term.inSubsets = AnnotationExtractor.extractSubsets(localizedJson); @@ -80,13 +80,13 @@ public static V1Term mapTerm(JsonElement json, String lang) { term.related = new ArrayList<>(); - for(JsonObject relatedTo : JsonHelper.getObjects(localizedJson, "relatedTo")) { + for(JsonObject relatedTo : JsonHelper.getObjects(localizedJson, RELATED_TO.getText())) { String predicate = relatedTo.getAsJsonPrimitive("property").getAsString(); JsonElement linkedEntity = linkedEntities.getAsJsonObject().get(predicate); String label = linkedEntity != null ? - JsonHelper.getString(linkedEntity.getAsJsonObject(), "label") : ShortFormExtractor.extractShortForm(predicate); + JsonHelper.getString(linkedEntity.getAsJsonObject(), LABEL.getText()) : ShortFormExtractor.extractShortForm(predicate); V1Related relatedObj = new V1Related(); relatedObj.iri = predicate; diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2ClassRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2ClassRepository.java index 9e621e734..eed89cb17 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2ClassRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2ClassRepository.java @@ -18,6 +18,8 @@ import uk.ac.ebi.spot.ols.repository.v2.helpers.V2DynamicFilterParser; import uk.ac.ebi.spot.ols.repository.v2.helpers.V2SearchFieldsParser; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -39,7 +41,7 @@ public OlsFacetedResultsPage find( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 definition"; + searchFields = LABEL.getText()+"^100 definition"; } OlsSolrQuery query = new OlsSolrQuery(); @@ -63,7 +65,7 @@ public OlsFacetedResultsPage findByOntologyId( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 definition"; + searchFields = LABEL.getText()+"^100 definition"; } OlsSolrQuery query = new OlsSolrQuery(); @@ -110,7 +112,8 @@ public Page getChildrenByOntologyId(String ontologyId, Pageable pageab String id = ontologyId + "+class+" + iri; - return this.neo4jClient.traverseIncomingEdges("OntologyClass", id, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.traverseIncomingEdges("OntologyClass", id, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(e -> LocalizationTransform.transform(e, lang)) .map(RemoveLiteralDatatypesTransform::transform) .map(V2Entity::new); @@ -123,7 +126,8 @@ public Page getAncestorsByOntologyId(String ontologyId, Pageable pagea String id = ontologyId + "+class+" + iri; - return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", id, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", id, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(e -> LocalizationTransform.transform(e, lang)) .map(RemoveLiteralDatatypesTransform::transform) .map(V2Entity::new); @@ -137,7 +141,8 @@ public Page getHierarchicalChildrenByOntologyId(String ontologyId, Pag String id = ontologyId + "+class+" + iri; - return this.neo4jClient.traverseIncomingEdges("OntologyClass", id, Arrays.asList("hierarchicalParent"), Map.of(), pageable) + return this.neo4jClient.traverseIncomingEdges("OntologyClass", id, Arrays.asList(HIERARCHICAL_PARENT.getText()), + Map.of(), pageable) .map(e -> LocalizationTransform.transform(e, lang)) .map(RemoveLiteralDatatypesTransform::transform) .map(V2Entity::new); @@ -150,7 +155,8 @@ public Page getHierarchicalAncestorsByOntologyId(String ontologyId, Pa String id = ontologyId + "+class+" + iri; - return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", id, Arrays.asList("hierarchicalParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyClass", id, + Arrays.asList(HIERARCHICAL_PARENT.getText()), Map.of(), pageable) .map(e -> LocalizationTransform.transform(e, lang)) .map(RemoveLiteralDatatypesTransform::transform) .map(V2Entity::new); @@ -164,7 +170,8 @@ public Page getIndividualAncestorsByOntologyId(String ontologyId, Page String id = ontologyId + "+individual+" + iri; - return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyEntity", id, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyEntity", id, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(e -> LocalizationTransform.transform(e, lang)) .map(RemoveLiteralDatatypesTransform::transform) .map(V2Entity::new); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2IndividualRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2IndividualRepository.java index 467e4cf80..b8b13ad75 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2IndividualRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2IndividualRepository.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.List; import java.util.Map; +import static uk.ac.ebi.ols.shared.DefinedFields.*; @Component public class V2IndividualRepository { @@ -38,7 +39,7 @@ public OlsFacetedResultsPage find( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 definition"; + searchFields = LABEL.getText()+"^100 definition"; } OlsSolrQuery query = new OlsSolrQuery(); @@ -62,7 +63,7 @@ public OlsFacetedResultsPage findByOntologyId( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 definition"; + searchFields = LABEL.getText() + "^100 definition"; } OlsSolrQuery query = new OlsSolrQuery(); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2OntologyRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2OntologyRepository.java index ce050838c..283a867f2 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2OntologyRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2OntologyRepository.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.util.Map; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + @Component public class V2OntologyRepository { @@ -39,7 +41,7 @@ public OlsFacetedResultsPage find( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 ontologyId^100 definition"; + searchFields = LABEL.getText() + "^100 ontologyId^100 " + DEFINITION.getText(); } OlsSolrQuery query = new OlsSolrQuery(); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2PropertyRepository.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2PropertyRepository.java index ef7e8bb8f..fb55f8941 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2PropertyRepository.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/V2PropertyRepository.java @@ -18,6 +18,8 @@ import uk.ac.ebi.spot.ols.repository.v2.helpers.V2DynamicFilterParser; import uk.ac.ebi.spot.ols.repository.v2.helpers.V2SearchFieldsParser; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -40,7 +42,7 @@ public OlsFacetedResultsPage find( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 definition"; + searchFields = LABEL.getText()+"^100 " + DEFINITION.getText(); } OlsSolrQuery query = new OlsSolrQuery(); @@ -64,7 +66,7 @@ public OlsFacetedResultsPage findByOntologyId( Validation.validateLang(lang); if(search != null && searchFields == null) { - searchFields = "label^100 definition"; + searchFields = LABEL.getText() + "^100 " + DEFINITION.getText(); } OlsSolrQuery query = new OlsSolrQuery(); @@ -109,7 +111,8 @@ public Page getChildrenByOntologyId(String ontologyId, Pageable pageab String id = ontologyId + "+property+" + iri; - return this.neo4jClient.traverseIncomingEdges("OntologyProperty", id, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.traverseIncomingEdges("OntologyProperty", id, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(e -> LocalizationTransform.transform(e, lang)) .map(RemoveLiteralDatatypesTransform::transform) .map(V2Entity::new); @@ -122,7 +125,8 @@ public Page getAncestorsByOntologyId(String ontologyId, Pageable pagea String id = ontologyId + "+property+" + iri; - return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyProperty", id, Arrays.asList("directParent"), Map.of(), pageable) + return this.neo4jClient.recursivelyTraverseOutgoingEdges("OntologyProperty", id, + Arrays.asList(DIRECT_PARENT.getText()), Map.of(), pageable) .map(RemoveLiteralDatatypesTransform::transform) .map(e -> LocalizationTransform.transform(e, lang)) .map(V2Entity::new); diff --git a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java index aa54693b3..b72734968 100644 --- a/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java +++ b/backend/src/main/java/uk/ac/ebi/spot/ols/repository/v2/helpers/V2SearchFieldsParser.java @@ -17,10 +17,10 @@ public static void addSearchFieldsToQuery(OlsSolrQuery query, String searchField query.addSearchField("ontologyId", 1, SearchType.WHITESPACE_EDGES); query.addSearchField("curie", 1, SearchType.WHITESPACE_EDGES); query.addSearchField("shortForm", 1, SearchType.WHITESPACE_EDGES); - query.addSearchField("label", 1, SearchType.WHITESPACE_EDGES); + query.addSearchField(LABEL.getText(), 1, SearchType.WHITESPACE_EDGES); query.addSearchField("id", 1, SearchType.WHITESPACE_EDGES); query.addSearchField("oboId", 1, SearchType.WHITESPACE_EDGES); - query.addSearchField("synonym", 1, SearchType.WHITESPACE_EDGES); + query.addSearchField(SYNONYM.getText(), 1, SearchType.WHITESPACE_EDGES); query.addSearchField("searchableAnnotationValues", 1, SearchType.WHITESPACE_EDGES); } else { for (ParsedField field : parseFieldsString(searchFields)) { @@ -34,11 +34,11 @@ public static void addBoostFieldsToQuery(OlsSolrQuery query, String boostFields) if(boostFields == null) { query.addBoostField("type", "ontology", 10, SearchType.WHOLE_FIELD); query.addBoostField(IS_DEFINING_ONTOLOGY.getText(), "true", 1000, SearchType.WHOLE_FIELD); - query.addBoostField("label", query.getSearchText(), 1000, SearchType.WHOLE_FIELD); - query.addBoostField("label", query.getSearchText(), 500, SearchType.EDGES); + query.addBoostField(LABEL.getText(), query.getSearchText(), 1000, SearchType.WHOLE_FIELD); + query.addBoostField(LABEL.getText(), query.getSearchText(), 500, SearchType.EDGES); query.addBoostField("curie", query.getSearchText(), 500, SearchType.EDGES); query.addBoostField("shortForm", query.getSearchText(), 500, SearchType.EDGES); - query.addBoostField("synonym", query.getSearchText(), 500, SearchType.WHOLE_FIELD); + query.addBoostField(SYNONYM.getText(), query.getSearchText(), 500, SearchType.WHOLE_FIELD); // query.addBoostField("synonym", query.getSearchText(), 100, SearchType.EDGES); } else { for (ParsedField field : parseFieldsString(boostFields)) { diff --git a/dataload/configs/edam.json b/dataload/configs/edam.json new file mode 100644 index 000000000..db7859a60 --- /dev/null +++ b/dataload/configs/edam.json @@ -0,0 +1,28 @@ +{ + "ontologies": [ + { + "id": "edam", + "preferredPrefix": "EDAM", + "title": "Ontology of bioinformatics topics, operations, identifiers, and formats", + "uri": "http://edamontology.org", + "description": "EDAM is a simple ontology of well established, familiar concepts that are prevalent within bioinformatics, including types of data and data identifiers, data formats, operations and topics. EDAM provides a set of terms with synonyms and definitions - organised into an intuitive hierarchy for convenient use.", + "homepage": "http://edamontology.org", + "mailing_list": "edam@elixir-dk.org", + "definition_property": [ + "http://www.geneontology.org/formats/oboInOwl#hasDefinition" + ], + "synonym_property": [ + "http://www.geneontology.org/formats/oboInOwl#hasExactSynonym", + "http://www.geneontology.org/formats/oboInOwl#hasNarrowSynonym" + ], + "base_uri": [ + "http://edamontology.org/data_", + "http://edamontology.org/topic_", + "http://edamontology.org/format_", + "http://edamontology.org/identifier_" + ], + "oboSlims": false, + "ontology_purl": "https://raw.githubusercontent.com/edamontology/edamontology/master/releases/EDAM.owl" + } + ] +} \ No newline at end of file diff --git a/dataload/configs/fobi.json b/dataload/configs/fobi.json new file mode 100644 index 000000000..665135877 --- /dev/null +++ b/dataload/configs/fobi.json @@ -0,0 +1,66 @@ +{ + "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": "polcaes@gmail.com", + "github": "pcastellanoescuder", + "label": "Pol Castellano Escuder", + "orcid": "0000-0001-6466-877X" + }, + "dependencies": [ + { + "id": "chebi" + }, + { + "id": "foodon" + } + ], + "description": "FOBI (Food-Biomarker Ontology) is an ontology to represent food intake data and associate it with metabolomic data", + "domain": "diet, metabolomics, and nutrition", + "homepage": "https://github.com/pcastellanoescuder/FoodBiomarkerOntology", + "id": "fobi", + "layout": "ontology_detail", + "license": { + "label": "CC BY 3.0", + "logo": "http://mirrors.creativecommons.org/presskit/buttons/80x15/png/by.png", + "url": "http://creativecommons.org/licenses/by/3.0/" + }, + "ontology_purl": "http://purl.obolibrary.org/obo/fobi.owl", + "preferredPrefix": "FOBI", + "products": [ + { + "format": "owl-rdf/xml", + "id": "fobi.owl", + "ontology_purl": "http://purl.obolibrary.org/obo/fobi.owl", + "title": "FOBI is an ontology to represent food intake data and associate it with metabolomic data" + } + ], + "publications": [ + { + "id": "https://www.ncbi.nlm.nih.gov/pubmed/32556148", + "title": "FOBI: an ontology to represent food intake data and associate it with metabolomic data" + }, + { + "id": "https://www.ncbi.nlm.nih.gov/pubmed/34601570", + "title": "The fobitools framework: the first steps towards food enrichment analysis" + } + ], + "repository": "https://github.com/pcastellanoescuder/FoodBiomarkerOntology", + "title": "Food-Biomarker Ontology", + "tracker": "https://github.com/pcastellanoescuder/FoodBiomarkerOntology/issues" + } + ] +} diff --git a/dataload/json2neo/pom.xml b/dataload/json2neo/pom.xml index 684b532e0..1e8f6935b 100644 --- a/dataload/json2neo/pom.xml +++ b/dataload/json2neo/pom.xml @@ -10,6 +10,11 @@ jar + + uk.ac.ebi.spot.ols + ols4-shared + 1.0.0-SNAPSHOT + org.apache.jena apache-jena-libs diff --git a/dataload/json2neo/src/main/java/OntologyWriter.java b/dataload/json2neo/src/main/java/OntologyWriter.java index 30c1a4fd5..cb788fe4d 100644 --- a/dataload/json2neo/src/main/java/OntologyWriter.java +++ b/dataload/json2neo/src/main/java/OntologyWriter.java @@ -9,6 +9,7 @@ import java.nio.charset.Charset; import java.util.*; +import static uk.ac.ebi.ols.shared.DefinedFields.*; public class OntologyWriter { Gson gson = new Gson(); @@ -23,7 +24,7 @@ public class OntologyWriter { public static final Set PROPERTY_BLACKLIST = Set.of( // large and doesn't get queried - "appearsIn", + APPEARS_IN.getText(), // all property values together, this is for solr and not useful in neo4j "searchableAnnotationValues" ); @@ -36,8 +37,8 @@ public class OntologyWriter { "definitionProperty", "synonymProperty", // these are redundant in neo4j as we already have the parent edges and cypher queries can be recursive - "directAncestor", - "hierarchicalAncestor", + DIRECT_ANCESTOR.getText(), + HIERARCHICAL_ANCESTOR.getText(), // redundant in neo4j because we already have relatedTo which can be queried in both directions "relatedFrom" ); diff --git a/dataload/json2solr/pom.xml b/dataload/json2solr/pom.xml index b4b6bfdac..bb50984bf 100644 --- a/dataload/json2solr/pom.xml +++ b/dataload/json2solr/pom.xml @@ -10,6 +10,11 @@ jar + + uk.ac.ebi.spot.ols + ols4-shared + 1.0.0-SNAPSHOT + org.apache.jena apache-jena-libs diff --git a/dataload/json2solr/src/main/java/JSON2Solr.java b/dataload/json2solr/src/main/java/JSON2Solr.java index cad0e0e57..728f4768d 100644 --- a/dataload/json2solr/src/main/java/JSON2Solr.java +++ b/dataload/json2solr/src/main/java/JSON2Solr.java @@ -6,6 +6,9 @@ import java.io.*; import java.util.*; + +import static uk.ac.ebi.ols.shared.DefinedFields.*; + public class JSON2Solr { static Gson gson = new Gson(); @@ -301,17 +304,17 @@ public static String objToString(Object obj) { static void writeAutocompleteEntries(String ontologyId, String entityId, Map flattenedEntity, PrintStream autocompleteWriter) { - Object labels = flattenedEntity.get("label"); + Object labels = flattenedEntity.get(LABEL.getText()); - if(labels instanceof List) { - for(Object label : (List) labels) { - autocompleteWriter.println( gson.toJson(makeAutocompleteEntry(ontologyId, entityId, (String)label), Map.class) ); - } - } else if(labels instanceof String) { - autocompleteWriter.println( gson.toJson(makeAutocompleteEntry(ontologyId, entityId, (String)labels), Map.class) ); - } + if (labels instanceof String) { + labels = (new ArrayList<>()).add(labels); + } + + for(Object label : (List) labels) { + autocompleteWriter.println( gson.toJson(makeAutocompleteEntry(ontologyId, entityId, (String)label), Map.class) ); + } - Object synonyms = flattenedEntity.get("synonym"); + Object synonyms = flattenedEntity.get(SYNONYM.getText()); if(synonyms instanceof List) { for(Object label : (List) synonyms) { diff --git a/dataload/linker/src/main/java/LinkerPass1.java b/dataload/linker/src/main/java/LinkerPass1.java index 19642b542..dc8dfec6b 100644 --- a/dataload/linker/src/main/java/LinkerPass1.java +++ b/dataload/linker/src/main/java/LinkerPass1.java @@ -10,6 +10,8 @@ import java.util.*; import java.util.stream.Collectors; +import static uk.ac.ebi.ols.shared.DefinedFields.BASE_URI; + public class LinkerPass1 { private static final Gson gson = new Gson(); @@ -91,7 +93,7 @@ public static LinkerPass1Result run(String inputJsonFilename) throws IOException ids.add(ontologyId); } - } else if(key.equals("base_uri")) { + } else if(key.equals(BASE_URI.getText())) { JsonArray baseUris = jsonParser.parse(jsonReader).getAsJsonArray(); for(JsonElement baseUri : baseUris) { diff --git a/dataload/linker/src/main/java/LinkerPass2.java b/dataload/linker/src/main/java/LinkerPass2.java index 6c511429f..9769b3db5 100644 --- a/dataload/linker/src/main/java/LinkerPass2.java +++ b/dataload/linker/src/main/java/LinkerPass2.java @@ -11,8 +11,7 @@ import java.util.Set; import java.util.TreeSet; -import static uk.ac.ebi.ols.shared.DefinedFields.HAS_LOCAL_DEFINITION; -import static uk.ac.ebi.ols.shared.DefinedFields.IS_DEFINING_ONTOLOGY; +import static uk.ac.ebi.ols.shared.DefinedFields.*; public class LinkerPass2 { @@ -63,7 +62,7 @@ public static void run(String inputJsonFilename, String outputJsonFilename, Leve - jsonWriter.name("importsFrom"); + jsonWriter.name(IMPORTS_FROM.getText()); jsonWriter.beginArray(); var imports = pass1Result.ontologyIdToImportedOntologyIds.get(ontologyId); if(imports != null) { @@ -74,7 +73,7 @@ public static void run(String inputJsonFilename, String outputJsonFilename, Leve jsonWriter.endArray(); - jsonWriter.name("exportsTo"); + jsonWriter.name(EXPORTS_TO.getText()); jsonWriter.beginArray(); var importedBy = pass1Result.ontologyIdToImportingOntologyIds.get(ontologyId); if(importedBy != null) { @@ -170,7 +169,7 @@ private static void writeEntityArray(JsonReader jsonReader, JsonWriter jsonWrite jsonWriter.value(defOfThisEntity.definingOntologyIds.contains(ontologyId)); if (defOfThisEntity.definingDefinitions.size() > 0) { - jsonWriter.name("definedBy"); + jsonWriter.name(DEFINED_BY.getText()); jsonWriter.beginArray(); for (var def : defOfThisEntity.definingDefinitions) { jsonWriter.value(def.ontologyId); @@ -179,7 +178,7 @@ private static void writeEntityArray(JsonReader jsonReader, JsonWriter jsonWrite } if (defOfThisEntity.definitions.size() > 0) { - jsonWriter.name("appearsIn"); + jsonWriter.name(APPEARS_IN.getText()); jsonWriter.beginArray(); for (var def : defOfThisEntity.definitions) { jsonWriter.value(def.ontologyId); @@ -329,7 +328,7 @@ private static void writeIriMapping(JsonWriter jsonWriter, EntityDefinitionSet d // There are ontologies which canonically define this term - jsonWriter.name("definedBy"); + jsonWriter.name(DEFINED_BY.getText()); jsonWriter.beginArray(); for(var def : definitions.definingDefinitions) { jsonWriter.value(def.ontologyId); @@ -343,7 +342,7 @@ private static void writeIriMapping(JsonWriter jsonWriter, EntityDefinitionSet d if(definitions.definingOntologyIds.size() == 1) { // ...and is only defined in ONE ontology. Therefore that ontology is the canonical defining ontology as far as OLS is concerned - jsonWriter.name("definedBy"); + jsonWriter.name(DEFINED_BY.getText()); jsonWriter.beginArray(); jsonWriter.value(definitions.definingOntologyIds.iterator().next()); jsonWriter.endArray(); diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyGraph.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyGraph.java index 659583938..d8b94d3b6 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyGraph.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyGraph.java @@ -245,9 +245,11 @@ private String urlToFilename(String url) { "sourceFileTimestamp", PropertyValueLiteral.fromString(new Date(sourceFileTimestamp).toString())); } + ArrayList languageList = new ArrayList<>(); for(String language : languages) { - ontologyNode.properties.addProperty("language", PropertyValueLiteral.fromString(language)); + languageList.add(PropertyValueLiteral.fromString(language)); } + ontologyNode.properties.addProperty(LANGUAGE.getText(), new PropertyValueList(languageList)); long endTime = System.nanoTime(); @@ -258,7 +260,7 @@ private String urlToFilename(String url) { NegativePropertyAssertionAnnotator.annotateNegativePropertyAssertions(this); OboSynonymTypeNameAnnotator.annotateOboSynonymTypeNames(this); // n.b. this one labels axioms so must run before the ReifiedPropertyAnnotator DirectParentsAnnotator.annotateDirectParents(this); - RelatedAnnotator.annotateRelated(this); + (new RelatedAnnotator()).annotateRelated(this); HierarchicalParentsAnnotator.annotateHierarchicalParents(this); // must run after RelatedAnnotator AncestorsAnnotator.annotateAncestors(this); HierarchyMetricsAnnotator.annotateHierarchyMetrics(this); // must run after HierarchicalParentsAnnotator @@ -318,6 +320,14 @@ public void write(JsonWriter writer) throws Throwable { if (configKey.equals("iri")) continue; + if (configKey.equals("base_uri")) { + // Config uses "base_uri" whereas rest of code base uses BASE_URI.getText(). + configKey = BASE_URI.getText(); + if (!(configVal instanceof Collection)) { + configVal = List.of(configVal); + } + + } // annotated as hasPreferredRoot by PreferredRootsAnnotator, no need to duplicate if (configKey.equals("preferred_root_term")) continue; @@ -447,8 +457,14 @@ private void writeProperties(JsonWriter writer, PropertySet properties, Set values = properties.getPropertyValues(predicate); writer.name(predicate); - - if(values.size() == 1) { + if (values.size() == 1 && values.get(0) instanceof PropertyValueList) { + List propertyValues = ((PropertyValueList) values.get(0)).getPropertyValues(); + writer.beginArray(); + for (PropertyValue propertyValue : propertyValues) { + writePropertyValue(writer, propertyValue, null); + } + writer.endArray(); + } else if(values.size() == 1) { writePropertyValue(writer, values.get(0), null); } else { writer.beginArray(); @@ -577,16 +593,21 @@ public void writeValue(JsonWriter writer, PropertyValue value) throws Throwable case ANCESTORS: PropertyValueAncestors ancestors = (PropertyValueAncestors) value; Set ancestorIris = ancestors.getAncestors(this); - if (ancestorIris.size() == 1) { - writer.value(ancestorIris.iterator().next()); - } else { - writer.beginArray(); - for (String ancestorIri : ancestorIris) { - writer.value(ancestorIri); - } - writer.endArray(); + + writer.beginArray(); + for (String ancestorIri : ancestorIris) { + writer.value(ancestorIri); } + writer.endArray(); + break; + case LIST: + PropertyValueList propertyValueList = (PropertyValueList)value; + writer.beginArray(); + for (PropertyValue propertyValue : propertyValueList.getPropertyValues()) { + writeValue(writer, propertyValue); + } + writer.endArray(); default: writer.value("?"); break; diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyNode.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyNode.java index 427ebf23c..80d0e2cef 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyNode.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/OntologyNode.java @@ -43,8 +43,18 @@ static public Set toString(Set nodeTypes) { // List parents; public PropertySet properties = new PropertySet(); + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + OntologyNode that = (OntologyNode) o; + return Objects.equals(uri, that.uri) && Objects.equals(types, that.types); + } - + @Override + public int hashCode() { + return Objects.hash(uri, types); + } } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/AncestorsAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/AncestorsAnnotator.java index a6c34c0ad..65e447054 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/AncestorsAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/AncestorsAnnotator.java @@ -6,6 +6,8 @@ import uk.ac.ebi.rdf2json.OntologyNode; import uk.ac.ebi.rdf2json.properties.PropertyValueAncestors; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + public class AncestorsAnnotator { private static final Logger logger = LoggerFactory.getLogger(AncestorsAnnotator.class); @@ -21,10 +23,10 @@ public static void annotateAncestors(OntologyGraph graph) { continue; if (c.types.contains(OntologyNode.NodeType.CLASS)) { - c.properties.addProperty("hierarchicalAncestor", new PropertyValueAncestors(c, "hierarchicalParent")); + c.properties.addProperty(HIERARCHICAL_ANCESTOR.getText(), new PropertyValueAncestors(c, HIERARCHICAL_PARENT.getText())); } - c.properties.addProperty("directAncestor", new PropertyValueAncestors(c, "directParent")); + c.properties.addProperty(DIRECT_ANCESTOR.getText(), new PropertyValueAncestors(c, DIRECT_PARENT.getText())); } long endTime3 = System.nanoTime(); diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DefinitionAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DefinitionAnnotator.java index a37f3fccc..d8e46775e 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DefinitionAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DefinitionAnnotator.java @@ -1,9 +1,14 @@ package uk.ac.ebi.rdf2json.annotators; -import java.util.*; + 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.PropertyValueList; +import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral; + +import java.util.*; + +import static uk.ac.ebi.ols.shared.DefinedFields.DEFINITION; public class DefinitionAnnotator { @@ -28,11 +33,12 @@ public static Set getDefinitionProperties(OntologyGraph graph) { } public static void annotateDefinitions(OntologyGraph graph) { - collateProperties(graph, "definition", getDefinitionProperties(graph)); + collateProperties(graph, DEFINITION.getText(), getDefinitionProperties(graph)); } private static void collateProperties(OntologyGraph graph, String destProp, Collection sourceProps) { + for(String id : graph.nodes.keySet()) { OntologyNode c = graph.nodes.get(id); @@ -40,14 +46,17 @@ private static void collateProperties(OntologyGraph graph, String destProp, Coll if(c.uri == null) continue; + List listOfValues = new ArrayList<>(); for(String prop : sourceProps) { List values = c.properties.getPropertyValues(prop); if(values != null) { for(PropertyValue value : values) { - c.properties.addProperty(destProp, value); + listOfValues.add(value); } } } + if (listOfValues.size() > 0) + c.properties.addProperty(destProp, new PropertyValueList(listOfValues)); } } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DirectParentsAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DirectParentsAnnotator.java index 6c4d0c365..fd5d326c6 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DirectParentsAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/DirectParentsAnnotator.java @@ -4,11 +4,13 @@ import org.slf4j.LoggerFactory; import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; -import uk.ac.ebi.rdf2json.properties.PropertyValue; -import uk.ac.ebi.rdf2json.properties.PropertyValueURI; +import uk.ac.ebi.rdf2json.properties.*; +import java.util.ArrayList; import java.util.List; +import static uk.ac.ebi.ols.shared.DefinedFields.*; + public class DirectParentsAnnotator { private static final Logger logger = LoggerFactory.getLogger(DirectParentsAnnotator.class); @@ -26,32 +28,39 @@ public static void annotateDirectParents(OntologyGraph graph) { if (c.types.contains(OntologyNode.NodeType.CLASS)) { List parents = c.properties.getPropertyValues("http://www.w3.org/2000/01/rdf-schema#subClassOf"); + List directParents = new ArrayList<>(); if(parents != null) { for(PropertyValue parent : parents) { if(parent.getType() == PropertyValue.Type.URI && graph.nodes.containsKey(((PropertyValueURI) parent).getUri())) { - c.properties.addProperty("directParent", parent); + directParents.add((PropertyValueURI) parent); } } } + if (directParents.size()>0) + c.properties.addProperty(DIRECT_PARENT.getText(), new PropertyValueList(directParents)); - } else if( c.types.contains(OntologyNode.NodeType.PROPERTY)) { + } else if( c.types.contains(OntologyNode.NodeType.PROPERTY)) { List parents = c.properties.getPropertyValues("http://www.w3.org/2000/01/rdf-schema#subPropertyOf"); + List directParents = new ArrayList<>(); if(parents != null) { for(PropertyValue parent : parents) { if(parent.getType() == PropertyValue.Type.URI && graph.nodes.containsKey(((PropertyValueURI) parent).getUri())) { - c.properties.addProperty("directParent", parent); + + directParents.add((PropertyValueURI) parent); } } } - + if (directParents.size()>0) + c.properties.addProperty(DIRECT_PARENT.getText(), new PropertyValueList(directParents)); } else if (c.types.contains(OntologyNode.NodeType.INDIVIDUAL)) { // The type of individuals becomes their parent in OLS // List types = c.properties.getPropertyValues("http://www.w3.org/1999/02/22-rdf-syntax-ns#type"); + List directParents = new ArrayList<>(); if(types != null) { for(PropertyValue type : types) { @@ -65,10 +74,12 @@ public static void annotateDirectParents(OntologyGraph graph) { continue; } - if(graph.nodes.containsKey(typeUri)) - c.properties.addProperty("directParent", type); + if(graph.nodes.containsKey(typeUri)) + directParents.add((PropertyValueURI)type); } } + if (directParents.size()>0) + c.properties.addProperty(DIRECT_PARENT.getText(), new PropertyValueList(directParents)); } } } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchicalParentsAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchicalParentsAnnotator.java index cc904af0b..020590c8f 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchicalParentsAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchicalParentsAnnotator.java @@ -4,15 +4,11 @@ import org.slf4j.LoggerFactory; import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; -import uk.ac.ebi.rdf2json.properties.PropertySet; -import uk.ac.ebi.rdf2json.properties.PropertyValue; -import uk.ac.ebi.rdf2json.properties.PropertyValueRelated; -import uk.ac.ebi.rdf2json.properties.PropertyValueURI; +import uk.ac.ebi.rdf2json.properties.*; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; + +import static uk.ac.ebi.ols.shared.DefinedFields.*; public class HierarchicalParentsAnnotator { private static final Logger logger = LoggerFactory.getLogger(HierarchicalParentsAnnotator.class); @@ -52,6 +48,7 @@ public static void annotateHierarchicalParents(OntologyGraph graph) { continue; List parents = c.properties.getPropertyValues("http://www.w3.org/2000/01/rdf-schema#subClassOf"); + List hierarchicalParents = new ArrayList<>(); if(parents != null) { for(PropertyValue parent : parents) { @@ -59,8 +56,7 @@ public static void annotateHierarchicalParents(OntologyGraph graph) { if (parent.getType() == PropertyValue.Type.URI && graph.nodes.containsKey(((PropertyValueURI) parent).getUri())) { // Direct parent; these are also considered hierarchical parents - c.properties.addProperty("hierarchicalParent", parent); - + hierarchicalParents.add((PropertyValueURI) parent); } } } @@ -68,53 +64,67 @@ public static void annotateHierarchicalParents(OntologyGraph graph) { // any non direct parents have already been interpreted by RelatedAnnotator, so we // can find their values in relatedTo // - List relatedTo = (List) c.properties.getPropertyValues("relatedTo"); + List relatedToList = (List) c.properties.getPropertyValues(RELATED_TO.getText()); + Map fillerToReifiedPropertiesMap = new HashMap<>(); - if(relatedTo != null) { - for(PropertyValue related : relatedTo) { + if(relatedToList != null) { + for(PropertyValue relatedToListElement : relatedToList) { + if (relatedToListElement.getType() == PropertyValue.Type.LIST) { + for (PropertyValue related : ((PropertyValueList)relatedToListElement).getPropertyValues()) { - if(related.getType() == PropertyValue.Type.RELATED) { + if (related.getType() == PropertyValue.Type.RELATED) { - String property = ((PropertyValueRelated) related).getProperty(); + String property = ((PropertyValueRelated) related).getProperty(); + // if the child->parent property is "part of" we also want to know the parent->child (inverse) property "has part" + // + var propertyNode = graph.nodes.get(property); + String inverseProperty = null; + if (propertyNode != null) { + var inversePropertyValue = propertyNode.properties.getPropertyValue("http://www.w3.org/2002/07/owl#inverseOf"); + if (inversePropertyValue != null && inversePropertyValue.getType() == PropertyValue.Type.URI) { + inverseProperty = ((PropertyValueURI) inversePropertyValue).getUri(); + } + } - // if the child->parent property is "part of" we also want to know the parent->child (inverse) property "has part" - // - var propertyNode = graph.nodes.get(property); - String inverseProperty = null; - if(propertyNode != null) { - var inversePropertyValue = propertyNode.properties.getPropertyValue("http://www.w3.org/2002/07/owl#inverseOf"); - if(inversePropertyValue != null && inversePropertyValue.getType() == PropertyValue.Type.URI) { - inverseProperty = ((PropertyValueURI) inversePropertyValue).getUri(); - } - } + if (hierarchicalProperties.contains(property)) { - if(hierarchicalProperties.contains(property)) { + var filler = new PropertyValueURI( + ((PropertyValueRelated) related).getFiller().uri + ); - var filler = new PropertyValueURI( - ((PropertyValueRelated) related).getFiller().uri - ); + hierarchicalParents.add(filler); - c.properties.addProperty("hierarchicalParent", filler); + // reify the hierarchicalParent edge with the property IRIs + // this enables the frontend to display e.g. "has part" relations in the tree + // + PropertySet reifiedProperties = new PropertySet(); + reifiedProperties.addProperty("childRelationToParent", PropertyValueURI.fromUri(property)); + if (inverseProperty != null) { + reifiedProperties.addProperty("parentRelationToChild", PropertyValueURI.fromUri(inverseProperty)); + } + fillerToReifiedPropertiesMap.put(filler, reifiedProperties); - // reify the hierarchicalParent edge with the property IRIs - // this enables the frontend to display e.g. "has part" relations in the tree - // - PropertySet reifiedProperties = new PropertySet(); - reifiedProperties.addProperty("childRelationToParent", PropertyValueURI.fromUri(property)); - if(inverseProperty != null) { - reifiedProperties.addProperty("parentRelationToChild", PropertyValueURI.fromUri(inverseProperty)); + } } - c.properties.annotatePropertyWithAxiom("hierarchicalParent", filler, reifiedProperties, graph); - } } } } + if (hierarchicalParents.size()>0) { + c.properties.addProperty(HIERARCHICAL_PARENT.getText(), new PropertyValueList(hierarchicalParents)); + for (PropertyValueURI propertyValueURI: fillerToReifiedPropertiesMap.keySet()) { + c.properties.annotatePropertyWithAxiom(HIERARCHICAL_PARENT.getText(), propertyValueURI, + fillerToReifiedPropertiesMap.get(propertyValueURI), graph); + + } + } } } + + long endTime3 = System.nanoTime(); logger.info("annotate hierarchical parents: {}", ((endTime3 - startTime3) / 1000 / 1000 / 1000)); } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyFlagsAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyFlagsAnnotator.java index 698d9969b..180337318 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyFlagsAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyFlagsAnnotator.java @@ -4,9 +4,7 @@ import org.slf4j.LoggerFactory; import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; -import uk.ac.ebi.rdf2json.properties.PropertyValue; -import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral; -import uk.ac.ebi.rdf2json.properties.PropertyValueURI; +import uk.ac.ebi.rdf2json.properties.*; import java.util.HashSet; import java.util.List; @@ -23,8 +21,8 @@ public static void annotateHierarchyFlags(OntologyGraph graph) { long startTime3 = System.nanoTime(); // Set of IRIs that have children - Set hasChildren = new HashSet<>(); - Set hasHierarchicalChildren = new HashSet<>(); + Set children = new HashSet<>(); + Set hierarchicalChildren = new HashSet<>(); for(String id : graph.nodes.keySet()) { OntologyNode c = graph.nodes.get(id); @@ -41,36 +39,44 @@ public static void annotateHierarchyFlags(OntologyGraph graph) { // 1. Direct parents (subClassOf) // - List parents = c.properties.getPropertyValues("directParent"); + PropertyValueList parentsList = (PropertyValueList)c.properties.getPropertyValue(DIRECT_PARENT.getText()); boolean hasDirectParents = false; - if(parents != null) { - for (PropertyValue parent : parents) { + if (parentsList != null && parentsList.getPropertyValues() != null) { + for (PropertyValue parent : parentsList.getPropertyValues()) { + if (parent.getType() == PropertyValue.Type.URI) { + String iri = ((PropertyValueURI) parent).getUri(); - String iri = ((PropertyValueURI) parent).getUri(); + if (iri.equals("http://www.w3.org/2002/07/owl#Thing") || + iri.equals("http://www.w3.org/2002/07/owl#TopObjectProperty")) { + continue; + } - if (iri.equals("http://www.w3.org/2002/07/owl#Thing") || - iri.equals("http://www.w3.org/2002/07/owl#TopObjectProperty")) { - continue; + hasDirectParents = true; + children.add(iri); } - - hasDirectParents = true; - hasChildren.add(iri); } + + c.properties.addProperty(HAS_DIRECT_PARENTS.getText(), + PropertyValueLiteral.fromBoolean(hasDirectParents ? "true" : "false")); + } else { + c.properties.addProperty(HAS_DIRECT_PARENTS.getText(), + PropertyValueLiteral.fromBoolean("false")); } - c.properties.addProperty(HAS_DIRECT_PARENTS.getText(), - PropertyValueLiteral.fromBoolean(hasDirectParents ? "true" : "false")); // 2. Hierarchical parents // - List hierarchicalParents = c.properties.getPropertyValues("hierarchicalParent"); + List hierarchicalParentsList = c.properties.getPropertyValues(HIERARCHICAL_PARENT.getText()); boolean hasHierarchicalParents = false; - if(hierarchicalParents != null) { + if(hierarchicalParentsList != null && hierarchicalParentsList.size() == 1 && + hierarchicalParentsList.get(0) instanceof PropertyValueList ) { + + List hierarchicalParents = ((PropertyValueList) hierarchicalParentsList.get(0)).getPropertyValues(); for (PropertyValue parent : hierarchicalParents) { String iri = ((PropertyValueURI) parent).getUri(); @@ -81,7 +87,7 @@ public static void annotateHierarchyFlags(OntologyGraph graph) { } hasHierarchicalParents = true; - hasHierarchicalChildren.add(iri); + hierarchicalChildren.add(iri); } } @@ -100,13 +106,13 @@ public static void annotateHierarchyFlags(OntologyGraph graph) { if(c.uri == null) continue; - if(hasChildren.contains(c.uri)) { + if(children.contains(c.uri)) { c.properties.addProperty(HAS_DIRECT_CHILDREN.getText(), PropertyValueLiteral.fromBoolean("true")); } else { c.properties.addProperty(HAS_DIRECT_CHILDREN.getText(), PropertyValueLiteral.fromBoolean("false")); } - if(hasHierarchicalChildren.contains(c.uri)) { + if(hierarchicalChildren.contains(c.uri)) { c.properties.addProperty(HAS_HIERARCHICAL_CHILDREN.getText(), PropertyValueLiteral.fromBoolean("true")); } else { c.properties.addProperty(HAS_HIERARCHICAL_CHILDREN.getText(), PropertyValueLiteral.fromBoolean("false")); diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyMetricsAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyMetricsAnnotator.java index 33a28d44e..dd2372e27 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyMetricsAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/HierarchyMetricsAnnotator.java @@ -12,8 +12,7 @@ import java.util.Map; import java.util.Set; -import static uk.ac.ebi.ols.shared.DefinedFields.NUM_DESCENDANTS; -import static uk.ac.ebi.ols.shared.DefinedFields.NUM_HIERARCHICAL_DESCENDANTS; +import static uk.ac.ebi.ols.shared.DefinedFields.*; public class HierarchyMetricsAnnotator { @@ -23,10 +22,10 @@ public static void annotateHierarchyMetrics(OntologyGraph graph) { long startTime3 = System.nanoTime(); - annotateHierarchyMetrics(graph, "directParent", NUM_DESCENDANTS.getText()); + annotateHierarchyMetrics(graph, DIRECT_PARENT.getText(), NUM_DESCENDANTS.getText()); System.gc(); - annotateHierarchyMetrics(graph, "hierarchicalParent", NUM_HIERARCHICAL_DESCENDANTS.getText()); + annotateHierarchyMetrics(graph, HIERARCHICAL_PARENT.getText(), NUM_HIERARCHICAL_DESCENDANTS.getText()); System.gc(); long endTime3 = System.nanoTime(); diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/LabelAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/LabelAnnotator.java index 9373f76ba..68288dd1b 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/LabelAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/LabelAnnotator.java @@ -5,12 +5,12 @@ import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; import uk.ac.ebi.rdf2json.properties.PropertyValue; +import uk.ac.ebi.rdf2json.properties.PropertyValueList; import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; + +import static uk.ac.ebi.ols.shared.DefinedFields.LABEL; public class LabelAnnotator { @@ -37,7 +37,7 @@ public static Set getLabelProperties(OntologyGraph graph) { } public static void annotateLabels(OntologyGraph graph) { - collateProperties(graph, "label", getLabelProperties(graph), List.of("shortForm")); + collateProperties(graph, LABEL.getText(), getLabelProperties(graph), List.of("shortForm")); } private static void collateProperties(OntologyGraph graph, String destProp, Collection sourceProps, Collection fallbackProps) { @@ -53,14 +53,27 @@ private static void collateProperties(OntologyGraph graph, String destProp, Coll boolean hasEnglishValue = false; + List labels = new ArrayList<>(); + for(String prop : sourceProps) { List values = c.properties.getPropertyValues(prop); if(values != null) { for(PropertyValue value : values) { - c.properties.addProperty(destProp, value); - if(!isNonEnglishValue(graph, value)) - hasEnglishValue = true; + if (value.getType() == PropertyValue.Type.LITERAL) { + labels.add((PropertyValueLiteral) value); + if (!isNonEnglishValue(graph, value)) + hasEnglishValue = true; + } else if (value.getType() == PropertyValue.Type.LIST) { + for (PropertyValue propertyValue: ((PropertyValueList)value).getPropertyValues()) { + if (propertyValue.getType() == PropertyValue.Type.LITERAL) { + labels.add((PropertyValueLiteral) propertyValue); + if (!isNonEnglishValue(graph, propertyValue)) + hasEnglishValue = true; + } + } + } } + } } @@ -69,11 +82,23 @@ private static void collateProperties(OntologyGraph graph, String destProp, Coll List values = c.properties.getPropertyValues(prop); if (values != null) { for (PropertyValue value : values) { - c.properties.addProperty(destProp, value); + if (value.getType() == PropertyValue.Type.LITERAL) { + labels.add((PropertyValueLiteral) value); + } else if (value.getType() == PropertyValue.Type.LIST) { + for (PropertyValue propertyValue: ((PropertyValueList)value).getPropertyValues()) { + if (propertyValue.getType() == PropertyValue.Type.LITERAL) { + labels.add((PropertyValueLiteral) propertyValue); + } + } + + } } } } } + + if (labels.size()>0) + c.properties.addProperty(destProp, new PropertyValueList(labels)); } long endTime3 = System.nanoTime(); diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/PreferredRootsAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/PreferredRootsAnnotator.java index 0858ed630..eec29e17d 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/PreferredRootsAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/PreferredRootsAnnotator.java @@ -4,17 +4,13 @@ import org.slf4j.LoggerFactory; import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; -import uk.ac.ebi.rdf2json.properties.PropertyValue; -import uk.ac.ebi.rdf2json.properties.PropertyValueLiteral; -import uk.ac.ebi.rdf2json.properties.PropertyValueURI; - -import java.util.Collection; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; +import uk.ac.ebi.rdf2json.properties.*; + +import java.util.*; import java.util.stream.Collectors; import static uk.ac.ebi.ols.shared.DefinedFields.IS_PREFERRED_ROOT; +import static uk.ac.ebi.ols.shared.DefinedFields.PREFERRED_ROOT; public class PreferredRootsAnnotator { private static final Logger logger = LoggerFactory.getLogger(PreferredRootsAnnotator.class); @@ -51,8 +47,13 @@ public static void annotatePreferredRoots(OntologyGraph graph) { Set preferredRoots = getPreferredRoots(graph); + List listOfUris = new ArrayList<>(); + for(String root : preferredRoots) - graph.ontologyNode.properties.addProperty("hasPreferredRoot", PropertyValueURI.fromUri(root)); + listOfUris.add(PropertyValueURI.fromUri(root)); + + if (listOfUris.size() > 0) + graph.ontologyNode.properties.addProperty(PREFERRED_ROOT.getText(), new PropertyValueList(listOfUris)); for(String id : graph.nodes.keySet()) { OntologyNode c = graph.nodes.get(id); diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/RelatedAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/RelatedAnnotator.java index f9cb3443a..b0c10d34d 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/RelatedAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/RelatedAnnotator.java @@ -11,16 +11,20 @@ import java.util.*; import java.util.stream.Collectors; +import static uk.ac.ebi.ols.shared.DefinedFields.RELATED_FROM; +import static uk.ac.ebi.ols.shared.DefinedFields.RELATED_TO; + public class RelatedAnnotator { private static final Logger logger = LoggerFactory.getLogger(RelatedAnnotator.class); - public static void annotateRelated(OntologyGraph graph) { + public void annotateRelated(OntologyGraph graph) { Set ontologyBaseUris = OntologyBaseUris.getOntologyBaseUris(graph); String preferredPrefix = (String)graph.config.get("preferredPrefix"); long startTime3 = System.nanoTime(); + RelatedInfo relatedInfo = new RelatedInfo(); for(String id : graph.nodes.keySet()) { OntologyNode c = graph.nodes.get(id); if (c.types.contains(OntologyNode.NodeType.CLASS)) { @@ -35,6 +39,7 @@ public static void annotateRelated(OntologyGraph graph) { for(PropertyValue parent : parents) { + // We are only looking for anonymous parents, which are either class expressions or restrictions. // if(parent.getType() != PropertyValue.Type.BNODE) { @@ -43,45 +48,49 @@ public static void annotateRelated(OntologyGraph graph) { OntologyNode parentClassExprOrRestriction = graph.nodes.get( ((PropertyValueBNode) parent).getId() ); - PropertyValue onProperty = parentClassExprOrRestriction.properties.getPropertyValue("http://www.w3.org/2002/07/owl#onProperty"); + PropertyValue onProperty = parentClassExprOrRestriction.properties + .getPropertyValue("http://www.w3.org/2002/07/owl#onProperty"); if(onProperty == null) { - annotateRelated_Class_subClassOf_ClassExpr( + relatedInfo = annotateRelated_Class_subClassOf_ClassExpr(relatedInfo, c, parentClassExprOrRestriction, ontologyBaseUris, preferredPrefix, graph); } else { - annotateRelated_Class_subClassOf_Restriction( - c, onProperty, parentClassExprOrRestriction, ontologyBaseUris, preferredPrefix, graph); + relatedInfo = annotateRelated_Class_subClassOf_Restriction(relatedInfo, + c, onProperty, parentClassExprOrRestriction, graph); } } } - } + } } + relatedInfo.updateOntologyNodesWithRelatedLists(); long endTime3 = System.nanoTime(); logger.info("annotate related: {}", ((endTime3 - startTime3) / 1000 / 1000 / 1000)); } - private static void annotateRelated_Class_subClassOf_ClassExpr( - OntologyNode classNode, OntologyNode fillerClassExpr, Set ontologyBaseUris, String preferredPrefix, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_ClassExpr(RelatedInfo relatedInfo, + OntologyNode classNode, OntologyNode fillerClassExpr, Set ontologyBaseUris, + String preferredPrefix, OntologyGraph graph) { PropertyValue oneOf = fillerClassExpr.properties.getPropertyValue("http://www.w3.org/2002/07/owl#oneOf"); if(oneOf != null) { // This is a oneOf class expression - annotateRelated_Class_subClassOf_ClassExpr_oneOf(classNode, fillerClassExpr, oneOf, graph); - return; + return annotateRelated_Class_subClassOf_ClassExpr_oneOf(relatedInfo, classNode, fillerClassExpr, oneOf, graph); } PropertyValue intersectionOf = fillerClassExpr.properties.getPropertyValue("http://www.w3.org/2002/07/owl#intersectionOf"); if(intersectionOf != null) { // This is an intersectionOf class expression (anonymous conjunction) - annotateRelated_Class_subClassOf_ClassExpr_intersectionOf(classNode, fillerClassExpr, intersectionOf, graph); - return; + return annotateRelated_Class_subClassOf_ClassExpr_intersectionOf(relatedInfo, classNode, fillerClassExpr, + intersectionOf, graph); } + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_ClassExpr_oneOf(OntologyNode classNode, OntologyNode fillerClassExpr, PropertyValue filler, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_ClassExpr_oneOf(RelatedInfo relatedInfo, OntologyNode classNode, + OntologyNode fillerClassExpr, PropertyValue filler, OntologyGraph graph) { // The filler is an RDF list of Individuals @@ -94,14 +103,17 @@ private static void annotateRelated_Class_subClassOf_ClassExpr_oneOf(OntologyNod .collect(Collectors.toList()); for(OntologyNode individualNode : fillerIndividuals) { - classNode.properties.addProperty("relatedTo", - new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", individualNode)); - individualNode.properties.addProperty("relatedFrom", - new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", classNode)); + relatedInfo.addRelatedTo(classNode, + new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", individualNode)); + + relatedInfo.addRelatedFrom(individualNode, + new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", classNode)); } + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_ClassExpr_intersectionOf(OntologyNode classNode, OntologyNode fillerClassExpr, PropertyValue filler, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_ClassExpr_intersectionOf(RelatedInfo relatedInfo, + OntologyNode classNode, OntologyNode fillerClassExpr, PropertyValue filler, OntologyGraph graph) { // The filler is an RDF list of Classes @@ -118,50 +130,54 @@ private static void annotateRelated_Class_subClassOf_ClassExpr_intersectionOf(On // Named nodes only. TODO what to do about bnodes in this case? if(fillerClassNode.uri != null) { - classNode.properties.addProperty("relatedTo", - new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", fillerClassNode)); + relatedInfo.addRelatedTo(classNode, + new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", fillerClassNode)); - fillerClassNode.properties.addProperty("relatedFrom", - new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", classNode)); + relatedInfo.addRelatedFrom(fillerClassNode, + new PropertyValueRelated(fillerClassExpr, "http://www.w3.org/2000/01/rdf-schema#subClassOf", classNode)); } } + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_Restriction( - OntologyNode classNode, PropertyValue property, OntologyNode fillerRestriction, Set ontologyBaseUris, String preferredPrefix, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_Restriction(RelatedInfo relatedInfo, + OntologyNode classNode, PropertyValue property, OntologyNode fillerRestriction, + OntologyGraph graph) { if(property.getType() != PropertyValue.Type.URI) { // We can't do anything with anonymous properties. - return; + return relatedInfo; } PropertyValue onProperty = fillerRestriction.properties.getPropertyValue("http://www.w3.org/2002/07/owl#onProperty"); if(onProperty == null || onProperty.getType() != PropertyValue.Type.URI) - return; + return relatedInfo; String propertyUri = ((PropertyValueURI) onProperty).getUri(); PropertyValue someValuesFrom = fillerRestriction.properties.getPropertyValue("http://www.w3.org/2002/07/owl#someValuesFrom"); if(someValuesFrom != null) { // This is a someValuesFrom restriction - annotateRelated_Class_subClassOf_Restriction_someValuesFrom( - classNode, propertyUri, fillerRestriction, someValuesFrom, ontologyBaseUris, preferredPrefix, graph); - return; + return annotateRelated_Class_subClassOf_Restriction_someValuesFrom(relatedInfo, + classNode, propertyUri, fillerRestriction, someValuesFrom, graph); } PropertyValue hasValue = fillerRestriction.properties.getPropertyValue("http://www.w3.org/2002/07/owl#hasValue"); if(hasValue != null) { // This is a hasValue restriction. The value can be either an individual or a literal data value. // - annotateRelated_Class_subClassOf_Restriction_hasValue(classNode, propertyUri, fillerRestriction, hasValue, graph); - return; + return annotateRelated_Class_subClassOf_Restriction_hasValue(relatedInfo, classNode, propertyUri, + fillerRestriction, hasValue, graph); + } + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom( - OntologyNode classNode, String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, Set ontologyBaseUris, String preferredPrefix, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_Restriction_someValuesFrom(RelatedInfo relatedInfo, + OntologyNode classNode, String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, + OntologyGraph graph) { if(filler.getType() == PropertyValue.Type.URI) { @@ -174,13 +190,13 @@ private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom( if(fillerNode != null) { // sometimes filler not included in ontology, e.g. "subClassOf some xsd:float" in cdao - classNode.properties.addProperty("relatedTo", new PropertyValueRelated(fillerRestriction, propertyUri, fillerNode)); - fillerNode.properties.addProperty("relatedFrom", new PropertyValueRelated(fillerRestriction, propertyUri, classNode)); + relatedInfo.addRelatedTo(classNode, new PropertyValueRelated(fillerRestriction, propertyUri, fillerNode)); + relatedInfo.addRelatedFrom(fillerNode, new PropertyValueRelated(fillerRestriction, propertyUri, classNode)); } } - return; + return relatedInfo; } @@ -191,22 +207,21 @@ private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom( PropertyValue oneOf = fillerClassExpr.properties.getPropertyValue("http://www.w3.org/2002/07/owl#oneOf"); if(oneOf != null) { // This is a oneOf class expression - annotateRelated_Class_subClassOf_Restriction_someValuesFrom_oneOf(classNode, propertyUri, fillerClassExpr, oneOf, ontologyBaseUris, preferredPrefix, graph); - return; + return annotateRelated_Class_subClassOf_Restriction_someValuesFrom_oneOf(relatedInfo, classNode, propertyUri, oneOf, graph); } PropertyValue intersectionOf = fillerClassExpr.properties.getPropertyValue("http://www.w3.org/2002/07/owl#intersectionOf"); if(intersectionOf != null) { // This is an intersectionOf class expression (anonymous conjunction) - annotateRelated_Class_subClassOf_Restriction_someValuesFrom_intersectionOf(classNode, propertyUri, fillerClassExpr, intersectionOf, ontologyBaseUris, preferredPrefix, graph); - return; + return annotateRelated_Class_subClassOf_Restriction_someValuesFrom_intersectionOf(relatedInfo, classNode, + propertyUri, fillerClassExpr, intersectionOf, graph); } } - + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom_oneOf( - OntologyNode classNode, String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, Set ontologyBaseUris, String preferredPrefix, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_Restriction_someValuesFrom_oneOf(RelatedInfo relatedInfo, + OntologyNode classNode, String propertyUri, PropertyValue filler, OntologyGraph graph) { // The filler is an RDF list of Individuals @@ -219,15 +234,14 @@ private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom_ .collect(Collectors.toList()); for(OntologyNode individualNode : fillerIndividuals) { - classNode.properties.addProperty("relatedTo", - new PropertyValueRelated(fillerNode, propertyUri, individualNode)); - individualNode.properties.addProperty("relatedFrom", - new PropertyValueRelated(fillerNode, propertyUri, classNode)); + relatedInfo.addRelatedTo(classNode, new PropertyValueRelated(fillerNode, propertyUri, individualNode)); + relatedInfo.addRelatedFrom(individualNode, new PropertyValueRelated(fillerNode, propertyUri, classNode)); } + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom_intersectionOf( - OntologyNode classNode, String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, Set ontologyBaseUris, String preferredPrefix, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_Restriction_someValuesFrom_intersectionOf(RelatedInfo relatedInfo, + OntologyNode classNode, String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, OntologyGraph graph) { // The filler is an RDF list of Classes @@ -243,18 +257,15 @@ private static void annotateRelated_Class_subClassOf_Restriction_someValuesFrom_ // Named nodes only. TODO what to do about bnodes in this case? if(fillerClassNode.uri != null) { - - classNode.properties.addProperty("relatedTo", - new PropertyValueRelated(fillerRestriction, propertyUri, fillerClassNode)); - - fillerClassNode.properties.addProperty("relatedFrom", - new PropertyValueRelated(fillerRestriction, propertyUri, classNode)); + relatedInfo.addRelatedTo(classNode, new PropertyValueRelated(fillerRestriction, propertyUri, fillerClassNode)); + relatedInfo.addRelatedFrom(fillerClassNode, new PropertyValueRelated(fillerRestriction, propertyUri, classNode)); } } - + return relatedInfo; } - private static void annotateRelated_Class_subClassOf_Restriction_hasValue(OntologyNode classNode, String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, OntologyGraph graph) { + private static RelatedInfo annotateRelated_Class_subClassOf_Restriction_hasValue(RelatedInfo relatedInfo, OntologyNode classNode, + String propertyUri, OntologyNode fillerRestriction, PropertyValue filler, OntologyGraph graph) { // The filler can be either an individual or a literal data value. @@ -264,14 +275,53 @@ private static void annotateRelated_Class_subClassOf_Restriction_hasValue(Ontolo if(fillerNode.types.contains(OntologyNode.NodeType.INDIVIDUAL)) { // fillerNode is an individual - fillerNode.properties.addProperty("relatedTo", new PropertyValueRelated(fillerRestriction, propertyUri, classNode)); - classNode.properties.addProperty("relatedFrom", new PropertyValueRelated(fillerRestriction, propertyUri, fillerNode)); + relatedInfo.addRelatedTo(fillerNode, new PropertyValueRelated(fillerRestriction, propertyUri, classNode)); + relatedInfo.addRelatedFrom(classNode, new PropertyValueRelated(fillerRestriction, propertyUri, fillerNode)); } - return; - } + + } // TODO: what to do with data values? + return relatedInfo; + } + + private class RelatedInfo { + private Map> relatedFromMap = new HashMap<>(); + private Map> relatedToMap = new HashMap<>(); + + void addRelatedFrom(OntologyNode ontologyNode, PropertyValueRelated relatedFrom) { + Set relatedFromSetToUpdate; + if (relatedFromMap.containsKey(ontologyNode)) { + relatedFromSetToUpdate = relatedFromMap.get(ontologyNode); + } else + relatedFromSetToUpdate = new HashSet<>(); + + relatedFromSetToUpdate.add(relatedFrom); + relatedFromMap.put(ontologyNode, relatedFromSetToUpdate); + } + + void addRelatedTo(OntologyNode ontologyNode, PropertyValueRelated relatedTo) { + Set relatedToSetToUpdate; + if (relatedToMap.containsKey(ontologyNode)) { + relatedToSetToUpdate = relatedToMap.get(ontologyNode); + } else + relatedToSetToUpdate = new HashSet<>(); + + relatedToSetToUpdate.add(relatedTo); + relatedToMap.put(ontologyNode, relatedToSetToUpdate); + } + void updateOntologyNodesWithRelatedLists() { + for(OntologyNode ontologyNode: relatedFromMap.keySet()) { + ontologyNode.properties.addProperty(RELATED_FROM.getText(), + new PropertyValueList(Arrays.asList(relatedFromMap.get(ontologyNode).toArray()))); + } + for(OntologyNode ontologyNode: relatedToMap.keySet()) { + ontologyNode.properties.addProperty(RELATED_TO.getText(), + new PropertyValueList(Arrays.asList(relatedToMap.get(ontologyNode).toArray()))); + } + } + } } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/SynonymAnnotator.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/SynonymAnnotator.java index 0d11cb1f5..ffc4f2ca7 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/SynonymAnnotator.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/annotators/SynonymAnnotator.java @@ -3,11 +3,11 @@ import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; import uk.ac.ebi.rdf2json.properties.PropertyValue; +import uk.ac.ebi.rdf2json.properties.PropertyValueList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; + +import static uk.ac.ebi.ols.shared.DefinedFields.SYNONYM; public class SynonymAnnotator { @@ -33,7 +33,7 @@ public static Set getSynonymProperties(OntologyGraph graph) { } public static void annotateSynonyms(OntologyGraph graph) { - collateProperties(graph, "synonym", getSynonymProperties(graph)); + collateProperties(graph, SYNONYM.getText(), getSynonymProperties(graph)); } private static void collateProperties(OntologyGraph graph, String destProp, Collection sourceProps) { @@ -45,14 +45,18 @@ private static void collateProperties(OntologyGraph graph, String destProp, Coll if(c.uri == null) continue; + List synonyms = new ArrayList<>(); for(String prop : sourceProps) { List values = c.properties.getPropertyValues(prop); if(values != null) { for(PropertyValue value : values) { - c.properties.addProperty(destProp, value); + synonyms.add(value); } } } + + if (synonyms.size()>0) + c.properties.addProperty(destProp, new PropertyValueList(synonyms)); } } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/helpers/AncestorsClosure.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/helpers/AncestorsClosure.java index 97fad19ec..70c842eef 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/helpers/AncestorsClosure.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/helpers/AncestorsClosure.java @@ -3,6 +3,7 @@ import uk.ac.ebi.rdf2json.OntologyGraph; import uk.ac.ebi.rdf2json.OntologyNode; import uk.ac.ebi.rdf2json.properties.PropertyValue; +import uk.ac.ebi.rdf2json.properties.PropertyValueList; import uk.ac.ebi.rdf2json.properties.PropertyValueURI; import java.util.LinkedHashSet; @@ -17,16 +18,21 @@ public static Set getAncestors(OntologyNode node, String hierarchyPredic private static Set getAncestors(OntologyNode node, String hierarchyPredicate, OntologyGraph graph, Set ancestors) { - List parents = node.properties.getPropertyValues(hierarchyPredicate); - if(parents != null) { - for(PropertyValue parent : parents) { - if(parent.getType() == PropertyValue.Type.URI) { - String uri = ((PropertyValueURI) parent).getUri(); - if(!ancestors.contains(uri)) { - ancestors.add( uri ); - OntologyNode parentNode = graph.getNodeForPropertyValue(parent); - if(parentNode != null) { - getAncestors(parentNode, hierarchyPredicate, graph, ancestors); + List parentsList = node.properties.getPropertyValues(hierarchyPredicate); + if(parentsList != null) { + for(PropertyValue parentListElement : parentsList) { + if (parentListElement.getType() == PropertyValue.Type.LIST) { + List parents = ((PropertyValueList)parentListElement).getPropertyValues(); + for (PropertyValue parent: parents) { + if (parent.getType() == PropertyValue.Type.URI) { + String uri = ((PropertyValueURI) parent).getUri(); + if (!ancestors.contains(uri)) { + ancestors.add(uri); + OntologyNode parentNode = graph.getNodeForPropertyValue(parent); + if (parentNode != null) { + getAncestors(parentNode, hierarchyPredicate, graph, ancestors); + } + } } } } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertySet.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertySet.java index 74bc523a3..5d8d6c2b4 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertySet.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertySet.java @@ -56,12 +56,21 @@ public void annotatePropertyWithAxiom(String predicate, PropertyValue value, Pro } else { // simple case, look for an equal value to reify for (PropertyValue p : props) { - if (p.equals(value)) { + if (p instanceof PropertyValueList) { + for (PropertyValue propertyValueListElement: ((PropertyValueList)p).getPropertyValues()) { + if (propertyValueListElement.equals(value)) { + prop = propertyValueListElement; + break; + } + } + } else if (p.equals(value)) { prop = p; break; } } } + + if (prop == null) { prop = value; props.add(prop); @@ -89,10 +98,6 @@ public PropertyValue getPropertyValue(String predicate) { if(values == null || values.size() == 0) { return null; } -// if(values.size() == 1) { -// return values.get(0); -// } -// throw new RuntimeException("More than one property value for getOne: " + predicate); return values.get(0); } diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValue.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValue.java index 97e40809e..42269c8fc 100644 --- a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValue.java +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValue.java @@ -16,7 +16,8 @@ public enum Type { ID, RELATED, REFERENCED_ENTITIES, - ANCESTORS + ANCESTORS, + LIST } // reification diff --git a/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValueList.java b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValueList.java new file mode 100644 index 000000000..66547e352 --- /dev/null +++ b/dataload/rdf2json/src/main/java/uk/ac/ebi/rdf2json/properties/PropertyValueList.java @@ -0,0 +1,55 @@ +package uk.ac.ebi.rdf2json.properties; + +import java.util.List; + +public class PropertyValueList extends PropertyValue { + + private List propertyValues; + + public PropertyValueList(List propertyValues) { + this.propertyValues = propertyValues; + } + + public List getPropertyValues() { + return propertyValues; + } + + @Override + public Type getType() { + return Type.LIST; + } +// public PropertyValueList addOrUpdateProperty(T newPropertyValue) { +// Optional propertyValueOptional = find(newPropertyValue); +// if (propertyValueOptional.isPresent()) { +// (propertyValueOptional.get()).axioms = newPropertyValue.axioms; +// } else +// listOfPropertyValues.add(newPropertyValue); +// return this; +// } +// +// public Optional find(PropertyValue propertyValueToFind) { +// for (PropertyValue propertyValue: listOfPropertyValues) { +// if (propertyValue.equals(propertyValueToFind)) +// return Optional.of(propertyValue); +// } +// return Optional.empty(); +// } + + @Override + public boolean equals(PropertyValue propertyValue) { + if (propertyValue.getType() != Type.LIST) + return false; + else if (getClass() != propertyValue.getClass()) + return false; + else if (propertyValues.size() != ((PropertyValueList)propertyValue).getPropertyValues().size()) + return false; + else { + List listToCompare = ((PropertyValueList)propertyValue).getPropertyValues(); + for (int i = 0; i + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBO Format metamodel. This meta-ontology is self-describing. OBO metamodel properties are described using OBO metamodel properties + + + This is an OWL translation of an ontology whose native representational form is .obo. The translation was performed using the oboInOwl xslt library. For details, see http://www.berkeleybop.org/obo-conv.cgi + + + + database_cross_reference + + + definition + we are forced to use the n-ary relation pattern in OWL1.0. For OWL2 we may make this a direct axiom between a class and the string + + + The textual definition of the current term. There must be zero or one instances of this tag per term description + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + URL:http://www.obofoundry.org/wiki/index.php/Definitions + http://www.obofoundry.org/wiki/index.php/Definitions + + + + + obsolete_class + + + pseudo-class. in the oboInOwl translation, all obsolete classes are subclasses of this class. Note that this is not a metaclass + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + subset + + + A grouping of terms from an ontology or ontologies. Note that this is not a metaclass - classes are linked to subsets via oboInOwl:inSubset + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + view + + + + + partition + + + + + slim + + + + + GO-slim + + + + + oboFormat:subsetdef + http://purl.org/obo/owl/oboFormat#oboFormat_subsetdef + + + + + synonym + we are forced to use the n-ary relation pattern in OWL1.0. For OWL2 we may make this a direct axiom between a class and the string + + + An instance of synonym usage. synonym instances are linked to classes via oboInOwl:has*Synonym properties + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + synonym_type + + + obsolete_property + Note that this is not a metaclass + + + pseudo-property. in the oboInOwl translation, all obsolete relations are subProperties of this class + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + consider + + + Gives a term which may be an appropriate substitute for an obsolete term, but needs to be looked at carefully by a human expert before the replacement is done + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + oboFormat:consider + http://purl.org/obo/owl/oboFormat#oboFormat_consider + + + + + has_alternative_id + + + An alternative identifier for this class; should follow ID syntax. These can result from class merges + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + oboFormat:alt_id + http://purl.org/obo/owl/oboFormat#oboFormat_alt_id + + + + + has_broad_synonym + + + + An alias in which the alias is broader than the primary class name. Example: cell division is a broad synonym of cytokinesis + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + oboFormat:broad_synonym + http://purl.org/obo/owl/oboFormat#oboFormat_broad_synonym + + + + + has_date + + + oboFormat:date + http://purl.org/obo/owl/oboFormat#oboFormat_date + + + + + has_dbxref + + + oboFormat:xref + http://purl.org/obo/owl/oboFormat#oboFormat_xref + + + + + has_default_namespace + + + oboFormat:default-namespace + http://purl.org/obo/owl/oboFormat#oboFormat_default-namespace + + + + + has_definition + we are forced to use the n-ary relation pattern in OWL1.0. For OWL2 we may make this a direct axiom between a class and the string + + + a relation between a class and an instance of a oboInOwl:Definition + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + oboFormat:def + http://purl.org/obo/owl/oboFormat#oboFormat_def + + + + + has_exact_synonym + + + + An alias in which the alias exhibits true synonymy. Example: ornithine cycle is an exact synonym of urea cycle + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + oboFormat:exact_synonym + http://purl.org/obo/owl/oboFormat#oboFormat_exact_synonym + + + + + has_narrow_synonym + + + + An alias in which the alias is narrower than the primary class name. Example: pyrimidine-dimer repair by photolyase is a narrow synonym of photoreactive repair + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + oboFormat:narrow_synonym + http://purl.org/obo/owl/oboFormat#oboFormat_narrow_synonym + + + + + has_obo_namespace + + + A relation between a class and an OBO namespace string. OBO namespaces are to be distinguished from IDspaces; for example, biological_process is a namespace, GO is an idspace. + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + oboFormat:namespace + http://purl.org/obo/owl/oboFormat#oboFormat_namespace + + + + + has_synonym + Note that this should be a super-property of hasRelatedSynonym, hasExactSynonym etc; however, we cannot state this and remain in OWL-DL + + + A relation between a class and an alias term. + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + oboFormat:synonym + http://purl.org/obo/owl/oboFormat#oboFormat_synonym + + + + + has_related_synonym + + + + An alias in which the alias is related the primary class name, but not necessarily broader or narrower. Example: cytochrome bc1 complex is a related synonym of ubiquinol-cytochrome-c reductase activity; virulence is a related synonym of pathogenesis + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + oboFormat:related_synonym + http://purl.org/obo/owl/oboFormat#oboFormat_related_synonym + + + + + has_subset + + + relation between an ontology and a oboInOwl:Subset, indicating classes in the ontology belong to the subset + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + has_synonym_type + + + URL:http://www.geneontology.org/GO.usage.shtml#type + http://www.geneontology.org/GO.usage.shtml#type + + + + + has_URI + + + has_version + + + oboFormat:version + http://purl.org/obo/owl/oboFormat#oboFormat_version + + + + + in_subset + + + relation between a class and a oboInOwl:Subset, indicating the class belongs (is a member of) the subset + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + oboFormat:subset + http://purl.org/obo/owl/oboFormat#oboFormat_subset + + + + + replaced_by + + + Gives a term which replaces an obsolete term. The value is the id of the replacement term. The value of this tag can safely be used to automatically reassign links to an obsolete term. The replaced_by tag may only be specified for obsolete terms. A single obsolete term may have more than one replaced_by tag. This tag can be used in conjunction with the consider tag. + + + oboInOwl:cjm + http://purl.org/obo/owl/oboInOwl#oboInOwl_cjm + + + + + + + oboFormat:replaced_by + http://purl.org/obo/owl/oboFormat#oboFormat_replaced_by + + + + + saved_by + + + oboFormat:saved_by + http://purl.org/obo/owl/oboFormat#oboFormat_saved_by + + + + + is_cyclic + + + + + + + + oboFormat:is_cyclic + http://purl.org/obo/owl/oboFormat#oboFormat_is_cyclic + + + + + subset_property + + + This annotation property groups all subsets declared in the ontology + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + + synonym_type_property + + + This annotation property groups all synonym types declared in the ontology + + + oboInOwl:GOC + http://purl.org/obo/owl/oboInOwl#oboInOwl_GOC + + + + + + \ No newline at end of file diff --git a/testcases/defined-fields/BaseUri.json b/testcases/defined-fields/BaseUri.json new file mode 100644 index 000000000..0d4990a92 --- /dev/null +++ b/testcases/defined-fields/BaseUri.json @@ -0,0 +1,15 @@ +{ + "ontologies": [ + { + "id": "BASE_URI", + "preferredPrefix": "BASE_URI", + "title": "Experimental Factor Ontology", + "base_uri": [ + "http://www.ebi.ac.uk/baseUri/BASE_URI_" + ], + "reasoner": "OWL2", + "oboSlims": false, + "ontology_purl": "./testcases/defined-fields/BaseUri.owl" + } + ] +} diff --git a/testcases/defined-fields/BaseUri.owl b/testcases/defined-fields/BaseUri.owl new file mode 100644 index 000000000..3d7408d15 --- /dev/null +++ b/testcases/defined-fields/BaseUri.owl @@ -0,0 +1,11 @@ + + + + + 3.63.0 + + \ No newline at end of file diff --git a/testcases/defined-fields/DefinitionMultiple.json b/testcases/defined-fields/DefinitionMultiple.json new file mode 100644 index 000000000..668200a64 --- /dev/null +++ b/testcases/defined-fields/DefinitionMultiple.json @@ -0,0 +1,9 @@ +{ + "ontologies": [ + { + "id": "Definition-Multiple", + "preferredPrefix": "Definition-Multiple", + "ontology_purl": "./testcases/defined-fields/DefinitionMultiple.owl" + } + ] +} diff --git a/testcases/defined-fields/DefinitionMultiple.owl b/testcases/defined-fields/DefinitionMultiple.owl new file mode 100644 index 000000000..08bd69022 --- /dev/null +++ b/testcases/defined-fields/DefinitionMultiple.owl @@ -0,0 +1,27 @@ + + + + + + + + + A disease involving the liver. + Any disease or dysfunction of the liver and the intrahepatic bile ducts. + Pathological processes of the LIVER. + liver disease + + + + + + + + diff --git a/testcases/defined-fields/DefinitionSingle.json b/testcases/defined-fields/DefinitionSingle.json new file mode 100644 index 000000000..d8a9c6114 --- /dev/null +++ b/testcases/defined-fields/DefinitionSingle.json @@ -0,0 +1,12 @@ +{ + "ontologies": [ + { + "id": "Definition-Single", + "preferredPrefix": "Definition-Single", + "ontology_purl": "./testcases/defined-fields/DefinitionSingle.ttl", + "base_uri": [ + "http://www.w3.org/2002/07/owl#" + ] + } + ] +} diff --git a/testcases/defined-fields/DefinitionSingle.ttl b/testcases/defined-fields/DefinitionSingle.ttl new file mode 100644 index 000000000..971b0473b --- /dev/null +++ b/testcases/defined-fields/DefinitionSingle.ttl @@ -0,0 +1,12 @@ +@prefix dc: . +@prefix grddl: . +@prefix owl: . +@prefix rdf: . +@prefix rdfs: . +@prefix xml: . +@prefix xsd: . + +owl:Thing a owl:Class ; + rdfs:label "Thing" ; + rdfs:comment "The class of OWL individuals." ; + rdfs:isDefinedBy . \ No newline at end of file diff --git a/testcases/defined-fields/DirectParentWithAnnotationAxiom.json b/testcases/defined-fields/DirectParentWithAnnotationAxiom.json new file mode 100644 index 000000000..ac20ae132 --- /dev/null +++ b/testcases/defined-fields/DirectParentWithAnnotationAxiom.json @@ -0,0 +1,9 @@ +{ + "ontologies": [ + { + "id": "Direct-Parent-With-Annotation-Axiom", + "preferredPrefix": "Direct-Parent-With-Annotation-Axiom", + "ontology_purl": "./testcases/defined-fields/DirectParentWithAnnotationAxiom.owl" + } + ] +} diff --git a/testcases/defined-fields/DirectParentWithAnnotationAxiom.owl b/testcases/defined-fields/DirectParentWithAnnotationAxiom.owl new file mode 100644 index 000000000..11b2964b7 --- /dev/null +++ b/testcases/defined-fields/DirectParentWithAnnotationAxiom.owl @@ -0,0 +1,88 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + A non-neoplastic or neoplastic disorder that affects the testis or the ovary. + gonadal disorder + + + + + + DOID:2277 + MESH:D006058 + + + + + + + + A disease involving the reproductive system. + reproductive system disorder + + + + + + + + A disease involving the endocrine system. + endocrine system disorder + + + + + + + diff --git a/testcases/defined-fields/PreferredRoot.json b/testcases/defined-fields/PreferredRoot.json new file mode 100644 index 000000000..2e61f2790 --- /dev/null +++ b/testcases/defined-fields/PreferredRoot.json @@ -0,0 +1,9 @@ +{ + "ontologies": [ + { + "id": "Preferred-Root", + "preferredPrefix": "Preferred-Root", + "ontology_purl": "./testcases/defined-fields/PreferredRoot.owl" + } + ] +} diff --git a/testcases/defined-fields/PreferredRoot.owl b/testcases/defined-fields/PreferredRoot.owl new file mode 100644 index 000000000..e5bd8416a --- /dev/null +++ b/testcases/defined-fields/PreferredRoot.owl @@ -0,0 +1,24 @@ + + + + + + + + + liver disease + + + + + + + + diff --git a/testcases/defined-fields/labelSingle.json b/testcases/defined-fields/labelSingle.json new file mode 100644 index 000000000..fe09055d2 --- /dev/null +++ b/testcases/defined-fields/labelSingle.json @@ -0,0 +1,9 @@ +{ + "ontologies": [ + { + "id": "labelSingle", + "preferredPrefix": "labelSingle", + "ontology_purl": "./testcases/defined-fields/labelSingle.owl" + } + ] +} diff --git a/testcases/defined-fields/labelSingle.owl b/testcases/defined-fields/labelSingle.owl new file mode 100644 index 000000000..85c310efb --- /dev/null +++ b/testcases/defined-fields/labelSingle.owl @@ -0,0 +1,21 @@ + + + + + + + + simple label + + + + + + + diff --git a/testcases/hierarchical-properties/partof.ttl b/testcases/hierarchical-properties/partof.ttl new file mode 100644 index 000000000..5f8e69870 --- /dev/null +++ b/testcases/hierarchical-properties/partof.ttl @@ -0,0 +1,59 @@ +@prefix : . +@prefix owl: . +@prefix rdf: . +@prefix xml: . +@prefix xsd: . +@prefix rdfs: . +@base . + + rdf:type owl:Ontology ; + owl:versionIRI . + +################################################################# +# Object Properties +################################################################# + +### http://purl.obolibrary.org/obo/BFO_0000050 + rdf:type owl:ObjectProperty , + owl:TransitiveProperty ; + rdfs:label "part_of" . + + +### http://purl.obolibrary.org/obo/ms#part_of + rdf:type owl:ObjectProperty , + owl:TransitiveProperty . + + +################################################################# +# Classes +################################################################# + +### http://purl.obolibrary.org/obo/MS_1000353 + rdf:type owl:Class ; + rdfs:label "adduct ion" . + + +### http://purl.obolibrary.org/obo/MS_1003056 + rdf:type owl:Class ; + rdfs:subClassOf [ rdf:type owl:Restriction ; + owl:onProperty ; + owl:someValuesFrom + ] ; + rdfs:label "adduct ion property" . + + +### http://purl.obolibrary.org/obo/UBERON_0000916 + rdf:type owl:Class ; + rdfs:label "abdomen" . + + +### http://purl.obolibrary.org/obo/UBERON_0003684 + rdf:type owl:Class ; + rdfs:subClassOf [ rdf:type owl:Restriction ; + owl:onProperty ; + owl:someValuesFrom + ] ; + rdfs:label "abdominal cavity" . + + +### Generated by the OWL API (version 4.5.24.2023-01-14T21:28:32Z) https://github.com/owlcs/owlapi diff --git a/testcases/owl2-primer/subClassOf.ttl b/testcases/owl2-primer/subClassOf.ttl new file mode 100644 index 000000000..6a1c00921 --- /dev/null +++ b/testcases/owl2-primer/subClassOf.ttl @@ -0,0 +1,30 @@ +@prefix : . +@prefix owl: . +@prefix rdf: . +@prefix xml: . +@prefix xsd: . +@prefix rdfs: . +@base . + + rdf:type owl:Ontology ; + owl:versionIRI . + +################################################################# +# Classes +################################################################# + +### http://www.ebi.ac.uk/testcases/owl2primer/subClassOf#Mother + rdf:type owl:Class ; + rdfs:subClassOf . + + +### http://www.ebi.ac.uk/testcases/owl2primer/subClassOf#Person + rdf:type owl:Class . + + +### http://www.ebi.ac.uk/testcases/owl2primer/subClassOf#Woman + rdf:type owl:Class ; + rdfs:subClassOf . + + +### Generated by the OWL API (version 4.5.24.2023-01-14T21:28:32Z) https://github.com/owlcs/owlapi