`
zwhc
  • 浏览: 262780 次
  • 性别: Icon_minigender_1
  • 来自: 福州
社区版块
存档分类
最新评论

typoglycemia

    博客分类:
  • java
阅读更多
单词里面字母乱序不影响阅读的现象,学名叫做Typoglycemia :
http://en.wikipedia.org/wiki/Typoglycemia

package test;

import java.util.ArrayList;
import java.util.Collections;

public class Test001 {

	private static String typoglycemia(String s){
		if(s.length()<3){
			return s;
		}
		ArrayList al = new ArrayList();
		for(int i=1; i<s.length()-1; i++){
			al.add(s.charAt(i));
		}
		Collections.shuffle(al);
		StringBuffer sb = new StringBuffer();
		sb.append(s.charAt(0));
		for(int i=1; i<s.length()-1; i++){
			sb.append( al.get(i-1) );
		}
		sb.append(s.charAt(s.length()-1));
		return sb.toString();
	}
	
	private static void test01(){
		String[] ss = {
				"This",
				"tutorial",
				"is",
				"designed",
				"for",
				"two",
				"groups",
				"of",
				"people",
				"The",
				"first",
				"includes",
				"those",
				"who",
				"are",
				"new",
				"to",
				"Eclipse",
				"and",
				"want",
				"to",
				"understand",
				"it's",
				"basic",
				"functionality",
				"Although",
				"we",
				"use",
				"a",
				"Java",
				"project",
				"as",
				"our",
				"example,",
				"this",
				"tutorial",
				"involves",
				"no",
				"programming",
				"and",
				"is",
				"designed",
				"so",
				"that",
				"the",
				"content",
				"is",
				"relevant",
				"to",
				"any",
				"application",
				"that",
				"uses",
				"the",
				"Eclipse",
				"workbench"
			};
		for(int i=0; i<ss.length; i++){
			//System.out.println( s );
			System.out.print( typoglycemia(ss[i]) );
			System.out.print( " " );
		}
	}
	
	private static void test02(){
		String s = "Typoglycemia is a neologism given to a purported recent discovery about the cognitive processes behind " +
				"reading written text. The word does not refer to any actual medical condition related to hypoglycemia. The " +
				"word appears to be a portmanteau of \"typo\", as in typographical error, and \"hypoglycemia\". It is an urban " +
				"legend/Internet meme that appears to have an element of truth to it.\r\n\r\n" +
				"The legend, propagated by email and message boards, purportedly demonstrates that readers can understand the " +
				"meaning of words in a sentence even when the interior letters of each word are scrambled. As long as all the " +
				"necessary letters are present, and the first and last letters remain the same, readers appear to have little " +
				"trouble reading the text.";
		StringBuffer sb = new StringBuffer();
		int begin = 0;
		int end = 0;
		boolean isBegin = false;
		for(int i=0; i<s.length(); i++){
			char c = s.charAt(i);
//			System.out.println( "isBegin:" + isBegin );
//			System.out.println( "c:" + c );
			if(isBegin == false){
				if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
					isBegin = true;
					begin = i;
				} else {
					sb.append(c);
				}
			}
			else{
				if( (c>='A' && c<='Z') || (c>='a' && c<='z') ){
				} else{
					isBegin = false;
					end = i;
//					System.out.println( "begin:" + begin );
//					System.out.println( "end:" + end );
					String s1 = s.substring(begin, end);
					sb.append(typoglycemia(s1));
					sb.append(c);
				}
				
			}
//			System.out.println( "isBegin:" + isBegin );

		}
		System.out.println( s );
		System.out.println( sb.toString() );
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		test02();
	}

}




运行结果:
原文:
Typoglycemia is a neologism given to a purported recent discovery about the cognitive processes behind reading written text. The word does not refer to any actual medical condition related to hypoglycemia. The word appears to be a portmanteau of "typo", as in typographical error, and "hypoglycemia". It is an urban legend/Internet meme that appears to have an element of truth to it.

The legend, propagated by email and message boards, purportedly demonstrates that readers can understand the meaning of words in a sentence even when the interior letters of each word are scrambled. As long as all the necessary letters are present, and the first and last letters remain the same, readers appear to have little trouble reading the text.

----------------------------
打乱后:
Toeiyyplmcga is a nlsoiogem gievn to a pruroeptd rneect deicvsroy about the cvtgiinoe pcseoress bnihed rianedg wteitrn txet. The word deos not refer to any aauctl micaedl cntodoiin rtlaeed to hymicyoplega. The wrod aepraps to be a potramnaetu of "typo", as in tpgiycphoaarl error, and "hepiymoylgca". It is an urabn leengd/Ieetnnrt mmee taht arpeaps to have an enelmet of tturh to it.

The leegnd, ptrapogead by email and msgaese brados, ptlrouedpry dtartmeonses taht rdreaes can udnetsnrad the manenig of wrdos in a snceetne eevn wehn the ineitorr leterts of each wrod are sleramcbd. As lnog as all the ncseerasy lttrees are prsenet, and the frist and last lrteets rmaein the same, rerdaes apepar to have ltilte tlbuore rnaedig the text.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics