OpenCC

From LemonWiki共筆
Revision as of 12:32, 10 March 2023 by Unknown user (talk) (→‎Usage)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Install OpenCC on Centos7 Linux. OpenCC is the project for "conversion between Traditional and Simplified Chinese".

Installation[edit]

Install OpenCC on Centos7

  1. git clone https://github.com/BYVoid/OpenCC.git --depth 1
  2. Install GCC from repository sudo yum -y install gcc[1]
    • Verify the version of gcc because gcc 4.6 is required. gcc --version
  3. Install CMake from repository sudo yum -y install cmake
    • Verify the installation of CMake: Input cmake--version Expected result are as the following:
      cmake version 2.8.12.2
  4. Install Make from repository sudo yum -y install make
    • Verify the installation of Make: Input make--version Expected result are as the following:
      GNU Make 3.82 ... 
  5. Install Doxygen from repository sudo yum -y install doxygen
    • Verify the installation of doxygen: Input doxygen--version Expected result are as the following:
      1.8.5
  6. cd OpenCC
  7. make
  8. sudo make install
  9. (optional) sudo ln -s /usr/lib/libopencc.so.2 /usr/lib64/libopencc.so.2

To check if the opencc was installed successfully, run this command in your terminal:

opencc --version

Expected result are as the following. Notice the version number may not be the same with yours.

Open Chinese Convert (OpenCC) Command Line Tool
Version: 1.0.5

Usage[edit]

See the details on the page: GitHub - BYVoid/OpenCC: A project for conversion between Traditional and Simplified Chinese

Input/Output: characters

##  Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom
# echo "项目管理" | opencc -c s2twp
專案管理

## Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom
# echo "專案管理" | opencc -c tw2sp
项目管理

## Traditional Chinese (Taiwan Standard) to Simplified Chinese
# echo "專案管理" | opencc -c tw2s
专案管理

## Simplified Chinese to Traditional Chinese (Taiwan Standard) 
# echo "项目管理" | opencc -c s2tw
項目管理

## Convert the Traditional Chinese if converted from Simplified Chinese words not correctly
# echo "項目管理" | opencc -c tw2s | opencc -c s2twp
專案管理

Input/Output: file

## Convert the text file encoding with Simplified Chinese to Traditional Chinese (Taiwan Standard) 
#  opencc -i input.txt -o output.txt -c s2tw

Troubleshootings[edit]

cmake: command not found on CentOS[edit]

Error message:

$ make
mkdir -p build/rel
(cd build/rel; cmake \
-DBUILD_DOCUMENTATION:BOOL=ON \
-DENABLE_GTEST:BOOL=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
../..)
/bin/sh: line 1: cmake: command not found
make: *** [build] Error 127

Solution[2]:

  1. Install GCC from repository sudo yum -y install gcc
    • Verify the version of gcc because gcc 4.6 is required. gcc --version

Doxygen is needed to build the documentation[edit]

Error message:

$ make
mkdir -p build/rel
(cd build/rel; cmake \
-DBUILD_DOCUMENTATION:BOOL=ON \
-DENABLE_GTEST:BOOL=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/usr \
../..)
-- The CXX compiler identification is GNU 4.8.5
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE)
CMake Error at doc/CMakeLists.txt:4 (message):
  Doxygen is needed to build the documentation.  Please install it correctly


-- Configuring incomplete, errors occurred!
See also "/home/user/build/rel/CMakeFiles/CMakeOutput.log".
make: *** [build] Error 1

Solution:

  1. Install Doxygen from repository sudo yum -y install doxygen

opencc: error while loading shared libraries: libopencc.so.2: cannot open shared object file: No such file or directory[edit]

Error message:

$ opencc --version
opencc: error while loading shared libraries: libopencc.so.2: cannot open shared object file: No such file or directory

Solution:

  1. Keyin: sudo ln -s /usr/lib/libopencc.so.2 /usr/lib64/libopencc.so.2[3]

References[edit]