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 2007/10/10 16:03:40 UTC
svn commit: r583480 - in
/incubator/uima/sandbox/trunk/RegularExpressionAnnotator:
docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml
src/main/java/org/apache/uima/annotator/regex/extension/Normalization.java
Author: mbaessler
Date: Wed Oct 10 07:03:39 2007
New Revision: 583480
URL: http://svn.apache.org/viewvc?rev=583480&view=rev
Log:
UIMA-594
added documentation for the custom annotation validation
https://issues.apache.org/jira/browse/UIMA-594
Modified:
incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml
incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/extension/Normalization.java
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=583480&r1=583479&r2=583480&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/docbook/RegexAnnotatorUserGuide/regexAnnotatorUserGuide.xml Wed Oct 10 07:03:39 2007
@@ -542,7 +542,8 @@
An annotation creation example with all possible settings is shown in the listing below.
</para>
<para>
- <programlisting><![CDATA[<annotation id="testannot" type="org.apache.uima.TestAnnot">
+ <programlisting><![CDATA[<annotation id="testannot" type="org.apache.uima.TestAnnot"
+ validate="CustomValidatorClass">
<begin group="0" location="start"/>
<end group="0" location="end"/>
<setFeature name="testFeature1" type="String">$0</setFeature>
@@ -556,8 +557,7 @@
<setFeature name="normalizedText" type="String"
normalization="Custom"
class="org.apache.CustomNormalizer">$0</setFeature>
-</annotation>
-]]></programlisting>
+</annotation>]]></programlisting>
</para>
<para>
@@ -584,6 +584,22 @@
</itemizedlist>
</para>
<para>
+ The optional features are:
+ </para>
+ <para>
+ <itemizedlist>
+ <listitem>
+ <para>
+ <code>validate</code>
+ - Specifies the custom validator class that is used to validate matches before
+ they are added as annotation to the CAS. For more details about the custom
+ annotation validation, please refer to
+ <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.validation"/>.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ <para>
The mandatory sub elements of the <code><annotation></code> element are:
</para>
<para>
@@ -593,7 +609,7 @@
<code><begin></code>
- Specifies the begin position of the annotation that is created.
For details about the <code><begin></code> element, please refer
- to the <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.boundaries"/>.
+ to <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.boundaries"/>.
</para>
</listitem>
<listitem>
@@ -601,7 +617,7 @@
<code><end></code>
- Specifies the end position of the annotation that is created.
For details about the <code><end></code> element, please refer
- to the <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.boundaries"/>.
+ to <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.boundaries"/>.
</para>
</listitem>
</itemizedlist>
@@ -616,7 +632,7 @@
<code><code><setFeature></code></code>
- set a UIMA feature for the created annotation.
For details about the <code><setFeature></code> element, please refer
- to the <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.features"/>
+ to <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.features"/>
</para>
</listitem>
</itemizedlist>
@@ -653,6 +669,54 @@
</itemizedlist>
</para>
</section>
+ <section id="sandbox.regexAnnotator.conceptsFile.annotationCreation.validation">
+ <title>Annotation Validation</title>
+ <para>
+ The custom annotation validation can be used to validate a regular expression match by using some
+ java code before the match is added as annotation to the CAS. For example if your regular expression
+ detects an ISBN number you can use the custom validation code to check if it is really an ISBN number
+ by calculating the last check digit or if it is just a phone number.
+ </para>
+ <para>
+ To use the custom annotation validation you have to specify the validation class at the <code>validate</code>
+ feature of the <code><annotation></code> element. The validation class must implement the
+ <code>org.apache.uima.annotator.regex.extension.Validation</code> interface
+ (<xref linkend="sandbox.regexAnnotator.Validation"/>). The interface defines one
+ method called <code>validate(String coveredText, String ruleID)</code>. The validate method is called by the annotator
+ before the match is added as annotation to the CAS. Annotations are only added if the validate method
+ returns <code>true</code>, otherwise the match is skipped. The <code>coveredText</code> parameter contains
+ the text span that will be covered by the annotation and was defined using the annotation boundaries (see
+ <xref linkend="sandbox.regexAnnotator.conceptsFile.annotationCreation.boundaries"/> for details).
+ The <code>ruleID</code> parameter contains the ruldId of the rule that creates the match. This can also be null
+ if no ruleID was specified. The listing below shows a sample implementation of the validation interface.
+ </para>
+ <para>
+ <programlisting><![CDATA[package org.apache.uima.annotator.regex;
+
+public class SampleValidator implements
+ org.apache.uima.annotator.regex.extension.Validation {
+
+ /* (non-Javadoc)
+ * @see org.apache.uima.annotator.regex.extension.Validation#validate(java.lang.String, java.lang.String)
+ */
+ public boolean validate(String coveredText, String ruleID) throws Exception {
+
+ //implement your custom validation, e.g. to validate ISBN numbers
+ return validateISBNNumbers(coveredText);
+ }
+}]]></programlisting>
+ </para>
+ <para>
+ The configuration for this example looks like:
+ </para>
+ <para>
+ <programlisting><![CDATA[<annotation id="isbnNumber" type="org.apache.uima.ISBNNumber"
+ validate="org.apache.uima.annotator.regex.SampleValidator">
+ <begin group="0"/>
+ <end group="0"/>
+</annotation>]]></programlisting>
+ </para>
+ </section>
<section id="sandbox.regexAnnotator.conceptsFile.annotationCreation.features">
<title>Annotation Features</title>
<para>
@@ -811,9 +875,10 @@
<code>Custom</code>, and an additional feature of the <code><setFeature></code> element
called <code>class</code> have to be specified containing the full qualified class name of the
custom normalization implementation. The custom normalization implementation have to implement
- the interface <code>org.apache.uima.annotator.regex.extension.Normalization</code> which defines to
+ the interface <code>org.apache.uima.annotator.regex.extension.Normalization</code>
+ (<xref linkend="sandbox.regexAnnotator.Normalization"/>) which defines the
<code>normalize</code> method to normalize the feature values. A sample implementation with
- the corresponding configuration is shown blow.
+ the corresponding configuration is shown below.
</para>
<para>
Custom normalization implementation:
@@ -1086,6 +1151,7 @@
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="optional"/>
<xs:attribute name="type" type="xs:string" use="required"/>
+ <xs:attribute name="validate" type="xs:string" use="optional" />
</xs:complexType>
</xs:element>
@@ -1175,6 +1241,97 @@
</para>
+</appendix>
+<appendix id="sandbox.regexAnnotator.Validation">
+ <title>Validation Interface</title>
+ <para>
+ <programlisting><![CDATA[/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.annotator.regex.extension;
+
+
+/**
+ * The Validation interface is provided to implement a custom validator
+ * that can be used to validate regular expression matches before
+ * they are added as annotations.
+ */
+public interface Validation {
+
+/**
+ * The validate method validates the covered text of an annotator and returns true or
+ * false whether the annotation is correct or not. The validate method is called between
+ * a rule match and the annotation creation. The annotation is only created if the method
+ * returns true.
+ *
+ * @param coveredText covered text of the annotation that should be validated
+ * @param ruleID ruleID of the rule which created the match
+ *
+ * @return true if the annotation is valid or false if the annotation is invalid
+ *
+ * @throws Exception throws an exception if an validation error occurred
+ */
+public boolean validate(String coveredText, String ruleID) throws Exception;
+
+}]]></programlisting>
+ </para>
</appendix>
+<appendix id="sandbox.regexAnnotator.Normalization">
+ <title>Normalization Interface</title>
+ <para>
+ <programlisting><![CDATA[/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.uima.annotator.regex.extension;
+
+
+/**
+ * The Normalization interface was add to implement a custom normalization
+ * for feature values before they are assigned to an anntoation.
+ */
+public interface Normalization {
+
+/**
+ * Custom feature value normalization. This interface must be implemented to
+ * perform a custom normalization on the given input string.
+ *
+ * @param input input string which should be normalized
+ *
+ * @return String - normalized input string
+ */
+public String normalize(String input) throws Exception;
+}]]></programlisting>
+ </para>
+</appendix>
</book>
Modified: incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/extension/Normalization.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/extension/Normalization.java?rev=583480&r1=583479&r2=583480&view=diff
==============================================================================
--- incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/extension/Normalization.java (original)
+++ incubator/uima/sandbox/trunk/RegularExpressionAnnotator/src/main/java/org/apache/uima/annotator/regex/extension/Normalization.java Wed Oct 10 07:03:39 2007
@@ -20,7 +20,8 @@
/**
- *
+ * The Normalization interface was add to implement a custom normalization
+ * for feature values before they are assigned to an anntoation.
*/
public interface Normalization {