Skip to content

Commit 93cee54

Browse files
committed
Check for better RegExpTypes even if we have already detected a Semantic Type + upgrade libs + remove use of deprecated methods
1 parent c6c7bcd commit 93cee54

File tree

34 files changed

+204
-122
lines changed

34 files changed

+204
-122
lines changed

ChangeLog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11

22
## Changes ##
33

4+
### 17.2.0
5+
- INT: Bump logback-classic to 1.5.24, gradle to 9.3.0, phonenumber to 9.0.21
6+
- CLI: Add --semanticTypesPre to control whether user-defined types (--semanticType) are registered before built-ins
7+
- BUG: findByName on TextAnalyzer was not returning user-defined types
8+
- BUG: Preserve precedence on plugins registered on TextAnalyzer template for RecordAnalyzer (Issue #152)
9+
- BUG: Check for better RegExpTypes even if we have already detected a Semantic Type (Issue #152)
10+
- INT: Remove remaining references to deprecated registerPluginList()
411

512
### 17.1.10
613
- INT: Bump logback-classic to 1.5.23, SpotBugs to 6.4.8, commons-text:1.15.0, google phonenumber to 9.0.21,

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ If the pluginType is 'java' then a *clazz* field is required and a new Instance
370370
If the pluginType is 'list' then the *content* field must be present and a new instance of LogicalTypeFiniteSimpleExternal will be instantiated.
371371
If the pluginType is 'regex' then an instance of LogicalTypeRegExp will be instantiated.
372372

373+
The JSON schema for plugin definitions is available [here](types/src/main/resources/reference/plugins-schema.json).
374+
373375
In all cases the plugin definition and locale are passed as arguments.
374376

375377
### All Plugins ###

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
wrapper {
7-
gradleVersion = '9.2.1'
7+
gradleVersion = '9.3.0'
88
}
99

1010
tasks.register('examples.clean') {

cli/src/main/java/com/cobber/fta/driver/Driver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ else if ("--help".equals(unprocessed[idx])) {
103103
error.println(" --noAnalysis - Do not do analysis");
104104
error.println(" --noPretty - Do not pretty print analysis");
105105
error.println(" --noQuantiles - Do not track quantiles");
106-
error.println(" --noSemanticTypes - Do not register any Semantic Types");
106+
error.println(" --noSemanticTypes - Do not register any of the built-in Semantic Types");
107107
error.println(" --noStatistics - Do not track statistics");
108108
error.println(" --pluginDefinition - Output the plugin definitions from the training data set");
109109
error.println(" --pluginMode true|false - Set the detect mode when running Plugin validate");
@@ -115,6 +115,7 @@ else if ("--help".equals(unprocessed[idx])) {
115115
error.println(" --resolutionMode <DayFirst|MonthFirst|Auto|None> - Auto DayFirst or MonthFirst is determined from Locale");
116116
error.println(" --samples - If set then generate samples (see --faker for comprehensive support)");
117117
error.println(" --semanticType <JSON representation of Semantic Types> - Can be inline or as a File");
118+
error.println(" --semanticTypesPre - If set then user-supplied Semantic Types (--semanticType) are registered ahead of built-ins");
118119
error.println(" --signature - Output the Signature for the supplied pluginName");
119120
error.println(" --skip <n> - Skip the initial <n> rows of the input");
120121
error.println(" --testMerge <n> - exercise merging of analyses, <n> is the number of samples per merge");

cli/src/main/java/com/cobber/fta/driver/DriverOptions.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class DriverOptions {
3636
protected int col = -1;
3737
protected int debug = -1;
3838
protected String semanticTypes;
39+
protected boolean semanticTypesPre;
3940
// Used to pass in a list of known Semantic Types - e.g. User-stated, or previously identified in some manner
4041
protected String knownTypes;
4142
protected boolean noAnalysis;
@@ -110,6 +111,7 @@ public DriverOptions(final DriverOptions other) {
110111
this.pluginMode = other.pluginMode;
111112
this.resolutionMode = other.resolutionMode;
112113
this.samples = other.samples;
114+
this.semanticTypesPre = other.semanticTypesPre;
113115
this.signature = other.signature;
114116
this.skip = other.skip;
115117
this.threshold = other.threshold;
@@ -164,14 +166,14 @@ public void apply(final TextAnalyzer analyzer) throws IOException {
164166
// If the argument starts with a '[' assume it is an inline definition, if not assume it is a file
165167
if (this.semanticTypes.charAt(0) == '[')
166168
analyzer.getPlugins().registerPlugins(new StringReader(this.semanticTypes),
167-
analyzer.getStreamName(), analyzer.getConfig());
169+
analyzer.getStreamName(), analyzer.getConfig(), semanticTypesPre);
168170
else {
169171
if(!Files.isRegularFile(Paths.get(this.semanticTypes))) {
170172
System.err.println("ERROR: Failed to read Semantic Types file: " + this.semanticTypes);
171173
System.exit(1);
172174
}
173175
try (FileReader logicalTypes = new FileReader(this.semanticTypes, StandardCharsets.UTF_8)) {
174-
analyzer.getPlugins().registerPlugins(logicalTypes, analyzer.getStreamName(), analyzer.getConfig());
176+
analyzer.getPlugins().registerPlugins(logicalTypes, analyzer.getStreamName(), analyzer.getConfig(), semanticTypesPre);
175177
}
176178
}
177179
} catch (SecurityException | FTAPluginException e) {
@@ -314,6 +316,8 @@ else if ("--samples".equals(args[idx]))
314316
samples = true;
315317
else if ("--semanticType".equals(args[idx]))
316318
semanticTypes = nextStringArg(args, idx++);
319+
else if ("--semanticTypesPre".equals(args[idx]))
320+
semanticTypesPre = true;
317321
else if ("--signature".equals(args[idx]))
318322
signature = true;
319323
else if ("--skip".equals(args[idx]))

cli/src/main/java/com/cobber/fta/driver/Processor.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,6 @@ public class Processor {
4242
this.options = options;
4343
this.streamCount = fieldNames.length;
4444

45-
if (options.pluginName != null && options.pluginMode != null) {
46-
final PluginDefinition pluginDefinition = PluginDefinition.findByName(options.pluginName);
47-
if (pluginDefinition == null) {
48-
logger.printf("ERROR: Failed to locate plugin named '%s', use --help%n", options.pluginName);
49-
System.exit(1);
50-
}
51-
52-
logicalType = LogicalTypeFactory.newInstance(pluginDefinition, new AnalysisConfig(options.getLocale()));
53-
}
54-
5545
if (options.col == -1) {
5646
final AnalyzerContext context = new AnalyzerContext(null, options.resolutionMode, compositeName, fieldNames);
5747
if (options.knownTypes != null)
@@ -64,14 +54,19 @@ public class Processor {
6454
}
6555

6656
analyzers = new TextAnalyzer[streamCount];
67-
for (int i = 0; i < fieldNames.length; i++) {
68-
if (options.col == -1 || options.col == i) {
69-
final AnalyzerContext context = new AnalyzerContext(fieldNames[i] == null ? "" : fieldNames[i].trim(), options.resolutionMode, compositeName, fieldNames);
70-
if (options.knownTypes != null)
71-
context.withSemanticTypes(options.knownTypes.split(","));
72-
analyzers[i] = new TextAnalyzer(context);
73-
options.apply(analyzers[i]);
57+
final AnalyzerContext context = new AnalyzerContext(fieldNames[options.col] == null ? "" : fieldNames[options.col].trim(), options.resolutionMode, compositeName, fieldNames);
58+
if (options.knownTypes != null)
59+
context.withSemanticTypes(options.knownTypes.split(","));
60+
analyzers[options.col] = new TextAnalyzer(context);
61+
options.apply(analyzers[options.col]);
62+
if (options.pluginName != null && options.pluginMode != null) {
63+
final PluginDefinition pluginDefinition = analyzers[options.col].findByName(options.pluginName);
64+
if (pluginDefinition == null) {
65+
logger.printf("ERROR: Failed to locate plugin named '%s', use --help%n", options.pluginName);
66+
System.exit(1);
7467
}
68+
69+
logicalType = LogicalTypeFactory.newInstance(pluginDefinition, new AnalysisConfig(options.getLocale()));
7570
}
7671
}
7772

examples/contextual/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
wrapper {
6-
gradleVersion = '9.2.1'
6+
gradleVersion = '9.3.0'
77
}
88

99
repositories {

examples/core/datedemo/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
wrapper {
6-
gradleVersion = '9.2.1'
6+
gradleVersion = '9.3.0'
77
}
88

99
repositories {

examples/core/dateformat/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
wrapper {
6-
gradleVersion = '9.2.1'
6+
gradleVersion = '9.3.0'
77
}
88

99
repositories {

examples/core/dateformattrained/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
wrapper {
6-
gradleVersion = '9.2.1'
6+
gradleVersion = '9.3.0'
77
}
88

99
repositories {

0 commit comments

Comments
 (0)