|
|
|
@ -1,3 +1,8 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2021 Anton Romanov - All Rights Reserved
|
|
|
|
|
* You may use, distribute and modify this code, please write to: romanov73@gmail.com.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package ru.ulstu.extractor.heuristic.service;
|
|
|
|
|
|
|
|
|
|
import com.gargoylesoftware.htmlunit.WebClient;
|
|
|
|
@ -9,11 +14,22 @@ import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
|
|
import static ru.ulstu.extractor.heuristic.service.DetectorService.LangDetectScrupulousness.LOW;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class DetectorService {
|
|
|
|
|
public enum LangDetectScrupulousness {LOW, HIGH}
|
|
|
|
|
|
|
|
|
|
private final static String BASE_URL = "http://localhost:8080/lang-detector.html";
|
|
|
|
|
|
|
|
|
|
public String getDetectedLanguage(String code) {
|
|
|
|
|
public String getDetectedLanguage(String fileName, String code, LangDetectScrupulousness scrupulousness) {
|
|
|
|
|
if (scrupulousness == LOW) {
|
|
|
|
|
return DirectoryService.getFileExtension(fileName).orElse("");
|
|
|
|
|
}
|
|
|
|
|
return getDetectedLanguage(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getDetectedLanguage(String code) {
|
|
|
|
|
String selectedLang = null;
|
|
|
|
|
try (WebClient webClient = new WebClient()) {
|
|
|
|
|
webClient.setJavaScriptTimeout(60 * 1000);
|
|
|
|
|