Convert verbs to base form by using Wordnet in Java

A verb can occurs in a sentence in various format such as base form, past tense, past participle, 3rd person singular present, etc. To have a general idea of how each word occurs, we often need to get base form of a word.

This examples shows how to convert a verb to its base form by using Java API for Wordnet – JAWS. I will do this in eclipse environment and Ubuntu.

1. Create a Java project called “TestJAWS” in your work space.

2. Go to Wordnet(http://wordnet.princeton.edu/wordnet/download/current-version/), and download “tar-gzipped: WordNet-3.0.tar.gz”.

Note: it is not just database file.

3. Unzip it, and copy dict direction to your workspace, let’s say “/home/mike/somedir/dict/”. The “dict” directory should contain the following files:

4. Download JAWS jar file: http://lyle.smu.edu/~tspell/jaws/jaws-bin.jar, and add it to your project build path. (right click the project -> Build path -> Configure build path -> Libraries -> add External Jars -> done)

5. The following is the code of finding base form of verb “implements”

public static void main(String[] args) {
 
		System.setProperty("wordnet.database.dir", "/home/.../wordnet/dict/");
		WordNetDatabase database = WordNetDatabase.getFileInstance();
 
		Morphology id = Morphology.getInstance();
 
		String[] arr = id.getBaseFormCandidates("implements", SynsetType.VERB);
 
		System.out.println(arr.length);
 
		for(String a: arr)
			System.out.println(a);
 
	}

If you are curious about what other things JAWS can do, go to JAWS Java Doc: http://lyle.smu.edu/~tspell/jaws/doc/overview-summary.html.

3 thoughts on “Convert verbs to base form by using Wordnet in Java”

  1. I’m getting “Morphology not resolved error”. Is there any other jar files which I need to include? I had installed wordnet in ubuntu by sudo apt-get install command and hence I wordnet location in System.setProperty(). So is this the cause for the error??

    thanks in advance

  2. I follow your guide, but axis2 generate this error:

    org.apache.axis2.AxisFault: edu/smu/tspell/wordnet/WordNetDatabase
    at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
    at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
    at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
    at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)

    The server said:

    [ERROR] edu/smu/tspell/wordnet/WordNetDatabase
    java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
    at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
    at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
    at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:114)
    at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
    at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
    at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:680)
    Caused by: java.lang.NoClassDefFoundError: edu/smu/tspell/wordnet/WordNetDatabase

    Why?

Leave a Comment