团队冲刺第二阶段8
图片识别后生成的结果乱,所以导致识别内容获取关键字不准确,于是我进行了文本分隔和导入本地txt文本文件
再从字节流读取关键字,优化了 程序:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package com.baidu.ai.aip.auth;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;import java.util.Set;import java.util.stream.Collectors;import java.util.stream.Stream;import java.io.File;import java.util.HashMap;import java.util.Iterator;import java.util.Map;import java.util.Map.Entry;@SuppressWarnings("rawtypes")public class text{ private Map map; public text(){ this.map=new HashMap(); } public Map getMap() { return map; } @SuppressWarnings("unchecked") public text addRegulation(String oldStr, String newStr){ this.map.put(oldStr, newStr); return this; } static String path = "D:\\photo"; String[] files1 = { "动物-猫", "人", "植物", "动物-狗", "商品"}; String suffixName1 = "云端智能相册"; public static void multiFloder(String path, String[] files, String suffixName){ String filename = "1"; for(int i = 0; i<files.length;i++){ filename = (i+1)+"-"+files[i]; File f = new File(path+"\\"+filename+suffixName); f.mkdirs(); System.out.println("创建文件夹成功!"); } } /** * 读取txt文件的内容 * @param file 想要读取的文件对象 * @return 返回文件内容 * @throws IOException */ private static final Set<String> shopType= Stream.of( "动物-猫", "人", "植物", "动物-狗", "商品" ).collect(Collectors.toSet()); public static void main(String[] args) throws IOException{ text.multiFloder(path, args, path); File file = new File("C:\\Users\\86188\\Desktop\\图片识别.txt"); BufferedReader br = new BufferedReader(new FileReader(file)); String line = null; while((line = br.readLine())!= null){ //一次读取一行 String regexp = "\""; line = line.replaceAll(regexp, " "); System.out.println(line); String[] tmp = line.split("result_num :5}"); //根据result将每行数据拆分成一个数组 for(int i=0; i<tmp.length; i++){ //String me = tmp[i].substring(tmp[i].indexOf("root :"),tmp[i].indexOf("'keyword :'")); String me = tmp[i].substring(0,50); //String me = tmp[i]; Set<String> name = getShoesType(me); System.out.println(name);} } _fileUtil.main(args); br.close(); } private static Set<String> getShoesType (String message){ Set<String> clothesTypeSet = shopType.stream() .filter(clothesType -> message.contains(clothesType)).collect(Collectors.toSet()); return clothesTypeSet; }} |

浙公网安备 33010602011771号