Skip to content

Commit

Permalink
Target ResourceDemo.pgf
Browse files Browse the repository at this point in the history
  • Loading branch information
lynn committed May 23, 2024
1 parent e38aaee commit 0829b0a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
25 changes: 17 additions & 8 deletions src/gf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type G_Num = 'NumSg' | 'NumPl';
type G_Tense = 'TPres' | 'TPast' | 'TFut' | 'TCond';
type G_Ant = 'ASimul' | 'AAnter';
type G_Pol = 'PPos' | 'PNeg';
type G_Det = ['DetQuant', G_Quant, G_Num] | 'every_Det';
type G_Det = ['DetQuant', G_Quant, G_Num] | `${string}_Det`;
type G_Pron = `${string}_Pron`;
type G_CN = ['UseN', G_N] | ['RelCN', G_CN, G_RS];
type G_NP =
Expand All @@ -28,6 +28,7 @@ type G_VPSlash =
type G_VP =
| ['UseV', G_V]
| ['UseComp', G_Comp]
| G_Comp
| ['ComplSlash', G_VPSlash, G_NP]
| ['ComplVS', G_VS, G_S];
type G_Cl =
Expand Down Expand Up @@ -165,6 +166,9 @@ function simplifyRsToCn(rs: G_RS): G_CN | undefined {
const comp = vp[1];
if (comp[0] === 'CompCN') return comp[1];
}
if (vp[0] === 'CompCN') {
return vp[1];
}
}
}
}
Expand All @@ -186,19 +190,19 @@ function dToGf(tree: StrictTree): G_Det {
const text = leafText(tree);
switch (text) {
case 'sá':
return ['DetQuant', 'IndefArt', 'NumSg'];
return 'aSg_Det'; // ['DetQuant', 'IndefArt', 'NumSg'];
case 'báq':
return ['DetQuant', 'IndefArt', 'NumPl'];
return 'aPl_Det'; // ['DetQuant', 'IndefArt', 'NumPl'];
case 'tú':
return 'every_Det';
case 'hú':
return ['DetQuant', 'that_Quant', 'NumSg'];
return 'that_Det'; // ['DetQuant', 'that_Quant', 'NumSg'];
case 'ní':
return ['DetQuant', 'this_Quant', 'NumSg'];
return 'this_Det'; // ['DetQuant', 'this_Quant', 'NumSg'];
case 'ké':
case 'ló':
case '◌́':
return ['DetQuant', 'DefArt', 'NumSg'];
return 'theSg_Det'; // ['DetQuant', 'DefArt', 'NumSg'];

default:
throw new Unimplemented('dToGf: ' + text);
Expand Down Expand Up @@ -285,11 +289,16 @@ function v0ToGf(tree: StrictTree): G_VP {
function vToGf(tree: StrictTree): G_VP {
const text = baseForm(leafText(tree));
const verb = lexicon.V.get(text);

// Different between ResourceDemo.pgf and LibraryBrowser.pgf?
// const useComp = (x: G_Comp) => ['UseComp', x];
const useComp = (x: G_Comp) => x;

if (verb) return ['UseV', verb];
const noun = lexicon.N.get(text);
if (noun) return ['UseComp', ['CompCN', ['UseN', noun]]];
if (noun) return useComp(['CompCN', ['UseN', noun]]);
const adj = lexicon.A.get(text);
if (adj) return ['UseComp', ['CompAP', ['PositA', adj]]];
if (adj) return useComp(['CompAP', ['PositA', adj]]);

throw new Unimplemented('Unknown V: ' + text);
}
Expand Down
12 changes: 2 additions & 10 deletions src/web/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,7 @@ export function ShowLinearization({
if (to === 'LibraryBrowserAPI') {
return undefined;
} else {
const lang = {
LibraryBrowserBul: 'bg',
LibraryBrowserChi: 'zh',
LibraryBrowserDut: 'nl',
LibraryBrowserEng: 'en',
LibraryBrowserSpa: 'es',
LibraryBrowserSwe: 'sv',
}[to];
if (lang === 'zh-Hans') text = text.replace(/\s/g, '');
const lang = to.replace(/^ResourceDemo/, '').toLowerCase();
return (
<div className="linearization">
<dd>{lang}:&nbsp;</dd>
Expand Down Expand Up @@ -255,7 +247,7 @@ export function Main(props: MainProps) {
const recovered = recover(tree);
const gf = showGf(treeToGf(recovered));
fetch(
'https://cloud.grammaticalframework.org/grammars/LibraryBrowser.pgf?command=linearize&tree=' +
'https://cloud.grammaticalframework.org/grammars/ResourceDemo.pgf?command=linearize&tree=' +
encodeURIComponent(gf),
).then(x => x.json().then(j => setLinearizations(j)));
return <>{showGf(treeToGf(recovered))}</>;
Expand Down

0 comments on commit 0829b0a

Please sign in to comment.