What library can i use to parse a Schedule String in Java - java

I am currently writing a program in Java where I have to parse User Input like "every 4 hours" "every day 6:00" or something like that and turn that into an interval.
The only thing I found was the Google Docs for Cloud Cronjobs https://cloud.google.com/appengine/docs/java/configyaml/cron#Java_app_yaml_The_schedule_format
Can someone tell me about some library that could achieve this?
EDIT:
I found a ruby library that can do this: https://github.com/yb66/tickle
Is there any Java Implementation of it?

Try JChronic which is a java implementation of Ruby Chronic:
https://github.com/samtingleff/jchronic
This gives allows you to convert things like next tuesday into real dates.

My solution was to take some parts from Rubys Tickle and Chronic and write it myself.
If anyone ever needs this, feel free to contact me

Related

How do you grab a certain string of text through a link in java?

Is it possible to grab a certain piece of text through Java in a website? like for example, https://weather.com/weather/today/l/41.93,-88.25?par=google&temp=f , how would i be able to figure out the temp that it displays in java?
The practical answer to your question is: You don't wanna do that.
Let me try to answer it, at which point you'll realize why you don't want to:
How do I programatically parse a website?
It's complicated. Just about every browser has an option to right click and 'view source'. Presumably the number(s) you want are in here; you can parse this text to find them. It's NOT easy though. You'll probably be tempted to use something like a regular expression or a simple 'find me this exact string of text' trick to find what you need. It may work. But generally that means the day that this site changes the style or just does some basic updates, your code ceases to work.
You'll need to put in your agenda to check, every day if you have to, if your code still works. That's 5 minutes out of your day, every day, for the rest of the life of this project. That sounds incredulously expensive, which is why you don't want this.
If you must, there are ways to tighten up your parsing code. If you use libraries like jsoup, that helps a bit. If you toss the entire site through a 'browser emulator', you can deal with javascript making ajax requests and the like (these days websites are like little programs, and to truly observe programmatically what the site shows to human eyes, you need to run that program to get the job done. If you're very lucky, you can inspect the 'source code' of the little program and that's all you need, but you're not always that lucky).
But, as I said, that just helps a bit. The day will come the weather channel changes their site and breaks your code. They won't announce it. It is not considered immoral or technically dubious to do so. Maybe you can update your agenda to check if your code works down to once a week instead of daily, but it'll be a permanent maintenance burden. You DO NOT WANT THIS.
Okay, forget that. How does this really work?
Sites that are designed to let you read this stuff have an API. They'll document it someplace. This is a 'website' made specifically for code. It has no formatting, and a well defined specification. Send it this specific simple string, and this specific simple answer comes out, and the site has tooling to let you know when they change it (for example, an 'API version') - all luxuries the site meant for human consumption will not have.
You're in luck. The weather channel has an API.
What you really want, is to read all that, figure out how that API works, and use that.
The API will not break when the weather channel decides that today is a good day to slightly change the shade of the background image.

Using what DatePicker in java8?

I want to make a user pick a date. After this, I want to convert it to a java.time.LocalDate without getting in trouble.
I would like to get something looking like this:
I know, this image is made from a JDatePicker. I read several tutorials about this, but it seems to be outdated or no longer supported – eclipse tells me it cannot import JDatePickerImpl (for example). (I tested that class by trying this tutorial (look for the answer by MadProgrammer)).
What do I search for? (I guess it already exists, I wonder if I had to implement it myself.)
How to use it? (Link for a good tutorial, for example)
setting date (using java.time.LocalDate)
getting date (using java.time.LocalDate)
I need to use "big" dates: I would like to make it work with at least 2000 years from now. For this purpose it's important to make the user able to type the year manually. (Instead of clicking up and down, but in the image it looks like this is possible.)
I am not sure if I understand all your specs well but at least I can share tutorial from Oracle docs which worked fine for me with Java8 (JavaFX) when I experimented with the date.
JavaFX Date Picker
Hope it helps.

In Java how to say speak/read instead of println/system.in

Just curious to know what it will take for me to have human capability to my java programs. Currently to display a message i use System.out.println and to read user's input i may use something like System.in. Wondering if there is a way for me to say System.out.speak() and System.hear();
If not possible with Java i'm okay to learn other languages please help.
Wondering if there is a way for me to say System.out.speak() and System.hear();
Literally, no.
System.out is a PrintWriter and there is no speak() method.
There is no System.hear() method.
Adding such methods would entail hacking on standard system classes ... making the resulting library "NOT Java(tm)".
Furthermore, there are no standard APIs in the Java libraries for text to speech or speech to text. (And I'm not aware of any other language that offers this functionality as a standard feature.)
However, I'm sure that if you looked hard enough you could find 3rd-party tools for doing this that could be integrated with Java, one way or another.
UPDATE
In fact, you have found the standard Android (as distinct from Java) APIs for this:
Speech recognition: android.speech
Text to speech: android.speech.tts
From a design perspective, I think it would be a better idea to support this kind of thing in the OS's user interface framework (where the user can control it), and not embed it in individual applications.
So it sounds like this is what you want:
"System.out.speak()" -- as you know by now, that's not a real thing. I think I could propose a high-level, temporary solution.
It sounds like you just want to be audibly notified when you reach a certain part in your code. Perhaps you could just record a wav or mp3 of yourself saying whatever it is you want to hear as an alert, and then import the wav/mp3 into your project directory. Refer to this article to figure out how to playback that audio:
Playing .mp3 and .wav in Java?
You could simply make a static method that takes in a string representing the desired audio playback and then does so by however the link above suggests.
If you want it to take in a string, and then have some sort of computer voice (e.g. Microsoft Sam) speak that string, that's a lot more complicated. I have no idea how to do that haha. But I'm guessing it's not as hard as your idea of "System.in.hear()"
"System.in.hear()" -- This is definitely not a thing. This requires knowledge in the field of Speech-To-Text (STT). This is basically how Siri or Google Now parses what you say to them. I'm sure there are libraries you could find that do this, but I'm too lazy to look for you :(
I hope this helps a little bit. I'm doing a little bit of research right now on STT and I saw your question pop up. I'm not very knowledgeable in the area, but I hope you figure out a way to get audio feedback instead of having to put println's everywhere. You should figure that out and reuse it.
Happy programming!

How to implement a solution in Java with ESHyperNEAT?

I'm interested in AI and 2 days ago I found an interesting recent development in this area, it's called ES-HyperNEAT, first there was NEAT, then HyperNEAT then ES-HyperNEAT.
Here are some links to the topic :
http://eplex.cs.ucf.edu/hyperNEATpage/
http://eplex.cs.ucf.edu/ESHyperNEAT/
So I've downloaded the Java version of AHNI, but there is no tutorial, I guess the developers took for granted that it's easy to use, but to me, I don't know how to implement a solution to the following problem, doesn't seem very hard, but could someone show me how to get started ?
Input looks like this :
Date , A , B , C , D
2013-07-26,18.94,19.06,18.50,18.63
2013-07-25,18.85,19.26,18.55,19.04
2013-07-24,19.32,19.40,18.47,18.99
2013-07-23,20.15,20.30,19.16,19.22 <-- Predict it ? [ Output ]
2013-07-22,20.09,20.23,19.80,20.03 <-- Start Date
2013-07-19,20.08,20.48,19.76,20.02
2013-07-18,19.88,20.68,19.64,20.12
2013-07-17,19.98,20.07,19.69,19.83
2013-07-16,20.38,20.49,19.51,19.92
......
2013-07-02,18.19,18.20,17.32,17.69
2013-07-01,18.38,18.96,17.95,18.15 <-- End Date
The program should read the above data from Start Date counting back n days to End Date, train on those data and the correct output will always be the next day's D value, I wonder how this can be implemented with ES-HyperNEAT ?
Specifically :
[1] Which classes to call to start the process ?
[2] How to tell it which fields in the input file to gather data, in this case it can ignore the Date field, and gather data from A,B,C,D [ not normalized to 0,1 ]
[3] How to tell it the correct result is the next day's D value ?
[4] How to specify the program should start from line x at the Start Date, and get data through line y at the End Date ?
Is there something like : myProgram.start(FilePath,Delimiliter,Filed2,Field3,..,Line_X,Line_Y,...) ?
The readme.txt (which you can see at https://github.com/OliverColeman/ahni) contains some info about getting started with your own experiments, specifically see the DEVELOPMENT AND CREATING NEW EXPERIMENTS section. There is currently no code specific to performing time-series prediction in AHNI, so you would have to extend one of the base fitness function classes (see the readme). Your code would need to do the things you ask about (points 2-4), but you could create a fairly generic time-series prediction class which can be configured via the .properties file to specify the things in points 2-4. If you do do this then feel free to contribute it and we'll add it to the AHNI software on github :).
AHNI is intended as a research platform to support my own research (and hopefully others along the way), rather than an "easy to use, throw generic machine learning problem X at it" kind of software package (depending on your definition of "easy to use"). I try to keep the code clean, well-organised and the API well-documented so that others may use it, but creating a full-blown tutorial (and functionality) for the many possible use-cases is beyond the scope of the project (though of course I'd gladly include tutorials written by others).
Before going further I recommend considering the below:
When googling around for previous research on using HyperNEAT for time-series prediction I came across a question I asked several years ago that is similar to yours that I had completely forgotten about (I was surprised to see my name attached to the question! :)) http://tech.groups.yahoo.com/group/neat/message/5470 The reply to this question is good food for thought on the matter. Additionally:
(ES-)HyperNEAT is designed to exploit geometric regularities (patterns, correlations) in the input or output (see http://eplex.cs.ucf.edu/papers/gauci_nc10.pdf), so one question that might be worth exploring is whether the data contains regularities that can be represented geometrically (in my question I suggested plotting some window of the time-series on a 2D plane, which the 2D input layer of the network "sees", similar to the approach used in http://eplex.cs.ucf.edu/papers/verbancsics_gecco10.pdf. However, it sounds like NEAT, using a recurrent network, might be just as good if not better than HyperNEAT for this kind of problem.

Comprehensive (Intelligent) Date library

I'm looking for a complete Date management library in java that would allow me to understand strings like :
Tomorrow at noon => 2011-10-20 12:00
Today at 4pm => 2011-10-20 16:00
etc...
But it would be perfect if this lib would also be Internationalized. I plan to use it in many languages, and "just" english wouldn't be enough.
I already found http://www.datejs.com/ as a possibility, but it's for Javascript (client)'s side. I'm looking for something in Server side.
Thanks for your help!
PrettyTime is what you need
You could easily build that yourself with e.g. Joda Time.
An similar question was at PHP's strtotime() in Java and here's a good answer. #dfa did an object that do exactly what I'm looking for, you can find the link here

Categories