代理代码提交
parent
33a1b87475
commit
e4996876ca
@ -0,0 +1,97 @@
|
||||
package com.baiye.fileread;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baiye.dao.LexiconFilterMapper;
|
||||
import com.baiye.dao.LexiconPinyinMapper;
|
||||
import com.baiye.entity.LexiconFilter;
|
||||
import com.baiye.entity.LexiconPinyin;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author YQY
|
||||
* @Date 2023/3/22
|
||||
*/
|
||||
@SpringBootTest
|
||||
@RunWith(SpringJUnit4ClassRunner.class)//mybatis-plus加上此注解
|
||||
public class ReadTet {
|
||||
|
||||
@Autowired
|
||||
public LexiconPinyinMapper lexiconPinyinMapper;
|
||||
|
||||
@Autowired
|
||||
public LexiconFilterMapper lexiconFilterMapper;
|
||||
|
||||
/**
|
||||
* 读取txt文件写入
|
||||
*/
|
||||
@Test
|
||||
public void readFile() {
|
||||
try {
|
||||
FileReader reader = new FileReader("C:\\Users\\Admin\\Desktop\\小红书\\组合拼音.txt");
|
||||
// 读取到缓冲区
|
||||
BufferedReader br = new BufferedReader(reader);
|
||||
String line;
|
||||
List<LexiconPinyin> arrayList = new ArrayList<>();
|
||||
// 一次读入一行数据
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] split = line.split("\t");
|
||||
|
||||
LexiconPinyin lexiconPinyin = new LexiconPinyin();
|
||||
lexiconPinyin.setId(1L);
|
||||
lexiconPinyin.setPhoneticTranscription(split[0]);
|
||||
|
||||
if (split.length >= 2){
|
||||
List<String> list = new ArrayList<>();
|
||||
for (int i = 1; i < split.length; i++) {
|
||||
list.add(split[i]);
|
||||
}
|
||||
lexiconPinyin.setWords(JSONUtil.toJsonStr(list));
|
||||
}
|
||||
arrayList.add(lexiconPinyin);
|
||||
if (arrayList.size() >= 3000){
|
||||
lexiconPinyinMapper.insertAll(arrayList);
|
||||
arrayList.clear();
|
||||
}
|
||||
}
|
||||
if (CollUtil.isNotEmpty(arrayList)){
|
||||
lexiconPinyinMapper.insertAll(arrayList);
|
||||
}
|
||||
reader.close();
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Test
|
||||
public void readFile2() {
|
||||
try {
|
||||
FileReader reader = new FileReader("C:\\Users\\Admin\\Desktop\\小红书\\过滤词.txt");
|
||||
// 读取到缓冲区
|
||||
BufferedReader br = new BufferedReader(reader);
|
||||
String line;
|
||||
// 一次读入一行数据
|
||||
while ((line = br.readLine()) != null) {
|
||||
String[] split = line.split("\t");
|
||||
LexiconFilter lexiconFilter = new LexiconFilter();
|
||||
lexiconFilter.setSpeech(split[0]);
|
||||
lexiconFilter.setOrganizeId(6L);
|
||||
lexiconFilter.setOrganizeName("最高级");
|
||||
lexiconFilterMapper.insert(lexiconFilter);
|
||||
}
|
||||
}catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
package com.baiye.redis;
|
||||
|
||||
import com.baiye.core.util.RedisUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author YQY
|
||||
* @Date 2023/3/23
|
||||
*/
|
||||
@SpringBootTest
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class HashTest {
|
||||
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
@Test
|
||||
public void Test1(){
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("de", "[\"的\",\"地\",\"得\",\"德\",\"嘚\",\"徳\",\"锝\",\"脦\",\"悳\",\"淂\",\"鍀\",\"惪\",\"恴\",\"棏\"]");
|
||||
map.put("le", "[\"了\",\"乐\",\"叻\",\"肋\",\"樂\",\"楽\",\"仂\",\"泐\",\"簕\",\"饹\",\"竻\",\"砳\",\"玏\",\"鳓\",\"扐\",\"艻\",\"忇\",\"氻\",\"阞\",\"韷\",\"鰳\",\"餎\"]");
|
||||
|
||||
// redisUtils.hmset("chai", map);
|
||||
// Map<Object, Object> de = redisUtils.hmget("chai");
|
||||
// System.out.println(de);
|
||||
Object hget = redisUtils.hget("chai", "de");
|
||||
System.out.println(hget);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue