gov.nih.nlm.nls.lvg.Flows.ToSynonyms 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 generates synonyms from the specified term. The synonyms are
* pre-computed and put in the Synonym table of the LVG database. The input
* term need to be stripped punctuationand then lowercased in SQL query before
* being sent to Lvg database.
*
* History:
*
*
*
* @author NLM NLS Development Team
*
* @see
* Design Document
*
* @version V-2010
****************************************************************************/
public class ToSynonyms 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:
Vector records = GetSynonyms(in.GetSourceTerm(), conn);
long inCat = in.GetSourceCategory().GetValue();
// update target LexItem
Vector out = new Vector();
for(int i = 0; i < records.size(); i++)
{
SynonymRecord record = records.elementAt(i);
String term = record.GetSynonym();
long curCat = record.GetCat1();
// input filter: category
if(InputFilter.IsLegal(inCat, curCat) == false)
{
continue;
}
// details & mutate
String details = null;
String mutate = null;
if(detailsFlag == true)
{
details = INFO;
}
if(mutateFlag == true)
{
String fs = GlobalBehavior.GetFieldSeparator();
mutate = "FACT" + fs
+ record.GetKeyFormNpLc() + fs
+ record.GetKeyForm() + fs
+ Category.ToName(record.GetCat1()) + fs
+ record.GetSynonym() + fs
+ Category.ToName(record.GetCat2()) + fs;
}
LexItem temp = UpdateLexItem(in, term, Flow.SYNONYMS,
record.GetCat2(),
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, "aminophylline");
// Mutate
LexItem in = new LexItem(testStr, Category.ALL_BIT_VALUE,
Inflection.ALL_BIT_VALUE);
Vector outs = new Vector();
try
{
Connection conn = DbBase.OpenConnection(conf);
if(conn != null)
{
outs = ToSynonyms.Mutate(in, conn, true, true);
}
DbBase.CloseConnection(conn, conf);
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
PrintResults(in, outs); // print out results
}
// private methods
private static Vector GetSynonyms(String inStr,
Connection conn)
{
// strip punctuations & lowercase
String strippedStr = ToStripPunctuation.StripPunctuation(inStr);
String lcStrippedStr = strippedStr.toLowerCase();
Vector out = new Vector();
// get synonyms from LVg DB
try
{
out = DbSynonym.GetSynonyms(lcStrippedStr, conn);
}
catch (SQLException e) { }
return out;
}
// data members
private static final String INFO = "Generate Synonyms";
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy