All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cobber.fta.examples.DetermineDateFormatTrained Maven / Gradle / Ivy

Go to download

Analyze Text data to determine simple type and Semantic type information as well as other key metrics associated with a text stream.

There is a newer version: 15.7.14
Show newest version
/*
 * Copyright 2017-2024 Tim Segall
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cobber.fta.examples;

import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import com.cobber.fta.dates.DateTimeParser;

public abstract class DetermineDateFormatTrained {

	public static void main(final String[] args) {
		final DateTimeParser dtp = new DateTimeParser().withLocale(Locale.ENGLISH);

		final List inputs = Arrays.asList( "10/1/2008", "10/2/2008", "10/3/2008", "10/4/2008", "10/5/2008", "10/10/2008" );

		inputs.forEach(dtp::train);

		// At this stage we are not sure of the date format, since with 'DateResolutionMode == None' we make no
		// assumption whether it is MM/DD or DD/MM and the format String is unbound (??/?/yyyy)
		System.err.println(dtp.getResult().getFormatString());

		// Once we train with another value which indicates that the Day must be the second field then the new
		// result is correctly determined to be MM/d/yyyy
		dtp.train("10/15/2008");
		System.err.println(dtp.getResult().getFormatString());

		// Once we train with another value which indicates that the Month is expressed using one or two digits the
		// result is correctly determined to be M/d/yyyy
		dtp.train("3/15/2008");
		System.err.println(dtp.getResult().getFormatString());
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy