1

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();
       }
    }

}

Michal Borek
  • 4,584
  • 2
  • 30
  • 40
ebruszl
  • 469
  • 4
  • 11
  • 27

1 Answers1

3

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

Paweł Wyrwiński
  • 1,393
  • 9
  • 13
  • Nice answer. I just had similar issue this weekend as I experimented with natty-0.8 outside maven build. The only two dependencies I needed at runtime were `antlr-runtime-3.2.jar` and `ical4j-1.0.2.jar`. Natty is a nice library from what I've tried so far. – Core May 20 '13 at 17:05
  • I have a problem again. I wrote this codes it works correctly at java project. But when i try it on android device, i took error as "it has stopped" at the beginning of running. What can be the reason? – ebruszl Jun 02 '13 at 00:52
  • It's generic error message. Anything can be the reason. Try to use your tools: read logcat, check Eclipse's console view, put some breakpoints in code and then run your app in debug mode. Without providing minimum input like exception stack trace no one will be able to help you. I'll extend my answer with links to complete solution, I hope you'll find them usefull. – Paweł Wyrwiński Jun 02 '13 at 11:12