为了缩小安装包大小,忍痛去掉一些依赖

This commit is contained in:
rememberber
2024-11-29 00:22:50 +08:00
parent 478fc39fc5
commit 898720a79a
3 changed files with 126 additions and 126 deletions
+31 -31
View File
@@ -350,39 +350,39 @@
<version>${bcprov-jdk15on.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>${tika.version}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.tika</groupId>-->
<!-- <artifactId>tika-core</artifactId>-->
<!-- <version>${tika.version}</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <artifactId>slf4j-api</artifactId>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-langdetect-optimaize</artifactId>
<version>${tika.version}</version>
<exclusions>
<exclusion>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
</exclusion>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency>-->
<!-- <groupId>org.apache.tika</groupId>-->
<!-- <artifactId>tika-langdetect-optimaize</artifactId>-->
<!-- <version>${tika.version}</version>-->
<!-- <exclusions>-->
<!-- <exclusion>-->
<!-- <artifactId>guava</artifactId>-->
<!-- <groupId>com.google.guava</groupId>-->
<!-- </exclusion>-->
<!-- <exclusion>-->
<!-- <artifactId>slf4j-api</artifactId>-->
<!-- <groupId>org.slf4j</groupId>-->
<!-- </exclusion>-->
<!-- </exclusions>-->
<!-- </dependency>-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>com.fasterxml.jackson.core</groupId>-->
<!-- <artifactId>jackson-databind</artifactId>-->
<!-- <version>${jackson-databind.version}</version>-->
<!-- </dependency>-->
</dependencies>
@@ -1,42 +1,42 @@
package com.luoboduner.moo.tool.util;
import org.apache.tika.language.detect.LanguageDetector;
import org.apache.tika.language.detect.LanguageResult;
/**
* 语言检测工具类
* <p>
* 依赖 tika-core
* <p>
* https://mvnrepository.com/artifact/org.apache.tika/tika-core
* <p>
* https://tika.apache.org/
* <p>
*/
public class LanguageDetectorUtil {
private static final LanguageDetector detector = LanguageDetector.getDefaultLanguageDetector();
static {
try {
detector.loadModels();
} catch (Exception e) {
e.printStackTrace();
}
}
public static String detectLanguage(String text) {
LanguageResult result = detector.detect(text);
return result.getLanguage();
}
public static void main(String[] args) {
String text = "This is a test sentence.";
String language = detectLanguage(text);
System.out.println("Detected language: " + language);
text = "这是一个测试句子。";
language = detectLanguage(text);
System.out.println("Detected language: " + language);
}
}
//package com.luoboduner.moo.tool.util;
//
//import org.apache.tika.language.detect.LanguageDetector;
//import org.apache.tika.language.detect.LanguageResult;
//
///**
// * 语言检测工具类
// * <p>
// * 依赖 tika-core
// * <p>
// * https://mvnrepository.com/artifact/org.apache.tika/tika-core
// * <p>
// * https://tika.apache.org/
// * <p>
// */
//public class LanguageDetectorUtil {
//
// private static final LanguageDetector detector = LanguageDetector.getDefaultLanguageDetector();
//
// static {
// try {
// detector.loadModels();
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
//
// public static String detectLanguage(String text) {
// LanguageResult result = detector.detect(text);
// return result.getLanguage();
// }
//
// public static void main(String[] args) {
// String text = "This is a test sentence.";
// String language = detectLanguage(text);
// System.out.println("Detected language: " + language);
//
// text = "这是一个测试句子。";
// language = detectLanguage(text);
// System.out.println("Detected language: " + language);
// }
//}
@@ -1,53 +1,53 @@
package com.luoboduner.moo.tool.util;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import okhttp3.*;
import java.io.IOException;
public class MicrosoftTranslatorUtil {
private static final String SUBSCRIPTION_KEY = "YOUR_SUBSCRIPTION_KEY";
private static final String ENDPOINT = "YOUR_ENDPOINT";
private static final String LOCATION = "YOUR_RESOURCE_LOCATION";
private static final OkHttpClient httpClient = new OkHttpClient();
private static final ObjectMapper objectMapper = new ObjectMapper();
public static String translate(String text, String from, String to) throws IOException {
String url = ENDPOINT + "/translate?api-version=3.0&from=" + from + "&to=" + to;
RequestBody body = RequestBody.create(
MediaType.parse("application/json"),
"[{\"Text\": \"" + text + "\"}]"
);
Request request = new Request.Builder()
.url(url)
.post(body)
.addHeader("Ocp-Apim-Subscription-Key", SUBSCRIPTION_KEY)
.addHeader("Ocp-Apim-Subscription-Region", LOCATION)
.addHeader("Content-Type", "application/json")
.build();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
JsonNode jsonNode = objectMapper.readTree(response.body().string());
return jsonNode.get(0).get("translations").get(0).get("text").asText();
}
}
public static void main(String[] args) {
try {
String text = "Hello, world!";
String translatedText = translate(text, "en", "zh-Hans");
System.out.println("Translated text: " + translatedText);
} catch (IOException e) {
e.printStackTrace();
}
}
}
//package com.luoboduner.moo.tool.util;
//
//import com.fasterxml.jackson.databind.JsonNode;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import okhttp3.*;
//
//import java.io.IOException;
//
//public class MicrosoftTranslatorUtil {
//
// private static final String SUBSCRIPTION_KEY = "YOUR_SUBSCRIPTION_KEY";
// private static final String ENDPOINT = "YOUR_ENDPOINT";
// private static final String LOCATION = "YOUR_RESOURCE_LOCATION";
//
// private static final OkHttpClient httpClient = new OkHttpClient();
// private static final ObjectMapper objectMapper = new ObjectMapper();
//
// public static String translate(String text, String from, String to) throws IOException {
// String url = ENDPOINT + "/translate?api-version=3.0&from=" + from + "&to=" + to;
//
// RequestBody body = RequestBody.create(
// MediaType.parse("application/json"),
// "[{\"Text\": \"" + text + "\"}]"
// );
//
// Request request = new Request.Builder()
// .url(url)
// .post(body)
// .addHeader("Ocp-Apim-Subscription-Key", SUBSCRIPTION_KEY)
// .addHeader("Ocp-Apim-Subscription-Region", LOCATION)
// .addHeader("Content-Type", "application/json")
// .build();
//
// try (Response response = httpClient.newCall(request).execute()) {
// if (!response.isSuccessful()) {
// throw new IOException("Unexpected code " + response);
// }
//
// JsonNode jsonNode = objectMapper.readTree(response.body().string());
// return jsonNode.get(0).get("translations").get(0).get("text").asText();
// }
// }
//
// public static void main(String[] args) {
// try {
// String text = "Hello, world!";
// String translatedText = translate(text, "en", "zh-Hans");
// System.out.println("Translated text: " + translatedText);
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
//}