1. What is OpenCC4J?
Opencc4j supports Chinese traditional and simplified conversion, taking into account the phrase level.
opencc4j is a version of java based on OpenCC’s tools.
Features
- Strictly distinguish between “one simple versus many” and “one simple versus many”.
- It is fully compatible with variant characters and can be dynamically replaced.
- Strictly review and revise a simple and complex entry, and the principle is “if it can be divided, it is not compatible”.
- The thesaurus and the function base are completely separated, and can be freely modified, imported, and expanded.
- Compatible with Windows, Linux, Mac platforms.
- Custom word segmentation is supported
- You can determine whether a single character (word) is simplified or traditional
- Simplified/Traditional lists in strings can be returned
- Support traditional and simplified Chinese conversion in Taiwan, China
2. Code engineering
Purpose of the experiment
- Traditional to Simplified
- Simplified to Traditional
pom.xml
<dependency>
<groupId>com.github.houbb</groupId>
<artifactId>opencc4j</artifactId>
<version>1.8.1</version>
</dependency>
Simplified
@RequestMapping("/toSimple")
public Map<String, Object> toSimple(String original){
Map<String, Object> map = new HashMap<>();
String result = ZhConverterUtil.toSimple(original);
map.put("original", original);
map.put("Simple", result);
return map;
}
Converted to Traditional
@RequestMapping("/toTraditional")
public Map<String, Object> toTraditional(String original){
Map<String, Object> map = new HashMap<>();
String result = ZhConverterUtil.toTraditional(original);
map.put("original", original);
map.put("Traditional", result);
return map;
}
The above are just some of the key codes, all of which can be found in the repositories below
Code repositories
3. Testing
- Start the Spring Boot application
- Convert to simple:http://127.0.0.1:8088/toSimple?original=%E7%94%9F%E5%91%BD%E4%B8%8D%E6%81%AF%EF%BC%8C%E5%A5%AE%E9%AC%A5%E4%B8%8D%E6%AD%A2
- Convert to traditional: http://127.0.0.1:8088/toTraditional?original=%E6%B5%8B%E8%AF%95