|
48 | 48 | import com.cobber.fta.core.FTAPluginException; |
49 | 49 | import com.cobber.fta.core.FTAType; |
50 | 50 | import com.cobber.fta.core.FTAUnsupportedLocaleException; |
| 51 | +import com.cobber.fta.core.HeaderEntry; |
51 | 52 | import com.cobber.fta.dates.DateTimeParser.DateResolutionMode; |
52 | 53 | import com.cobber.fta.plugins.CheckDigitEAN13; |
53 | 54 | import com.cobber.fta.plugins.CheckDigitISBN; |
@@ -1962,34 +1963,37 @@ public void pluginsPost() throws FTAException { |
1962 | 1963 |
|
1963 | 1964 | @Test(groups = { TestGroups.ALL, TestGroups.DATETIME }) |
1964 | 1965 | public void pluginsEdit() throws FTAException { |
1965 | | - PluginDefinition defn = PluginDefinition.findByName("NAME.FIRST"); |
1966 | | - for (PluginLocaleEntry localeEntry : defn.validLocales) { |
1967 | | - System.err.printf("Found - '%s'\n", localeEntry.localeTag); |
1968 | | - if ("en".equals(localeEntry.localeTag)) |
1969 | | - System.err.printf("Found - '%s'\n", localeEntry.headerRegExps[0]); |
1970 | | - } |
1971 | | - PluginDefinition newDefn = new PluginDefinition(defn); |
1972 | | - System.err.printf("New - '%s'\n", newDefn.semanticType); |
1973 | | - for (PluginLocaleEntry localeEntry : newDefn.validLocales) { |
1974 | | - System.err.printf("Found - '%s'\n", localeEntry.localeTag); |
1975 | | - if ("en".equals(localeEntry.localeTag)) { |
1976 | | - System.err.printf("Found - '%s'\n", localeEntry.headerRegExps[0].regExp); |
1977 | | - localeEntry.headerRegExps[0].regExp = localeEntry.headerRegExps[0].regExp.replace("fname", "fname|fn"); |
1978 | | - System.err.printf("Found - '%s'\n", localeEntry.headerRegExps[0].regExp); |
1979 | | - } |
1980 | | - } |
1981 | | -// for (PluginDefinition defn : pluginDefinitions) { |
1982 | | -// if ("NAME.FIRST".equals(defn.semanticType)) { |
1983 | | -// System.err.printf("Found - '%s'\n", defn.semanticType); |
1984 | | -// for (PluginLocaleEntry localeEntry : defn.validLocales) { |
1985 | | -// System.err.printf("Found - '%s'\n", localeEntry.localeTag); |
1986 | | -// if ("en".equals(localeEntry.localeTag)) |
1987 | | -// System.err.printf("Found - '%s'\n", localeEntry.headerRegExps[0]); |
1988 | | -// } |
1989 | | -// } |
1990 | | -// } |
1991 | | - } |
| 1966 | + final String inputs[] = { |
| 1967 | + "Anna", "Buffalo", "Peter", "David", "Janet", "Mary", "Joe", "Tim", "Jeremy", "Reginald", |
| 1968 | + "Roger", "Lois", "Janet", "Polaris", "Sean", "Shawn", "Shaun", "Regina", "Gail", "Max" |
| 1969 | + }; |
| 1970 | + final TextAnalyzer analysisPre = new TextAnalyzer("fn"); |
| 1971 | + analysisPre.setLocale(Locale.US); |
| 1972 | + for (final String input : inputs) |
| 1973 | + analysisPre.train(input); |
| 1974 | + final TextAnalysisResult resultPre = analysisPre.getResult(); |
| 1975 | + assertNull(resultPre.getSemanticType()); |
| 1976 | + |
| 1977 | + // Edit the FIRST NAME plugin to add our header "fn" |
| 1978 | + PluginDefinition defn = analysisPre.findByName("NAME.FIRST"); |
| 1979 | + for (PluginLocaleEntry localeEntry : defn.validLocales) |
| 1980 | + if ("en".equals(localeEntry.localeTag)) { |
| 1981 | + final int entries = localeEntry.headerRegExps.length; |
| 1982 | + HeaderEntry[] newHeaders = new HeaderEntry[entries + 1]; |
| 1983 | + for (int i = 0; i < entries; i++) |
| 1984 | + newHeaders[i] = new HeaderEntry(localeEntry.headerRegExps[i]); |
| 1985 | + newHeaders[entries] = new HeaderEntry("(?i)fn", 100); |
| 1986 | + localeEntry.headerRegExps = newHeaders; |
| 1987 | + } |
| 1988 | + |
| 1989 | + final TextAnalyzer analysisPost = new TextAnalyzer("fn"); |
| 1990 | + analysisPost.setLocale(Locale.US); |
| 1991 | + for (final String input : inputs) |
| 1992 | + analysisPost.train(input); |
| 1993 | + final TextAnalysisResult resultPost = analysisPost.getResult(); |
| 1994 | + assertEquals(resultPost.getSemanticType(), "NAME.FIRST"); |
1992 | 1995 |
|
| 1996 | + } |
1993 | 1997 |
|
1994 | 1998 | @Test(groups = { TestGroups.ALL, TestGroups.PLUGINS }) |
1995 | 1999 | public void basicISIN() throws IOException, FTAException { |
|
0 commit comments