Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

natural language date parser #72

Open
platonai opened this issue Jul 20, 2024 · 0 comments
Open

natural language date parser #72

platonai opened this issue Jul 20, 2024 · 0 comments

Comments

@platonai
Copy link
Owner

platonai commented Jul 20, 2024

We need parse dates from natural language text:

String text = "Let's meet next Friday for coffee.";
Parser parser = new Parser();
List<DateGroup> groups = parser.parse(text);

Popular Libraries:

Natty:
A widely-used library that handles a variety of date formats, including relative dates ("next Tuesday"), formal dates ("2023-07-20"), and relaxed expressions ("the first Monday of April 2000").
Hawking:
Developed by Zoho, Hawking is another powerful option that excels at context understanding. It considers the tense of the sentence and can extract multiple dates from a single input.

import com.joestelmach.natty.DateGroup;
import com.joestelmach.natty.Parser;
import java.util.List;

public class DateParserExample {
    public static void main(String[] args) {
        String text = "Let's meet next Friday for coffee.";
        Parser parser = new Parser();
        List<DateGroup> groups = parser.parse(text);

        if (!groups.isEmpty()) {
            DateGroup group = groups.get(0);
            System.out.println("Parsed date: " + group.getDates().get(0));
        } else {
            System.out.println("No dates found.");
        }
    }
}

Key considerations:

Accuracy: While these libraries are quite accurate, they might struggle with ambiguous expressions or domain-specific language.
Context: Hawking particularly shines at considering the context of the date expression, leading to more accurate results.
Dependencies: Remember to include the necessary library dependencies in your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant