Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified backend and frontend for handling grouping of datasets #460

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
/**
* Contains all information needed to load an annotator for a specific
* experiment type.
*
*
* @author Michael Röder ([email protected])
*
*/
Expand All @@ -39,7 +39,7 @@ public class AnnotatorConfigurationImpl extends AbstractAdapterConfiguration imp
public AnnotatorConfigurationImpl(String annotatorName, boolean couldBeCached,
Constructor<? extends Annotator> constructor, Object constructorArgs[],
ExperimentType applicableForExperiment) {
super(annotatorName, couldBeCached, applicableForExperiment);
super(annotatorName,"Others", couldBeCached, applicableForExperiment);
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
this.constructor = constructor;
this.constructorArgs = constructorArgs;
}
Expand Down Expand Up @@ -87,4 +87,4 @@ public String toString() {
builder.append(')');
return builder.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public abstract class AbstractDatasetConfiguration extends AbstractAdapterConfig
protected EntityCheckerManager entityCheckerManager;
protected SameAsRetriever globalRetriever;

public AbstractDatasetConfiguration(String datasetName, boolean couldBeCached,
public AbstractDatasetConfiguration(String datasetName,String datasetGroup, boolean couldBeCached,
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
SameAsRetriever globalRetriever) {
super(datasetName, couldBeCached, applicableForExperiment);
super(datasetName,datasetGroup, couldBeCached, applicableForExperiment);
this.entityCheckerManager = entityCheckerManager;
this.globalRetriever = globalRetriever;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/aksw/gerbil/dataset/Dataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ public interface Dataset extends Closeable {
public void setName(String name);

public List<Document> getInstances();

public void setClosePermitionGranter(ClosePermitionGranter granter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public class DatasetConfigurationImpl extends AbstractDatasetConfiguration {
protected Constructor<? extends Dataset> constructor;
protected Object constructorArgs[];

public DatasetConfigurationImpl(String datasetName, boolean couldBeCached,
public DatasetConfigurationImpl(String datasetName,String datasetGroup, boolean couldBeCached,
Constructor<? extends Dataset> constructor, Object constructorArgs[],
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
SameAsRetriever globalRetriever) {
super(datasetName, couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
super(datasetName, datasetGroup, couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
this.constructor = constructor;
this.constructorArgs = constructorArgs;
}
Expand Down Expand Up @@ -66,4 +66,4 @@ public String toString() {
builder.append(')');
return builder.toString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ public InstanceListBasedDataset(List<Document> instances, ExperimentType applica
}

public InstanceListBasedDataset(String name, List<Document> instances, ExperimentType applicableForExperiment) {
super(name, false, applicableForExperiment, null, null);
super(name,"Others", false, applicableForExperiment, null, null);
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
this.instances = instances;
}

public InstanceListBasedDataset(String name, List<Document> instances, ExperimentType applicableForExperiment,
EntityCheckerManager entityCheckerManager, SameAsRetriever globalRetriever) {
super(name, false, applicableForExperiment, entityCheckerManager, globalRetriever);
super(name,"Others", false, applicableForExperiment, entityCheckerManager, globalRetriever);
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
this.instances = instances;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ public class SingletonDatasetConfigImpl extends DatasetConfigurationImpl impleme
protected int instanceUsages = 0;
protected Semaphore instanceMutex = new Semaphore(1);

public SingletonDatasetConfigImpl(String annotatorName, boolean couldBeCached,
public SingletonDatasetConfigImpl(String annotatorName, String annotatorGroup, boolean couldBeCached,
Constructor<? extends Dataset> constructor, Object constructorArgs[],
ExperimentType applicableForExperiment, EntityCheckerManager entityCheckerManager,
SameAsRetriever globalRetriever) {
super(annotatorName, couldBeCached, constructor, constructorArgs, applicableForExperiment, entityCheckerManager,
super(annotatorName, annotatorGroup, couldBeCached, constructor, constructorArgs, applicableForExperiment, entityCheckerManager,
globalRetriever);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DatahubNIFConfig extends AbstractDatasetConfiguration {

public DatahubNIFConfig(String datasetName, String datasetUrl, boolean couldBeCached, EntityCheckerManager entityCheckerManager,
SameAsRetriever globalRetriever) {
super(datasetName, couldBeCached, ExperimentType.A2KB, entityCheckerManager, globalRetriever);
super(datasetName,"Others", couldBeCached, ExperimentType.A2KB, entityCheckerManager, globalRetriever);
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
this.datasetUrl = datasetUrl;
rt = new RestTemplate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
public abstract class AbstractDataset implements Dataset {

protected String name;

protected String group;

protected ClosePermitionGranter granter;

public AbstractDataset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class NIFFileDatasetConfig extends AbstractDatasetConfiguration {

public NIFFileDatasetConfig(String name, String file, boolean couldBeCached, ExperimentType applicableForExperiment,
EntityCheckerManager entityCheckerManager, SameAsRetriever globalRetriever) {
super(name, couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
super(name,"Others", couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
this.file = file;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ public abstract class AbstractAdapterConfiguration implements AdapterConfigurati
private static final ExperimentTypeComparator EXP_TYPE_COMPARATOR = new ExperimentTypeComparator();

protected String name;
protected String group;
protected boolean couldBeCached;
protected ExperimentType applicableForExperiment;

public AbstractAdapterConfiguration(String name, boolean couldBeCached, ExperimentType applicableForExperiment) {
public AbstractAdapterConfiguration(String name,String group, boolean couldBeCached, ExperimentType applicableForExperiment) {
this.name = name;
this.group = group;
this.couldBeCached = couldBeCached;
this.applicableForExperiment = applicableForExperiment;
}
Expand All @@ -37,6 +39,10 @@ public String getName() {
return name;
}

public String getGroup() {
return group;
}

@Override
public void setName(String name) {
this.name = name;
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/org/aksw/gerbil/datatypes/AdapterConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@
/**
* Interface of an adpater configuration of the GERBIL system. It represents the
* adapter and is able to create an adapter instance.
*
*
* @author Michael Röder
*
*
*/
public interface AdapterConfiguration extends Comparable<AdapterConfiguration>{

/**
* Getter of the adapters name.
*
*
* @return The name of the adapter.
*/
public String getName();

/**
* Setter of the adapters name.
*
*
* @param name
* The name of the adapter.
*/
Expand All @@ -43,7 +43,7 @@ public interface AdapterConfiguration extends Comparable<AdapterConfiguration>{
/**
* Returns true if the system is allowed to cache the results of experiments
* in which this adapter has been involved.
*
*
* @return true if the results could be cached inside the database.
* Otherwise false is returned.
*/
Expand All @@ -53,21 +53,23 @@ public interface AdapterConfiguration extends Comparable<AdapterConfiguration>{
* Setter for the caching flag which should be set to true if the system is
* allowed to cache the results of experiments in which this adapter has
* been involved.
*
*
* @param couldBeCached
*/
public void setCouldBeCached(boolean couldBeCached);

/**
* Returns true if this adapter can be used for an experiment of the given
* type.
*
*
* @param type
* the experiment type that should be checked
* @return true if this adapter can be used for an experiment of the given
* type.
*/
public boolean isApplicableForExperiment(ExperimentType type);

public ExperimentType getExperimentType();

public String getGroup();
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
}
18 changes: 8 additions & 10 deletions src/main/java/org/aksw/gerbil/web/MainController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -306,18 +302,20 @@ public ModelAndView experiment(@RequestParam(value = "id") String id, HttpServle
}

@RequestMapping("/datasets")
public @ResponseBody List<String> datasets(@RequestParam(value = "experimentType") String experimentType) {
public @ResponseBody Map<String, List<String>> datasets(@RequestParam(value = "experimentType") String experimentType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning a Set or List of adapter configurations and serializing them as JSON would be better, since it allows us to add more details about the datasets later on.

I sent you a link about how the Jackson serialization (used by the Spring framework) works. You can also try to simply return the set of configuration objects as it is since the serialization is typically not hard for most Java objects.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a solution that would work 👍

However, the current implementation handles something that the Spring framework can already do for you. I am afraid that I have described the goal in an ambiguous way, so let me try to explain what I would suggest.
The method should return Map<String, List<DatasetCofiguration>> and the Spring framework should apply it's "magic" to transform it into JSON 🪄

Of course, Spring cannot do magic things, so we still have to provide the serialization 😉
However, it is sufficient if we tell Spring that there is exactly one class that implements the serialization and Spring can simply make use of it whenever it is necessary. You can do that with the method that is shown under point 3.2 in https://www.baeldung.com/spring-boot-customize-jackson-objectmapper (if I am not mistaken, I didn't read the whole text 😅 so let me know if you encounter problems). This method should go into our RootConfig.

ExperimentType type = null;
Map<String, List<String>> response = new TreeMap<>(Comparator.comparing((String key) -> key.equals("Others")).thenComparing(Comparator.naturalOrder()));
try {
type = ExperimentType.valueOf(experimentType);
} catch (IllegalArgumentException e) {
LOGGER.warn("Got a request containing a wrong ExperimentType (\"{}\"). Ignoring it.", experimentType);
return null;
}
Set<String> datasets = adapterManager.getDatasetNamesForExperiment(type);
List<String> list = Lists.newArrayList(datasets);
Collections.sort(list);
return list;
for(Map.Entry<String, String> entry :adapterManager.getDatasetDetailsForExperiment(type).entrySet()){
response.computeIfAbsent(entry.getValue(), k -> new ArrayList<>()).add(entry.getKey());
}
response.values().forEach(Collections::sort);
return response;
MichaelRoeder marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/aksw/gerbil/web/config/AdapterList.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public Set<String> getAdapterNamesForExperiment(ExperimentType type) {
return names;
}

public Map<String, String> getAdapterDetailsForExperiment(ExperimentType type) {
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
List<T> configs = getAdaptersForExperiment(type);
Map<String,String> names = new HashMap<String,String>(configs.size());
for (T config : configs) {
names.put(config.getName(), config.getGroup());
}
return names;
}
MichaelRoeder marked this conversation as resolved.
Show resolved Hide resolved

public List<T> getAdaptersForName(String name) {
if (nameToAdapterMapping.containsKey(name)) {
return nameToAdapterMapping.get(name);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/aksw/gerbil/web/config/AdapterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.aksw.gerbil.web.config;

import java.util.List;
import java.util.Map;
import java.util.Set;

import org.aksw.gerbil.annotator.AnnotatorConfiguration;
Expand Down Expand Up @@ -66,6 +67,9 @@ public Set<String> getAnnotatorNamesForExperiment(ExperimentType type) {
public Set<String> getDatasetNamesForExperiment(ExperimentType type) {
return datasets.getAdapterNamesForExperiment(type);
}
public Map<String,String> getDatasetDetailsForExperiment(ExperimentType type) {
return datasets.getAdapterDetailsForExperiment(type);
}

public AnnotatorConfiguration getAnnotatorConfig(String name, ExperimentType type) {
List<AnnotatorConfiguration> configs = annotators.getAdaptersForName(name);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/org/aksw/gerbil/web/config/DatasetsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@
package org.aksw.gerbil.web.config;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;

import org.aksw.gerbil.config.GerbilConfiguration;
import org.aksw.gerbil.dataset.Dataset;
Expand Down Expand Up @@ -51,6 +46,8 @@ public class DatasetsConfig {
public static final String ANNOTATOR_EXPERIMENT_TYPE_SUFFIX = "experimentType";
public static final String ANNOTATOR_NAME_SUFFIX = "name";

public static final String ANNOTATOR_GROUP_SUFFIX = "group";

public static final String ANNOTATOR_CHECK_CLASS_SUFFIX = "check.class";
public static final String ANNOTATOR_CHECK_ARGS_SUFFIX = "check.args";

Expand Down Expand Up @@ -116,6 +113,12 @@ private static DatasetConfiguration getConfiguration(String datasetKey, EntityCh
}
String name = config.getString(key);

key = buildKey(keyBuilder, datasetKey, ANNOTATOR_GROUP_SUFFIX);
if (!config.containsKey(key)) {
LOGGER.error("Couldn't get a group for the \"" + datasetKey + "\" dataset.");
Hardiksh16 marked this conversation as resolved.
Show resolved Hide resolved
}
String group = config.getString(key,"Others");

key = buildKey(keyBuilder, datasetKey, ANNOTATOR_CLASS_SUFFIX);
if (!config.containsKey(key)) {
LOGGER.error("Couldn't get a class for the \"" + datasetKey + "\" dataset.");
Expand Down Expand Up @@ -188,7 +191,7 @@ private static DatasetConfiguration getConfiguration(String datasetKey, EntityCh

// return new DatasetConfigurationImpl(name, cacheable, constructor,
// constructorArgs, type, entityCheckerManager);
return new SingletonDatasetConfigImpl(name, cacheable, constructor, constructorArgs, type, entityCheckerManager,
return new SingletonDatasetConfigImpl(name, group, cacheable, constructor, constructorArgs, type, entityCheckerManager,
globalRetriever);
}

Expand Down
Loading
Loading