Clear Special character

 

	public static String[] analyzer(String string) {
		List<String> list = new ArrayList<String>();
		try {
			StringReader reader = new StringReader(string);
			IKSegmenter ik = new IKSegmenter(reader, true);
			Lexeme lexeme = null;
			while ((lexeme = ik.next()) != null) {
				list.add(lexeme.getLexemeText());
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return list.toArray(new String[list.size()]);
	}

	public static String[] generate(String string) {
		List<String> list = new ArrayList<String>();
		string = clear_special_character(string);
		String[] tags = string.split("[,\\s]");
		for (String tag : tags) {
			tag = tag.trim();
			if (tag.length() > 0) {
				list.add(tag);
			}
		}
		return list.toArray(new String[list.size()]);
	}

	public static String clear_special_character(String string) {
		string = string.replaceAll("\\pP|\\pS", " ");
		string = string.replaceAll("\\s+", " ");
		return string;
	}
	

你可能感兴趣的:(character)