%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                               %
%       Thai Link Grammar                                       %
%                                                               %
%       Copyright (C) 2021  Prachya Boonkwan                    %
%       National Electronics and Computer Technology Center     %
%       Thailand                                                %
%                                                               %
%       License: Creative Commons, Attribution (CC-BY)          %
%                                                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#define dictionary-version-number 5.10.4;
#define dictionary-locale th_TH.UTF-8;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   DEPENDENCY LINKS
%
%   Utterance
%   ---------
%   LW = left wall
%       LWs = sentence
%       LWn = utterance of noun phrase
%       LWp = utterance of preposition phrase
%   RW = right wall
%   IJ = interjection
%   PT = particle
%
%   Sentence
%   --------
%   S  = subject
%   O  = object
%   VZ = serial verb
%   VC = controlled verb
%   TP = topicalization
%
%   Noun Phrase
%   -----------
%   NZ = serial noun
%   AJ = adjective
%       AJr = relative clause
%       AJj = simple adjective
%       AJv = attributive verb
%       AJp = preposition phrase
%   RI = implicit relative clause
%   AT = attribute
%   PS = possessive pronoun
%
%   Verb Phrase
%   -----------
%   AX = auxiliary
%       AXw = simple auxiliary
%       AXg = negative auxiliary
%   AV = adverb
%       AVp = preposition phrase
%       AVw = simple adverb
%       AVg = negative adverb
%       AVn = numeral phrase modifying noun phrase
%       AVv = numeral phrase modifying verb phrase
%       AVt = temporal entity modifying verb phrase
%       AVc = clause-level adverb
%
%   Preposition Phrase
%   ------------------
%   PO = prepositional object (noun)
%   PC = prepositional complement (verb)
%   PZ = serial preposition
%
%   Numeral Phrase
%   --------------
%   NU = number
%       NUn = simple number
%       NUv = number for verb
%   CL = classifier
%       CLn = classifier for noun
%       CLv = classifier for verb
%   QF = numeral quantifier
%
%   Coordinate Structure
%   --------------------
%   JN = conjoined noun phrase
%   JV = conjoined verb phrase
%
%   Punctuation
%   -----------
%   PU = punctuation
%       PUs = white space
%       PUp = paiyal noi 'ฯ'
%       PUy = mai yamok 'ๆ'
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                       %
%   COMMON MACROS                       %
%                                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

<left-wall-sent> :
    {@IJ-}
    & {LWn-}
    & LWs-;

<left-wall-noun> :
    {@IJ-}
    & LWn-;

<left-wall-prep> :
    {@IJ-}
    & LWp-;

<right-wall> :
    {@PT+} 
    & RW+;

<utterance-noun> :
    <left-wall-noun>
    & <right-wall>;

<utterance-prep> :
    <left-wall-prep>
    & <right-wall>;

<num-cl> :
    hNUn-
    or [hNUn+]
    or [[hNUv+]];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                       %
%   GRAMMAR                             %
%                                       %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
% Noun
%%%%%%%%%%%%%%%%%%%%

<noun-looking-for-mods> :
    {hAJj-}
    & {@hAJ+ or hPS+}
    & {PUp+ or PUy+}
    & {<num-cl>}
    & {@hAJ+};

<noun-start> :
    {[NZ+] or hAT+}
    & <noun-looking-for-mods>;

<noun-start-temporal> :
    {TS+ or hAT+}
    & <noun-looking-for-mods>
    & {PUsr+ & TS+};

<noun-serial> :
    NZ-
    & {NZ+};

<noun-serial-temporal> :
    TS-
    & {TS+};

<noun-imprel> :
    (hRI+ or hAJv+)
    & {@hAJ+};

<noun-attribute> :
    dAT-
    & (@hAJ+ or hPO+);

<noun-element> :
    dS+
    or dO-
    or [<utterance-noun>]
    or dPO-
    or JNl+ 
    or JNr- 
    or ({PUst+} & TP+);

<noun-simple> :
    (<noun-start> & <noun-element>)
    or <noun-serial>
    or (<noun-imprel> & <noun-element>);

<noun-temporal> :
    dAVtl+
    or dAVtr-;

%%%% Common Noun %%%%

/th/words/words.n.common 
THAI-COLOR.n :
    <noun-simple>;

%%%% Attributive Noun %%%%

/th/words/words.n.attribute :
    (<noun-start> & <noun-element>)
    or <noun-attribute>;

%%%% Nominalizing Prefix %%%%

/th/words/words.n.prefix :
    <noun-imprel>
    & <noun-element>;

%%%% Temporal Entity %%%%

THAI-DATE THAI-TIME :
    <noun-start-temporal>
    & (<noun-temporal> or <noun-element>);

%%%%%%%%%%%%%%%%%%%%
%   Pronoun
%%%%%%%%%%%%%%%%%%%%

/th/words/words.pro.common :
    (
        {hAJr+}
        & {<num-cl>}
        & <noun-element>
    )
    or dPS-;

%%%%%%%%%%%%%%%%%%%%
% Classifier
%%%%%%%%%%%%%%%%%%%%

<cls-n> :
    dCLn+ or dCLn-;

<cls-v> :
    dCLv+ or dCLv-;

/th/words/words.cl.noun :
    <cls-n>;

/th/words/words.cl.verb :
    <cls-v>;

%%%%%%%%%%%%%%%%%%%%
% Verb
%%%%%%%%%%%%%%%%%%%%

<core-of-verb> :
    {@hAX-}
    & (
        (hS- & ([TP-] or ()))
        or [()]
    )
    & {hAVpl-}
    & {hAVtl-}
    & {hAVcl-};

<verb-start> :
    <core-of-verb>
    & (<left-wall-sent> or JVr-)
    & (hO+ or [()])
    & (
        ({@hAV+} & <right-wall>)
        or [VZ+] 
        or ({@hAV+} & JVl+)
    );

<passive-marker> :
    <core-of-verb>
    & (<left-wall-sent> or JVr-)
    & (hO+ or [()])
    & hVC+;

<verb-intrans> :
    <core-of-verb>
    & (<left-wall-sent> or JVr-)
    & (
        ({@hAV+} & {@hAV-} & <right-wall>)
        or [VZ+]
        or ({@hAV+} & JVl+)
    );

<verb-serial> :
    VZ-
    & (hO+ or [()])
    & {@hAV+}
    & (<right-wall> or VZ+);

<verb-control> :
    dVC-
    & (hO+ or [()])
    & {@hAV+}
    & (<right-wall> or VZ+);

<verb-comp> :
    {@hAX-}
    & {hS- & ([TP-] or ())}
    & {hAVpl-}
    & {dPC- or dRC- or dZN-}
    & (hO+ or [()])
    & {@hAV+}
    & {[VZ+]};

<verb-imprel> :
    [dRI-]
    & (hO+ or [()])
    & {[hAV+]};

<verb-simple> :
    (
        {[[PUsl-]]}
        & {[[PUsr+]]}
        & (<verb-start> or <verb-serial> or <verb-comp>)
    )
    or <verb-control>
    or [<verb-imprel>];

<verb-simple-intrans> :
    {[[PUsl-]]}
    & {[[PUsr+]]}
    & <verb-intrans>;

%%%% Common Verb %%%%

/th/words/words.v.common :
    <verb-simple>;

%%%% Passive Marker %%%%

/th/words/words.passmark :
    <passive-marker>;

%%%%%%%%%%%%%%%%%%%%
% Adjective
%%%%%%%%%%%%%%%%%%%%

<adj-simple> :
    {PUy+}
    & {hCL-}
    & dAJj-
    & {hAVw+};

<adj-lhs> :
    dAJj+;

<adj-attribute> :
    {PUy+}
    & {hCL-}
    & dAJv-
    & {hAVw+ or hAVp+};

%%%% Simple Adjective %%%%

% Test frame: _____ (non-verb) + kwàa/láew
%     If not allowed, it is an adjective.
%     Otherwise, it is an attributive verb.

/th/words/words.adj.common
/th/words/words.num.ordinal
THAI-COLOR.j 
ROMAN-NUMERAL-WORDS.j :
    <adj-simple>;

/th/words/words.adj.lhs 
/th/words/words.n.title
/th/words/words.n.designator :
    <adj-lhs>;

%%%% Attributive Verb %%%%

% Test frame: khwaam + _____

/th/words/words.v.attribute
THAI-COLOR.va :
    <adj-attribute>
    or [{PUy+} & <verb-simple-intrans>]
    or [<verb-comp>];

%%%%%%%%%%%%%%%%%%%%
% Number
%%%%%%%%%%%%%%%%%%%%

<number-simple> :
    ({hQFl-} & dNUnr- & hCLn+ & {hQFr+})
    or [[{hQFl-} & dNUvr- & hCLv+ & {hQFr+}]]
    or [{hQFl-} & dAVnr- & hCLn+ & {hQFr+}]
    or [{hQFl-} & dAVvr- & hCLv+ & {hQFr+}]
    or dNUnl+
    or dNUtr-
    or dONr-;

/th/words/words.num.common
NUMBERS.nu FRACTION.nu 
THAI-NUMBERS.nu THAI-FRACTION.nu:
    {PUsl-} & {PUsr+} & <number-simple>;

/th/words/words.num.movable :
    (hCLn- & (dNUnr- or [dAVnr-]))
    or (hCLv- & (dNUvr- or [dAVvr-]));

/th/words/words.qf.lhs :
    dQFl+;

/th/words/words.qf.rhs :
    dQFr-;

/th/words/words.ordmark :
    hONr+
    & <adj-simple>;

%%%%%%%%%%%%%%%%%%%%
% Auxiliary
%%%%%%%%%%%%%%%%%%%%

/th/words/words.aux.common :
    dAXw+;

%%%%%%%%%%%%%%%%%%%%
% Adverb
%%%%%%%%%%%%%%%%%%%%

/th/words/words.adv.common :
    dAVw- & {hAV+};

/th/words/words.adv.attrmod :
    dAVw+;

/th/words/words.adv.cohesive :
    dAVcl+;

%%%%%%%%%%%%%%%%%%%%
% Negator
%%%%%%%%%%%%%%%%%%%%

/th/words/words.neg.lhs :
    dAXg+;

/th/words/words.neg.rhs :
    dAVgr-;

%%%%%%%%%%%%%%%%%%%%
% Preposition
%%%%%%%%%%%%%%%%%%%%

<ablative> :
    [dAVpr-]
    or dAVpl+;

<prep-conjoined> :
    JPl+
    or JPr-;

<p-obj> :
    hPO+ or [[()]];

<prep-noun> :
    ({hPZn-} & {PUs-} & (dAVpr- or [dAJpr-]) & <p-obj>)
    or [{hPZn-} & <p-obj> & <utterance-prep>]
    or [{hPZn-} & <p-obj> & <prep-conjoined> & {JD-}]
    or ({hPZn-} & <p-obj> & {PUs+} & dAVpl+)
    or dPZn+;

<prep-verb> :
    ({hPZv-} & {PUs-} & (dAVpr- or [dAJpr-]) & hPC+)
    or [{hPZv-} & hPC+ & <utterance-prep>]
    or ({hPZv-} & hPC+ & {PUs+} & dAVpl+)
    or dPZv+;

<prep-lw-comp> :
    @hPO+
    or @hPC+
    or @hAVp+
    or @hAJp+;

<prep-lw> :
    ({PUs-} & (dAVpr- or [dAJpr-]) & <prep-lw-comp>)
    or [<prep-lw-comp> & <utterance-prep>]
    or (<prep-lw-comp> & dAVpl+);

<nprep-noun> :
    ({hPZn-} & {PUs-} & dAJpr- & <p-obj>)
    or [{hPZn-} & <p-obj> & <utterance-prep>]
    or [{hPZn-} & <p-obj> & <prep-conjoined> & {JD-}]
    or ({hPZn-} & <p-obj> & {PUs+} & dAVpl+)
    or dPZn+;

<nprep-verb> :
    ({PUs-} & dAJpr- & hPC+)
    or [hPC+ & <utterance-prep>]
    or (hPC+ & {PUs+} & dAVpl+);

<vprep-noun> :
    ({hPZn-} & {PUs-} & dAVpr- & <p-obj>)
    or [{hPZn-} & <p-obj> & <utterance-prep>]
    or [{hPZn-} & <p-obj> & <prep-conjoined> & {JD-}]
    or ({hPZn-} & <p-obj> & {PUs+} & dAVpl+)
    or dPZn+;

<vprep-verb> :
    ({hPZv-} & {PUs-} & dAVpr- & hPC+)
    or [{hPZv-} & hPC+ & <utterance-prep>]
    or ({hPZv-} & hPC+ & {PUs+} & dAVpl+)
    or dPZv+;

/th/words/words.prep.n :
    <prep-noun>;

/th/words/words.prep.v :
    <prep-verb>;

/th/words/words.prep.nv :
    <prep-noun>
    or <prep-verb>;

/th/words/words.prep-n.n :
    <nprep-noun>;

/th/words/words.prep-n.v :
    <nprep-verb>;

% /th/words/words.nprep.nv :
%     <nprep-noun>
%     or <nprep-verb>;

/th/words/words.prep-v.n :
    <vprep-noun>;

/th/words/words.prep-v.v :
    <vprep-verb>;

/th/words/words.prep-v.nv :
    <vprep-noun>
    or <vprep-verb>;

/th/words/words.prep.lw :
    <prep-lw>;

%%%%%%%%%%%%%%%%%%%%
% Relative Pronoun
%%%%%%%%%%%%%%%%%%%%

<relcls> :
    {hCLn-}
    & dAJr-
    & hPC+;

<relsent> :
    (dAVr- or hRC+)
    & <left-wall-sent>
    & <right-wall>;

/th/words/words.relpro.common :
    <relcls> or [<relsent>];

%%%%%%%%%%%%%%%%%%%%
% Conjunction
%%%%%%%%%%%%%%%%%%%%

/th/words/words.conj.noun :
    {PUs-}
    & {PUs+}
    & JNl-
    & JNr+
    & {JD-}
    & <noun-start>
    & <noun-element>;

_.cn :
    [[
        JNl-
        & JNr+
    ]]
    & <noun-start>
    & <noun-element>;

/th/words/words.conj.verb :
    {PUs-}
    & {PUs+}
    & JVl-
    & JVr+;

_.cv :
    [[
        JVl-
        & JVr+
    ]];

/th/words/words.conj.prep :
    (AVpr+ & AVpl- & {JD-} & (dAVpr- or dAVpl+))
    or 
    [JPr+ & JPl- & {JD-} & (dAJpr- or dAJpl+)];

_.cp :
    [[
        (AVpl- & AVpr+)
        or (AJpl- & AJpr+)
    ]]
    & (dAVpr- or [dAJpr-]);

/th/words/words.conj.discont :
    JD+;

%%%%%%%%%%%%%%%%%%%%
% Particle
%%%%%%%%%%%%%%%%%%%%

/th/words/words.part.common :
    PT-;

ครัช.#ครับ ครัล.#ครับ คนับ.#ครับ: [ครับ.pt]bad-spelling;
คับ.#ครับ จั๊บ.#ครับ: [ครับ.pt]colloquial;

%%%%%%%%%%%%%%%%%%%%
% Interjection
%%%%%%%%%%%%%%%%%%%%

/th/words/words.intj.common
EMOTICON :
    {PUs-}
    & {PUs+}
    & (IJ+ or PT-);

%%%%%%%%%%%%%%%%%%%%
% Punctuation
%%%%%%%%%%%%%%%%%%%%

_.pu :
    PUs+ or PUs-;

ๆ.pu ฯลฯ.pu :
    {PUs-}
    & PUy-
    & {PUs+};

ฯ.pu :
    {PUs-}
    & PUp-
    & {PUs+};

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%
% Date and Time
%%%%%%%%%%%%%%%%%%%%

HMS-TIME.n DECADE-DATE.n YEAR-DATE.n THAI-DATE.n THAI-TIME.n :
    <noun-simple>;

HMS-TIME.r YEAR-DATE.r THAI-DATE.r THAI-TIME.r :
    <ablative>;

%%%%%%%%%%%%%%%%%%%%
% Part Number
%%%%%%%%%%%%%%%%%%%%

PART-NUMBER THAI-PART-NUMBER :
    <noun-simple>;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

LEFT-WALL :
    LW+;

RIGHT-WALL :
    RW-;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

<UNKNOWN-WORD> : XXXXXXXX+;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
