Skip to content

Commit

Permalink
Modified backend and frontend for handling grouping of datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Hardiksh16 committed Nov 12, 2024
1 parent 8539b7d commit d550337
Show file tree
Hide file tree
Showing 19 changed files with 491 additions and 73 deletions.
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 (roeder@informatik.uni-leipzig.de)
*
*/
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,"Ungrouped", couldBeCached, applicableForExperiment);
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,"UnGrouped", false, applicableForExperiment, null, null);
this.instances = instances;
}

public InstanceListBasedDataset(String name, List<Document> instances, ExperimentType applicableForExperiment,
EntityCheckerManager entityCheckerManager, SameAsRetriever globalRetriever) {
super(name, false, applicableForExperiment, entityCheckerManager, globalRetriever);
super(name,"UnGrouped", false, applicableForExperiment, entityCheckerManager, globalRetriever);
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,"UnGrouped", couldBeCached, ExperimentType.A2KB, entityCheckerManager, globalRetriever);
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,"UnGrouped", couldBeCached, applicableForExperiment, entityCheckerManager, globalRetriever);
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();
}
17 changes: 7 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,19 @@ 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) {
ExperimentType type = null;
Map<String, List<String>> response = new HashMap<>();
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());
}
return response;
}

/**
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) {
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;
}

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.");
}
String group = config.getString(key,"UnGrouped");

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

0 comments on commit d550337

Please sign in to comment.