Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/858-Out-of-tagset-tags-should-map-t…
Browse files Browse the repository at this point in the history
…o-the-generic-type
  • Loading branch information
reckart committed Jan 13, 2019
2 parents a8fb184 + 7beaef2 commit 93dc360
Show file tree
Hide file tree
Showing 68 changed files with 878 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,13 @@ else if (value < 0) {
// Not using the type constants here because they are capitalized for use with verbs
// =============================================================================================

public static final String DEFAULT_MAPPING_ENABLED = "true";

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = "mappingEnabled";

/**
* Location of the mapping file for part-of-speech tags to UIMA types.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@

public class MappingProvider extends CasConfigurableProviderBase<Map<String, String>>
{
/**
* Flag indicating whether the entire mapping mechanism should be skipped and the default base
* type should always be applied.
*/
public static final String MAPPING_ENABLED = "mappingEnabled";

public static final String BASE_TYPE = "baseType";

private TypeSystem typeSystem;
Expand All @@ -64,6 +70,13 @@ public void configure(CAS aCas) throws AnalysisEngineProcessException
{
typeSystem = aCas.getTypeSystem();

// If mapping is disabled, then we simply skip the loading of the mapping and pretend we
// didn't find a mapping.
if ("false".equalsIgnoreCase(getOverride(MAPPING_ENABLED))) {
notFound = true;
return;
}

// Tag mappings can exist independently from the type mappings because tag mappings
// are configured in the model metadata
tagMappings = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@
*/
package de.tudarmstadt.ukp.dkpro.core.api.resources;

import de.tudarmstadt.ukp.dkpro.core.api.parameter.ComponentParameters;

public class MappingProviderFactory
{
private static final String CONSTITUENT_TAGSET = "constituent.tagset";
private static final String DEPENDENCY_TAGSET = "dependency.tagset";
private static final String CHUNK_TAGSET = "chunk.tagset";
private static final String POS_TAGSET = "pos.tagset";

public static MappingProvider createPosMappingProvider(String aMappingLocation,
String aLanguage, HasResourceMetadata aSource)
public static MappingProvider createPosMappingProvider(Object aContextObject,
String aMappingLocation, String aLanguage, HasResourceMetadata aSource)
{
MappingProvider p = createPosMappingProvider(aMappingLocation, null, aLanguage);
MappingProvider p = createPosMappingProvider(aContextObject, aMappingLocation, null,
aLanguage);
p.addImport(POS_TAGSET, aSource);
return p;
}

public static MappingProvider createPosMappingProvider(String aMappingLocation, String aTagset,
String aLanguage)
public static MappingProvider createPosMappingProvider(Object aContextObject,
String aMappingLocation, String aTagset, String aLanguage)
{
MappingProvider p = new MappingProvider();
p.setDefault(MappingProvider.LOCATION,
Expand All @@ -45,44 +48,60 @@ public static MappingProvider createPosMappingProvider(String aMappingLocation,
p.setOverride(MappingProvider.LOCATION, aMappingLocation);
p.setOverride(MappingProvider.LANGUAGE, aLanguage);
p.setOverride(POS_TAGSET, aTagset);

if (aContextObject != null) {
p.addAutoOverride(ComponentParameters.PARAM_MAPPING_ENABLED,
MappingProvider.MAPPING_ENABLED);
p.applyAutoOverrides(aContextObject);
}

return p;
}

public static MappingProvider createChunkMappingProvider(String aMappingLocation,
String aLanguage, HasResourceMetadata aSource)
public static MappingProvider createChunkMappingProvider(Object aContextObject,
String aMappingLocation, String aLanguage, HasResourceMetadata aSource)
{
MappingProvider p = createChunkMappingProvider(aMappingLocation, null, aLanguage);
MappingProvider p = createChunkMappingProvider(aContextObject, aMappingLocation, null,
aLanguage);
p.addImport(CHUNK_TAGSET, aSource);
return p;
}

public static MappingProvider createChunkMappingProvider(String aMappingLocation,
String aTagset, String aLanguage)
public static MappingProvider createChunkMappingProvider(Object aContextObject,
String aMappingLocation, String aTagset, String aLanguage)
{
MappingProvider chunkMappingProvider = new MappingProvider();
chunkMappingProvider = new MappingProvider();
chunkMappingProvider.setDefault(MappingProvider.LOCATION, "classpath:/de/tudarmstadt/ukp/"
MappingProvider p = new MappingProvider();
p = new MappingProvider();
p.setDefault(MappingProvider.LOCATION, "classpath:/de/tudarmstadt/ukp/"
+ "dkpro/core/api/syntax/tagset/${language}-${chunk.tagset}-chunk.map");
chunkMappingProvider.setDefault(MappingProvider.BASE_TYPE,
p.setDefault(MappingProvider.BASE_TYPE,
"de.tudarmstadt.ukp.dkpro.core.api.syntax.type.chunk.Chunk");
chunkMappingProvider.setDefault(CHUNK_TAGSET, "default");
chunkMappingProvider.setOverride(MappingProvider.LOCATION, aMappingLocation);
chunkMappingProvider.setOverride(MappingProvider.LANGUAGE, aLanguage);
chunkMappingProvider.setOverride(CHUNK_TAGSET, aTagset);
return chunkMappingProvider;
p.setDefault(CHUNK_TAGSET, "default");
p.setOverride(MappingProvider.LOCATION, aMappingLocation);
p.setOverride(MappingProvider.LANGUAGE, aLanguage);
p.setOverride(CHUNK_TAGSET, aTagset);

if (aContextObject != null) {
p.addAutoOverride(ComponentParameters.PARAM_MAPPING_ENABLED,
MappingProvider.MAPPING_ENABLED);
p.applyAutoOverrides(aContextObject);
}

return p;
}

public static MappingProvider createConstituentMappingProvider(String aMappingLocation,
String aLanguage, HasResourceMetadata aSource)
public static MappingProvider createConstituentMappingProvider(Object aContextObject,
String aMappingLocation, String aLanguage, HasResourceMetadata aSource)
{
MappingProvider p = createConstituentMappingProvider(aMappingLocation, null, aLanguage);
MappingProvider p = createConstituentMappingProvider(aContextObject, aMappingLocation, null,
aLanguage);
p.addImport(CONSTITUENT_TAGSET, aSource);
p.addTagMappingImport("constituent", aSource);
return p;
}

public static MappingProvider createConstituentMappingProvider(String aMappingLocation,
String aTagset, String aLanguage)
public static MappingProvider createConstituentMappingProvider(Object aContextObject,
String aMappingLocation, String aTagset, String aLanguage)
{
MappingProvider p = new MappingProvider();
p.setDefault(MappingProvider.LOCATION,
Expand All @@ -94,19 +113,27 @@ public static MappingProvider createConstituentMappingProvider(String aMappingLo
p.setOverride(MappingProvider.LOCATION, aMappingLocation);
p.setOverride(MappingProvider.LANGUAGE, aLanguage);
p.setOverride(CONSTITUENT_TAGSET, aTagset);

if (aContextObject != null) {
p.addAutoOverride(ComponentParameters.PARAM_MAPPING_ENABLED,
MappingProvider.MAPPING_ENABLED);
p.applyAutoOverrides(aContextObject);
}

return p;
}

public static MappingProvider createDependencyMappingProvider(String aMappingLocation,
String aLanguage, HasResourceMetadata aSource)
public static MappingProvider createDependencyMappingProvider(Object aContextObject,
String aMappingLocation, String aLanguage, HasResourceMetadata aSource)
{
MappingProvider p = createDependencyMappingProvider(aMappingLocation, null, aLanguage);
MappingProvider p = createDependencyMappingProvider(aContextObject, aMappingLocation, null,
aLanguage);
p.addImport(DEPENDENCY_TAGSET, aSource);
return p;
}

public static MappingProvider createDependencyMappingProvider(String aMappingLocation,
String aTagset, String aLanguage)
public static MappingProvider createDependencyMappingProvider(Object aContextObject,
String aMappingLocation, String aTagset, String aLanguage)
{
MappingProvider p = new MappingProvider();
p.setDefault(MappingProvider.LOCATION,
Expand All @@ -118,6 +145,13 @@ public static MappingProvider createDependencyMappingProvider(String aMappingLoc
p.setOverride(MappingProvider.LOCATION, aMappingLocation);
p.setOverride(MappingProvider.LANGUAGE, aLanguage);
p.setOverride(DEPENDENCY_TAGSET, aTagset);

if (aContextObject != null) {
p.addAutoOverride(ComponentParameters.PARAM_MAPPING_ENABLED,
MappingProvider.MAPPING_ENABLED);
p.applyAutoOverrides(aContextObject);
}

return p;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,8 @@ public void applyAutoOverrides(Object aObject)

if (property != null) {
try {
setOverride(property, (String) FieldUtils.readField(field, aObject, true));
Object value = FieldUtils.readField(field, aObject, true);
setOverride(property, value != null ? value.toString() : null);
}
catch (IllegalAccessException e) {
throw new IllegalStateException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ public class ArktweetPosTagger
@ResourceParameter(MimeTypes.APPLICATION_X_ARKTWEET_TAGGER)
protected String modelLocation;

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = ComponentParameters.PARAM_MAPPING_ENABLED;
@ConfigurationParameter(name = PARAM_MAPPING_ENABLED, mandatory = true, defaultValue =
ComponentParameters.DEFAULT_MAPPING_ENABLED)
protected boolean mappingEnabled;

/**
* Location of the mapping file for part-of-speech tags to UIMA types.
*/
Expand Down Expand Up @@ -193,7 +201,7 @@ protected TweetTagger produceResource(URL aUrl)
}
};

mappingProvider = MappingProviderFactory.createPosMappingProvider(posMappingLocation,
mappingProvider = MappingProviderFactory.createPosMappingProvider(this, posMappingLocation,
language, modelProvider);

}
Expand Down
4 changes: 2 additions & 2 deletions dkpro-core-asl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
</dependency>
<dependency>
<groupId>org.dkpro.core</groupId>
<artifactId>dkpro-core-io-nyt-asl</artifactId>
<artifactId>dkpro-core-io-nitf-asl</artifactId>
<version>1.11.0-SNAPSHOT</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -572,7 +572,7 @@
<module>../dkpro-core-io-lxf-asl</module>
<module>../dkpro-core-io-negra-asl</module>
<module>../dkpro-core-io-nif-asl</module>
<module>../dkpro-core-io-nyt-asl</module>
<module>../dkpro-core-io-nitf-asl</module>
<module>../dkpro-core-io-pdf-asl</module>
<module>../dkpro-core-io-penntree-asl</module>
<module>../dkpro-core-io-pubannotation-asl</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ public class BerkeleyParser
@ConfigurationParameter(name = PARAM_MODEL_LOCATION, mandatory = false)
protected String modelLocation;

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = ComponentParameters.PARAM_MAPPING_ENABLED;
@ConfigurationParameter(name = PARAM_MAPPING_ENABLED, mandatory = true, defaultValue =
ComponentParameters.DEFAULT_MAPPING_ENABLED)
protected boolean mappingEnabled;

/**
* Location of the mapping file for part-of-speech tags to UIMA types.
*/
Expand Down Expand Up @@ -233,10 +241,10 @@ public void initialize(UimaContext aContext)

modelProvider = new BerkeleyParserModelProvider();

posMappingProvider = MappingProviderFactory.createPosMappingProvider(posMappingLocation,
language, modelProvider);
posMappingProvider = MappingProviderFactory.createPosMappingProvider(this,
posMappingLocation, language, modelProvider);

constituentMappingProvider = MappingProviderFactory.createConstituentMappingProvider(
constituentMappingProvider = MappingProviderFactory.createConstituentMappingProvider(this,
constituentMappingLocation, language, modelProvider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ public class ClearNlpPosTagger
@ConfigurationParameter(name = PARAM_MODEL_LOCATION, mandatory = false)
protected String posModelLocation;

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = ComponentParameters.PARAM_MAPPING_ENABLED;
@ConfigurationParameter(name = PARAM_MAPPING_ENABLED, mandatory = true, defaultValue =
ComponentParameters.DEFAULT_MAPPING_ENABLED)
protected boolean mappingEnabled;

/**
* Load the part-of-speech tag to UIMA type mapping from this location instead of locating the
* mapping automatically.
Expand Down Expand Up @@ -243,8 +251,8 @@ protected AbstractPOSTagger produceResource(InputStream aStream)

};

posMappingProvider = MappingProviderFactory.createPosMappingProvider(posMappingLocation,
language, posTaggingModelProvider);
posMappingProvider = MappingProviderFactory.createPosMappingProvider(this,
posMappingLocation, language, posTaggingModelProvider);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ public class CogrooPosTagger
@ConfigurationParameter(name = PARAM_LANGUAGE, mandatory = false)
protected String language;

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = ComponentParameters.PARAM_MAPPING_ENABLED;
@ConfigurationParameter(name = PARAM_MAPPING_ENABLED, mandatory = true, defaultValue =
ComponentParameters.DEFAULT_MAPPING_ENABLED)
protected boolean mappingEnabled;

/**
* Load the part-of-speech tag to UIMA type mapping from this location instead of locating
* the mapping automatically.
Expand Down Expand Up @@ -125,7 +133,7 @@ protected Analyzer produceResource(URL aUrl)
}
};

mappingProvider = MappingProviderFactory.createPosMappingProvider(posMappingLocation,
mappingProvider = MappingProviderFactory.createPosMappingProvider(this, posMappingLocation,
"bosque", language);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ public class CoreNlpDependencyParser
@ConfigurationParameter(name = PARAM_MODEL_ENCODING, mandatory = false)
private String modelEncoding;

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = ComponentParameters.PARAM_MAPPING_ENABLED;
@ConfigurationParameter(name = PARAM_MAPPING_ENABLED, mandatory = true, defaultValue =
ComponentParameters.DEFAULT_MAPPING_ENABLED)
protected boolean mappingEnabled;

/**
* Location of the mapping file for part-of-speech tags to UIMA types.
*/
Expand Down Expand Up @@ -196,7 +204,7 @@ public void initialize(UimaContext aContext)

annotatorProvider = new CoreNlpDependencyParserModelProvider(this);

mappingProvider = MappingProviderFactory.createDependencyMappingProvider(
mappingProvider = MappingProviderFactory.createDependencyMappingProvider(this,
dependencyMappingLocation, language, annotatorProvider);

numThreads = ComponentParameters.computeNumThreads(numThreads);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ public class CoreNlpParser
@ConfigurationParameter(name = PARAM_MODEL_ENCODING, mandatory = false)
private String modelEncoding;

/**
* Enable/disable type mapping.
*/
public static final String PARAM_MAPPING_ENABLED = ComponentParameters.PARAM_MAPPING_ENABLED;
@ConfigurationParameter(name = PARAM_MAPPING_ENABLED, mandatory = true, defaultValue =
ComponentParameters.DEFAULT_MAPPING_ENABLED)
protected boolean mappingEnabled;

/**
* Location of the mapping file for dependency tags to UIMA types.
*/
Expand Down Expand Up @@ -285,13 +293,13 @@ public void initialize(UimaContext aContext)
annotatorProvider = new CoreNlpParserModelProvider(this);

constituentMappingProvider = MappingProviderFactory.createConstituentMappingProvider(
constituentMappingLocation, language, annotatorProvider);
this, constituentMappingLocation, language, annotatorProvider);

dependencyMappingProvider = MappingProviderFactory.createDependencyMappingProvider(
dependencyMappingLocation, language, annotatorProvider);
this, dependencyMappingLocation, language, annotatorProvider);

posMappingProvider = MappingProviderFactory.createPosMappingProvider(
posMappingLocation, language, annotatorProvider);
this, posMappingLocation, language, annotatorProvider);

numThreads = ComponentParameters.computeNumThreads(numThreads);
}
Expand Down
Loading

0 comments on commit 93dc360

Please sign in to comment.