Skip to content

Commit

Permalink
Merge branch 'dict_headless_opt' into dev-0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kanedai committed Feb 29, 2024
2 parents aae1aee + 21efd66 commit 49c93c0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand All @@ -17,9 +19,9 @@
@Slf4j
@Component
public class FileHandlerImpl implements FileHandler {
public static final String FILE_SPILT = File.separator;

private final LocalFileConfig localFileConfig;

public FileHandlerImpl(LocalFileConfig localFileConfig) {
this.localFileConfig = localFileConfig;
}
Expand All @@ -31,8 +33,8 @@ public void backupFile(String fileName) {
createDir(dictDirectoryBackup);
}

String source = localFileConfig.getDictDirectoryLatest() + "/" + fileName;
String target = dictDirectoryBackup + "/" + fileName;
String source = localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName;
String target = dictDirectoryBackup + FILE_SPILT + fileName;
Path sourcePath = Paths.get(source);
Path targetPath = Paths.get(target);
try {
Expand Down Expand Up @@ -88,7 +90,7 @@ public void writeFile(List<String> lines, String fileName, Boolean append) {
if (!existPath(dictDirectoryLatest)) {
createDir(dictDirectoryLatest);
}
String filePath = dictDirectoryLatest + "/" + fileName;
String filePath = dictDirectoryLatest + FILE_SPILT + fileName;
if (existPath(filePath)) {
backupFile(fileName);
}
Expand Down Expand Up @@ -117,7 +119,7 @@ public String getDictRootPath() {
@Override
public Boolean deleteDictFile(String fileName) {
backupFile(fileName);
deleteFile(localFileConfig.getDictDirectoryLatest() + "/" + fileName);
deleteFile(localFileConfig.getDictDirectoryLatest() + FILE_SPILT + fileName);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.tencent.supersonic.headless.core.file;

import com.tencent.supersonic.headless.core.knowledge.helper.HanlpHelper;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.io.FileNotFoundException;

@Data
@Configuration
@Slf4j
Expand All @@ -18,16 +21,21 @@ public class LocalFileConfig {
private String dictDirectoryBackup;

public String getDictDirectoryLatest() {
return getResourceDir() + dictDirectoryLatest;
return getDictDirectoryPrefixDir() + dictDirectoryLatest;
}

public String getDictDirectoryBackup() {
return getResourceDir() + dictDirectoryBackup;
return getDictDirectoryPrefixDir() + dictDirectoryBackup;
}

private String getResourceDir() {
//return hanlpPropertiesPath = HanlpHelper.getHanlpPropertiesPath();
return ClassLoader.getSystemClassLoader().getResource("").getPath();
private String getDictDirectoryPrefixDir() {
try {
return HanlpHelper.getHanlpPropertiesPath();
} catch (FileNotFoundException e) {
log.warn("getDictDirectoryPrefixDir error: " + e);
e.printStackTrace();
}
return "";
}

}

0 comments on commit 49c93c0

Please sign in to comment.