UIMA ruta Get a part of input number - uima

I have a input number(ex.01234567 and 98765432) and i need to get 45(from first) and 54(from second) to annotation MM, it is 5 and 6 position. How to make this in UIMA ruta?

DECLARE MM;
NUM->{"....(..)"-> 1 = MM;};
DISCLAIMER: I am a developer of UIMA Ruta

Related

Add two date variables in Scala

I have a date string and a date interval which I want to add it to that date in Scala, but I don't know how I can do this (preferably without using Java Calendar)!
Something like this:
val d1 = new SimpleDateFormat("YYYY-MM-DD").parse("1999-12-01")
val d2 = ??? // 1 Year interval
d1 + d2
java.time
LocalDate d1 = LocalDate.parse("1999-12-01");
Period p2 = Period.ofYears(1);
LocalDate oneYearLater = d1.plus(p2);
System.out.println(oneYearLater);
Output from this snippet is:
2000-12-01
Sorry that I cannot write Scala code. I trust you to translate from Java.
Provided that you are based on at least Java 8 you don’t need an external library. For Java 6 and 7 use the same code, only add the ThreeTen Backport library to your project and import from the org.threeten.bp package. For Java 5 Joda-Time is the good solution, see the other answer.
Both java.time and the ThreeTen Backport were developed by the same folks that developed Joda-Time and drew heavily on the good (and the few poor) experiences from there. Joda-Time is now in maintenance mode. The Joda-Time home page says: “Note that Joda-Time is considered to be a largely “finished” project. No major enhancements are planned. If using Java SE 8, please migrate to java.time (JSR-310).”
Links
Oracle tutorial: Date Time explaining how to use java.time.
Java Specification Request (JSR) 310, where java.time was first described.
ThreeTen Backport project, the backport of java.time to Java 6 and 7 (ThreeTen for JSR-310).
ThreeTenABP, Android edition of ThreeTen Backport
Joda-Time hmoepage
You are better off using joda dates rather than "vanilla" java:
import org.joda.time.DateTime
val d1 = DateTime.parse("1999-12-01")
val d2 = d1.plusYears(1)
There is no need for external dependencies. You can use java.time.LocalDate:
import java.time.LocalDate
val date1 = LocalDate.parse("1999-12-01")
val date2 = date1.plusYears(1)
As mentioned, you can use the API provided by Java. However, and in case you need a more Scala-like library, you could use https://github.com/nscala-time/nscala-time which is a wrapper around JodaTime.
Some examples:
DateTime.now() + 2.months // returns org.joda.time.DateTime = 2009-06-27T13:25:59.195-07:00
DateTime.nextMonth < DateTime.now() + 2.months // returns Boolean = true
DateTime.now() to DateTime.tomorrow // return org.joda.time.Interval = > 2009-04-27T13:47:14.840/2009-04-28T13:47:14.840
(DateTime.now() to DateTime.nextSecond).millis // returns Long = 1000
2.hours + 45.minutes + 10.seconds // returns com.github.nscala_time.time.DurationBuilder
// (can be used as a Duration or as a Period)
(2.hours + 45.minutes + 10.seconds).millis // returns Long = 9910000
2.months + 3.days // returns Period
Cheers.

Charts iOS I have used LineCharts in iOS but after upgrading to swift 4 Charts removed date from bottom

After swift 4 upgrade it is not showing dates here at bottom.
Before it was showing like below.
After converting my code to swift 4(Xcode 9.2) date just disappear from my data. I have passed my dates array here as:
// x-Axis Setup months
self.lineChart.xAxis.valueFormatter = IndexAxisValueFormatter(values: ["12 Jan", "14 Feb", "8 Mar", "23 Apr"])
Hey I found solution for this after a long days. To fix this, use this line in your Podfile.
pod 'Charts', '3.0.4'
It works by doing this.
Now 3.1.1 resolved this issue you can directly install latest one.

How to find the previous two Sundays from the current day in Scala?

If current time is `2015-05-16 13:05:06+1793` then I should get `2015-05-03 00:00:00+0000` and `2015-05-10 00:00:00+0000`
If current time is `2015-05-10 00:00:00+0000` then I should get `2015-05-03 00:00:00+0000` and `2015-05-10 00:00:00+0000`
And so forth... How can I compute these two dates in scala?
EDIT:
As I mentioned, I would prefer a solution which is not at all based on external libraries. In addition, please mention explicitly all necessary imports I have to made cause I am a newby both in Java and Scala.
If you're on Java 8, you can do pretty well without joda-time.
import java.time.LocalDate
val today = new LocalDate()
val lastSunday = today minusDays ( today.getDayOfWeek.getValue % 7 ) // Monday = 1 ... Sunday = 7
val twoSundaysAgo = lastSunday minusDays 7
You can have a look at joda-time. It is the best library to manage dates.
In your case, you could create a LocalTime and use something like this:
d.plusWeeks(-2).withDayOfWeek(DateTimeConstants.SUNDAY))
For starters you probably want to be using joda-time, as Carlos suggested. One way to look at the problem would be to filter the right days out of a set of possible days. This would look something like the following:
val today: LocalDate = new LocalDate()
val sundays: Seq[LocalDate] = (1 to 13) map {date.minusDays(_)} filter {_.dayOfWeek() == DateTimeConstants.SUNDAY}

How to make Jasper Reports programmatically determine the Name of Columns within the report it self?

I am generating a report with that will have a 7 columns where the last 6 should have the the last 6 months listed. So as of the time of this writing it should be:
NAME -> September -> August -> July -> June -> May -> April
ss the column headers. I am trying to avoid having to pass them in as parameters, and am trying to get Jasper Reports to figure it out at runtime. I can get the first month pretty easily using a Text Field Expression. It looks like:
new java.text.SimpleDateFormat("MMMMM").format(new Date())
The issue comes in with the other months. I initially tried
new java.text.SimpleDateFormat("MMMMM").format(java.util.Calendar.getInstance().add(Calendar.MONTH, new Integer("-1)).getTime())
This does not work since Calendar.add does not return a Calendar instance. I then tried using a variable and then a combination of variables which also did not work.
How to make Jasper Reports programmatically determine the Name of Columns within the report it self?
I think the best approach to solving this problem is to use Commons Lang. That package provides utilities to make calculations like this very easy. By adding one extra jar you can then use expressions like this:
DateUtils.addMonths(new Date(),-1)
I find that easier to maintain than first creating a helper Calendar class and then using the ternary operator but ignoring its results.
$P{cal}.add(Calendar.MONTH, -1)
? null : $P{cal}.getTime()
If you ever need to generalize the solution then it's a lot easier to get a Date back from a SQL query than to get a Calendar. So you can quickly change to "DateUtils.addMonths($F{MyDate},-1)". Initializing a Calendar to match a date returned by a query isn't nearly as simple. But of course there's a certain benefit to not having to add one more .jar file. So sometimes that ternary operator technique is the quickest way to get things done.
I wrote about using the Commons Lang approach a couple of years ago here: http://mdahlman.wordpress.com/2009/09/09/jasperreports-first-dates/
I also needed a certain format for the previous month. I ended up combining the other two answers:
new java.text.SimpleDateFormat("yyyyMM").format(
org.apache.commons.lang3.time.DateUtils.addMonths(
new java.util.Date(),
-6
)
)
This way I don't need to add another parameter. Adding the Commons Lang jar is a non issue for me since JasperServer 5.5 comes with version 3.0 out of the box.
I hope this helps someone who stumples upon this page, just like I did.
I found a working solution that is pretty ingenious (no I did not come up with it). I found it here. The gist of it is create a parameter called call, with a default value of:
Calendar.getInstance()
and un-check the option 'Use as a prompt'. Then in your text field expression you would do:
new java.text.SimpleDateFormat("MMMMM").format(
(
$P{cal}.add(Calendar.MONTH, -1)
? null : $P{cal}.getTime()
)
)
What happens is it will set the default value for the calendar instance, then execute the add method, which will resolve to false, so then it will then return the result from getTime() method which gets formatted how I want.

How to set the Eclipse date variable format?

How can I set the format for the ${date} variable which can be used in Eclipse templates?
Update February 2016: bug 75981 is officially fixed!
See Jmini's answer below
Update July 2015, 6 years later:
The bug mentioned below seems fixed in Eclipse 4.x.
Eric Wang comments below:
#date ${id:date('YYYY-MMM-dd')} ${time}
this give me English datetime format in eclipse 4.
Original Answer 2009 Eclipse 3.x
Argh! There is a long standing bug just for that: bug 75981
The ${date} variable could be enhanced to accept an argument (similar to other
parameterizations added in 3.3M1), e.g. ${d:date(format)}, where format is a pattern for SimpleDateFormat.
The only alternative would be to modify the class SimpleTemplateVariableResolver (as described in this thread), from the package org.eclipse.jface.text.templates. (You have here an example of such an extension).
This thread mentions the sources where you can find the class.
\eclipse\plugins\org.eclipse.platform.source_3.1.0\src\org.eclipse.text_3.1.0\src.zip
Example:
public static class Date extends SimpleTemplateVariableResolver {
/**
* Creates a new date variable
*/
public Date() {
super("date", TextTemplateMessages.getString("GlobalVariables.variable.description.date")); //$NON-NLS-1$ //$NON-NLS-2$ }
protected String resolve(TemplateContext context) {
//return DateFormat.getDateInstance().format(new java.util.Date());
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
return df.format(new java.util.Date()); } }
You could tell Eclipse to use a specific locale different from that of your operating system. Eclipse 3.5 (64 bit) doesn't use the MacOS X region setting. MacOS X english installation language with Germany as country provides a wrong date format.
You can fix it for your Eclipse installation when you append following lines to your eclipse.ini:
-Duser.language=de
-Duser.region=DE
I have fixed Bug 75981 with Eclipse Neon M5. You can download this Milestone Release here:
http://www.eclipse.org/downloads/index-developer.php
… or wait until June 2016 for the official Neon Release.
Here a quick description of how it works:
As before you can use the date variable with no argument. Example: ${date}
You can use the variable with additional arguments. In this case you will need to name the variable (since you are not reusing the date somewhere else, the name of the variable doesn't matter). Example: ${mydate:date}
The first parameter is the date format. Example: ${d:date('yyyy-MM-dd')}
The second parameter is the locale. Example: ${maDate:date('EEEE dd MMMM yyyy HH:mm:ss Z', 'fr')}
More info about this feature on my blog: Bug 75981 is fixed!
Additional information for those stumbling over this lately (like me):
For ISO 8601 date format, one can use the language settings fr-CA.