-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from lapalme/master
Version 3 : major rewrite
- Loading branch information
Showing
424 changed files
with
86,694 additions
and
599,225 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
|
||
<title>jsRealB-IDE</title> | ||
|
||
</head> | ||
<body> | ||
<div id="jsRealB-repl"> | ||
require("jsRealB-IDE-repl.js") | ||
</div> | ||
<script src="https://embed.runkit.com" data-element-id="jsRealB-repl"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# `jsRealB` Interactive Development Environment (IDE) | ||
|
||
One way of testing and developing `jsRealB` expressions is by using the Javascript console in a browser. But we found it much more convenient to use a command line environment built on top of the `node.js` *Read-Eval-Print Loop*. | ||
|
||
The system is started by typing | ||
|
||
node jsRealB-IDE-repl.js en | ||
|
||
which displays a prompt indicating the version and the date the system was compiled, it also loads a default language lexicon and rule set. The second parameter is either `en`, `dme` or `fr` (the default) which indicates the initial realization language, `dme` is a larger English lexicon. | ||
|
||
** jsRealB 2.0 (2019-11-25 21:17) Development Environment [help() for info]** | ||
English lexicon and rules loaded | ||
jsRealB > | ||
|
||
|
||
The *read-eval-print* loop allows the evaluation of any Javascript expression. If the result of the evaluation is an *object* whose prototype chain contains `Constituent` (i.e. *object* `instanceof Constituent` returns `true`), then it calls `toString()` on this value in order to show the realized sentence. If the result is a String, it is displayed without enclosing quotes. Otherwise, the value is shown as it would be in the standard *read-eval-print loop* using `util.inspect(...)`. | ||
|
||
This allows the use of `jsRealB` functions such as `loadEn()` or `loadFr()` for setting the realization language for the following expressions. | ||
|
||
The IDE also adds a few commands (i.e. expressions starting with a period) for querying the current lexicon and rule tables. This is useful to find the appropriate information when adding new words with `addToLexicon(lemma,information)`. | ||
|
||
These commands also accept a regular expression in place of a specific value, in which case they will return the result for each form that matches the regular expression. | ||
|
||
* `.ce` *ending* : conjugation information for tables with a given *ending*. | ||
For example, to show the conjugation information for verbs ending with `ve`: | ||
|
||
jsRealB > .ce ve | ||
v83: | ||
{ ending: 've', | ||
t: | ||
{ b: 've', | ||
ps: 'd', | ||
pr: 'ving', | ||
pp: 'd', | ||
p: [ 've', 've', 's', 've', 've', 've' ] } } | ||
|
||
* `.cn` *no* : conjugation information for table *no*. | ||
For example, to show the content of table `v2`: | ||
|
||
jsRealB > .cn v2 | ||
{ ending: '', | ||
t: | ||
{ b: '', | ||
ps: 'ed', | ||
pr: 'ing', | ||
pp: 'ed', | ||
p: [ '', '', 'es', '', '', '' ] } } | ||
|
||
|
||
* `.de` *ending* : declension information for table with a given *ending*. | ||
For example, to show the declension information for words ending by `ouse` | ||
|
||
jsRealB > .de ouse | ||
n16: | ||
{ ending: 'ouse', | ||
declension: [ { val: 'ouse', n: 's' }, { val: 'ice', n: 'p' } ] } | ||
|
||
* `.dn` *no* : declension information for table *no*. | ||
For example, to show the declension information for table `n1` | ||
|
||
jsRealB > .dn n1 | ||
{ ending: '', | ||
declension: [ { val: '', n: 's' }, { val: 's', n: 'p' } ] } | ||
|
||
* `.lx` *lemma* : dictionary information for lemma in a format that can be used as input for `addToLexicon()`; this is useful for adding a new lemma that is conjugated or declensed similarly to a word already in the lexicon. | ||
For example, to show the lexicon information for the word `love` | ||
|
||
jsRealB > .lm love | ||
{ N: { tab: [ 'n1' ] }, V: { tab: 'v3' } } | ||
|
||
* `.lm` *form* : find jsRealB expressions that can realize this form. | ||
For example, to find how to realize `his` | ||
|
||
jsRealB > .lm his | ||
Pro("mine").g("m").ow("s") | ||
D("my").g("m").ow("s") | ||
|
||
to find to how to realize all forms matching the pattern `l.ve` | ||
|
||
jsRealB > .lm l.ve | ||
live: A("live"); V("live").t("b"); V("live").pe(1); V("live").pe(2); V("live").pe(1).n("p"); V("live").pe(2).n("p"); V("live").n("p") | ||
love: N("love"); V("love").t("b"); V("love").pe(1); V("love").pe(2); V("love").pe(1).n("p"); V("love").pe(2).n("p"); V("love").n("p") | ||
|
||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* | ||
Customized node.js READ-EVAL-PRINT loop for developing jsRealB expressions | ||
- when the expression is a Constituent, call toString() to get its realization | ||
- output a string as is without enclosing quotes | ||
- usual util.inspect for all other types of values | ||
- history of previous commands is saved on a normal exit (^D) only | ||
example call: | ||
node /path/to/jsRealB-IDE/jsRealB-IDE-repl.js [en|dme|fr] (fr is the default...) | ||
*/ | ||
|
||
// preload jsRealB module | ||
jsRealB=require("./jsRealB-IDE.min.js"); | ||
// import constructors and other functions | ||
for (var v in jsRealB){eval (''+v+"=jsRealB."+v)} | ||
// select language | ||
var args=process.argv | ||
console.log("** jsRealB "+jsRealB_version+" ("+jsRealB_dateCreated+") Development Environment [help() for info]**") | ||
if (args.length>2){ | ||
if (args[2]=="en")loadEn(true); | ||
if (args[2]=="dme"){ | ||
loadEn(true); | ||
updateLexicon(require("../data/lexicon-dme.json")); | ||
console.log("dme lexicon loaded") | ||
} else if (args[2]=="fr")loadFr(true); | ||
else { | ||
console.log("Language "+args[2]+" not implemented"); | ||
loadFr(true); | ||
} | ||
} else loadFr(true); | ||
|
||
// customize Read-Eval-Print loop | ||
var repl = require('repl'); | ||
// specialized output | ||
function myWriter(output) { | ||
if (isConstituent(output)) // realize the sentence | ||
return "=> "+output.toString(); | ||
if (typeof output == "string") // output a string as is | ||
return output; | ||
return util.inspect(output); // inspect other types of output | ||
} | ||
|
||
const replServer=repl.start({ | ||
prompt: 'jsRealB > ', | ||
useGlobal: true, | ||
ignoreUndefined: true, | ||
writer:myWriter, | ||
replMode: repl.REPL_MODE_STRICT | ||
}); | ||
|
||
// add commands for querying the linguistic resources | ||
replServer.defineCommand('cn', { | ||
help: 'conjugation information for table no', | ||
action(no) { | ||
console.log(getConjugation(no)); | ||
this.displayPrompt(); | ||
} | ||
}); | ||
replServer.defineCommand('ce', { | ||
help: 'conjugation information for table with ending', | ||
action(ending) { | ||
console.log(getConjugationEnding(ending)); | ||
this.displayPrompt(); | ||
} | ||
}); | ||
replServer.defineCommand('dn', { | ||
help: 'declension information for table no', | ||
action(no) { | ||
console.log(getDeclension(no)); | ||
this.displayPrompt(); | ||
} | ||
}); | ||
replServer.defineCommand('de', { | ||
help: 'declension information for table with ending', | ||
action(ending) { | ||
console.log(getDeclensionEnding(ending)); | ||
this.displayPrompt(); | ||
} | ||
}); | ||
replServer.defineCommand('lm', { | ||
help: 'lemmatize: get jsRealB expression for form', | ||
action(word) { | ||
console.log(lemmatize(word)); | ||
this.displayPrompt(); | ||
} | ||
}); | ||
replServer.defineCommand('lx', { | ||
help: 'get lexicon info for form', | ||
action(word) { | ||
var info=getLexiconInfo(word); | ||
if (info===undefined) | ||
console.log(word+":"+(getLanguage()=="en"?" not found":"pas trouvé")); | ||
else console.log(util.inspect(info,{depth:null})); | ||
this.displayPrompt(); | ||
} | ||
}); | ||
|
||
// save the history of commands... which is not done when a custom repl is used | ||
// adapted from https://medium.com/@tjwebb/a-custom-node-repl-with-history-is-not-as-hard-as-it-looks-3eb2ca7ec0bd | ||
|
||
// load saved history | ||
const historyFile=require('os').homedir()+'/.node_repl_history' | ||
|
||
fs.statSync(historyFile) | ||
fs.readFileSync(historyFile,"utf8").split('\n') | ||
.reverse() | ||
.filter(line => line.trim()) | ||
.map(line => replServer.history.push(line)) | ||
|
||
// save the commands from this session on normal exit | ||
process.on('exit', function () { | ||
fs.appendFileSync(historyFile, replServer.lines.join('\n')) | ||
}); |
Oops, something went wrong.