![JAR search and dependency download from the Maven repository](/logo.png)
gov.nih.nlm.nls.lvg.Flows.ToAcronyms 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 java.sql.*;
import gov.nih.nlm.nls.lvg.Lib.*;
import gov.nih.nlm.nls.lvg.Db.*;
/*****************************************************************************
* This class provides features of generating known acronyms for a specified
* acronym expansion. The input acronym expansion is stripped punctuationand
* then lowercase before put into SQL for database query.
*
* History:
*
*
*
* @author NLM NLS Development Team
*
* @see
* Design Document
*
* @version V-2010
****************************************************************************/
public class ToAcronyms 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 conn LVG database connection
* @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
*
* @see DbBase
*/
public static Vector Mutate(LexItem in, Connection conn,
boolean detailsFlag, boolean mutateFlag)
{
// mutate: Get acronyms record from Lvg database
Vector records = GetAcronyms(in.GetSourceTerm(), conn);
// update target LexItem by going through all acronym records
Vector out = new Vector();
int size = records.size();
// tag: set true if output is unique, used in frutiful variants
boolean curTagFlag = ((size==1)?true:false);
Tag tag = new Tag(in.GetTag());
tag.SetBitFlag(Tag.UNIQUE_ACR_EXP_BIT, curTagFlag);
String tagStr = ((curTagFlag)?"Unique":"NotUnique");
in.SetTag(tag.GetValue());
for(int i = 0; i < size; i++)
{
AcronymRecord record = records.elementAt(i);
String term = record.GetAcronym();
// details & mutate
String details = null;
String mutate = null;
if(detailsFlag == true)
{
details = INFO + " (" + record.GetType() + ")";
}
if(mutateFlag == true)
{
mutate = record.GetType() + GlobalBehavior.GetFieldSeparator()
+ tagStr + GlobalBehavior.GetFieldSeparator();
}
// update output LexItem
LexItem temp = UpdateLexItem(in, term, Flow.ACRONYMS,
Transformation.UPDATE,
Inflection.GetBitValue(Inflection.BASE_BIT),
details, mutate);
out.addElement(temp);
}
return out;
}
/**
* A unit test driver for this flow component.
*/
public static void main(String[] args)
{
// load config file
Configuration conf = new Configuration("data.config.lvg", true);
String testStr = GetTestStr(args, "VERY LOW-DENSITY LIPOPROTEIN");
// Mutate
LexItem in = new LexItem(testStr);
Vector outs = new Vector();
try
{
Connection conn = DbBase.OpenConnection(conf);
if(conn != null)
{
outs = ToAcronyms.Mutate(in, conn, true, true);
}
DbBase.CloseConnection(conn, conf);
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
PrintResults(in, outs); // print out results
}
// private method
private static Vector GetAcronyms(String inStr,
Connection conn)
{
// strip punctuations & lowercase
String strippedStr = ToStripPunctuation.StripPunctuation(inStr);
String lcStrippedStr = strippedStr.toLowerCase();
Vector out = new Vector();
try
{
out = DbAcronym.GetAcronyms(lcStrippedStr, conn);
}
catch (SQLException e) { }
return out;
}
// data members
private static final String INFO = "Generate Acronyms";
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy