// Path: src/main/java/org/kew/rmf/transformers/SqueezeWhitespaceTransformer.java
// public class SqueezeWhitespaceTransformer implements Transformer {
// 
// 	protected static final Pattern MULTIPLE_WHITESPACE = Pattern.compile("\\s+");
// 
// 	@Override
// 	public String transform(String s) {
// 		return MULTIPLE_WHITESPACE.matcher(s).replaceAll(" ").trim();
// 	}
// }
// 
// Path: src/main/java/org/kew/rmf/transformers/StringShrinkerTransformer.java
// public class StringShrinkerTransformer implements Transformer {
// 
// 	private int length = Integer.MAX_VALUE;
// 
// 	@Override
// 	public String transform(String s) {
// 		if (s.length() > this.length) s = s.substring(0, this.length);
// 		return s;
// 	}
// 
// 	public Integer getLength() {
// 		return length;
// 	}
// 	public void setLength(int length) {
// 		this.length = length;
// 	}
// }
// 
// Path: src/main/java/org/kew/rmf/transformers/StripNonAlphanumericCharactersTransformer.java
// public class StripNonAlphanumericCharactersTransformer implements Transformer {
// 
// 	private NormaliseDiacriticalMarksTransformer normaliseDiacriticalMarksTransformer = new NormaliseDiacriticalMarksTransformer();
// 	private SqueezeWhitespaceTransformer squeezeWhitespaceTransformer = new SqueezeWhitespaceTransformer();
// 
// 	private final Pattern nonAlphanumeric = Pattern.compile("[^\\p{L}\\p{N}]");
// 	private String replacement = " ";
// 
// 	@Override
// 	public String transform(String s) {
// 		s = normaliseDiacriticalMarksTransformer.transform(s);
// 		s = nonAlphanumeric.matcher(s).replaceAll(replacement);
// 		s = squeezeWhitespaceTransformer.transform(s);
// 		return s.trim();
// 	}
// 
// 	public String getReplacement() {
// 		return replacement;
// 	}
// 	public void setReplacement(String replacement) {
// 		this.replacement = replacement;
// 	}
// }
// 
// Path: src/main/java/org/kew/rmf/transformers/Transformer.java
// public interface Transformer {
// 	/**
// 	 * Transform <code>s</code> into another String.
// 	 * @param s	The string to transform
// 	 * @return	The transformed string
// 	 * @throws TransformationException	 If there is a problem with the transformer, e.g. unable to load external resource.
// 	 */
// 	public String transform(String s) throws TransformationException;
// }


import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.kew.rmf.transformers.SqueezeWhitespaceTransformer;
import org.kew.rmf.transformers.StringShrinkerTransformer;
import org.kew.rmf.transformers.StripNonAlphanumericCharactersTransformer;
import org.kew.rmf.transformers.Transformer;
/*
 * Copyright © 2012, 2013, 2014 Royal Botanic Gardens, Kew.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.kew.rmf.transformers.authors;



/**
 * This transformer tries to identify <strong>all</strong> authors (accepts publishing-,
 * basionym-, ex-, in-) of plant names in a string and returns a string where
 * each of their surnames are shrunk/cropped to a length
 * of {@link #setShrinkTo(int)}.
 */
/*
 * For examples of standard usage and corner cases see {@link ShrunkAuthorsTest}
 */
public class ShrunkAuthors implements Transformer {

	private DotFDotCleaner dotFDotCleaner = new DotFDotCleaner();
	private SurnameExtractor surnameExtractor = new SurnameExtractor();

	private StripBasionymAuthorTransformer stripBasionymAuthor =new StripBasionymAuthorTransformer();
	private StripPublishingAuthorTransformer stripPublishingAuthor = new StripPublishingAuthorTransformer();

	private Pattern inEx = Pattern.compile(StripExAuthorTransformer.EX_MARKER_REGEX + "|" + StripInAuthorTransformer.IN_MARKER_REGEX);

	private SqueezeWhitespaceTransformer shrinkWhitespace = new SqueezeWhitespaceTransformer();
	private StripNonAlphanumericCharactersTransformer safeStripNonAlphanumerics = new StripNonAlphanumericCharactersTransformer();

	private StringShrinkerTransformer stringShrinker = new StringShrinkerTransformer();

	@Override
// Path: src/main/java/org/kew/rmf/transformers/SqueezeWhitespaceTransformer.java
// public class SqueezeWhitespaceTransformer implements Transformer {
// 
// 	protected static final Pattern MULTIPLE_WHITESPACE = Pattern.compile("\\s+");
// 
// 	@Override
// 	public String transform(String s) {
// 		return MULTIPLE_WHITESPACE.matcher(s).replaceAll(" ").trim();
// 	}
// }
// 
// Path: src/main/java/org/kew/rmf/transformers/StringShrinkerTransformer.java
// public class StringShrinkerTransformer implements Transformer {
// 
// 	private int length = Integer.MAX_VALUE;
// 
// 	@Override
// 	public String transform(String s) {
// 		if (s.length() > this.length) s = s.substring(0, this.length);
// 		return s;
// 	}
// 
// 	public Integer getLength() {
// 		return length;
// 	}
// 	public void setLength(int length) {
// 		this.length = length;
// 	}
// }
// 
// Path: src/main/java/org/kew/rmf/transformers/StripNonAlphanumericCharactersTransformer.java
// public class StripNonAlphanumericCharactersTransformer implements Transformer {
// 
// 	private NormaliseDiacriticalMarksTransformer normaliseDiacriticalMarksTransformer = new NormaliseDiacriticalMarksTransformer();
// 	private SqueezeWhitespaceTransformer squeezeWhitespaceTransformer = new SqueezeWhitespaceTransformer();
// 
// 	private final Pattern nonAlphanumeric = Pattern.compile("[^\\p{L}\\p{N}]");
// 	private String replacement = " ";
// 
// 	@Override
// 	public String transform(String s) {
// 		s = normaliseDiacriticalMarksTransformer.transform(s);
// 		s = nonAlphanumeric.matcher(s).replaceAll(replacement);
// 		s = squeezeWhitespaceTransformer.transform(s);
// 		return s.trim();
// 	}
// 
// 	public String getReplacement() {
// 		return replacement;
// 	}
// 	public void setReplacement(String replacement) {
// 		this.replacement = replacement;
// 	}
// }
// 
// Path: src/main/java/org/kew/rmf/transformers/Transformer.java
// public interface Transformer {
// 	/**
// 	 * Transform <code>s</code> into another String.
// 	 * @param s	The string to transform
// 	 * @return	The transformed string
// 	 * @throws TransformationException	 If there is a problem with the transformer, e.g. unable to load external resource.
// 	 */
// 	public String transform(String s) throws TransformationException;
// }


// Path: src/main/java/org/kew/rmf/transformers/authors/ShrunkAuthors.java
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
import org.kew.rmf.transformers.SqueezeWhitespaceTransformer;
import org.kew.rmf.transformers.StringShrinkerTransformer;
import org.kew.rmf.transformers.StripNonAlphanumericCharactersTransformer;
import org.kew.rmf.transformers.Transformer;

/*
 * Copyright © 2012, 2013, 2014 Royal Botanic Gardens, Kew.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
package org.kew.rmf.transformers.authors;



/**
 * This transformer tries to identify <strong>all</strong> authors (accepts publishing-,
 * basionym-, ex-, in-) of plant names in a string and returns a string where
 * each of their surnames are shrunk/cropped to a length
 * of {@link #setShrinkTo(int)}.
 */
/*
 * For examples of standard usage and corner cases see {@link ShrunkAuthorsTest}
 */
public class ShrunkAuthors implements Transformer {

	private DotFDotCleaner dotFDotCleaner = new DotFDotCleaner();
	private SurnameExtractor surnameExtractor = new SurnameExtractor();

	private StripBasionymAuthorTransformer stripBasionymAuthor =new StripBasionymAuthorTransformer();
	private StripPublishingAuthorTransformer stripPublishingAuthor = new StripPublishingAuthorTransformer();

	private Pattern inEx = Pattern.compile(StripExAuthorTransformer.EX_MARKER_REGEX + "|" + StripInAuthorTransformer.IN_MARKER_REGEX);

	private SqueezeWhitespaceTransformer shrinkWhitespace = new SqueezeWhitespaceTransformer();
	private StripNonAlphanumericCharactersTransformer safeStripNonAlphanumerics = new StripNonAlphanumericCharactersTransformer();

	private StringShrinkerTransformer stringShrinker = new StringShrinkerTransformer();

	@Override
	public String transform(String s) {