Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DataCleaner (community edition) Copyright (C) 2014 Neopost - Customer Information Management This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the GNU Lesser General Public License, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this distribution; if not, write to: Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
 package org.datacleaner.beans.standardize;
 import java.util.List;
Tokenizes/standardizes four components of a full name: Firstname, Lastname, Middlename and Titulation.
 @Named("Name standardizer")
 @Description("Identify the various parts of a full name column and turn it into separate, standardized tokens.")
 public class NameStandardizerTransformer implements Transformer {
 	public static enum NamePart implements HasGroupLiteral {
 		public String getGroupLiteral() {
 			if (this == ) {
 				return "(Mr|Ms|Mrs|Hr|Fru|Frk|Miss|Mister)";
 			return null;
 	@Configured("Name patterns")
 	public void init() {
 		if ( == null) {
 			 = new String[0];
 		for (String stringPattern : ) {
 			.add(new NamedPattern<NamePart>(stringPatternNamePart.class));
 		return new OutputColumns(String.class"Firstname""Lastname""Middlename""Titulation");
 	public String[] transform(InputRow inputRow) {
 		String value = inputRow.getValue();
 		return transform(value);
	public String[] transform(String value) {
		String firstName = null;
		String lastName = null;
		String middleName = null;
		String titulation = null;
		if (value != null) {
			for (NamedPattern<NamePartnamedPattern : ) {
				NamedPatternMatch<NamePartmatch = namedPattern.match(value);
				if (match != null) {
					firstName = match.get(.);
					lastName = match.get(.);
					middleName = match.get(.);
					titulation = match.get(.);
		return new String[] { firstNamelastNamemiddleNametitulation };
	public void setInputColumn(InputColumn<?> inputColumn) {
		this. = (InputColumn<String>) inputColumn;
	public void setStringPatterns(String... stringPatterns) {
		this. = stringPatterns;
New to GrepCode? Check out our FAQ X