추상 위키백과/위키함수용 템플릿 언어/템플릿 구문을 위키함수로 변환
구문을 사용하는 템플릿이 주어지면 컴포지션 구문(따라서 Z7 함수 호출 개체)으로 구문 분석할 수 있으며 그런 다음 위키함수 오케스트레이터에서 직접 평가할 수 있습니다.
평가 출력 유형
제안된 NLG 아키텍처에 따라 템플릿 렌더러의 출력은 "렘마 트리"여야 합니다. 아래 제안된 현재 구현에서 필요한 출력은 완전히 지정된 트리가 아니라 다음 필드가 있는 Z 유형으로 정의되는 “어휘소 목록”, 어휘소[Note 1]입니다:[Note 2]
- 의미표제어: 어휘의 인용 형식(대부분 디버깅 목적으로 필요)
- 언어 코드 (대부분 템플릿의 대상 언어 코드와 동일하지만 특수한 경우에 따라 다를 수 있음)
- 품사
- 모든 형식에 적용할 수 있는 통합 가능한 문법적 특징 목록
- 형식에 대한 제약 조건으로 사용되는 통합할 수 있는 문법적 특징 목록(종속 규칙 적용으로 채워짐)
- 실제로, 위의 두 목록은 문법적 특징의 단일 목록으로 구현될 수 있습니다.
- 형식 목록, 후자는 다음 필드가 있는 Z-유형입니다.
- 정자법
- 공백 처리(다양한 유형의 접어/접사를 처리하기 위해 형식 앞/뒤에 공백을 표시할지 여부)
- 형식에 특정한 불확실한 문법적 특징 목록
위에서 언급한 통일할 수 없는 문법적 특징 유형에는 세 가지 필드가 있습니다:
- 통합 색인: 파생된 다른 어휘와 함께 이러한 기능을 식별하는 역할을 합니다.
- 문법 범주: 기능 유형, 예: "숫자" 또는 "성별"
- 문법적 특징(적절한): 특징 자체, 예를 들어 "복수" 또는 "남성"
어휘소 목록 유형은 항목이 어휘소 유형이거나 어휘소 목록 자체일 수 있는 목록입니다. 또한 이러한 각 목록은 아마도 Z22(쌍) 유형을 통해 루트 어휘소의 인덱스로 확장됩니다. 그 결과 하위 템플릿의 루트와 상위 템플릿 사이의 호만 기록되고 단일 템플릿 내의 호는 유지되지 않는 어휘소의 부분적으로 지정된 종속성 트리가 생성됩니다.[Note 3]
합성된 함수의 구성
The composed function call is built as follows:[Note 4]
- Every template element is transformed into a function call, as follows:
- Textual elements, including punctuation marks, are passed as arguments to a TemplateText function, e.g.
TemplateText("is")
,TemplateText(".")
.- The TemplateText function transforms every word (or punctuation mark) into a lexeme (or more precisely, a lexeme list of length 1). In most cases that lexeme will contain exactly one form, namely the text provided, effectively simulating static text. However, in select cases, this gives an opportunity to expand certain words to a list of forms (e.g. the English determiner "a" could be expanded to {"a", "an"}), or apply some relevant annotation, for easier access to certain common grammatical patterns.
- Slots with strings or interpolation of string arguments are also transformed to TemplateText calls, e.g.
{"text"} → TemplateText("text")
,{string_field} → TemplateText(string_field)
. - Interpolations of other argument types will be handled similarly, but with other functions (TBD).
- Numeric types, for instance, may be converted to lexemes using an implicit
Cardinal
function, which would not only convert the numeric value to a lexeme type – e.g., the number 1 to a string 1 – but would also enrich the lexeme with a grammatical number feature (e.g., that a 1 in the sentence, when quantifying count nouns, will forcesingular
rendering of the noun it is associated with, and e.g. 2 forplural
, according to the language's grammar for grammatical number) corresponding to the numeric value.
- Numeric types, for instance, may be converted to lexemes using an implicit
- Slots with function invocations will simply use the corresponding function call (which may be a sub-template), e.g.
{Lexeme(entity}) → Lexeme(entity)
. Note that these functions must return a lexeme list type. - Any conditional function would be applied on top of the previously given function call, e.g.
{Lexeme(entity}|Elide_if(ellipsis)} → Elide_if(ellipsis, Lexeme(entity))
.
- Textual elements, including punctuation marks, are passed as arguments to a TemplateText function, e.g.
- The list of resulting function calls is passed into a Template function, together with the 1-based index of the root-labeled slot.[Note 5] For example:
Hello {root:Person(entity}|Elide_if(ellipsis)}! →
Template(2, [TemplateText("Hello") Elide_if(ellipsis, Person(entity)) TemplateText("!")])
- The dependency relations are applied as further function invocations on top of the Template invocation, together with the 1-based indexes of the target and source labels. Note that this means that each dependency role should correspond to a Wikifunctions function transforming the lemma tree to reflect the application of the given role; e.g. an
amod
role would enforce subject-verb agreement on the lemma tree. For example:Bonjour {det:DefiniteArticle()} {amod:Lexeme(L10098)} {root:Person(entity}! →
amod(3, 4, det(2, 4, Template(4, [
TemplateText("Bonjour")
DefiniteArticle()
Lexeme("L10098") -- adjective "petit"
Person(entity)
TemplateText("!")
]))
Note that the Template and TemplateText functions as well as those derived from the dependency relation names, are all expected to return a lexeme list. Thus, when transforming a Constructor to a template a further function needs to be applied, tentatively named Render, which should process the lemma-tree through the other modules of the NLG pipeline to return the realized text as a string.
Language-specific function dispatch
In Wikifunctions, the language-specific function dispatch will be implemented by augmenting every function label with a language-code suffix. For instance, the English, German and Brazilian Portuguese versions of TemplateText will be named (in English) TemplateText_en
, TemplateText_de
and TemplateText_pt-BR
.[Note 6] It will be the task of the template parser, when delabeling the function names, to look up for the most language-specific version of a given function.
Examples of transformation to composition syntax
We repeat here the examples given in the template specification document, together with their transformation to Composition syntax.
Swedish
For convenience of reading, we repeat the template syntax:
Age_renderer_sv(Entity, Age_in_years): "{Person(Entity)} är {Age_in_years} år gammal ."
The corresponding composition syntax (short-hand):
Age_renderer_sv(Entity, Age_in_years): Template(1, [
Person(Entity)
TemplateText("är")
TemplateText(Age_in_years)
TemplateText("år")
TemplateText("gammal")
TemplateText(".")
])
French
Template syntax:
Age_renderer_fr(Entity, Age_in_years):
"{Person(Entity)} a {Year(Age_in_years)}."
Year_fr(years): "{nummod:Cardinal(years)} {root:Lexeme(L10081)}"
Composition syntax:
Age_renderer_fr(Entity, Age_in_years): Template(1, [
Person(Entity)
TemplateText("a")
Year_fr(Age_in_years)
TemplateText(".")
])
Year_fr(years): num(1, 2, Template(2, [
Cardinal_fr(years)
Lexeme_fr(L10081)
]))
Hebrew
Template syntax:
Age_renderer_he(Entity, Age_in_years):
"{subj:Person(Entity)} {root:GenderedLexeme(L64310, L64399)} {gmod:Year(Age_in_years)}."
Year_he(years):
"{nummod:Cardinal(years)|Elide_if(years<=2)} {root:Lexeme(L68440)|Elide_if(years>2)}"
Composition syntax:
Age_renderer_he(Entity, Age_in_years):
gmod(3, 2, subj(1, 2, Template(2, [
Person(Entity)
GenderedLexeme(L64310, L64399)
Year_he(Age_in_years)
TemplateText(".")
])))
Year_he(years):
nummod(1, 2, Template(2, [
ElideIf(years<=2, Cardinal_he(years))
ElideIf(years>2, Lexeme(L68440)) ]))
Zulu
Template syntax:
Age_renderer_zu(Entity, Age_in_years):
"{subj:Person(Entity)} {sc:SubjectConcord()}na{Year(Age_in_years)}."
Year_zu(years):
"{root:Lexeme(L686326} {concord:RelativeConcord()}{Copula()}{concord_1<nummod:NounConcord()}-{nummod:Cardinal(years)}"
Composition syntax:
Age_renderer_zu(Entity, Age_in_years):
subj(1, 2, Template(2, [
Person(Entity)
SubjectConcord()
TemplateText("na")
Year(Age_in_years)
TemplateText(".")
]))
Year_zu(years):
nummod(6, 1, concord(4, 6, concord(2, 1, Template(1, [
Lexeme(L686326)
RelativeConcord()
Copula()
NounConcord()
TemplateText("-")
Cardinal(years)
]))))
Breton
Template syntax:
Age_renderer_br(Entity, Age_in_years):
"{Cardinal(Age_in_years)} {Lexeme(L45068)} eo {Person(Entity)} ."
Composition syntax:
Age_renderer_br(Entity, Age_in_years):
Template(1, [
Cardinal_br(Age_in_years)
Lexeme(L45068)
TemplateText("eo")
Person(Entity)
TemplateText(".")
])
Footnotes
- ↑ 여기에서 "어휘소"이라는 용어는 상당히 광범위하게 사용됩니다. 언어의 전형적인 내용어, 문법 형태소 또는 (특정 상황에서는) 문법 구를 가리킬 수 있습니다. 본질적인 것은 문법적 특징을 특징으로 하는 하나 이상의 형식 목록을 표시한다는 것입니다.
- ↑ 위키데이터의 어휘소 정의와 데이터 유형 정의가 매우 유사하다는 점에 유의하세요. 그러나 이것들은 별개의 개체입니다.
- ↑ 서브템플릿은 반드시 어떤 언어 단위와도 일치하지 않으며(비록 이상적으로는 종속성 트리의 언어 구성 요소와 일치해야 함) 더욱이 그 사용은 템플릿 작성자의 재량에 달려 있기 때문에 이 부분 트리 사양은 특정 특정 항목과 반드시 일치하지 않습니다. 언어 논리가 아닌 하위 템플릿 사용 측면에서 템플릿 구성을 반영합니다.
- ↑ An initial implementation of this can be found in Gerrit.
- ↑ If no slot is labeled
root
(which is allowed only if there are no other labels as well), the first slot will be identified as the root. - ↑ Note that this is independent of the fact that every Wikifunctions function may have labels in different languages. All these labels should follow the convention of marking the language code of the implementation, as handled by the implementation.