Lexical Tools

Application: Inflectional Variants

I. Objective

To use Lexical Tools APIs to retrieve inflectional variants of an input term.

In NLP applications, we often want to know the inflectional variants of terms include the singular and plurals for nouns, the various tenses of verbs, the positive, superlative and the comparative of adjectives and adverbs. This example illustrates how to use a Lexical Tools flow component (inflections) APIs in the applications.

II. Pre-Requirements
install lvg.${YEAR} package to "/Projects/LVG/lvg${YEAR}"

III. Source Code

import java.util.*;

import gov.nih.nlm.nls.lvg.Lib.*;
import gov.nih.nlm.nls.lvg.Flows.*;
import gov.nih.nlm.nls.lvg.Api.*;

public class Inflections
{
    // test driver
    public static void main(String[] args)
    {
        // instantiate a LvgApi object by config file
        String lvgConfigFile
            = "/Projects/LVG/lvg2012/data/config/lvg.properties";
        LvgApi lvgApi = new LvgApi(lvgConfigFile);

        // use the inflectional flow APIs
        LexItem in = new LexItem("Take"); // use lexItem as input to lvgApi
        Vector outs = ToInflection.Mutate(in, lvgApi.GetConnection(), 
            lvgApi.GetInflectionTrie(), OutputFilter.LVG_OR_ALL, false, true);

        // print out the Result
        for(LexItem out: outs)
        {
            System.out.println(out.ToString());
        }

        // clean up
        lvgApi.CleanUp();
    }
}

IV. Compile

shell>javac -classpath ../lib/lvg2012dist.jar RetrieveInflections.java

V. Run & Results

shell>java -classpath ./:../lib/lvg2012dist.jar:/Projects/LVG/lvg2012/ RetrieveInflections

Take|Take|all|all|take|noun|base|FACT|take|noun|base|take|noun|base|E0059817||
Take|Take|all|all|take|noun|singular|FACT|take|noun|base|take|noun|singular|E0059817||
Take|Take|all|all|takes|noun|plural|FACT|take|noun|base|takes|noun|plural|E0059817||
Take|Take|all|all|take|verb|base|FACT|take|verb|base|take|verb|base|E0059816||
Take|Take|all|all|take|verb|pres1p23p|FACT|take|verb|base|take|verb|pres1p23p|E0059816||
Take|Take|all|all|take|verb|infinitive|FACT|take|verb|base|take|verb|infinitive|E0059816||
Take|Take|all|all|took|verb|past|FACT|take|verb|base|took|verb|past|E0059816||
Take|Take|all|all|taken|verb|pastPart|FACT|take|verb|base|taken|verb|pastPart|E0059816||
Take|Take|all|all|takes|verb|pres3s|FACT|take|verb|base|takes|verb|pres3s|E0059816||
Take|Take|all|all|taking|verb|presPart|FACT|take|verb|base|taking|verb|presPart|E0059816||

=> Retrieve all inflectional variants of input term (Take).

VI. Application Package Download

The whole package, Inflections.tgz can be down here.