package Lvg.Flows;
import java.util.*;
import java.sql.*;
import Lvg.Lib.*;
import Lvg.Db.*;
import Lvg.Trie.*;
/*****************************************************************************
* This class generates inflectional variants with specifying categories and
* inflections. It utilizes classes of ToInflection and OutputFilter.
*
*
History:
*
02/06/2001, clu, Initial creation
* 03/06/2001, clu, SCR-4, add & check detailsFlag in Mutate method
* 03/06/2001, clu, SCR-6, add & check mutateFlag in Mutate method
* 09/25/2001, clu, SCR-87, utilize StringBuffer to improve performance
*
* 04/15/2002, clu, SCR-34, use Ram trie to improve performance
*
* @author NLM LVG Development Team
*
* @see
*
* Design Document
* @see ToInflection
* @see OutputFilter
*
* @version V-2002
****************************************************************************/
public class ToInflectionByCatInfl 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 trie LVG persistent trie
* @param restrictFlag a numerical flag to filter the output. It's
* values are defined in OutputFilter as:
*
LVG_ONLY, LVG_OR_ALL, ALL.
* @param outCategory the specified categories filter.
* Inflectional variants contain all these categories will be in the results.
* @param outInflection the specified categories filter.
* all these categories will be in the output results.
* Inflectional variants contain all these inflections will be in the
* results.
* @param detailsFlag a boolean flag for processing details information
* @param mutateFlag a boolean flag for processing mutate information
*
* @return the results from this flow component - a collection (Vector)
* of LexItems
*
* @see DbBase
* @see OutputFilter
* @see Category
* @see Inflection
*/
public static Vector Mutate(LexItem in, Connection conn,
RamTrie trie, int restrictFlag, long outCategory,
long outInflection, boolean detailsFlag, boolean mutateFlag)
{
// Mutate: retrieve EUI & uninflected term from Inflected term
// calling package method from Toinflection is much slower than private
StringBuffer buffer = new StringBuffer();
buffer.append(INFO);
buffer.append(" <");
buffer.append(outCategory);
buffer.append(", ");
buffer.append(outInflection);
buffer.append(">");
String infoStr = buffer.toString();
Vector ori = ToInflection.InflectWords(in, conn, trie, restrictFlag,
infoStr, detailsFlag, mutateFlag, Flow.INFLECTION_BY_CAT_INFL);
// restrict output by category & inflection
Vector out = RestrictOutputByCatInfl(ori, outCategory, outInflection);
return out;
}
/**
* A unit test driver for this flow component.
*/
public static void main(String[] args)
{
// read in configuration file
Configuration conf = new Configuration("data.config.lvg", true);
String testStr = GetTestStr(args, "sleep");
int minTermLen = Integer.parseInt(
conf.GetConfiguration(Configuration.MIN_TERM_LENGTH));
String lvgDir = conf.GetConfiguration(Configuration.LVG_DIR);
// Mutate: connect to DB
LexItem in = new LexItem(testStr, Category.ALL_BIT_VALUE,
Inflection.ALL_BIT_VALUE);
Vector outs = new Vector();
try
{
Connection conn = DbBase.OpenConnection(conf);
boolean isInflection = true;
RamTrie trie = new RamTrie(isInflection, minTermLen, lvgDir);
if(conn != null)
{
outs = ToInflectionByCatInfl.Mutate(in, conn, trie,
OutputFilter.LVG_OR_ALL, 128, 1, true, true);
}
DbBase.CloseConnection(conn);
}
catch (Exception e)
{
System.err.println(e.getMessage());
}
// print out results
PrintResults(in, outs);
}
// private methods
private static Vector RestrictOutputByCatInfl(Vector in, long category,
long inflection)
{
Vector out = new Vector();
for(int i = 0; i < in.size(); i++)
{
LexItem temp = (LexItem) in.elementAt(i);
// filter out items by category and inflections
if(OutputFilter.IsCategoryInflectionOK(temp, category, inflection))
{
out.addElement(temp);
}
}
return out;
}
// data members
private static final String INFO = "InflectionByCatInfl";
}