欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Clear Special character

程序员文章站 2022-07-15 09:19:45
...

 

	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;
	}