2.X/3. Dealing with Human Language

3-1-6. Mixed-Language Fields

drscg 2017. 9. 24. 17:42

Usually, documents that mix multiple languages in a single field come from sources beyond your control, such as pages scraped from the Web:

일반적으로, 하나의 field에 여러 가지 언어가 섞여 있는 document는, web에서 스크랩한 페이지처럼, 통제할 수 없는 소스에서 나타난다.

{ "body": "Page not found / Seite nicht gefunden / Page non trouvée" }

They are the most difficult type of multilingual document to handle correctly. Although you can simply use the standard analyzer on all fields, your documents will be less searchable than if you had used an appropriate stemmer. But of course, you can’t choose just one stemmer—stemmers are language specific. Or rather, stemmers are language and script specific. As discussed in 문자(script)별 형태소 분석기, if every language uses a different script, then stemmers can be combined.

그것들은, 여러 가지 언어로 된 document 중, 올바르게 처리하기가 가장 어려운 형태이다. 간단하게 모든 field에 standard analyzer를 사용할 수 있지만, 적절한 형태소 분석기를 사용한 경우보다, 검색 가능성이 더 적어진다. 그러나 물론, 형태소 분석기를 하나만 선택할 수는 없다. 형태소 분석기는 언어별이라기 보다는 오히려, 언어와 문자 별이다. 문자(script)별 형태소 분석기에서 이야기 했듯이, 모든 언어가 다른 문자를 사용한다면, 형태소 분석기는 조합될 수 있다.

Assuming that your mix of languages uses the same script such as Latin, you have three choices available to you:

언어의 섞임이 라틴어처럼 동일한 문자를 사용한다고 가정하면, 아래처럼 3가지 선택이 있을 수 있다.

  • Split into separate fields

    개별 field로 분할

  • Analyze multiple times

    여러 번 분석

  • Use n-grams

    n-grams 사용

Split into Separate Fieldsedit

The Compact Language Detector mentioned in Identifying Language can tell you which parts of the document are in which language. You can split up the text based on language and use the same approach as was used in One Language per Field.

Identifying Language에서 언급한, CLD를 이용하여, document의 어떤 부분이 어떤 언어로 되어 있는지 알 수 있다. 언어를 기반으로 문장(text)을 분할할 수 있고, One Language per Field에서 사용된 것과 동일한 방식을 사용할 수 있다.

Analyze Multiple Timesedit

If you primarily deal with a limited number of languages, you could use multi-fields to analyze the text once per language:

주로 제한된 수의 언어를 다룬다면, 언어별로 한번씩 문장(text)을 분석하여, 다중 field를 사용할 수 있다.

PUT /movies
{
  "mappings": {
    "title": {
      "properties": {
        "title": { 
          "type": "string",
          "fields": {
            "de": { 
              "type":     "string",
              "analyzer": "german"
            },
            "en": { 
              "type":     "string",
              "analyzer": "english"
            },
            "fr": { 
              "type":     "string",
              "analyzer": "french"
            },
            "es": { 
              "type":     "string",
              "analyzer": "spanish"
            }
          }
        }
      }
    }
  }
}

title field는 standard analyzer를 사용한다.

   

각 하위 field는, title field의 텍스트에 대해, 다른 언어로 된 analyzer를 적용한다.

Use n-gramsedit

You could index all words as n-grams, using the same approach as described in Ngrams for Compound Words. Most inflections involve adding a suffix (or in some languages, a prefix) to a word, so by breaking each word into n-grams, you have a good chance of matching words that are similar but not exactly the same. This can be combined with the analyze-multiple times approach to provide a catchall field for unsupported languages:

Ngrams for Compound Words에서 언급했던 것과 동일한 방식으로, 모든 단어를 n-grams으로 색인할 수 있다. 대부분의 어형 변화는 단어에 접미사(또는 어떤 언어에서는 접두사)를 추가한다.따라서 각 단어를 n-grams로 나누면, 유사한 단어를 일치시킬 좋은 기회가 된다. 하지만 정확하게 동일하지는 않다. 이 방식은 지원하지 않는 언어에 대해 예외(catch-all) field를 제공하기 위해, 여러 번 분석 하는 방식과 조합될 수 있다.

PUT /movies
{
  "settings": {
    "analysis": {...} 
  },
  "mappings": {
    "title": {
      "properties": {
        "title": {
          "type": "string",
          "fields": {
            "de": {
              "type":     "string",
              "analyzer": "german"
            },
            "en": {
              "type":     "string",
              "analyzer": "english"
            },
            "fr": {
              "type":     "string",
              "analyzer": "french"
            },
            "es": {
              "type":     "string",
              "analyzer": "spanish"
            },
            "general": { 
              "type":     "string",
              "analyzer": "trigrams"
            }
          }
        }
      }
    }
  }
}

analysis 부분에, Ngrams for Compound Words에서 언급한 것과 동일한 trigrams analyzer를 정의한다.

title.general field는, 다른 모든 언어를 색인 하기 위하여, trigrams analyzer를 사용한다.

When querying the catchall general field, you can use minimum_should_match to reduce the number of low-quality matches. It may also be necessary to boost the other fields slightly more than the general field, so that matches on the main language fields are given more weight than those on the general field:

예외(catch-all)인 general field를 검색하는 경우, 낮은 품질의 일치 건수를 줄이기 위해,minimum_should_match 를 사용할 수 있다. 주요 언어로 된 field에 일치하는 것들은 general field의 그것보다 많은 비중을 주기 위해, general field보다 다른 field에 약간 더 많은 가중치를 부여하는 것이 필요할 수도 있다.

GET /movies/movie/_search
{
    "query": {
        "multi_match": {
            "query":    "club de la lucha",
            "fields": [ "title*^1.5", "title.general" ], 
            "type":     "most_fields",
            "minimum_should_match": "75%" 
        }
    }
}

title 과 title.* field 모두에게는 title.general field 이상의 가중치가 주어진다.

minimum_should_match 매개변수는 반환되는 낮는 품질의 일치 건수를 줄인다. 특히, title.generalfield에게 중요하다.


'2.X > 3. Dealing with Human Language' 카테고리의 다른 글

3-1-4. One Language per Document  (0) 2017.09.24
3-1-5. One Language per Field  (0) 2017.09.24
3-2. Identifying Words  (0) 2017.09.24
3-2-1. standard Analyzer  (0) 2017.09.24
3-2-2. standard Tokenizer  (0) 2017.09.24