Skip to content

Commit

Permalink
Merged with changes from origin.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRoeder committed Mar 2, 2017
2 parents a664f06 + 9081d31 commit 07a2fe7
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.aksw.gerbil.transfer.nif.Marking;
import org.aksw.gerbil.transfer.nif.data.Annotation;
import org.aksw.gerbil.transfer.nif.data.DocumentImpl;
import org.aksw.gerbil.transfer.nif.data.NamedEntity;
import org.aksw.gerbil.utils.WikipediaHelper;
import org.json.JSONObject;
import org.slf4j.Logger;
Expand Down Expand Up @@ -62,7 +63,7 @@ private List<Document> loadDocuments(File annotations, File tweets)
String documentUriPrefix = "http://" + getName() + "/";
//its json per line
try (BufferedReader bReader = new BufferedReader(new InputStreamReader(
new FileInputStream(tweetsFile), Charset.forName("UTF-8")))) {
new FileInputStream(tweets), Charset.forName("UTF-8")))) {
String line;
List<Marking> markings;
while ((line = bReader.readLine()) != null) {
Expand Down Expand Up @@ -90,7 +91,6 @@ protected static List<Marking> findMarkings(Set<String> lines, String text) {

String uri = WikipediaHelper.getWikipediaUri(WIKIPEDIA_DOMAIN , annotation[2]);
markings.add(new Annotation(uri));

}

return markings;
Expand Down
36 changes: 35 additions & 1 deletion src/main/java/org/aksw/gerbil/web/config/AnnotatorsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.aksw.gerbil.annotator.SingletonAnnotatorConfigImpl;
import org.aksw.gerbil.config.GerbilConfiguration;
import org.aksw.gerbil.datatypes.ExperimentType;
import org.aksw.gerbil.web.config.check.Checker;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
Expand All @@ -46,6 +47,9 @@ public class AnnotatorsConfig {
public static final String ANNOTATOR_EXPERIMENT_TYPE_SUFFIX = "experimentType";
public static final String ANNOTATOR_NAME_SUFFIX = "name";
public static final String ANNOTATOR_SINGLETON_FLAG_SUFFIX = "singleton";

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

public static void main(String[] args) {
annotators();
Expand Down Expand Up @@ -95,7 +99,7 @@ private static AnnotatorConfiguration getConfiguration(String annotatorKey)
org.apache.commons.configuration.Configuration config = GerbilConfiguration.getInstance();
StringBuilder keyBuilder = new StringBuilder();
String key;

key = buildKey(keyBuilder, annotatorKey, ANNOTATOR_NAME_SUFFIX);
if (!config.containsKey(key)) {
LOGGER.error("Couldn't get a name for the \"" + annotatorKey + "\" annotator.");
Expand Down Expand Up @@ -144,6 +148,36 @@ private static AnnotatorConfiguration getConfiguration(String annotatorKey)
constructorArgClasses[i] = String.class;
}
Constructor<? extends Annotator> constructor = annotatorClass.getConstructor(constructorArgClasses);

// If a checker class has been defined
key = buildKey(keyBuilder, annotatorKey, ANNOTATOR_CHECK_CLASS_SUFFIX);
if (config.containsKey(key)) {
String checkerClassName = config.getString(key);
// If checker arguments have been defined
key = buildKey(keyBuilder, annotatorKey, ANNOTATOR_CHECK_ARGS_SUFFIX);
String checkerArgStrings[];
if (config.containsKey(key)) {
checkerArgStrings = config.getStringArray(key);
} else {
checkerArgStrings = new String[0];
}
Object checkerArgs[] = new Object[checkerArgStrings.length];
for (int i = 0; i < checkerArgs.length; ++i) {
checkerArgs[i] = checkerArgStrings[i];
}
try {
@SuppressWarnings("unchecked")
Class<? extends Checker> checkerClass = (Class<? extends Checker>) AnnotatorsConfig.class.getClassLoader()
.loadClass(checkerClassName);
Checker checker = checkerClass.newInstance();
if (!checker.check(checkerArgs)) {
LOGGER.info("Check for annotator \"{}\" failed. It won't be available.", name);
return null;
}
} catch (Exception e) {
LOGGER.error("Error while trying to run check for annotator \"" + name + "\". Returning null.", e);
}
}

if (isSingleton) {
return new SingletonAnnotatorConfigImpl(name, cacheable, constructor, constructorArgs, type);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.aksw.gerbil.web.config.check;

import org.aksw.gerbil.config.GerbilConfiguration;
import org.apache.commons.configuration.Configuration;

/**
* A {@link Checker} that checks whether the given object(s) (interpreted as
* String) are defined properties.
*
*
*/
public class AnnotatorChecker implements Checker{
private static Configuration config= GerbilConfiguration.getInstance();

@Override
public boolean check(Object... objects) {

for(Object it: objects){
Object prop=config.getProperty(it.toString());
if(prop==null){
return false;
}

}


return true;
}

}
14 changes: 14 additions & 0 deletions src/main/properties/annotators.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ org.aksw.gerbil.annotators.definition.EcEU.name=Entityclassifier.eu NER
org.aksw.gerbil.annotators.definition.EcEU.experimentType=A2KB
org.aksw.gerbil.annotators.definition.EcEU.cacheable=true
org.aksw.gerbil.annotators.definition.EcEU.class=org.aksw.gerbil.annotator.impl.nif.NIFBasedAnnotatorWebservice
org.aksw.gerbil.annotators.definition.EcEU.check.class=org.aksw.gerbil.web.config.check.AnnotatorChecker
org.aksw.gerbil.annotators.definition.EcEU.check.args=org.aksw.gerbil.annotators.EntityclassifierEUConfig.apiKey
org.aksw.gerbil.annotators.definition.EcEU.constructorArgs=${org.aksw.gerbil.annotators.EntityclassifierEUConfig.url}${org.aksw.gerbil.annotators.EntityclassifierEUConfig.apiKey}

### FRED
Expand Down Expand Up @@ -130,14 +132,21 @@ org.aksw.gerbil.annotators.definition.kea.experimentType=A2KB
org.aksw.gerbil.annotators.definition.kea.cacheable=true
#org.aksw.gerbil.annotators.definition.kea.singleton=true
org.aksw.gerbil.annotators.definition.kea.class=org.aksw.gerbil.annotator.impl.nif.NIFBasedAnnotatorWebservice
org.aksw.gerbil.annotators.definition.kea.check.class=org.aksw.gerbil.web.config.check.AnnotatorChecker
org.aksw.gerbil.annotators.definition.kea.check.args=org.aksw.gerbil.annotators.KeaAnnotatorConfig.user
org.aksw.gerbil.annotators.definition.kea.check.args=org.aksw.gerbil.annotators.KeaAnnotatorConfig.password
org.aksw.gerbil.annotators.definition.kea.constructorArgs=http://${org.aksw.gerbil.annotators.KeaAnnotatorConfig.user}:${org.aksw.gerbil.annotators.KeaAnnotatorConfig.password}@${org.aksw.gerbil.annotators.KeaAnnotatorConfig.annotationUrl}
org.aksw.gerbil.annotators.definition.kea2.name=Kea
org.aksw.gerbil.annotators.definition.kea2.experimentType=D2KB
org.aksw.gerbil.annotators.definition.kea2.cacheable=true
#org.aksw.gerbil.annotators.definition.kea2.singleton=true
org.aksw.gerbil.annotators.definition.kea2.class=org.aksw.gerbil.annotator.impl.nif.NIFBasedAnnotatorWebservice
org.aksw.gerbil.annotators.definition.kea2.check.class=org.aksw.gerbil.web.config.check.AnnotatorChecker
org.aksw.gerbil.annotators.definition.kea2.check.args=org.aksw.gerbil.annotators.KeaAnnotatorConfig.user
org.aksw.gerbil.annotators.definition.kea2.check.args=org.aksw.gerbil.annotators.KeaAnnotatorConfig.password
org.aksw.gerbil.annotators.definition.kea2.constructorArgs=http://${org.aksw.gerbil.annotators.KeaAnnotatorConfig.user}:${org.aksw.gerbil.annotators.KeaAnnotatorConfig.password}@${org.aksw.gerbil.annotators.KeaAnnotatorConfig.disambiguationUrl}


### NERD-ML
#NERD endpoint
org.aksw.gerbil.annotators.NERD.host=http://nerd.eurecom.fr/api/
Expand All @@ -147,6 +156,8 @@ org.aksw.gerbil.annotators.definition.NERD.name=NERD-ML
org.aksw.gerbil.annotators.definition.NERD.experimentType=A2KB
org.aksw.gerbil.annotators.definition.NERD.cacheable=true
org.aksw.gerbil.annotators.definition.NERD.class=org.aksw.gerbil.annotator.impl.nerd.NERDAnnotator
org.aksw.gerbil.annotators.definition.NERD.check.class=org.aksw.gerbil.web.config.check.AnnotatorChecker
org.aksw.gerbil.annotators.definition.NERD.check.args=org.aksw.gerbil.annotators.nerd.Key
org.aksw.gerbil.annotators.definition.NERD.constructorArgs=${org.aksw.gerbil.annotators.NERD.host}

### NERFGUN
Expand All @@ -170,6 +181,9 @@ org.aksw.gerbil.annotators.TagmeAnnotator.annotateUrl=https://tagme.d4science.or
org.aksw.gerbil.annotators.TagmeAnnotator.spotUrl=https://tagme.d4science.org/tagme/spot
#Use this property to set the TagMe key (moved this to the gerbil_keys.properties file)
#org.aksw.gerbil.annotators.TagMe.key
org.aksw.gerbil.annotators.definition.TagMe.check.class=org.aksw.gerbil.web.config.check.AnnotatorChecker
org.aksw.gerbil.annotators.definition.TagMe.check.args=org.aksw.gerbil.annotators.TagMe.key

org.aksw.gerbil.annotators.definition.TagMe.name=TagMe 2
org.aksw.gerbil.annotators.definition.TagMe.experimentType=A2KB
org.aksw.gerbil.annotators.definition.TagMe.cacheable=true
Expand Down

0 comments on commit 07a2fe7

Please sign in to comment.