gov.nih.nlm.nls.lvg.Flows.ToStripPunctuation Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lvg2010dist Show documentation
Show all versions of lvg2010dist Show documentation
LVG tools is used by Apache cTAKES.
The newest version!
package gov.nih.nlm.nls.lvg.Flows;
import java.util.*;
import gov.nih.nlm.nls.lvg.Lib.*;
import gov.nih.nlm.nls.lvg.Util.*;
/*****************************************************************************
* This class strips punctuations from a specified term. Punctuations include:
*
* - DASH_PUNCTUATION (20): -
*
- START_PUNCTUATION (21): ( { [
*
- END_PUNCTUATION (22): ) } ]
*
- CONNECTOR_PUNCTUATION (23): _
*
- OTHER_PUNCTUATION (24): ! @ # % & * \ : ; " ' , . ? /
*
- MATH_SYMBOL (25): ~ + = | < >
*
- CURRENCY_SYMBOL (26): $
*
- MODIFIER_SYMBOL (27): ` ^
*
*
* History:
*
*
*
* @author NLM NLS Development Team
*
* @see
* Design Document
*
* @version V-2010
****************************************************************************/
public class ToStripPunctuation extends Transformation implements Cloneable
{
// public methods
/**
* Performs the mutation of this flow component.
*
* @param in a LexItem as the input for this flow component
* @param detailsFlag a boolean flag for processing details information
* @param mutateFlag a boolean flag for processing mutate information
*
* @return Vector - results from this flow component
*/
public static Vector Mutate(LexItem in, boolean detailsFlag,
boolean mutateFlag)
{
// Mutate the term:
String term = StripPunctuation(in.GetSourceTerm());
// details & mutate
String details = null;
String mutate = null;
if(detailsFlag == true)
{
details = INFO;
}
if(mutateFlag == true)
{
mutate = Transformation.NO_MUTATE_INFO;
}
// update target
Vector out = new Vector();
LexItem temp = UpdateLexItem(in, term, Flow.STRIP_PUNCTUATION,
Transformation.UPDATE, Transformation.UPDATE, details, mutate);
out.addElement(temp);
return out;
}
/**
* A unit test driver for this flow component.
*/
public static void main(String[] args)
{
String testStr = GetTestStr(args, "Left's 12.34.56");
// Mutate
LexItem in = new LexItem(testStr);
Vector outs = ToStripPunctuation.Mutate(in, true, true);
PrintResults(in, outs); // print out result
}
// package method
/**
* Strip punctuations from a specified term.
*
* @param inStr the specified term to be stripped punctuations from.
*
* @return the term after being stripped punctuations
*/
static String StripPunctuation(String inStr)
{
int length = inStr.length();
char[] temp = new char[length];
int index = 0;
for(int i = 0; i < length; i++)
{
char tempChar = inStr.charAt(i);
if(Char.IsPunctuation(tempChar) == false)
{
temp[index] = tempChar;
index++;
}
}
String out = new String(temp);
return out.trim(); // must be trimmed
}
// data members
private static final String INFO = "Strip Punctuation";
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy