package edu.buffalo.cse.ir.wikiindexer.tokenizer.rules;

import edu.buffalo.cse.ir.wikiindexer.tokenizer.TokenStream;
import edu.buffalo.cse.ir.wikiindexer.tokenizer.TokenizerException;
import edu.buffalo.cse.ir.wikiindexer.tokenizer.rules.TokenizerRule.RULENAMES;

import java.lang.Character;

@RuleClass(className = RULENAMES.PUNCTUATION)

public class CapitalizationDefault implements TokenizerRule {

	@Override
	public void apply(TokenStream stream) throws TokenizerException {
		stream.reset();
		boolean isFirstWord = true;
		// 遍历stream中的每一个元素
		while (stream.hasNext()) {
			String token = stream.next();
			if (isFirstWord) {
				isFirstWord = false;
				stream.previous();
				stream.set(this.getLowerCase(token));
				stream.next();
			}
			if (token.matches(".*?[\\.\\!\\?]")) {
				isFirstWord = true;
			}
		}
	}
	
	private String getLowerCase (String s) {
		if (s.matches("[A-Z]*")) {
			return s;
		}
		return s.toLowerCase();
	}

}

@@ -872,75 +872,315 @@
 %0A%09%09i
-f (s.matches(%22%5BA-Z%5D*%22)) %7B%0A%09%09%09return s;%0A%09%09%7D%0A%09%09return s.toLowerCase()
+nt countOfUpChar = 0;%0A%09%09for (char c:s.toCharArray()) %7B%0A%09%09%09if (c %3E= 'A' && c %3C= 'Z') %7B%0A%09%09%09%09countOfUpChar += 1;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if (countOfUpChar == 0) %7B%0A%09%09%09return s;%0A%09%09%7D else if (countOfUpChar == 1 && (s.charAt(0) %3E= 'A' && s.charAt(0) %3C= 'Z')) %7B%0A%09%09%09return s.toLowerCase();%0A%09%09%7D%0A%09%09System.out.println(s);%0A%09%09return s
 ;%0A%09%7D

update Capitalize code