Skip to content

Commit 09349d5

Browse files
update
1 parent 5300e2b commit 09349d5

File tree

11 files changed

+215
-57
lines changed

11 files changed

+215
-57
lines changed

src_code/README-Chinese.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ import java.sql.SQLException;
665665

666666

667667
public class MAIN1 {
668-
public static void main(String[] args) throws SQLException {
668+
public static void main(String[] args) {
669669
// 将一些图像文件转换成为一个图像矩阵对象
670670
ColorMatrix colorMatrix1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test2.bmp");
671671
// 对图像进行二值化
@@ -677,4 +677,42 @@ public class MAIN1 {
677677
}
678678
```
679679

680+
* 支持列的添加,但是需要注意的是列的添加会返回一个新的 DataFrame DF中的数据将会被浅拷贝出来。
681+
682+
```java
683+
package zhao.algorithmMagic;
684+
685+
import zhao.algorithmMagic.operands.table.*;
686+
687+
import java.sql.SQLException;
688+
689+
public class MAIN1 {
690+
public static void main(String[] args) {
691+
// 创建一个空的 DataFrame 对象
692+
FDataFrame select = FDataFrame.select(
693+
FieldCell.parse("id", "name", "sex", "age"), 1
694+
);
695+
// 手动插入数据
696+
select.insert(
697+
FinalSeries.parse("1", "zhao", "M", "19"),
698+
FinalSeries.parse("2", "tang", "W", "18"),
699+
FinalSeries.parse("3", "yang", "W", "20"),
700+
FinalSeries.parse("4", "shen", "W", "19")
701+
);
702+
// 打印出 DF 对象有关的信息
703+
System.out.println(
704+
select.desc()
705+
);
706+
// 添加一列数据,用于表示年龄是否为偶数
707+
DataFrame ageIsE = select.insertColGetNew(
708+
// 新列的列名称
709+
FieldCell.$("AgeIsE"),
710+
// 新列的数值生成逻辑 如果第 4 列(index == 3)的数值 % 2 == 0 就是true
711+
cells -> cells.getCell(3).getIntValue() % 2 == 0 ? new FinalCell<>(true) : new FinalCell<>(false)
712+
);
713+
System.out.println(ageIsE);
714+
}
715+
}
716+
```
717+
680718
### Version update date : xx xx-xx-xx

src_code/README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,16 +667,55 @@ import java.sql.SQLException;
667667

668668

669669
public class MAIN1 {
670-
public static void main(String[] args) throws SQLException {
670+
public static void main(String[] args) {
671671
// 将一些图像文件转换成为一个图像矩阵对象
672672
ColorMatrix colorMatrix1 = ColorMatrix.parseGrayscale("C:\\Users\\Liming\\Desktop\\fsdownload\\test2.bmp");
673673
// 对图像进行二值化
674-
colorMatrix1.globalBinary(ColorMatrix._G_, 100 , 0xffffff, 0);
674+
colorMatrix1.globalBinary(ColorMatrix._G_, 100, 0xffffff, 0);
675675
colorMatrix1.show("腐蚀之前的 image");
676676
// 开始对图像矩阵进行腐蚀操作
677677
colorMatrix1.erode(2, 2, false).show("腐蚀之后的 image");
678678
}
679679
}
680680
```
681681

682+
* The addition of columns is supported, but it should be noted that the addition of columns will return a new DataFrame
683+
DF in which the data will be lightly copied.
684+
685+
```java
686+
package zhao.algorithmMagic;
687+
688+
import zhao.algorithmMagic.operands.table.*;
689+
690+
import java.sql.SQLException;
691+
692+
public class MAIN1 {
693+
public static void main(String[] args) {
694+
// 创建一个空的 DataFrame 对象
695+
FDataFrame select = FDataFrame.select(
696+
FieldCell.parse("id", "name", "sex", "age"), 1
697+
);
698+
// 手动插入数据
699+
select.insert(
700+
FinalSeries.parse("1", "zhao", "M", "19"),
701+
FinalSeries.parse("2", "tang", "W", "18"),
702+
FinalSeries.parse("3", "yang", "W", "20"),
703+
FinalSeries.parse("4", "shen", "W", "19")
704+
);
705+
// 打印出 DF 对象有关的信息
706+
System.out.println(
707+
select.desc()
708+
);
709+
// 添加一列数据,用于表示年龄是否为偶数
710+
DataFrame ageIsE = select.insertColGetNew(
711+
// 新列的列名称
712+
FieldCell.$("AgeIsE"),
713+
// 新列的数值生成逻辑 如果第 4 列(index == 3)的数值 % 2 == 0 就是true
714+
cells -> cells.getCell(3).getIntValue() % 2 == 0 ? new FinalCell<>(true) : new FinalCell<>(false)
715+
);
716+
System.out.println(ageIsE);
717+
}
718+
}
719+
```
720+
682721
### Version update date : xx xx-xx-xx
Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
package zhao.algorithmMagic;
2-
3-
import zhao.algorithmMagic.operands.table.FDataFrame;
4-
import zhao.algorithmMagic.operands.table.FinalSeries;
5-
6-
import java.sql.SQLException;
2+
import zhao.algorithmMagic.operands.table.*;
73

84
public class MAIN1 {
9-
public static void main(String[] args) throws SQLException {
5+
public static void main(String[] args) {
106
// 创建一个空的 DataFrame 对象
117
FDataFrame select = FDataFrame.select(
12-
FinalSeries.parse("id", "name", "sex", "age"), 1
8+
FieldCell.parse("id", "name", "sex", "age"), 1
139
);
1410
// 手动插入数据
1511
select.insert(
1612
FinalSeries.parse("1", "zhao", "M", "19"),
17-
FinalSeries.parse("1", "tang", "W", "18"),
18-
FinalSeries.parse("1", "yang", "W", "20")
13+
FinalSeries.parse("2", "tang", "W", "18"),
14+
FinalSeries.parse("3", "yang", "W", "20"),
15+
FinalSeries.parse("4", "shen", "W", "19")
1916
);
20-
21-
System.out.println(select);
17+
// 将数据的HTML网页表格输出到磁盘中
18+
select.into_outHtml("C:\\Users\\zhao\\Desktop\\out\\res.html", "数据表名称");
2219
}
2320
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1100,7 +1100,7 @@ public void globalBinary(byte Mode, int colorBoundary, int trueColor, int falseC
11001100
/**
11011101
* 基于坐标周边点进行图像二值化的计算,该操作与全局二值化操作做之间最大的差别在于,其中的与阈值进行比对的数值并不是所有坐标点,而是当前坐标点的周边坐标点的对应通道的颜色数值,能够有效的将二值化体现出来。
11021102
* <p>
1103-
* The biggest difference between the calculation of image binarization based on coordinate peripheral points and the global binarization operation is that the value compared to the threshold value is not all coordinate points, but the color value of the corresponding channel of the peripheral coordinate points of the current coordinate point, which can effectively reflect binarization.
1103+
* The biggest difference between the calculation of image binary based on coordinate peripheral points and the global binary operation is that the value compared to the threshold value is not all coordinate points, but the color value of the corresponding channel of the peripheral coordinate points of the current coordinate point, which can effectively reflect binary.
11041104
*
11051105
* @param Mode 在进行通道色彩的获取的时候,需要指定规整时的颜色通道标准,在指定通道的基础上进行规整,该参数可以直接从 ColorMatrix 类中获取到。
11061106
* <p>

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ public interface DataFrame extends AggDataFrameData, Iterable<Series>, Serializa
168168
*/
169169
DataFrame insert(Series... rowSeries);
170170

171+
/**
172+
* 以当前数据集为基准,添加一列新数据,并将添加列数据之后的 Data Frame 对象返回出来。
173+
* <p>
174+
* Based on the current dataset, add a new column of data, and return the Data Frame object after adding the column data.
175+
*
176+
* @param fieldName 需要被添加的列数据所对应的列名称,要求不得与已有的DataFrame字段名称重名!
177+
* <p>
178+
* The column name corresponding to the column data to be added must not duplicate the existing DataFrame field name!
179+
* @param transformation 在添加的列新数据的过程中,提供一个新数据的生成函数,函数中的参数是每行数据的系列对象,您可以根据行数据生成新数值,也可以根据自己的规则生成新数据。
180+
* <p>
181+
* During the process of adding new data for a column, a new data generation function is provided. The parameters in the function are a series of objects for each row of data. You can generate new values based on the row data or generate new data based on your own rules.
182+
* @return 添加了列字段与列数据之后的DataFrame对象。
183+
* <p>
184+
* The DataFrame object after adding column fields and column data.
185+
*/
186+
DataFrame insertColGetNew(FieldCell fieldName, Transformation<Series, Cell<?>> transformation);
187+
171188
/**
172189
* 将一列字段对应的所有数据按照指定的函数进行更新。
173190
* <p>

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

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ public DataFrame where(Condition whereClause) {
311311
for (Series cells : this.list) {
312312
if (whereClause.isComplianceEvents(cells)) arrayList.add(cells);
313313
}
314-
return new FDataFrame(this.colNameRow, this.primaryIndex, arrayList.toArray(new Series[0]))
314+
return new FDataFrame(this.colNameRow, this.primaryIndex, arrayList)
315315
.refreshField(true, false);
316316
}
317317

@@ -440,7 +440,7 @@ public DataFrame insert(Series rowSeries) {
440440
*/
441441
@Override
442442
public DataFrame insert(Series... rowSeries) {
443-
int startLen = this.list.size() - 1;
443+
int startLen = this.list.size();
444444
this.list.addAll(Arrays.asList(rowSeries));
445445
// 增量更新行索引
446446
for (int i = startLen, count = 0; count < rowSeries.length; count++, i++) {
@@ -452,6 +452,38 @@ public DataFrame insert(Series... rowSeries) {
452452
return this;
453453
}
454454

455+
/**
456+
* 以当前数据集为基准,添加一列新数据,并将添加列数据之后的 Data Frame 对象返回出来。
457+
* <p>
458+
* Based on the current dataset, add a new column of data, and return the Data Frame object after adding the column data.
459+
*
460+
* @param fieldName 需要被添加的列数据所对应的列名称,要求不得与已有的DataFrame字段名称重名!
461+
* <p>
462+
* The column name corresponding to the column data to be added must not duplicate the existing DataFrame field name!
463+
* @param transformation 在添加的列新数据的过程中,提供一个新数据的生成函数,函数中的参数是每行数据的系列对象,您可以根据行数据生成新数值,也可以根据自己的规则生成新数据。
464+
* <p>
465+
* During the process of adding new data for a column, a new data generation function is provided. The parameters in the function are a series of objects for each row of data. You can generate new values based on the row data or generate new data based on your own rules.
466+
* @return 添加了列字段与列数据之后的DataFrame对象。
467+
* <p>
468+
* The DataFrame object after adding column fields and column data.
469+
*/
470+
@Override
471+
public DataFrame insertColGetNew(FieldCell fieldName, Transformation<Series, Cell<?>> transformation) {
472+
ArrayList<Series> arrayList = new ArrayList<>(this.list.size() + 10);
473+
for (Series cells : this.list) {
474+
arrayList.add(FinalSeries.merge(
475+
cells, transformation.function(cells)
476+
));
477+
}
478+
return new FDataFrame(
479+
FinalSeries.merge(this.colNameRow, fieldName),
480+
this.primaryIndex,
481+
arrayList,
482+
this.rowHashMap,
483+
new HashMap<>(this.colHashMap.size() + 1)
484+
);
485+
}
486+
455487
/**
456488
* 将一列字段对应的所有数据按照指定的函数进行更新。
457489
* <p>
@@ -563,7 +595,7 @@ public DataFrame into_outHtml(String outPath, String tableName) {
563595
bufferedWriter.newLine();
564596
bufferedWriter.write("<meta charset=\"UTF-8\"><title>");
565597
bufferedWriter.write(tableName);
566-
bufferedWriter.write("Title</title>");
598+
bufferedWriter.write("</title>");
567599
bufferedWriter.newLine();
568600
bufferedWriter.write("</head>");
569601
bufferedWriter.newLine();
@@ -608,27 +640,6 @@ public DataFrame into_outHtml(String outPath, String tableName) {
608640
return this;
609641
}
610642

611-
/**
612-
* Returns a string representation of the object. In general, the
613-
* {@code toString} method returns a string that
614-
* "textually represents" this object. The result should
615-
* be a concise but informative representation that is easy for a
616-
* person to read.
617-
* It is recommended that all subclasses override this method.
618-
* <p>
619-
* The {@code toString} method for class {@code Object}
620-
* returns a string consisting of the name of the class of which the
621-
* object is an instance, the at-sign character `{@code @}', and
622-
* the unsigned hexadecimal representation of the hash code of the
623-
* object. In other words, this method returns a string equal to the
624-
* value of:
625-
* <blockquote>
626-
* <pre>
627-
* getClass().getName() + '@' + Integer.toHexString(hashCode())
628-
* </pre></blockquote>
629-
*
630-
* @return a string representation of the object.
631-
*/
632643
@Override
633644
public String toString() {
634645
StringBuilder stringBuilder = new StringBuilder();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public FinalGroupTable(Series colNameRow, int primaryIndex, int index, DataFrame
4343
}
4444
hashMap = new HashMap<>();
4545
hashMap1.forEach((key, value) -> {
46-
hashMap.put(key, new FDataFrame(colNameRow, primaryIndex, value.toArray(new Series[0])));
46+
hashMap.put(key, new FDataFrame(colNameRow, primaryIndex, value));
4747
value.clear();
4848
});
4949
groupKey = colNameRow.getCell(index);
@@ -79,7 +79,7 @@ public FinalGroupTable(Series colNameRow, int primaryIndex, int index, DataFrame
7979
}
8080
hashMap = new HashMap<>();
8181
hashMap1.forEach((key, value) -> {
82-
hashMap.put(key, new FDataFrame(colNameRow, primaryIndex, value.toArray(new Series[0])));
82+
hashMap.put(key, new FDataFrame(colNameRow, primaryIndex, value));
8383
value.clear();
8484
});
8585
groupKey = colNameRow.getCell(index);

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

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

33
import zhao.algorithmMagic.exception.OperatorOperationException;
4+
import zhao.algorithmMagic.utils.ASClass;
45
import zhao.algorithmMagic.utils.Event;
56
import zhao.algorithmMagic.utils.transformation.Transformation;
67

@@ -32,6 +33,21 @@ public FinalSeries(Cell<?>... cells) {
3233
}
3334
}
3435

36+
/**
37+
* 将一个Series 和很多个单元格进行数据合并
38+
*
39+
* @param finalSeries 需要被合并的Series对象
40+
* @param cells 合需要被合并的所有单元格
41+
* @return 合并之后的数据对象
42+
*/
43+
public static FinalSeries merge(Series finalSeries, Cell<?>... cells) {
44+
Cell<?>[] cells1 = finalSeries.toArray();
45+
int length1 = cells1.length;
46+
Cell<?>[] res = new Cell[length1 + cells.length];
47+
ASClass.mergeArray(res, cells1, cells);
48+
return new FinalSeries(res);
49+
}
50+
3551
public static FinalSeries parse(String... arr) {
3652
return new FinalSeries(
3753
Arrays.stream(arr).map(FinalCell::new)

src_code/src/main/java/zhao/algorithmMagic/operands/vector/SparkVector.scala

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
7777
else throw new OperatorOperationException("'DoubleVector1 innerProduct DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + doubles1.length + "],DoubleVector2=[" + doubles2.length + "]\n" + "When 'DoubleVector1 innerProduct DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + doubles1.length + "], DoubleVector2=[" + doubles2.length + "]")
7878
}
7979

80-
/**
81-
*
82-
* @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
83-
*
84-
* Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
85-
*/
86-
override def copyToNewArray(): Array[Double] = vector.toArray
87-
8880
/**
8981
* @return 该类的实现类对象,用于拓展该接口的子类
9082
*/
@@ -115,6 +107,21 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
115107
else throw new OperatorOperationException("'DoubleVector1 add DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + numberOfDimensions1 + "],DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 add DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]")
116108
}
117109

110+
/**
111+
* @return 向量中包含的维度数量
112+
* <p>
113+
* the number of dimensions contained in the vector
114+
*/
115+
override def getNumberOfDimensions: Int = size
116+
117+
/**
118+
*
119+
* @return 将本对象中存储的向量序列数组拷贝到一个新数组并将新数组返回,这里返回的是一个新数组,支持修改等操作。
120+
*
121+
* Copy the vector sequence array stored in this object to a new array and return the new array. Here, a new array is returned, which supports modification and other operations.
122+
*/
123+
override def copyToNewArray(): Array[Double] = vector.toArray
124+
118125
/**
119126
* 在两个操作数之间做差的方法,具体用法请参阅API说明。
120127
* <p>
@@ -139,13 +146,6 @@ final class SparkVector(sparkContext: SparkContext, vector: org.apache.spark.mll
139146
else throw new OperatorOperationException("'DoubleVector1 diff DoubleVector2' 时,两个'DoubleVector'的向量所包含的数量不同,DoubleVector1=[" + numberOfDimensions1 + "],DoubleVector2=[" + numberOfDimensions2 + "]\n" + "When 'DoubleVector1 diff DoubleVector2', the two vectors of 'DoubleVector' contain different quantities, DoubleVector1=[" + numberOfDimensions1 + "], DoubleVector2=[" + numberOfDimensions2 + "]")
140147
}
141148

142-
/**
143-
* @return 向量中包含的维度数量
144-
* <p>
145-
* the number of dimensions contained in the vector
146-
*/
147-
override def getNumberOfDimensions: Int = size
148-
149149
/**
150150
*
151151
* @return 第三方向量中所维护的向量序列,通过此函数您可以直接获取到第三方库中的对象。

0 commit comments

Comments
 (0)