Skip to content
Snippets Groups Projects
Commit 6d5c9ec2 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '548-automatic-vmh-annotation' into 'devel_12.1.x'

Resolve "automatic VMH annotation not working"

See merge request !517
parents eca816a7 ec96ebc5
No related branches found
No related tags found
2 merge requests!541version 12.1.3 into master,!517Resolve "automatic VMH annotation not working"
Pipeline #7612 passed
...@@ -523,6 +523,11 @@ public abstract class ElementAnnotator extends CachableInterface { ...@@ -523,6 +523,11 @@ public abstract class ElementAnnotator extends CachableInterface {
element.addMiriamData(md); element.addMiriamData(md);
} }
protected void addRhea(BioEntity element, String value) {
MiriamData md = createMiriamData(MiriamType.RHEA, value);
element.addMiriamData(md);
}
/** /**
* Sets {@link BioEntity#getFormula()}. * Sets {@link BioEntity#getFormula()}.
* *
......
...@@ -7,6 +7,7 @@ import java.util.Map.Entry; ...@@ -7,6 +7,7 @@ import java.util.Map.Entry;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser; import com.google.gson.JsonParser;
...@@ -142,7 +143,7 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService ...@@ -142,7 +143,7 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
JsonElement jelement = new JsonParser().parse(content); JsonElement jelement = new JsonParser().parse(content);
JsonObject jobject = jelement.getAsJsonObject(); JsonObject jobject = jelement.getAsJsonObject();
if (jobject.get("results").getAsJsonArray().size() > 0) { if (jobject.get("results").getAsJsonArray().size() > 0) {
jobject = jobject.get("results").getAsJsonArray().get(0).getAsJsonObject(); jobject = getBestMatchForAbbreviation(id, jobject.get("results").getAsJsonArray());
for (Entry<String, JsonElement> entry : jobject.entrySet()) { for (Entry<String, JsonElement> entry : jobject.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
...@@ -294,9 +295,18 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService ...@@ -294,9 +295,18 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
continue; continue;
} else if (key.equals("casRegistry")) { } else if (key.equals("casRegistry")) {
addCas(annotatedObject, value); addCas(annotatedObject, value);
} else if (key.equals("rhea")) {
addRhea(annotatedObject, value);
} else if (key.equals("epa_id")) { } else if (key.equals("epa_id")) {
// for now we don't handle it // for now we don't handle it
continue; continue;
} else if (key.equals("biocyc")) {
// for now we don't handle it
continue;
} else if (key.equals("createdDate")) {
continue;
} else if (key.equals("updatedDate")) {
continue;
} else { } else {
unknown = true; unknown = true;
} }
...@@ -316,6 +326,31 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService ...@@ -316,6 +326,31 @@ public class ReconAnnotator extends ElementAnnotator implements IExternalService
} }
} }
private JsonObject getBestMatchForAbbreviation(String id, JsonArray asJsonArray) {
String match = null;
JsonObject result = null;
for (JsonElement element : asJsonArray) {
if (((JsonObject) element).get("abbreviation") != null) {
String objAbreviation = ((JsonObject) element).get("abbreviation").getAsString();
if (match == null) {
match = objAbreviation;
result = (JsonObject) element;
} else if (match.length() > objAbreviation.length()) {
match = objAbreviation;
result = (JsonObject) element;
} else if (id.equalsIgnoreCase(objAbreviation)) {
match = objAbreviation;
result = (JsonObject) element;
}
} else if (match == null) {
logger.warn("No abbreviation found for element: " + element);
result = (JsonObject) element;
}
}
return result;
}
@Override @Override
public String getCommonName() { public String getCommonName() {
return "Recon annotator"; return "Recon annotator";
......
...@@ -189,6 +189,21 @@ public class ReconAnnotatorTest extends AnnotationTestFunctions { ...@@ -189,6 +189,21 @@ public class ReconAnnotatorTest extends AnnotationTestFunctions {
} }
} }
@Test
public void testAnnotatingForOxygen() throws Exception {
try {
SimpleMolecule molecule = new SimpleMolecule("id");
molecule.setName("o2");
reconAnnotator.annotateElement(molecule);
assertTrue(molecule.getMiriamData().size() > 0);
assertEquals(0, getWarnings().size());
assertEquals("O2", molecule.getFormula());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test @Test
public void testAnnotatingWithWhitespace() throws Exception { public void testAnnotatingWithWhitespace() throws Exception {
try { try {
......
...@@ -469,7 +469,7 @@ public enum MiriamType { ...@@ -469,7 +469,7 @@ public enum MiriamType {
*/ */
VMH_METABOLITE("VMH metabolite", // VMH_METABOLITE("VMH metabolite", //
"https://vmh.uni.lu/", // "https://vmh.uni.lu/", //
"urn:miriam:vmhmetabolite", // new String[] { "urn:miriam:vmhmetabolite", "http://identifiers.org/vmhmetabolite/" }, //
new Class<?>[] { Chemical.class }, "MIR:00000636"), new Class<?>[] { Chemical.class }, "MIR:00000636"),
/** /**
...@@ -477,7 +477,7 @@ public enum MiriamType { ...@@ -477,7 +477,7 @@ public enum MiriamType {
*/ */
VMH_REACTION("VMH reaction", // VMH_REACTION("VMH reaction", //
"https://vmh.uni.lu/", // "https://vmh.uni.lu/", //
"urn:miriam:vmhreaction", // new String[] { "urn:miriam:vmhreaction", "http://identifiers.org/vmhreaction/" }, //
new Class<?>[] { Reaction.class }, "MIR:00000640"), new Class<?>[] { Reaction.class }, "MIR:00000640"),
/** /**
...@@ -741,6 +741,11 @@ public enum MiriamType { ...@@ -741,6 +741,11 @@ public enum MiriamType {
foundType = type; foundType = type;
foundUri = uri; foundUri = uri;
} }
} else if (miriamUri.startsWith(uri) && uri.endsWith("/")) {
if (uri.length() > foundUri.length()) {
foundType = type;
foundUri = uri;
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment