Skip to content

Commit

Permalink
Merge pull request #804 from EBISPOT/dev
Browse files Browse the repository at this point in the history
Merge dev into stable
  • Loading branch information
henrietteharmse authored Nov 19, 2024
2 parents 5e094c6 + 27a4cbf commit 6a0ef76
Show file tree
Hide file tree
Showing 1,393 changed files with 255,578 additions and 155,906 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ new expected output:

git add -A testcases_expected_output

8. Commit the updates to testcases to a branch with suffix `-testcases`.
8. Commit the updates to testcases to a branch with suffix `-testcases` and message "TESTCASES updated".
9. Now continue with API testing.

### Testing API
Expand Down Expand Up @@ -440,7 +440,7 @@ the old `testcases_expected_output_api` and replace with new expected output:

git add -A testcases_expected_output_api

16. Commit the API tests to a branch with suffix `-api-tests`.
16. Commit the API tests to a branch with suffix `-api-tests` and message "API-TESTS updated".

17. You can stop the OLS4 backend with "Ctrl-C", and Solr and Neo4J with:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -36,23 +38,23 @@ public static List<String> mapFieldsList(Collection<String> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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))));

Expand Down Expand Up @@ -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 + ")");
}

}
Expand All @@ -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 + ")");
}
}

Expand Down Expand Up @@ -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");
Expand All @@ -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(),
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -146,9 +146,9 @@ public void select(
solrQuery.add("hl.simple.pre", "<b>");
solrQuery.add("hl.simple.post", "</b>");
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());

Expand All @@ -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");
}

Expand All @@ -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(),
Expand All @@ -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);
Expand Down Expand Up @@ -228,9 +229,9 @@ public void select(
Map<String,Object> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand All @@ -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");


Expand All @@ -90,7 +92,7 @@ public void suggest(
for(SolrDocument res : qr.getResults()) {
Map<String,Object> outDoc = new HashMap<>();

outDoc.put("autosuggest", res.get("label"));
outDoc.put("autosuggest", res.get(LABEL.getText()));

docs.add(outDoc);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void createJsTreeEntries(List<Map<String,Object>> jstree, JsonObject ent
}

jstreeEntry.put("iri", entityIri);
jstreeEntry.put("text", JsonHelper.getString(entity, "label"));
jstreeEntry.put("text", JsonHelper.getString(entity, LABEL.getText()));

Collection<String> childIris = entityIriToChildIris.get(entityIri);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ List<Map<String,Object>> 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<String,Object> attrObj = new LinkedHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -76,13 +78,13 @@ private Map<String, Object> 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<String, Object> 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());
Expand All @@ -107,7 +109,7 @@ private Map<String, Object> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -30,7 +32,7 @@ public List<Map<String,Object>> getJsTreeForIndividual(String iri, String ontolo

private List<Map<String,Object>> getJsTreeForEntity(String iri, String type, String neo4jType, String ontologyId, String lang) {

List<String> parentRelationIRIs = List.of("directParent");
List<String> parentRelationIRIs = List.of(DIRECT_PARENT.getText());

String thisEntityId = ontologyId + "+" + type + "+" + iri;

Expand Down Expand Up @@ -59,7 +61,7 @@ public List<Map<String,Object>> getJsTreeChildrenForIndividual(String individual

private List<Map<String,Object>> getJsTreeChildrenForEntity(String iri, String jstreeId, String type, String neo4jType, String ontologyId, String lang) {

List<String> parentRelationIRIs = List.of("directParent");
List<String> parentRelationIRIs = List.of(DIRECT_PARENT.getText());

String thisEntityId = ontologyId + "+" + type + "+" + iri;

Expand Down
Loading

0 comments on commit 6a0ef76

Please sign in to comment.