java去除字母_java 字符串中去除 数字 字母 符号&&N*1*senten.Length=>M*M

这段代码主要展示了如何从字符串中移除特殊字符并进行词向量化处理。首先,通过正则表达式移除了非字母数字的字符,然后利用词向量模型将分词后的词汇转换为向量,最后将向量写入文件。整个过程涉及文本预处理和词向量技术。
摘要由CSDN通过智能技术生成

字符串中去除 数字 字母 符号

String str = "今天1@天%。气^64很?不?错.心情6666很好。。。。。";

String str1 = str.replaceAll("[,。、|~!@#¥;【》‘“”、】《·\\-?:,:{}%……&*()\\=—+ A-Za-z0-9]","").trim().equals("");

N14=》M*M

public static void preCNN(String modelPathName,String sentence) throws IOException {

//分词

String Participle = ANJS_Participle.ANJS_FC(sentence);

String[] ReParticiple = Participle.trim().split(" ");

//词转向量

Word2VEC vec = new Word2VEC();

vec.loadJavaModel("model/four_dimensional_My40d_");

double[] reVec = new double[1600];

int toPreNum = 0;

for (int i = 0; i < ReParticiple.length; i++) {

float[] vecrDes = vec.getWordVector(ReParticiple[i].trim());//转向量

if (vecrDes!=null) {

for (int j = 0; j < vecrDes.length; j++) {

reVec[toPreNum] = vecrDes[j];

toPreNum++;

}

}

}

if (toPreNum!=0) {

//N*1*=>M*M

OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(new File("temp/txt2Vec2Array1600.txt")),"GBK") ;

double[] toPre = new double[1600];

for (int i = 0; i < toPre.length; i++) {

toPre[i] = reVec[i%toPreNum];

out.write(reVec[i%toPreNum]+",");

}

out.close(); //关闭写操作

}else {

System.out.println(sentence+" 《= 该句话无词向量。。。。。");

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值