

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

# Liquid를 사용하여 자동화 추가
<a name="sms-custom-templates-step2-automate"></a>

Amazon의 사용자 지정 템플릿 시스템은 자동화를 위해 [Liquid](https://shopify.github.io/liquid/)를 사용합니다. Liquid는 오픈 소스 인라인 마크업 언어입니다. Liquid에서 단일 중괄호와 퍼센트 기호 사이에 있는 텍스트는 제어 흐름 또는 반복과 같은 작업을 수행하는 지침 또는 *태그*입니다. 이중 중괄호 사이에 있는 텍스트는 변수 또는 변수의 값을 출력하는 *객체*입니다.

Liquid는 가장 일반적으로 입력 매니페스트 파일에서 가져온 데이터를 구분 분석하고 작업을 생성하기 위해 관련 변수를 가져오는 데 사용됩니다. Ground Truth는 사전 주석 Lambda가 지정되지 않는 한 작업을 자동으로 생성합니다. Ground Truth 또는 에서 반환하는 `taskInput` 객체[주석 전 Lambda](sms-custom-templates-step3-lambda-requirements.md#sms-custom-templates-step3-prelambda)는 템플릿의 `task.input` 객체입니다.

입력 매니페스트 내 속성이 `event.dataObject`로 템플릿에 전달됩니다.

**Example 매니페스트 데이터 객체**  

```
{
  "source": "This is a sample text for classification",
  "labels": [ "angry" , "sad" , "happy" , "inconclusive" ],
  "header": "What emotion is the speaker feeling?"
}
```

**Example 변수를 사용하는 샘플 HTM**  

```
<crowd-classifier 
  name='tweetFeeling'
  categories='{{ task.input.labels | to_json }}'
  header='{{ task.input.header }}' >
<classification-target>
  {{ task.input.source }}
</classification-target>
```

위에서 `labels` 속성에 ` | to_json`이 추가되는 데 유의하세요 이것은 입력 매니페이스를 배열의 JSON 표현으로 변환하는 필터입니다. 변수 필터는 다음 섹션에서 설명합니다.

다음 목록에는 템플릿 입력 데이터 처리를 자동화하는 데 유용할 수 있는 두 가지 유형의 Liquid 태그가 포함되어 있습니다. 다음 태그 유형 중 하나를 선택하면 Liquid 설명서로 리디렉션됩니다.
+ [제어 흐름](https://shopify.github.io/liquid/tags/control-flow/): `if/else`, `unless`, `case/when`과 같은 프로그래밍 로직 연산자를 포함합니다.
+ [반복](https://shopify.github.io/liquid/tags/iteration/): for 루프와 같은 명령문을 사용하여 코드 블록을 반복적으로 실행할 수 있습니다.

  Liquid 요소를 사용하여 for 루프를 만드는 HTML 템플릿의 예시는 GitHub의 [translation-review-and-correction.liquid.html](https://github.com/aws-samples/amazon-sagemaker-ground-truth-task-uis/blob/8ae02533ea5a91087561b1daecd0bc22a37ca393/text/translation-review-and-correction.liquid.html)을 참조하세요.

자세한 내용 및 설명서는 [Liquid 홈페이지](https://shopify.github.io/liquid/)를 참조하세요.

## 변수 필터
<a name="sms-custom-templates-step2-automate-filters"></a>

Ground Truth는 표준 [Liquid 필터](https://shopify.github.io/liquid/filters/abs/) 및 작업 이외에 몇 가지 추가 필터를 제공합니다. 필터는 변수 이름 뒤에 파이프(`|`) 문자를 삽입한 후 필터 이름을 지정하여 적용됩니다. 필터는 다음 형식으로 함께 묶을 수 있습니다.

**Example**  

```
{{ <content> | <filter> | <filter> }}
```

### Autoescape 및 explicit escape
<a name="sms-custom-templates-step2-automate-filters-autoescape"></a>

기본적으로 입력은 변수 텍스트와 HTML 간에 혼동을 피하기 위해 이스케이프된 HTML입니다. 이스케이프가 완료된 템플릿의 소스를 보다 분명하게 읽을 수 있도록 `escape` 필터를 명시적으로 추가할 수 있습니다.

### escape\$1once
<a name="sms-custom-templates-step2-automate-escapeonce"></a>

`escape_once`는 코드를 이미 이스케이프한 경우 이후에 해당 코드가 다시 이스케이프되지 않도록 합니다. 예를 들어, &amp;는 &amp;amp;가 되지 않습니다.

### skip\$1autoescape
<a name="sms-custom-templates-step2-automate-skipautoescape"></a>

`skip_autoescape`는 콘텐츠가 HTML로 사용되는 경우 유용합니다. 예를 들어, 경계 상자에 대한 전체 지침에 텍스트 단락 몇 개와 이미지 몇 개가 있을 수 있습니다.

**드물게 `skip_autoescape` 사용**  
템플릿을 사용할 때, 전달 항목에 대해 엄격한 제어 권한이 없는 한 `skip_autoescape`로 함수 코드나 마크업을 전달하지 않는 것이 좋습니다. 사용자 입력을 전달하는 경우 작업자가 교차 사이트 스크립팅 공격에 노출되도록 할 수 있습니다.

### to\$1json
<a name="sms-custom-templates-step2-automate-tojson"></a>

`to_json`은 JSON(JavaScript Object Notation)에 제공하는 항목을 인코딩합니다. 객체를 제공하는 경우 직렬화합니다.

### grant\$1read\$1access
<a name="sms-custom-templates-step2-automate-grantreadaccess"></a>

`grant_read_access`는 S3 URI를 가져와 해당 리소스에 대해 수명이 짧은 액세스 토큰을 사용하여 HTTPS URL로 인코딩합니다. 따라서 작업자에게 S3 버킷에 저장된 사진, 오디오 또는 비디오 객체를 표시할 수 있습니다. 그렇지 않으면 이러한 객체는 공개적으로 액세스할 수 없습니다.

### s3\$1presign
<a name="sms-custom-templates-step2-automate-s3"></a>

 `s3_presign` 필터는 `grant_read_access` 필터와 동일한 방식으로 작동합니다. `s3_presign`는 Amazon S3 URI를 가져와 해당 리소스에 대한 수명이 짧은 액세스 토큰을 사용하여 HTTPS URL로 인코딩합니다. 이를 통해 작업자가 공개적으로 액세스할 수 없는 S3 버킷에 저장된 사진, 오디오 또는 비디오 객체를 표시할 수 있습니다.

**Example 변수 필터 중**  
입력  

```
auto-escape: {{ "Have you read 'James & the Giant Peach'?" }}
explicit escape: {{ "Have you read 'James & the Giant Peach'?" | escape }}
explicit escape_once: {{ "Have you read 'James &amp; the Giant Peach'?" | escape_once }}
skip_autoescape: {{ "Have you read 'James & the Giant Peach'?" | skip_autoescape }}
to_json: {{ jsObject | to_json }}                
grant_read_access: {{ "s3://amzn-s3-demo-bucket/myphoto.png" | grant_read_access }}
s3_presign: {{ "s3://amzn-s3-demo-bucket/myphoto.png" | s3_presign }}
```

**Example**  
출력  

```
auto-escape: Have you read &#39;James &amp; the Giant Peach&#39;?
explicit escape: Have you read &#39;James &amp; the Giant Peach&#39;?
explicit escape_once: Have you read &#39;James &amp; the Giant Peach&#39;?
skip_autoescape: Have you read 'James & the Giant Peach'?
to_json: { "point_number": 8, "coords": [ 59, 76 ] }
grant_read_access: https://s3.amazonaws.com/amzn-s3-demo-bucket/myphoto.png?<access token and other params>
s3_presign: https://s3.amazonaws.com/amzn-s3-demo-bucket/myphoto.png?<access token and other params>
```

**Example 자동화된 분류 템플릿.**  
간단한 텍스트 분류 샘플을 자동화하려면 트윗 텍스트를 변수로 바꿉니다.  
아래 텍스트 분류 템플릿에는 자동화가 추가되어 있습니다. 변경/추가된 내용은 굵게 강조 표시되어 있습니다.  

```
<script src="https://assets.crowd.aws/crowd-html-elements.js"></script>
<crowd-form>
  <crowd-classifier 
    name="tweetFeeling"
    categories="['positive', 'negative', 'neutral', 'cannot determine']"
    header="Which term best describes this tweet?" 
  >
    <classification-target>
       {{ task.input.source }}
    </classification-target>

    <full-instructions header="Analyzing a sentiment">
      Try to determine the feeling the author 
      of the tweet is trying to express. 
      If none seem to match, choose "other."
    </full-instructions>

    <short-instructions>
      Pick the term best describing the sentiment 
      of the tweet. 
    </short-instructions>

  </crowd-classifier>
</crowd-form>
```
이전 샘플에 있던 트윗 텍스트는 이제 객체로 바뀝니다. `entry.taskInput` 객체는 `source`(또는 주석 전 Lambda에서 지정한 다른 이름)를 텍스트에 대한 속성 이름으로 사용하고, 이것은 이중 중괄호 사이에 있기 때문에 HTML에 직접 삽입됩니다.