사용자:Yes0song/다지모/간체 번체간 자동 변환

※ 원문 : Automatic conversion between simplified and traditional Chinese



이 페이지는 현재 중국어 위키백과에서 사용중인 변환 시스템을 설명하고 있습니다. 이 시스템은 2005년 1월부터 중국어 커뮤니티에서 사용중입니다. 이 페이지의 중국어 시스템의 설명을 통해 이런 시스템에 관심이 있거나 도입하고자 하는 사람에게 도움이 되었으면 합니다.

현재 전환 체제의 문제점을 보려면 meta:Problems with server-side Chinese to Chinese translation in MediaWiki를 읽어 주십시오.

배경 편집

현재 중국에서는 2가지 방식의 쓰기 체제가 사용되고 있습니다 - 간체자번체자인데, 번체자는 타이완, 홍콩, 북미 이주민 사이에서 사용되고 있으며, 간체자는 중국 본토와 싱가포르에서 사용되고 있습니다.

차이점 예시
번체자 간체자Simplified


가장 변환 시스템은 중국 위키백과의 핵심적인 기능입니다. 서로 다른 인코딩(such as GB and BIG5)을 변환하기 위해 libiconv과 현재 통용되는 변환기가 있습니다. 하지만 현재 중국어 위키백과에서는 간체자와 번체자를 동시에 사용하는 유니코드 체제를 사용하고 있습니다. 대부분의 글자는 1:1로 치환이 가능하지만, 그렇지 않은 글자가 100쌍 정도 있습니다. 또한, 중국어에는 단어 사이의 띄어쓰기가 없기때문에 문장 분석을 더욱 힘들게 합니다.

완벽한 인공지능 전환 기능을 만들기는 어렵습니다. 따라서, 우리는 그 대신 새로운 마크업(markup) 기능으로 해결하였습니다.

기술적 설명 편집

변환 편집

중국의 변환 도구는 인공지능 기능 없이 단순합니다. 대신, it exploits the wiki nature of Wikipedia and other related projects to build community knowledge, as discussed later.

렌더링(render)될 때 페이지가 변환 됩니다. 페이지가 어떤 방언으로 쓰여저 있는지 관여하지 않기 때문에, 사실 페이지는 어떤 방언으로 써도 무관합니다.

현재는 4개의 방언을 지원하고 있습니다:

  • zh-cn (Mainland China)
  • zh-tw (Taiwan)
  • zh-hk (Hong Kong and Macao)
  • zh-sg (Singapore)

따라서, 이 시스템에는 각 방언마다 한개씩, 4개의 변환표가 들어 있습니다. 변환표는, 단순한 맵핑(mapping) 규칙으로 구성되어 있습니다. 예를들어 zh-cn에는, 이런 규칙이 들어 있을것입니다:

 => 

이것은 번체자인 國을 간체자인 国으로 변환합니다. 같은 계념을 나타내는 단어가 방언에 따라 다르게 나타나는 경우도 있으므로, 문장 전환 기능도 포함됩니다. 예를들어:

电脑 => 计算机

이 규칙은 타이완과 홍콩에서 컴퓨터를 뜻하는 电脑를 사용되는 중국 본토에서 해당 단어인 计算机로 전환해 줍니다.

초기의 변환표는 반자동으로 만들어졌습니다. 데이터 베이스는 간체자와 번체자를 mappings하는데 사용되었습니다. Three phrase dictionaries bundled with and libtabe were used to create the initial phrase mapping tables.

이러한 방법에서, 변환되어 져서는 안되는 몇몇 단어는, 자기 자신을 맵핑(mapping) 하였습니다. 예를들어:

电脑 => 电脑

위 구문은 단어 电脑의 변환을 방지합니다.

이러한 규칙을 (연상배열?)로 저장하였습니다. 변환은 php function strtr()으로 이루어 집니다.

띄어쓰기가 없으므로 의해 모호해 질 수 있는 단어는 시스템에 포함하지 않았습니다.


변환표 편집

분명하게 변환하기 위해선, 정확하고 완벽한 변환표가 필요합니다. 하지만, 현재 정확성와 완전성을 둘다 만족하는 표준변환표가 없습니다. 따라서, 중국 커뮤니티에서 표와 시스템을 후에 수정할 수 있도록 허용하였습니다. 수정 가능한 변환표는 MediaWiki: 표준 페이지에, 간단한 방식으로 저장되어 있습니다.

현재 중국 위키 정책에서는 변화를 적용하기 위해, 몇몇 정규 회원과 관리자에게 변집할 수 있는 권한을 부여하였습니다.

변환표 링크:

위키 링크 편집

중국어 위키백과에서 주로 발생하는 문제는 아티클의 제목이 방언에 따라 다르게 나타나서, 다른 방언간 아티클을 링크하는데 문제가 될 수 있다는 것입니다. The current implementation would attempt to find links in different variant form. 예를들어, zh-cn에서 몇몇 단어 "foo"는 zh-tw에서 "bar"와 동등합니다. 만약 누군가가 "foo"라는 제목으로 쓴다면, zh-tw유저는 해당 제목이 "bar"로 표기될 것입니다. 게다가 타이완 유저가 [[bar]]라는 링크를 만들었을 경우 자동적으로 "foo"로 링크가 되어야합니다.

수동 마크업 편집

Sometimes a conversion rule is only used in rare situations. Putting such rules in the customizable tables incurrs unnecessary cost when processing other pages. Therefore a manual markup was implemented to allow manually specifying conversion rules in the wiki text. The general syntax of the markup is as follow:

-{language_code1: text1; language_code2: text2; ...}-

예를 들어:

-{zh-cn: 计算机; zh-tw: 电脑}-

언어 코드를 사용하지 않은, 아래 마크업은 변화되어서는 안되는 텍스트에 사용됩니다:

-{text not to be converted}-

아래와 같은 문장으로 변환 규칙을 아티클에 적용할 수 있습니다:

-{A|zh-cn:foo; zh-tw: bar}-

Any "foo" or "bar" in the remain of the text will be converted according to this rule. (This is in CVS HEAD but not in 1.4 yet.)


아티클의 내용에 이런 테그를 사용함으로서, 아티클 제목을 변환할 수 있습니다:

-{T|zh-cn: foo; zh-tw: bar}-

아티클을 나타낼 때, zh-cn 유저에게는 "foo"로, zh-tw 유저에게는 "bar"로 보일 것입니다.

또한, 이 마크업은 언어에 관계 없이 특정 제목으로 나타나게 합니다:

-{T|foo}-

이것은 제목이 하나의언어로 되어있거나, 첫번째 글자가 소문자일때 유용합니다.

두가지의 magic words 또한 제목이나 내용의 변환을 막기위해 도입되었습니다 :

  • : 제목의 자동 변환을 막습니다
  • : 내용의 자동 변환을 막습니다

Implementing similar conversion system for other languages 편집

In MediaWiki 1.4 편집

Most conversion related functions are implemented in the language object. For Chinese, this is in LanguageZh.php. At a minimal, the language object should override the following methods to support multiple variants:

  • getVariants
function getVariants() {
        return array('zh', 'zh-cn', 'zh-tw', 'zh-sg', 'zh-hk');
}

This function returns an array of language variants that's supported. There should exist language files for the supported variants.

  • getPreferredVariant()
function getPreferredVariant()

This function should return the user's preferred variant.

  • convert()
function convert( $text, $isTitle=false )

This function implements the actual conversion of the text. the flag isTitle signals whether the input text is the article title. In the Chinese, sometime titles are converted a bit differently. This function is called near the end of the parser (Parser.php). Anything that's parsed by the parser will be converted. Note that the parsing of the manual markup -{}- is also done in this function. This should probably be singled out so that other languages can reuse it easily.

  • getExtraHashOptions()
function  getExtraHashOptions() {
        $variant = $this->getPreferredVariant();
        return '!' . $variant ;	   
}

This function returns a string of the user's preferred language variant. It is used for caching purpose.

Note that some of these functions are not Chinese specific, for example getExtraHashOptions() and getPreferredVariant(), and the parsing code for the manual markup in convert(). Some code refactoring can be done if and when there is a need to implement conversion systems for other languages.

The code for supporting customizable conversion table is a bit messy currently. Code cleanup is underway and it's usage will be updated here shortly.

In MediaWiki 1.5 편집

The upcomming MediaWiki 1.5 will include a LanguageConverter object that encapsulates most conversion related functionalities. Conversion system for the Serbian language is being actively worked on, and a preliminary test site is up and running at

There is also a test site with conversion support for English, just for fun atm:

같이 읽기 편집

참조 링크 (중국어) 편집