Search code examples
javaandroidnlpnatty

How can i use natty-master?


I should use natty-master in my android project. But i couldn't import it. How can i use natty without maven? I find these codes, i added jars but it doesn't work.

import java.util.Date;

import java.util.List;

import java.util.Map;

import com.joestelmach.natty.*;

public class natty {

public static void main(String[] args) {

    Parser parser = new Parser();

    List<DateGroup> groups = parser.parse("the day before next thursday");
    for(DateGroup group:groups)  {
    Date dates = group.getDates().get(0);           
    int line = group.getLine();
    int column = group.getPosition();
    String matchingValue = group.getText();
    String syntaxTree = group.getSyntaxTree().toStringTree();
        Map parseMap = group.getParseLocations();
    boolean isRecurreing = group.isRecurring();
    Date recursUntil = group.getRecursUntil();
       }
    }

}


Solution

  • I investigated it for you a little bit.
    I assume you're using Eclipse with current version of ADT plugin. First let's ensure you're adding jars properly:

    1. You have to create folder named libs on root level of your project (alongside the src, res, etc.).
    2. Copy 3rd-party jars into libs.
    3. Right-click on project and execute Refresh, ADT will discover libs and will add them as Android Dependencies.

    Now for the libraries. All dependencies of natty-07.jar listed by Maven are:

    antlr-2.7.7.jar
    antlr-runtime-3.2.jar
    backport-util-concurrent-3.1.jar
    commons-codec-1.5.jar
    commons-lang-2.6.jar
    commons-logging-1.1.1.jar
    ical4j-1.0.2.jar
    stringtemplate-3.2.jar
    

    Yep, that's 2.3 MB of dependencies you have to copy into libs.
    I don't think all of them are necessary at runtime, but I have no way to tell which ones are crucial.
    Using ProGuard probably could slim down some of them, but that's another story.

    I created quick 'n dirty application with minSdkVersion="8" and targetSdkVersion="17". Then put sample code you provided into Activity and run it against input: "the day before next thursday". As a result I got single group with date [Wed May 22 16:52:49 GMT 2013], which is OK since today is Friday May 17.


    Edit 2013-06-02
    essential code:
    http://pastebin.com/XrF5k10M
    complete solution:
    https://www.dropbox.com/sh/qk2cs51twrpobuz/YaFZWiG5jP/StackOverflow/16610375/NattyApp.zip