You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by mb...@apache.org on 2008/02/21 12:52:00 UTC
svn commit: r629760 - in
/incubator/uima/sandbox/trunk/RegularExpressionAnnotator:
docbook/RegexAnnotatorUserGuide/
src/main/java/org/apache/uima/annotator/regex/impl/
src/main/resources/org/apache/uima/annotator/regex/
Author: mbaessler
Date: Thu Feb 21 03:51:59 2008
New Revision: 629760
URL: http://svn.apache.org/viewvc?rev=629760&view=rev
Log:
UIMA-806
use default local and NumberFormat to convert string numbers to int or float.
https://issues.apache.org/jira/browse/UIMA-806
Modified:
incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml
incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java
incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/resources/org/apache/uima/annotator/regex/regexMessages.properties
Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml?rev=629760&r1=629759&r2=629760&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml Thu Feb 21 03:51:59 2008
@@ -992,6 +992,15 @@
</itemizedlist>
</para>
+ <note>
+ <para>
+ Float and Integer based feature values are converted using the Java NumberFormat for the
+ current Java default locale. If the feature value cannot be converted the feature value is not
+ set and a warning is written to the log. To prevent these warnings it may be useful
+ to do a custom normalization of the numbers before they are added to the feature.
+ </para>
+ </note>
+
</section>
<section id="sandbox.regexAnnotator.conceptsFile.annotationCreation.featureNormalization">
<title>Features Value Normalization</title>
Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java?rev=629760&r1=629759&r2=629760&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/impl/RegExAnnotator.java Thu Feb 21 03:51:59 2008
@@ -25,6 +25,8 @@
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.net.URL;
+import java.text.NumberFormat;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -76,6 +78,10 @@
private AnnotationFS lastRuleExceptionAnnotation = null;
+ private NumberFormat floatNumberFormat = null;
+
+ private NumberFormat integerNumberFormat = null;
+
/**
* Performs any startup tasks required by this annotator. This implementation
* reads the configuration parameters and compiles the regular expressions.
@@ -89,13 +95,17 @@
// initialize annotator logger
this.logger = getContext().getLogger();
+ // default initialization for number format
+ this.floatNumberFormat = NumberFormat.getNumberInstance();
+ this.integerNumberFormat = NumberFormat.getIntegerInstance();
+
// create a concept file parser object
ConceptFileParser parser = new ConceptFileParser_impl();
// get configuration parameter settings
// get parameter ConceptFiles, default is an empty array
- String[] conceptFileNames = safeGetConfigParameterStringArrayValue(getContext(),
- REGEX_CONCEPTS_FILES, new String[] {});
+ String[] conceptFileNames = safeGetConfigParameterStringArrayValue(
+ getContext(), REGEX_CONCEPTS_FILES, new String[] {});
// get UIMA datapath and tokenize it into its elements
StringTokenizer tokenizer = new StringTokenizer(getContext()
@@ -160,9 +170,9 @@
}
// initialize the regex concepts
- for (int i = 0; i < this.regexConcepts.length; i++) {
- ((Concept_impl) this.regexConcepts[i]).initialize(this.logger);
- }
+ for (int i = 0; i < this.regexConcepts.length; i++) {
+ ((Concept_impl) this.regexConcepts[i]).initialize(this.logger);
+ }
}
/**
@@ -631,7 +641,8 @@
throw new RegexAnnotatorProcessException(
"regex_annotator_error_validating_annotation",
new Object[] { annotations[a].getId(), matchText,
- Integer.valueOf(localStart), Integer.valueOf(localEnd) }, ex);
+ Integer.valueOf(localStart),
+ Integer.valueOf(localEnd) }, ex);
}
}
@@ -686,11 +697,42 @@
// set feature value at the annotation in dependence of the
// feature type
if (type == Feature.FLOAT_FEATURE) {
- fs.setFloatValue(features[f].getFeature(), Float
- .parseFloat(featureValue));
+ try {
+ Number number = this.floatNumberFormat
+ .parse(featureValue);
+ fs.setFloatValue(features[f].getFeature(), number
+ .floatValue());
+ } catch (ParseException ex) {
+ this.logger
+ .logrb(
+ Level.WARNING,
+ "RegExAnnotator",
+ "processConceptInstructions",
+ MESSAGE_DIGEST,
+ "regex_annotator_warning_number_format_conversion",
+ new Object[] { featureValue,
+ features[f].getFeature().getName(),
+ "float" });
+ }
+
} else if (type == Feature.INTEGER_FEATURE) {
- fs.setIntValue(features[f].getFeature(), Integer
- .parseInt(featureValue));
+ try {
+ Number number = this.integerNumberFormat
+ .parse(featureValue);
+ fs.setIntValue(features[f].getFeature(), number
+ .intValue());
+ } catch (ParseException ex) {
+ this.logger
+ .logrb(
+ Level.WARNING,
+ "RegExAnnotator",
+ "processConceptInstructions",
+ MESSAGE_DIGEST,
+ "regex_annotator_warning_number_format_conversion",
+ new Object[] { featureValue,
+ features[f].getFeature().getName(),
+ "integer" });
+ }
} else if (type == Feature.STRING_FEATURE) {
fs.setStringValue(features[f].getFeature(), featureValue);
}
@@ -836,7 +878,7 @@
* @return returns the replaced match group value content
*/
private String replaceMatchGroupValues(String featureValue, Matcher matcher,
- Rule rule) throws RegexAnnotatorProcessException{
+ Rule rule) throws RegexAnnotatorProcessException {
StringBuffer replaced = new StringBuffer();
int pos = 0;
int end = featureValue.length();
Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/resources/org/apache/uima/annotator/regex/regexMessages.properties
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/resources/org/apache/uima/annotator/regex/regexMessages.properties?rev=629760&r1=629759&r2=629760&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/resources/org/apache/uima/annotator/regex/regexMessages.properties (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/resources/org/apache/uima/annotator/regex/regexMessages.properties Thu Feb 21 03:51:59 2008
@@ -37,4 +37,5 @@
regex_annotator_error_feature_path_element_not_supported = "The feature path element type {0} of the feature name {1} in the featurePath {2} is currently not supported."
regex_annotator_error_invalid_feature_path_syntax = "The featurePath syntax for featurePath {0} is wrong. \"{1}\" is not allowed.
regex_annotator_error_variable_not_found = "The variable \"{0}\" of rule \"{1}\" is not defined.
-regex_annotator_error_match_group_name_not_found = "The match group name \"{0}\" of rule \"{1}\" was not found.
\ No newline at end of file
+regex_annotator_error_match_group_name_not_found = "The match group name \"{0}\" of rule \"{1}\" was not found.
+regex_annotator_warning_number_format_conversion = "The feature value {0} of feature {1} could not be parsed as {2} number. Feature value not set!
\ No newline at end of file