Commit a5578611 authored by David Hoksza's avatar David Hoksza
Browse files

Implemented paramaters for all annotators + createMiriamData for all annotators

parent 9ca41336
package lcsb.mapviewer.annotation.services.annotators;
/**
* Definition of a single parameter of an annotator.
*
* @author David Hoksza
*
*/
public class AnnotatorParamDefinition {
private String name;
private String decription;
private Class<?> type;
public AnnotatorParamDefinition(String name, String decription, Class<?> type) {
super();
this.name = name;
this.decription = decription;
this.type = type;
}
public String getName() {
return name;
}
public String getDecription() {
return decription;
}
public Class<?> getType() {
return type;
}
}
......@@ -178,14 +178,14 @@ public class ChebiAnnotator extends ElementAnnotator implements IExternalService
String synonym = dataItem.getData();
if (synonym.trim().equalsIgnoreCase(name)) {
setCacheValue("name: " + name, entity.getChebiId());
return new MiriamData(MiriamType.CHEBI, entity.getChebiId());
return createMiriamData(MiriamType.CHEBI, entity.getChebiId());
}
}
for (DataItem dataItem : entity.getSynonyms()) {
String synonym = dataItem.getData();
if (synonym.trim().equalsIgnoreCase(name)) {
setCacheValue("name: " + name, entity.getChebiId());
return new MiriamData(MiriamType.CHEBI, entity.getChebiId());
return createMiriamData(MiriamType.CHEBI, entity.getChebiId());
}
}
}
......@@ -197,14 +197,14 @@ public class ChebiAnnotator extends ElementAnnotator implements IExternalService
String formula = dataItem.getData();
if (formula.trim().equalsIgnoreCase(name)) {
setCacheValue("name: " + name, entity.getChebiId());
return new MiriamData(MiriamType.CHEBI, entity.getChebiId());
return createMiriamData(MiriamType.CHEBI, entity.getChebiId());
}
}
for (DataItem dataItem : entity.getSynonyms()) {
String synonym = dataItem.getData();
if (synonym.trim().equalsIgnoreCase(name)) {
setCacheValue("name: " + name, entity.getChebiId());
return new MiriamData(MiriamType.CHEBI, entity.getChebiId());
return createMiriamData(MiriamType.CHEBI, entity.getChebiId());
}
}
}
......
......@@ -44,6 +44,11 @@ public abstract class ElementAnnotator extends CachableInterface {
* Should be this annotator used as a default annotator.
*/
private boolean isDefault = false;
/**
* Parameters which this annotator can be provided. Should be set in constructor.
*/
protected List<AnnotatorParamDefinition> paramsDefs = new ArrayList<>();
/**
* Default constructor.
......@@ -78,6 +83,22 @@ public abstract class ElementAnnotator extends CachableInterface {
* data
*/
public abstract void annotateElement(BioEntity element) throws AnnotatorException;
/**
* Annotate element using parameters.
*
* @param element
* object to be annotated
* @param parameters
* list of parameters passed to the annotator which is expected to
* be in the same order as its {@link this#parameterDefs}
* @throws AnnotatorException
* thrown when there is a problem with annotating not related to
* data
*/
public void annotateElement(BioEntity element, List<Object> parameters) throws AnnotatorException {
annotateElement(element);
}
/**
* Returns a list of all classes that can be annotated using this annotator.
......@@ -130,6 +151,42 @@ public abstract class ElementAnnotator extends CachableInterface {
* @return url
*/
public abstract String getUrl();
/**
* Provides description for {@link ElementAnnotator} and {@link MiriamType} pair
* to be used in the frontend.
* @param mt
* {@link MiriamType} annotated by this annotator.
* @return
* the description
*/
public String getDescription(MiriamType mt){
return "";
}
/**
* Provides description for {@link ElementAnnotator}, {@link MiriamType} and
* {@link MiriamRelationType} triplet to be used in the frontend.
* @param mt
* {@link MiriamType} annotated by this annotator
* @param relationType
* {@link MiriamRelationType} annotated by this annotator.
* @return
* the description
*/
public String getDescription(MiriamType mt, MiriamRelationType relationType){
return "";
}
/**
* Returns list with definitions of the parameters available for this annotator.
* @return the parameters {@link AnnotatorParamDefinition} list
*/
public Collection<AnnotatorParamDefinition> getParametersDefinitions(){
return paramsDefs;
}
/**
* Returns <code>true</code> if this annotator can annotate the object of
......@@ -475,33 +532,69 @@ public abstract class ElementAnnotator extends CachableInterface {
}
}
/**
* Sets MiriamData.annotator to this annotator
*
* @param md
* data for which the annotator is to be set
*/
private void setAnnotator(MiriamData md){
md.setAnnotator(this.getClass());
}
/**
* Creates {@link MiriamData} and sets its annotator to this annotator
* @return
* created {@link MiriamData}
*/
protected MiriamData createMiriamData(){
MiriamData md = new MiriamData();
setAnnotator(md);
return md;
}
/**
* Creates {@link MiriamData} and sets its annotator to this annotator
* @param _md
* {@link MiriamData} based on which the new {@link MiriamData} should be created
* @return
* created {@link MiriamData}
*/
protected MiriamData createMiriamData(MiriamData _md){
MiriamData md = new MiriamData(_md);
setAnnotator(md);
return md;
}
/**
* Creates {@link MiriamData} and sets its annotator to this annotator
* @param mt
* {@link MiriamType} to be set
* @param resource
* resource to be set
* @return
* created {@link MiriamData}
*/
protected MiriamData createMiriamData(MiriamType mt, String resource){
MiriamData md = new MiriamData(mt, resource);
setAnnotator(md);
return md;
}
/**
* Creates {@link MiriamData} and sets its annotator to this annotator
* @param relationType
* {@link MiriamRelationType} to be set
* @param mt
* {@link MiriamType} to be set
* @param resource
* resource to be set
* @return
* created {@link MiriamData}
*/
protected MiriamData createMiriamData(MiriamRelationType relationType, MiriamType mt, String resource){
MiriamData md = new MiriamData(relationType, mt, resource);
setAnnotator(md);
return md;
}
}
......@@ -230,11 +230,11 @@ public class EnsemblAnnotator extends ElementAnnotator implements IExternalServi
String hgncId = super.getNodeAttr("primary_id", node);
if (hgncId != null && !hgncId.isEmpty()) {
hgncId = hgncId.replaceAll("HGNC:", "");
annotatedObject.addMiriamData(new MiriamData(MiriamType.HGNC, hgncId));
annotatedObject.addMiriamData(createMiriamData(MiriamType.HGNC, hgncId));
}
String hgncSymbol = super.getNodeAttr("display_id", node);
if (hgncSymbol != null && !hgncSymbol.isEmpty()) {
annotatedObject.addMiriamData(new MiriamData(MiriamType.HGNC_SYMBOL, hgncSymbol));
annotatedObject.addMiriamData(createMiriamData(MiriamType.HGNC_SYMBOL, hgncSymbol));
}
NodeList synonymNodeList = node.getChildNodes();
......
......@@ -232,7 +232,7 @@ public class HgncAnnotator extends ElementAnnotator implements IExternalService
for (int j = 0; j < sublist.getLength(); j++) {
Node subnode = sublist.item(j);
if (subnode.getNodeType() == Node.ELEMENT_NODE) {
element.addMiriamData(new MiriamData(MiriamType.UNIPROT, getNodeValue(subnode)));
element.addMiriamData(createMiriamData(MiriamType.UNIPROT, getNodeValue(subnode)));
}
}
}
......
......@@ -6,6 +6,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ AnnotatorExceptionTest.class, //
AnnotatorParamDefTest.class, //
BrendaAnnotatorTest.class, //
BiocompendiumAnnotatorTest.class, //
CazyAnnotatorTest.class, //
......
......@@ -23,8 +23,10 @@ public class AnnotatorExceptionTest {
@Test
public void testConstructor() {
AnnotatorException e = new AnnotatorException("messss");
assertEquals("messss",e.getMessage());
AnnotatorParamDefinition d = new AnnotatorParamDefinition("name", "description", String.class);
assertEquals(d.getName(), "name");
assertEquals(d.getDecription(), "description");
assertEquals(d.getType(), String.class);
}
}
package lcsb.mapviewer.annotation.services.annotators;
import static org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
public class AnnotatorParamDefTest {
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
@Before
public void setUp() throws Exception {
}
@After
public void tearDown() throws Exception {
}
@Test
public void testConstructor() {
AnnotatorException e = new AnnotatorException("messss");
assertEquals("messss",e.getMessage());
}
}
......@@ -225,6 +225,9 @@ public class ElementAnnotatorTest extends AnnotationTestFunctions {
assertEquals(md2.getAnnotator(), annotator.getClass());
}
@Test
public void testEmptyParamsDefs() {
assertEquals(annotator.getParametersDefinitions().size(), 0);
}
}
......@@ -87,8 +87,6 @@ public class StitchAnnotatorTest extends AnnotationTestFunctions {
assertEquals(1, bioEntity.getMiriamData().size());
assertEquals(1, getWarnings().size());
} catch (Exception e) {
e.printStackTrace();
throw e;
......
......@@ -247,6 +247,7 @@ public class ConfigurationRestImpl extends BaseRestImpl {
result.put("name", annotator.getCommonName());
result.put("url", annotator.getUrl());
result.put("elementClassNames", annotator.getValidClasses());
result.put("parametersDefinitions", annotator.getParametersDefinitions());
return result;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment