|
@@ -1,6 +1,6 @@
|
|
|
package com.tzld.piaoquan.ad.engine.commons.util;
|
|
|
|
|
|
-import org.xm.Similarity;
|
|
|
+// import org.xm.Similarity;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
@@ -13,6 +13,7 @@ public class ExtractorUtils {
|
|
|
public static double sigmoid(double x) {
|
|
|
return 1.0 / (1.0 + Math.exp(-x));
|
|
|
}
|
|
|
+
|
|
|
public static int findInsertPosition(double[] sortedArray, double target) {
|
|
|
int low = 0;
|
|
|
int high = sortedArray.length - 1;
|
|
@@ -36,47 +37,52 @@ public class ExtractorUtils {
|
|
|
|
|
|
return low; // 返回low作为插入点
|
|
|
}
|
|
|
- public static Double[] funcC34567ForTags(String tags, String title) {
|
|
|
- String[] tagsList = tags.split(",");
|
|
|
- int d1 = 0;
|
|
|
- List<String> d2 = new ArrayList<>();
|
|
|
- double d3 = 0.0;
|
|
|
- double d4 = 0.0;
|
|
|
-
|
|
|
- for (String tag : tagsList) {
|
|
|
- if (title.contains(tag)) {
|
|
|
- d1++;
|
|
|
- d2.add(tag);
|
|
|
- }
|
|
|
- double score = Similarity.conceptSimilarity(tag, title);
|
|
|
- if (score > d3) {
|
|
|
- d3 = score;
|
|
|
- }
|
|
|
- d4 += score;
|
|
|
- }
|
|
|
|
|
|
- d4 = (tagsList.length > 0) ? d4 / tagsList.length : d4;
|
|
|
+ public static Double[] funcC34567ForTags(String tags, String title) {
|
|
|
+ // String[] tagsList = tags.split(",");
|
|
|
+ // int d1 = 0;
|
|
|
+ // List<String> d2 = new ArrayList<>();
|
|
|
+ // double d3 = 0.0;
|
|
|
+ // double d4 = 0.0;
|
|
|
+ //
|
|
|
+ // for (String tag : tagsList) {
|
|
|
+ // if (title.contains(tag)) {
|
|
|
+ // d1++;
|
|
|
+ // d2.add(tag);
|
|
|
+ // }
|
|
|
+ // double score = Similarity.conceptSimilarity(tag, title);
|
|
|
+ // if (score > d3) {
|
|
|
+ // d3 = score;
|
|
|
+ // }
|
|
|
+ // d4 += score;
|
|
|
+ // }
|
|
|
+ //
|
|
|
+ // d4 = (tagsList.length > 0) ? d4 / tagsList.length : d4;
|
|
|
|
|
|
// 使用数组来返回多个值
|
|
|
- return new Double[]{(double) d1, d3, d4};
|
|
|
+ // return new Double[]{(double) d1, d3, d4};
|
|
|
+ return new Double[]{(double) 0.0, 0.0, 0.0};
|
|
|
}
|
|
|
- public static Double calDiv(double a, double b){
|
|
|
- if (a == 0 || b == 0){
|
|
|
+
|
|
|
+ public static Double calDiv(double a, double b) {
|
|
|
+ if (a == 0 || b == 0) {
|
|
|
return 0D;
|
|
|
}
|
|
|
return a / b;
|
|
|
}
|
|
|
- public static Double calLog(double a){
|
|
|
- if (a <= 0){
|
|
|
+
|
|
|
+ public static Double calLog(double a) {
|
|
|
+ if (a <= 0) {
|
|
|
return 0D;
|
|
|
}
|
|
|
return Math.log(a + 1.0);
|
|
|
}
|
|
|
- public static Double division(String s1, String s2, Map<String, String> maps){
|
|
|
+
|
|
|
+ public static Double division(String s1, String s2, Map<String, String> maps) {
|
|
|
double rate = 0.0;
|
|
|
- if (maps.containsKey(s1) && maps.containsKey(s2)){
|
|
|
+ if (maps.containsKey(s1) && maps.containsKey(s2)) {
|
|
|
Double d1 = Double.valueOf(maps.get(s1));
|
|
|
- if (isDoubleEqualToZero(d1)){
|
|
|
+ if (isDoubleEqualToZero(d1)) {
|
|
|
return rate;
|
|
|
}
|
|
|
Double d2 = Double.valueOf(maps.get(s2));
|
|
@@ -84,9 +90,10 @@ public class ExtractorUtils {
|
|
|
}
|
|
|
return rate;
|
|
|
}
|
|
|
- public static Double divisionDouble(Double d1, Double d2){
|
|
|
+
|
|
|
+ public static Double divisionDouble(Double d1, Double d2) {
|
|
|
double rate = 0.0;
|
|
|
- if (isDoubleEqualToZero(d1)){
|
|
|
+ if (isDoubleEqualToZero(d1)) {
|
|
|
return rate;
|
|
|
}
|
|
|
rate = d2 / d1;
|
|
@@ -100,7 +107,6 @@ public class ExtractorUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
public static double calculateVariance(List<Double> numbers) {
|
|
|
double average = numbers.stream()
|
|
|
.mapToDouble(Double::doubleValue)
|
|
@@ -131,7 +137,7 @@ public class ExtractorUtils {
|
|
|
|
|
|
for (int i = 0; i < numbers.size() - 1; i++) {
|
|
|
Double diff = 0.0;
|
|
|
- if (!isDoubleEqualToZero(numbers.get(i))){
|
|
|
+ if (!isDoubleEqualToZero(numbers.get(i))) {
|
|
|
diff = (numbers.get(i + 1) - numbers.get(i)) / numbers.get(i);
|
|
|
}
|
|
|
differences.add(diff);
|
|
@@ -168,7 +174,7 @@ public class ExtractorUtils {
|
|
|
if (bucket < 0) {
|
|
|
bucket = 0;
|
|
|
}
|
|
|
- return (int)bucket;
|
|
|
+ return (int) bucket;
|
|
|
}
|
|
|
|
|
|
// 针对大于1的数字,进行分桶。
|
|
@@ -180,7 +186,7 @@ public class ExtractorUtils {
|
|
|
if (bucket < 0) {
|
|
|
bucket = 0;
|
|
|
}
|
|
|
- return (int)bucket;
|
|
|
+ return (int) bucket;
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|