|
|
@@ -0,0 +1,138 @@
|
|
|
+package top.zhixinghe1.money;
|
|
|
+
|
|
|
+import me.tongfei.progressbar.ProgressBar;
|
|
|
+import org.apache.commons.text.similarity.CosineSimilarity;
|
|
|
+import redis.clients.jedis.Jedis;
|
|
|
+import redis.clients.jedis.JedisPool;
|
|
|
+import redis.clients.jedis.Pipeline;
|
|
|
+import redis.clients.jedis.Response;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.Reader;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.BitSet;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Locale;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.TreeMap;
|
|
|
+import java.util.logging.SimpleFormatter;
|
|
|
+import java.util.regex.Matcher;
|
|
|
+import java.util.regex.Pattern;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class Test {
|
|
|
+ public static void main(String[] args) throws InterruptedException {
|
|
|
+// "QQ邮箱格式怎么写" "QQ邮箱格式如何写", 相似度约0.8
|
|
|
+// Map<CharSequence, Integer> leftVector = Arrays.asList("QQ", "邮箱", "格式", "怎么", "写").stream().collect(Collectors.toMap(v -> v, v -> 1));
|
|
|
+// Map<CharSequence, Integer> rightVector = Arrays.asList("QQ", "邮箱", "格式", "如何", "写").stream().collect(Collectors.toMap(v -> v, v -> 1));
|
|
|
+// CosineSimilarity cosineSimilarity = new CosineSimilarity();
|
|
|
+// long start = System.currentTimeMillis();
|
|
|
+// for (int i = 0; i < 300; i++) {
|
|
|
+// Double v = cosineSimilarity.cosineSimilarity(leftVector, rightVector);
|
|
|
+// }
|
|
|
+// System.out.println(System.currentTimeMillis() - start);
|
|
|
+
|
|
|
+
|
|
|
+// try (ProgressBar pb1 = new ProgressBar("文本聚合计算", 100)) {
|
|
|
+// for (int i = 0; i < 100; i++) {
|
|
|
+// Thread.sleep(1000);
|
|
|
+// pb1.step();
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+ JedisPool pool = new JedisPool("127.0.0.1", 6379);
|
|
|
+ try (Jedis jedis = pool.getResource()) {
|
|
|
+// // Store & Retrieve a simple string
|
|
|
+// jedis.set("foo", "bar");
|
|
|
+// String foo = jedis.get("foo");
|
|
|
+// System.out.println(); // prints bar
|
|
|
+//
|
|
|
+// // Store & Retrieve a HashMap
|
|
|
+// Map<String, String> hash = new HashMap<>();;
|
|
|
+// hash.put("name", "John");
|
|
|
+// hash.put("surname", "Smith");
|
|
|
+// hash.put("company", "Redis");
|
|
|
+// hash.put("age", "29");
|
|
|
+// jedis.hset("user-session:123", hash);
|
|
|
+// Map<String, String> stringStringMap = jedis.hgetAll("user-session:123");
|
|
|
+// System.out.println(stringStringMap);
|
|
|
+// // Prints: {name=John, surname=Smith, company=Redis, age=29}
|
|
|
+//
|
|
|
+// // 核心:获取分词列表 进行相似度计算
|
|
|
+// //长尾词获取
|
|
|
+// String word = jedis.hget("word", "1");
|
|
|
+// List<String> word1 = jedis.hmget("word", "1", "2");
|
|
|
+// // 管道使用
|
|
|
+// try (Pipeline pipelined = jedis.pipelined();) {
|
|
|
+// // 分词List获取
|
|
|
+//// pipelined.lpush("testList", "QQ");
|
|
|
+//// pipelined.lpush("testList", "邮箱");
|
|
|
+//// pipelined.lpush("testList", "格式");
|
|
|
+//// pipelined.lpush("testList", "怎么");
|
|
|
+//// pipelined.lpush("testList", "写");
|
|
|
+//// pipelined.sync();
|
|
|
+// List<String> testList = jedis.lrange("testList", 0L, -1L);
|
|
|
+//
|
|
|
+// // 批量获取、list对象为空
|
|
|
+//// pipelined.lpush("testList2", "QQ");
|
|
|
+//// pipelined.lpush("testList2", "邮箱");
|
|
|
+//// pipelined.lpush("testList2", "格式");
|
|
|
+//// pipelined.lpush("testList2", "如何");
|
|
|
+//// pipelined.lpush("testList2", "写");
|
|
|
+// pipelined.sync();
|
|
|
+// pipelined.lrange("testList", 0L, -1L);
|
|
|
+// pipelined.lrange("testList2", 0L, -1L);
|
|
|
+// pipelined.lrange("testList3", 0L, -1L);
|
|
|
+// List<Object> allResult = pipelined.syncAndReturnAll();
|
|
|
+//
|
|
|
+// // 倒排索引获取
|
|
|
+// pipelined.sadd("testIndex1", "1", "2", "3", "4");
|
|
|
+// pipelined.sadd("testIndex2", "2", "4", "5", "7");
|
|
|
+// pipelined.sync();
|
|
|
+// Set<String> sinter = jedis.sunion("testIndex1", "testIndex2");
|
|
|
+//
|
|
|
+// // 删除set中指定元素
|
|
|
+// long testIndex2 = jedis.srem("testIndex2", "4", "8");
|
|
|
+
|
|
|
+// // 批量删除key
|
|
|
+// Set<String> keys = jedis.keys("word*");
|
|
|
+// String[] array = keys.toArray(String[]::new);
|
|
|
+// jedis.del(array);
|
|
|
+// System.out.println("暂停");
|
|
|
+// }
|
|
|
+// TODO bitmap使用
|
|
|
+ jedis.setbit("testBit", 32, true);
|
|
|
+ jedis.setbit("testBit", 1, true);
|
|
|
+ jedis.setbit("testBit", 15, true);
|
|
|
+ jedis.setbit("testBit", 27, true);
|
|
|
+ List<Integer> list = Arrays.asList(1, 15, 27, 32);
|
|
|
+ for (Integer p : list) {
|
|
|
+ boolean testBit = jedis.getbit("testBit", p);
|
|
|
+ if (testBit) {
|
|
|
+ System.out.println(String.format("redis testBit 设置成功"));
|
|
|
+ } else {
|
|
|
+ System.out.println(String.format("redis testBit 设置失败"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BitSet bitSet = BitSet.valueOf(jedis.get("testBit").getBytes());
|
|
|
+ for (Integer p : list) {
|
|
|
+ boolean testBit = bitSet.get(p);
|
|
|
+ if (testBit) {
|
|
|
+ System.out.println(String.format("bitset testBit 设置成功"));
|
|
|
+ } else {
|
|
|
+ System.out.println(String.format("bitset testBit 设置失败"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("暂停");
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("暂停");
|
|
|
+ }
|
|
|
+}
|