Skip to content

Commit 7c92e92

Browse files
update
1 parent 8a9f1e6 commit 7c92e92

File tree

11 files changed

+316
-32
lines changed

11 files changed

+316
-32
lines changed

src_code/README-Chinese.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ import java.io.IOException;
296296
import java.sql.SQLException;
297297

298298
public class MAIN1 {
299-
public static void main(String[] args) throws InterruptedException, SQLException, IOException {
299+
public static void main(String[] args) {
300300
// 准备文件对象
301301
File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv");
302302
// 使用 FDF 加载文件
@@ -334,4 +334,55 @@ public class MAIN1 {
334334

335335
```
336336

337+
* 能够针对DF数据集对象中的所有数值进行行或列数据的函数式更新,同时支持DF数据对象到矩阵之间的转换。
338+
339+
```java
340+
package zhao.algorithmMagic;
341+
342+
import zhao.algorithmMagic.operands.matrix.IntegerMatrix;
343+
import zhao.algorithmMagic.operands.table.DataFrame;
344+
import zhao.algorithmMagic.operands.table.FDataFrame;
345+
import zhao.algorithmMagic.operands.table.FieldCell;
346+
import zhao.algorithmMagic.operands.table.FinalCell;
347+
import zhao.algorithmMagic.operands.vector.IntegerVector;
348+
349+
import java.io.File;
350+
351+
public class MAIN1 {
352+
public static void main(String[] args) {
353+
// 准备文件对象
354+
File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv");
355+
// 使用 FDF 加载文件
356+
DataFrame execute1 = FDataFrame.builder(file)
357+
// 文件对象的读取需要指定文本分隔符
358+
.setSep(',')
359+
// 文件对象需要指定好列名称,不能使用 * 这里代表的不是查询,而是创建一个DF的列字段
360+
.create("id", "name", "sex")
361+
// 文件对象的主键指定允许使用列名称
362+
.primaryKey("name")
363+
// 执行查询
364+
.execute()
365+
// 为列起别名
366+
.select(
367+
FieldCell.$("id"),
368+
FieldCell.$("name").as("名称"),
369+
FieldCell.$("sex").as("性别")
370+
)
371+
// 将性别列进行转换,男生为1 女生为0
372+
.updateCol(FieldCell.$("性别"), cell -> new FinalCell<>(cell.getStringValue().equals("") ? 1 : 0))
373+
// 将行主键数值为ZLY的数据行中的所有单元格替换成为数据 405
374+
.updateRow("ZLY", cell -> new FinalCell<>(405));
375+
376+
// 打印出表中的行主键名称为 405 的数据行
377+
System.out.println(execute1.selectRow("405"));
378+
long start = System.currentTimeMillis();
379+
// 将表转换成为一个整形矩阵对象,该操作会将DF对象中的所有数值试图转换成为 col.count()*3 的矩阵对象
380+
IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3);
381+
System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2)));
382+
System.out.print("处理耗时(MS):");
383+
System.out.println(System.currentTimeMillis() - start);
384+
}
385+
}
386+
```
387+
337388
### Version update date : xx xx-xx-xx

src_code/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,4 +331,56 @@ public class MAIN1 {
331331
}
332332
```
333333

334+
* Capable of functional update of row or column data for all values in DF data set objects, and supports conversion from
335+
DF data objects to matrices.
336+
337+
```java
338+
package zhao.algorithmMagic;
339+
340+
import zhao.algorithmMagic.operands.matrix.IntegerMatrix;
341+
import zhao.algorithmMagic.operands.table.DataFrame;
342+
import zhao.algorithmMagic.operands.table.FDataFrame;
343+
import zhao.algorithmMagic.operands.table.FieldCell;
344+
import zhao.algorithmMagic.operands.table.FinalCell;
345+
import zhao.algorithmMagic.operands.vector.IntegerVector;
346+
347+
import java.io.File;
348+
349+
public class MAIN1 {
350+
public static void main(String[] args) {
351+
// 准备文件对象
352+
File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv");
353+
// 使用 FDF 加载文件
354+
DataFrame execute1 = FDataFrame.builder(file)
355+
// 文件对象的读取需要指定文本分隔符
356+
.setSep(',')
357+
// 文件对象需要指定好列名称,不能使用 * 这里代表的不是查询,而是创建一个DF的列字段
358+
.create("id", "name", "sex")
359+
// 文件对象的主键指定允许使用列名称
360+
.primaryKey("name")
361+
// 执行查询
362+
.execute()
363+
// 为列起别名
364+
.select(
365+
FieldCell.$("id"),
366+
FieldCell.$("name").as("名称"),
367+
FieldCell.$("sex").as("性别")
368+
)
369+
// 将性别列进行转换,男生为1 女生为0
370+
.updateCol(FieldCell.$("性别"), cell -> new FinalCell<>(cell.getStringValue().equals("") ? 1 : 0))
371+
// 将行主键数值为ZLY的数据行中的所有单元格替换成为数据 405
372+
.updateRow("ZLY", cell -> new FinalCell<>(405));
373+
374+
// 打印出表中的行主键名称为 405 的数据行
375+
System.out.println(execute1.selectRow("405"));
376+
long start = System.currentTimeMillis();
377+
// 将表转换成为一个整形矩阵对象,该操作会将DF对象中的所有数值试图转换成为 col.count()*3 的矩阵对象
378+
IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3);
379+
System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2)));
380+
System.out.print("处理耗时(MS):");
381+
System.out.println(System.currentTimeMillis() - start);
382+
}
383+
}
384+
```
385+
334386
### Version update date : xx xx-xx-xx

src_code/src/main/java/zhao/algorithmMagic/MAIN1.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package zhao.algorithmMagic;
22

3+
import zhao.algorithmMagic.operands.matrix.IntegerMatrix;
34
import zhao.algorithmMagic.operands.table.DataFrame;
45
import zhao.algorithmMagic.operands.table.FDataFrame;
56
import zhao.algorithmMagic.operands.table.FieldCell;
7+
import zhao.algorithmMagic.operands.table.FinalCell;
8+
import zhao.algorithmMagic.operands.vector.IntegerVector;
69

710
import java.io.File;
8-
import java.io.IOException;
9-
import java.sql.SQLException;
1011

1112
public class MAIN1 {
12-
public static void main(String[] args) throws InterruptedException, SQLException, IOException {
13+
public static void main(String[] args) {
1314
// 准备文件对象
1415
File file = new File("C:\\Users\\zhao\\Desktop\\out\\res1.csv");
1516
// 使用 FDF 加载文件
@@ -27,15 +28,18 @@ public static void main(String[] args) throws InterruptedException, SQLException
2728
FieldCell.$("id"),
2829
FieldCell.$("name").as("名称"),
2930
FieldCell.$("sex").as("性别")
30-
);
31-
// 打印出表中的所有信息数据
31+
)
32+
// 将性别列进行转换,男生为1 女生为0
33+
.updateCol(FieldCell.$("性别"), cell -> new FinalCell<>(cell.getStringValue().equals("男") ? 1 : 0))
34+
// 将行主键数值为ZLY的数据行中的所有单元格替换成为数据 405
35+
.updateRow("ZLY", cell -> new FinalCell<>(405));
36+
37+
// 打印出表中的行主键名称为 405 的数据行
38+
System.out.println(execute1.selectRow("405"));
3239
long start = System.currentTimeMillis();
33-
System.out.println(
34-
execute1
35-
.groupBy("性别")
36-
.count()
37-
.desc()
38-
);
40+
// 将表转换成为一个整形矩阵对象,该操作会将DF对象中的所有数值试图转换成为 col.count()*3 的矩阵对象
41+
IntegerMatrix parse = IntegerMatrix.parse(execute1, execute1.count().getIntValue(), 3);
42+
System.out.println(IntegerVector.parse(parse.getArrayByColIndex(2)));
3943
System.out.print("处理耗时(MS):");
4044
System.out.println(System.currentTimeMillis() - start);
4145
}

src_code/src/main/java/zhao/algorithmMagic/operands/matrix/DoubleMatrix.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import zhao.algorithmMagic.core.ASDynamicLibrary;
44
import zhao.algorithmMagic.exception.OperatorOperationException;
5+
import zhao.algorithmMagic.operands.table.Cell;
6+
import zhao.algorithmMagic.operands.table.DataFrame;
7+
import zhao.algorithmMagic.operands.table.Series;
58
import zhao.algorithmMagic.operands.vector.DoubleVector;
69
import zhao.algorithmMagic.utils.ASClass;
710
import zhao.algorithmMagic.utils.ASMath;
@@ -148,6 +151,40 @@ protected static void ex(double thresholdLeft, double thresholdRight, double[][]
148151
}
149152
}
150153

154+
/**
155+
* 将一个DF数据对象中的所有单元格数据转换成为一个指定行列长度的数值类型的矩阵对象。
156+
* <p>
157+
* Converts all cell data in a DF data object into a matrix object of numeric type with specified row and column length.
158+
*
159+
* @param dataFrame 需要被进行转换的 DF 数据对象。
160+
* <p>
161+
* DF data object to be converted.
162+
* @param height 转换之后的新矩阵的高度。
163+
* <p>
164+
* The height of the new matrix after conversion.
165+
* @param width 转换之后的新矩阵的宽度。
166+
* <p>
167+
* The width of the new matrix after conversion.
168+
* @return 转换成功后会返回一个数值类型的矩阵对象。
169+
* <p>
170+
* A matrix object of numeric type will be returned after successful conversion.
171+
*/
172+
public static DoubleMatrix parse(DataFrame dataFrame, int height, int width) {
173+
double[][] doubles = new double[height][width];
174+
int h = -1;
175+
for (Series cells : dataFrame) {
176+
if (++h > height) break;
177+
double[] row = doubles[h];
178+
int w = -1;
179+
for (Cell<?> cell : cells) {
180+
if (cell.isNumber() && ++w < width) {
181+
row[w] = cell.getDoubleValue();
182+
}
183+
}
184+
}
185+
return parse(doubles);
186+
}
187+
151188
/**
152189
* 获取到矩阵中指定坐标点的数值
153190
*

src_code/src/main/java/zhao/algorithmMagic/operands/matrix/IntegerMatrix.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
import zhao.algorithmMagic.core.ASDynamicLibrary;
44
import zhao.algorithmMagic.exception.OperatorOperationException;
5+
import zhao.algorithmMagic.operands.table.Cell;
6+
import zhao.algorithmMagic.operands.table.DataFrame;
7+
import zhao.algorithmMagic.operands.table.Series;
58
import zhao.algorithmMagic.operands.vector.IntegerVector;
69
import zhao.algorithmMagic.utils.ASClass;
710
import zhao.algorithmMagic.utils.ASIO;
@@ -174,6 +177,40 @@ protected static void ex(double thresholdLeft, double thresholdRight, int[][] in
174177
}
175178
}
176179

180+
/**
181+
* 将一个DF数据对象中的所有单元格数据转换成为一个指定行列长度的数值类型的矩阵对象。
182+
* <p>
183+
* Converts all cell data in a DF data object into a matrix object of numeric type with specified row and column length.
184+
*
185+
* @param dataFrame 需要被进行转换的 DF 数据对象。
186+
* <p>
187+
* DF data object to be converted.
188+
* @param height 转换之后的新矩阵的高度。
189+
* <p>
190+
* The height of the new matrix after conversion.
191+
* @param width 转换之后的新矩阵的宽度。
192+
* <p>
193+
* The width of the new matrix after conversion.
194+
* @return 转换成功后会返回一个数值类型的矩阵对象。
195+
* <p>
196+
* A matrix object of numeric type will be returned after successful conversion.
197+
*/
198+
public static IntegerMatrix parse(DataFrame dataFrame, int height, int width) {
199+
int[][] ints = new int[height][width];
200+
int h = -1;
201+
for (Series cells : dataFrame) {
202+
if (++h >= height) break;
203+
int[] row = ints[h];
204+
int w = -1;
205+
for (Cell<?> cell : cells) {
206+
if (++w < width && cell.isNumber()) {
207+
row[w] = cell.getIntValue();
208+
}
209+
}
210+
}
211+
return parse(ints);
212+
}
213+
177214
/**
178215
* 将两个操作数进行求和的方法,具体用法请参阅API说明。
179216
* <p>

src_code/src/main/java/zhao/algorithmMagic/operands/table/DataFrame.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package zhao.algorithmMagic.operands.table;
22

3+
import zhao.algorithmMagic.utils.transformation.Transformation;
4+
35
import java.io.Serializable;
46

57
/**
@@ -157,6 +159,34 @@ public interface DataFrame extends AggDataFrameData, Iterable<Series>, Serializa
157159
*/
158160
DataFrame insert(Series... rowSeries);
159161

162+
/**
163+
* 将一列字段对应的所有数据按照指定的函数进行更新。
164+
* <p>
165+
* Update all data corresponding to a column of fields according to the specified function.
166+
*
167+
* @param fieldCell 需要被提取的列字段名称。
168+
* <p>
169+
* The name of the column field to be extracted.
170+
* @return 更新之后的DF数据对象。
171+
* <p>
172+
* DF data object after update.
173+
*/
174+
DataFrame updateCol(FieldCell fieldCell, Transformation<Cell<?>, Cell<?>> transformation);
175+
176+
/**
177+
* 将一行字段对应的所有数据按照指定的函数进行更新。
178+
* <p>
179+
* Update all data corresponding to a column of fields according to the specified function.
180+
*
181+
* @param rowName 需要被提取的列字段名称。
182+
* <p>
183+
* The name of the column field to be extracted.
184+
* @return 更新之后的DF数据对象。
185+
* <p>
186+
* DF data object after update.
187+
*/
188+
DataFrame updateRow(String rowName, Transformation<Cell<?>, Cell<?>> transformation);
189+
160190
/**
161191
* 将计算结果输出到指定的目录的文本文件中。
162192
* <p>

0 commit comments

Comments
 (0)