|
8 | 8 |
|
9 | 9 | ### 更新日志
|
10 | 10 |
|
11 |
| -* 框架版本:1.24 - 1.25 |
12 |
| -* 更新版本号。 |
13 |
| -* 移除 RouteNet 接口中“不支持操作异常”针对外部项目的依赖,避免出现下面所列出的异常信息,此版本中无需获取“javax.ws.rs”的第三方依赖。 |
14 |
| - |
15 |
| -``` |
16 |
| -Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/NotSupportedException |
17 |
| - at zhao.algorithmMagic.MAIN1.main(MAIN1.java:38) |
18 |
| -Caused by: java.lang.ClassNotFoundException: javax.ws.rs.NotSupportedException |
19 |
| - at java.net.URLClassLoader.findClass(URLClassLoader.java:387) |
20 |
| - at java.lang.ClassLoader.loadClass(ClassLoader.java:418) |
21 |
| - at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355) |
22 |
| - at java.lang.ClassLoader.loadClass(ClassLoader.java:351) |
23 |
| - ... 1 more |
24 |
| -``` |
25 |
| - |
26 |
| -* 新增 Graphx 类,能够在基于线路网络类的前提下通过节点与边表进行图的构造,后期将会对此类新增诸多的操作函数。 |
| 11 | +* 框架版本:1.25 - 1.26 |
| 12 | +* 针对诸多的序列化操作,可以通过组件的方式来实现序列化,在IO组件库中已经集成了针对序列化对象IO的组件,下面就是一个示例。 |
27 | 13 |
|
28 | 14 | ```java
|
29 | 15 | package zhao.algorithmMagic;
|
30 | 16 |
|
31 |
| -import zhao.algorithmMagic.integrator.Route2DDrawingIntegrator; |
32 |
| -import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; |
33 |
| -import zhao.algorithmMagic.operands.coordinateNet.Graph; |
34 |
| -import zhao.algorithmMagic.operands.table.SingletonCell; |
| 17 | +import zhao.algorithmMagic.io.*; |
| 18 | +import zhao.algorithmMagic.operands.table.FDataFrame; |
| 19 | +import zhao.algorithmMagic.operands.table.FinalCell; |
| 20 | +import zhao.algorithmMagic.operands.table.SFDataFrame; |
| 21 | +import zhao.algorithmMagic.operands.table.SingletonSeries; |
35 | 22 |
|
| 23 | +import java.io.FileInputStream; |
| 24 | +import java.io.FileOutputStream; |
| 25 | +import java.io.IOException; |
| 26 | +import java.io.OutputStream; |
36 | 27 |
|
37 | 28 | public class MAIN1 {
|
38 |
| - public static void main(String[] args) { |
39 |
| - // 首先创建出两个节点的坐标 |
40 |
| - final IntegerCoordinateTwo c1 = new IntegerCoordinateTwo(-10, 2); |
41 |
| - final IntegerCoordinateTwo c2 = new IntegerCoordinateTwo(20, 20); |
42 |
| - // 然后创建两个节点数据的表 |
43 |
| - final Graph.GraphNodeDF nodeDF = Graph.GraphNodeDF.create( |
44 |
| - Graph.GraphNodeSeries.create(c1, SingletonCell.$("zhao"), SingletonCell.$("20")), |
45 |
| - Graph.GraphNodeSeries.create(c2, SingletonCell.$("TY"), SingletonCell.$("22")) |
46 |
| - ); |
47 |
| - // 然后创建出两个节点之间的边 |
48 |
| - final Graph.GraphEdgeDF edgeDF = Graph.GraphEdgeDF.create( |
49 |
| - // C1 <- 前任 -> C2 代表 C1的前任是C2 C2的前任是C1 |
50 |
| - Graph.GraphEdgeSeries.create(c1, c2, SingletonCell.$("前任")) |
51 |
| - ); |
52 |
| - // 最后创建图对象 |
53 |
| - final Graph parse = Graph.create(nodeDF, edgeDF); |
54 |
| - |
55 |
| - // 开始绘制图 首先准备线路绘图器 |
56 |
| - final Route2DDrawingIntegrator draw = new Route2DDrawingIntegrator("draw", parse); |
57 |
| - if (draw.setImageOutPath("C:\\Users\\zhao\\Desktop\\fsdownload\\res.jpg").run()) { |
58 |
| - System.out.println("ok!!!"); |
| 29 | + public static void main(String[] args) throws IOException { |
| 30 | +// System.out.println(OperationAlgorithmManager.VERSION); |
| 31 | +// if (args.length > 0) { |
| 32 | +// ASDynamicLibrary.addDllDir(new File(args[0])); |
| 33 | +// System.out.println(OperationAlgorithmManager.getAlgorithmStarUrl()); |
| 34 | +// } else { |
| 35 | +// System.out.println("感谢您的使用。"); |
| 36 | +// } |
| 37 | + |
| 38 | + |
| 39 | + // 创建一个对象输出组件 TODO 首先需要创建对应的数据输出流 |
| 40 | + final OutputStream outputStream = new FileOutputStream("C:\\Users\\zhao\\Downloads\\test\\res"); |
| 41 | + // 然后开始构建组件 |
| 42 | + final OutputComponent outputComponent = OutputObject.builder() |
| 43 | + // 在这里将数据流装载进去 |
| 44 | + .addOutputArg(OutputObjectBuilder.OUT_STREAM, new FinalCell<>(outputStream)) |
| 45 | + .create(); |
| 46 | + // 启动组件 |
| 47 | + if (outputComponent.open()) { |
| 48 | + // 如果启动成功就创建一个 DF 对象 |
| 49 | + final FDataFrame select = SFDataFrame.select( |
| 50 | + SingletonSeries.parse("name", "age"), 1 |
| 51 | + ); |
| 52 | + select.insert("zhao", "20").insert("tang", "22") |
| 53 | + // 使用组件将 DF 对象输出 |
| 54 | + .into_outComponent(outputComponent); |
59 | 55 | }
|
| 56 | + // 使用完毕就关闭组件 |
| 57 | + outputComponent.close(); |
| 58 | + |
| 59 | + // 当然,TODO 您也可以通过 InputObject 对象来实现反序列化。 |
| 60 | + // 如果您不习惯通过组件实现,也可以通过Java中的序列化方式来实现。 |
| 61 | + final InputComponent inputObject = InputObject.builder() |
| 62 | + .addInputArg(InputObjectBuilder.IN_STREAM, new FinalCell<>(new FileInputStream(""))) |
| 63 | + .create(); |
60 | 64 | }
|
61 | 65 | }
|
| 66 | + |
| 67 | + |
62 | 68 | ```
|
63 | 69 |
|
64 |
| -* 针对 Graph 类,我们可以通过 get 函数获取到 node 和 edge 的映射表。 |
| 70 | +* 通过简单的函数实现序列化,在 DF 对象中的 into_file 系列函数中,做了一些优化,其可以在最后接收一个布尔类型的参数来代表是否使用序列化输出。 |
65 | 71 |
|
66 | 72 | ```java
|
67 | 73 | package zhao.algorithmMagic;
|
68 | 74 |
|
69 |
| -import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo; |
70 |
| -import zhao.algorithmMagic.operands.coordinateNet.Graph; |
71 |
| -import zhao.algorithmMagic.operands.route.IntegerConsanguinityRoute2D; |
72 |
| -import zhao.algorithmMagic.operands.table.SingletonCell; |
| 75 | +import zhao.algorithmMagic.io.InputComponent; |
| 76 | +import zhao.algorithmMagic.io.InputObject; |
| 77 | +import zhao.algorithmMagic.io.InputObjectBuilder; |
| 78 | +import zhao.algorithmMagic.operands.table.DataFrame; |
| 79 | +import zhao.algorithmMagic.operands.table.FinalCell; |
| 80 | +import zhao.algorithmMagic.operands.table.SFDataFrame; |
73 | 81 |
|
74 |
| -import java.util.Collection; |
75 |
| -import java.util.HashMap; |
| 82 | +import java.io.FileInputStream; |
| 83 | +import java.io.IOException; |
76 | 84 |
|
77 | 85 | public class MAIN1 {
|
78 |
| - public static void main(String[] args) { |
79 |
| - // 首先创建出两个节点的坐标 |
80 |
| - final IntegerCoordinateTwo c1 = new IntegerCoordinateTwo(-10, 2), c2 = new IntegerCoordinateTwo(20, 20); |
81 |
| - // 然后创建图对象 |
82 |
| - final Graph parse = Graph.create( |
83 |
| - // 创建两个节点数据的表 |
84 |
| - Graph.GraphNodeDF.create( |
85 |
| - Graph.GraphNodeSeries.create(c1, SingletonCell.$("zhao"), SingletonCell.$("20")), |
86 |
| - Graph.GraphNodeSeries.create(c2, SingletonCell.$("TY"), SingletonCell.$("22")) |
87 |
| - ), |
88 |
| - // 创建出两个节点之间的边 |
89 |
| - Graph.GraphEdgeDF.create( |
90 |
| - // C1 <- 前任 -> C2 代表 C1的前任是C2 C2的前任是C1 |
91 |
| - Graph.GraphEdgeSeries.create(c1, c2, SingletonCell.$("前任")) |
92 |
| - ) |
93 |
| - ); |
94 |
| - // TODO 获取到图对象中的所有节点数据映射表 |
95 |
| - final HashMap<String, Graph.GraphNodeSeries> nodes = parse.getNodes(); |
96 |
| - // TODO 获取到图对象中的所有边数据映射表 |
97 |
| - final HashMap<String, Graph.GraphEdgeSeries> edges = parse.getEdges(); |
98 |
| - // TODO 获取到图中的所有边数据线路对象 |
99 |
| - final Collection<IntegerConsanguinityRoute2D> edgesRoute = parse.getEdgesRoute(); |
100 |
| - // 我们在这里打印其中的每个线路的信息 TODO 我们将通过线路中的数据从映射表中取出详细数据 |
101 |
| - /* |
102 |
| - * nodes映射表中的数据 |
103 |
| - * +----------+------------+ |
104 |
| - * | key | value | |
105 |
| - * +----------+------------+ |
106 |
| - * | (-10,2) | zhao | |
107 |
| - * | (20,20) | TY | |
108 |
| - * +----------+------------+ |
109 |
| - * |
110 |
| - * |
111 |
| - * edges映射表中的数据 |
112 |
| - * +----------------------------------+------------------------------------+ |
113 |
| - * | key | value | |
114 |
| - * +----------------------------------+------------------------------------+ |
115 |
| - * | (-10,2)(-10,2) -> (20,20)(20,20) | series [(-10,2), (20,20), 前任] | |
116 |
| - * +----------------------------------+------------------- ----------------+ |
117 |
| - * */ |
118 |
| - edgesRoute.forEach(edge -> { |
119 |
| - // 通过坐标名称 从节点映射表中 获取到起始节点与终止节点的数据Series |
120 |
| - final Graph.GraphNodeSeries start = nodes.get(edge.getStartingCoordinateName()); |
121 |
| - final Graph.GraphNodeSeries end = nodes.get(edge.getEndPointCoordinateName()); |
122 |
| - System.out.println( |
123 |
| - "当前线路:" + edge + '\n' + |
124 |
| - "起始点:" + edge.getStartingCoordinate() + |
125 |
| - // 由于上面构建节点Series的时候 第一个是坐标 第二个是名字 第三个是age |
126 |
| - // 所以在这里也是相同的格式 |
127 |
| - "\t名称:" + start.getCell(1).getValue() + '\n' + |
128 |
| - "终止点:" + edge.getEndPointCoordinate() + "\t名称:" + end.getCell(1) + '\n' + |
129 |
| - "两个点之间的关系: " + edges.get(edge.toString()) |
130 |
| - ); |
131 |
| - }); |
| 86 | + public static void main(String[] args) throws IOException { |
| 87 | + // 创建一个序列化数据输入组件 |
| 88 | + final InputComponent inputObject = InputObject.builder() |
| 89 | + .addInputArg(InputObjectBuilder.IN_STREAM, new FinalCell<>(new FileInputStream("C:\\Users\\zhao\\Downloads\\test\\res"))) |
| 90 | + .create(); |
| 91 | + // 从其中获取到 DF 对象 |
| 92 | + final DataFrame dataFrame = SFDataFrame.builder(inputObject); |
| 93 | + // 查看其中的数据 并通过最新的 简洁函数来实现序列化输出 |
| 94 | + dataFrame |
| 95 | + // TODO into 函数的结尾参数为 true 代表二进制输出 |
| 96 | + .into_outfile("C:\\Users\\zhao\\Downloads\\test\\res1", true) |
| 97 | + // 查看内容 |
| 98 | + .show(); |
| 99 | + // TODO 当然 into 函数的使用方式与之前一样,只是可以选择性的在结尾加上 true / false |
| 100 | + // 如果最后不加布尔数值或者为 false 代表就是使用文本的方式来输出 |
| 101 | + dataFrame |
| 102 | + .into_outfile("C:\\Users\\zhao\\Downloads\\test\\res2") |
| 103 | + .into_outfile("C:\\Users\\zhao\\Downloads\\test\\res3", ",") |
| 104 | + .into_outfile("C:\\Users\\zhao\\Downloads\\test\\res4", false); |
132 | 105 | }
|
133 | 106 | }
|
134 | 107 | ```
|
135 | 108 |
|
136 |
| -* 针对 Graphx 系列的 Series 类的构造中,如果配置项全是字符串,那么我们就可以不显式的指定 Cell 单元格构造,是的构造操作更加简洁。 |
| 109 | +* 新增颜色替换函数 |
137 | 110 |
|
138 | 111 | ```java
|
139 | 112 | package zhao.algorithmMagic;
|
140 | 113 |
|
141 | 114 | import zhao.algorithmMagic.operands.coordinate.IntegerCoordinateTwo;
|
142 |
| -import zhao.algorithmMagic.operands.coordinateNet.Graph; |
| 115 | +import zhao.algorithmMagic.operands.matrix.ColorMatrix; |
| 116 | +import zhao.algorithmMagic.operands.matrix.ImageMatrix; |
| 117 | +import zhao.algorithmMagic.utils.transformation.Transformation; |
| 118 | + |
| 119 | +import java.awt.*; |
143 | 120 |
|
144 | 121 | public class MAIN1 {
|
145 | 122 | public static void main(String[] args) {
|
146 |
| - // 首先创建出两个节点的坐标 |
147 |
| - final IntegerCoordinateTwo c1 = new IntegerCoordinateTwo(-10, 2), c2 = new IntegerCoordinateTwo(20, 20); |
148 |
| - // 然后创建图对象 |
149 |
| - final Graph parse = Graph.create( |
150 |
| - // 创建两个节点数据的表 TODO 在这里使用的是字符串,因此不需要使用 Cell 类的构造包装。 |
151 |
| - Graph.GraphNodeDF.create( |
152 |
| - Graph.GraphNodeSeries.create(c1, "zhao", "20"), |
153 |
| - Graph.GraphNodeSeries.create(c2, "TY", "22") |
154 |
| - ), |
155 |
| - // 创建出两个节点之间的边 TODO 在这里使用的是字符串,因此不需要使用 Cell 类的构造包装。 |
156 |
| - Graph.GraphEdgeDF.create( |
157 |
| - // C1 <- 前任 -> C2 代表 C1的前任是C2 C2的前任是C1 |
158 |
| - Graph.GraphEdgeSeries.create(c1, c2, "前任") |
159 |
| - ) |
| 123 | + Color color = new Color(239, 216, 194); |
| 124 | + |
| 125 | + // 实例化图片 |
| 126 | + ColorMatrix parse = ImageMatrix.parse("C:\\Users\\zhao\\Desktop\\Test\\无标题.jpg"); |
| 127 | + parse.show("原图"); |
| 128 | + |
| 129 | + // 进行颜色替换 将 标记的颜色做为被替换的颜色 |
| 130 | + parse = parse.colorReplace( |
| 131 | + // 设置需要被替换的颜色 |
| 132 | + color, |
| 133 | + // 设置替换操作进行时候的颜色转换逻辑 |
| 134 | + (Transformation<ColorMatrix, Color>) colors -> { |
| 135 | + // 使用 RGB 的均值做为替换颜色 |
| 136 | + return new Color( |
| 137 | + (int) colors.avg(ColorMatrix._R_), |
| 138 | + (int) colors.avg(ColorMatrix._G_), |
| 139 | + (int) colors.avg(ColorMatrix._B_) |
| 140 | + ); |
| 141 | + }, |
| 142 | + // 设置替换操作回调函数中接收到的范围 |
| 143 | + 1024, |
| 144 | + // 设置颜色阈值 与 color 颜色值的差小于此值代表需要替换 此值为 [0, 255] |
| 145 | + 32, |
| 146 | + new IntegerCoordinateTwo(453, 195), |
| 147 | + // 不使用拷贝,性能更好 |
| 148 | + false |
160 | 149 | );
|
| 150 | + parse.show("替换之后的结果"); |
161 | 151 | }
|
162 | 152 | }
|
163 | 153 | ```
|
164 | 154 |
|
165 |
| -* 针对 DataFrame 以及其有关的模块,在此次更新中,将使用统一的序列化版本号来实现序列化操作数对象在不同版本的AS库被重复解析和读取的能力,拓展灵活性。 |
166 |
| - |
167 |
| -```java |
168 |
| -package zhao.algorithmMagic; |
169 |
| - |
170 |
| -import zhao.algorithmMagic.algorithm.OperationAlgorithmManager; |
171 |
| -import zhao.algorithmMagic.operands.table.DataFrame; |
172 |
| -import zhao.algorithmMagic.operands.table.FDataFrame; |
173 |
| - |
174 |
| -import java.io.File; |
175 |
| -import java.io.FileInputStream; |
176 |
| -import java.io.IOException; |
177 |
| -import java.io.ObjectInputStream; |
178 |
| - |
179 |
| -public class MAIN1 { |
180 |
| - public static void main(String[] args) throws IOException, ClassNotFoundException { |
181 |
| - System.out.println(OperationAlgorithmManager.VERSION); |
182 |
| - final ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("path")); |
183 |
| - final DataFrame sfDataFrame = (FDataFrame) objectInputStream.readObject(); |
184 |
| - sfDataFrame.show(); |
185 |
| - } |
186 |
| -} |
187 |
| -``` |
188 |
| - |
189 |
| -### Version update date : xx xx-xx-xx |
| 155 | +### Version update date : 2023-12-15 |
0 commit comments