Commit Graph

103 Commits

Author SHA1 Message Date
hallgren
38ce5826a8 GF shell: change parse & linearize to obtain useful results from p|l and l|p in more cases
These changes are inspired by the gf -cshell implementation of these commands.

The output of the linearize command has been changed to remove superfluous
blank lines and commas, and deliver the result as a list of strings instead of
a single multi-line string. This makes it possible to use -all and pipe the
results to the parse command. This also means that with -treebank -all,
the language tag will be repeated for each result from the same language.

The parse command, when trying to parse with more than one language, would
"forget" other results after a failed parse, and thus not send all
successful parses through the pipe. For example, if English is not the first
language in the grammar,

    p "hello" | l

would output nothing, instead of translations of "hello" to all languages,
forcing the user to write

   p -lang=Eng "hello" | l

instead, to get the expected result. The cause of this behaviour was in the
function fromParse, which was rather messy, so I assume it is not intentional,
but the result of a programming mistake at some point.

The fromParse function has now been refactored from a big recursive function
into 

    fromParse opts = foldr (joinPiped . fromParse1 opts) void

where the helper functions fromParse1 deals with a single parse result and
joinPiped combines multiple parse results.
2015-08-26 13:56:23 +00:00
hallgren
09f3937da1 GF shell bug fix: visualize_parse didn't accept the -lang flag
Even though the -lang flag was handled in the implementation, it was not
documented, and GF.Command.Interpreter rejects undocumented flags:

	option not interpreted: lang

This must be a fairly old bug, so it suggests that the vp command isn't used
much...
2015-08-21 12:20:40 +00:00
hallgren
5339c1e6b5 GF Shell: refactoring for improved modularity and reusability:
+ Generalize the CommandInfo type by parameterizing it on the monad
  instead of just the environment.
+ Generalize the commands defined in
  GF.Command.{Commands,Commands2,CommonCommands,SourceCommands,HelpCommand}
  to work in any monad that supports the needed operations.
+ Liberate GF.Command.Interpreter from the IO monad.
  Also, move the current PGF from CommandEnv to GFEnv in
  GF.Interactive, making the command interpreter even more generic.
+ Use a state monad to maintain the state of the interpreter in
  GF.{Interactive,Interactive2}.
2015-08-13 10:49:50 +00:00
hallgren
721f653e99 GF shell: source commands (cc, sd, so, ss & dg) can now be used in pipes
These commands are now implemented as regular commands (i.e. using the
CommandInfo data type) in the new module GF.Command.SourceCommands.

The list of commands exported from GF.Command.Commmands now called pgfCommands
instead of allCommands.

The list allCommands of all commands is now assembled
from sourceCommands, pgfCommands, commonCommands and helpCommand in
GF.Interactive.
2015-08-12 11:05:08 +00:00
hallgren
07fd298700 GF shell: make environment types abstract, comment out some dead code 2015-08-11 16:14:38 +00:00
hallgren
f371a020f9 Factor out common code from GF.Command.Commands and GF.Command.Commands2
Created module GF.Command.CommonCommands with ~250 lines of code for commands
that do not depend on the type of PGF in the environemnt, either because they
don't use the PGF or because they are just documented here and implemented
elsewhere.

TODO: further refactoring so that documentation and implementation of
*all* commands can be kept together.
2015-08-10 16:30:17 +00:00
hallgren
97c6ffd462 Refactor GF shell modules to improve modularity and reusability
+ Move type CommandInfo from GF.Command.Commands to a new module
  GF.Commands.CommandInfo and make it independent of the PGF type.
+ Make the module GF.Command.Interpreter independent of the PGF type and
  eliminate the import of GF.Command.Commands.
+ Move the implementation of the "help" command to its own module
  GF.Command.Help
2015-08-10 13:01:02 +00:00
krasimir
61e37c9e5e drop the dependency to FST 2015-04-20 11:56:13 +00:00
aarne
0025e078ea (un)lexmixed: added the other math environments than $ used in latex 2014-10-19 17:43:39 +00:00
aarne
2cda0ea770 ps -lines preserves line-by-line structure when preprocessing files for parsing line by line 2014-10-17 15:50:03 +00:00
kr.angelov
03b067782c a partial support for def rules in the C runtime
The def rules are now compiled to byte code by the compiler and then to
native code by the JIT compiler in the runtime. Not all constructions
are implemented yet. The partial implementation is now in the repository
but it is not activated by default since this requires changes in the
PGF format. I will enable it only after it is complete.
2014-08-11 10:59:10 +00:00
hallgren
f27d509075 Introducing GF.Text.Pretty for more concise pretty printers and GF.Infra.Location for modularity
GF.Text.Pretty provides the class Pretty and overloaded versions of the pretty
printing combinators in Text.PrettyPrint, allowing pretty printable values to
be used directly instead of first having to convert them to Doc with functions
like text, int, char and ppIdent. Some modules have been converted to use
GF.Text.Pretty, but not all. Precedences could be added to simplify the pretty
printers for terms and patterns.

GF.Infra.Location contains the types Location and L, factored out from
GF.Grammar.Grammar, and the class HasSourcePath. This allowed the import
of GF.Grammar.Grammar to be removed from GF.Infra.CheckM, making it more
like a pure library module.
2014-07-27 22:06:23 +00:00
hallgren
f739841497 PGF library: expose only PGF and PGF.Internal instead of all modules
PGF exports the public, stable API.
PGF.Internal exports additional things needed in the GF compiler & shell,
including the nonstardard version of Data.Binary.
2014-06-12 14:43:18 +00:00
hallgren
e6096bffc5 GF shell: fix help text for generate_trees
Trees are not generated with increasing depth.
2013-12-06 13:45:12 +00:00
hallgren
c29326d074 GF shell: improved system_pipe (aka "?") command
1. No temporary files are created.

2. The output of a system command is read lazily, making it feasible to 
   process large or even infinite output, e.g. the following works as
   expected:

	? "yes" | ? "head -5" | ps -lextext
2013-11-19 15:18:58 +00:00
hallgren
4a5b9ca8cb Fix Issue 60: Weird output when executing system commands from the gf shell
The system_pipe (aka "?") command creates a temporary file _tmpi containing
the input of the system command. It *both* appends _tmpi as an extra argument
to the system command line *and* adds an input redirection "< _tmpi". (It
also uses and output redirection "> _tmpo" to captures the output of the
command.)

With this patch, the _tmpi argument is no longer appended to the command line.
This allows system_pipe to work with pure filters, such as the "tr" commands,
but it will no longer work with commands that require an input file name.
(It is possible to use write_file instead...)

TODO: it would also be fairly easy to eliminate the creation of the _tmpi and
_tmpo files altogether.
2013-11-12 18:07:38 +00:00
hallgren
5beded9330 Make PGF.Tree internal
The only use of PGF.Tree outside the PGF library was in GF.Command.Commands,
and it was eliminated by using PGF.Expr directly instead.
PGF.Paraphrase still uses PGF.Tree.
2013-11-06 14:29:17 +00:00
kr.angelov
475f213c99 the content of ParseEngAbs3.probs is now merged with ParseEngAbs.probs. The later is now retrained. Once the grammar is compiled with the .probs file now it doesn't need anything more to do robust parsing. The robustness itself is controlled by the flags 'heuristic_search_factor', 'meta_prob' and 'meta_token_prob' in ParseEngAbs.gf 2013-11-06 10:21:46 +00:00
aarne
acefeec541 added a -treebank option to the lc command 2013-11-05 20:42:22 +00:00
aarne
6bc1baa7f7 linearization by chunks in the GF shell: a new command 'lc' needed because 'l' requires type checking and trees with metavariable function heads don't type check. This will hopefully be a temporary command. 2013-11-05 17:28:47 +00:00
hallgren
decd7122de Eliminate mutual dependencies between the GF compiler and the PGF library
+ References to modules under src/compiler have been eliminated from the PGF
  library (under src/runtime/haskell). Only two functions had to be moved (from
  GF.Data.Utilities to PGF.Utilities) to make this possible, other apparent
  dependencies turned out to be vacuous.

+ In gf.cabal, the GF executable no longer directly depends on the PGF library
  source directory, but only on the exposed library modules. This means that
  there is less duplication in gf.cabal and that the 30 modules in the
  PGF library will no longer be compiled twice while building GF.

  To make this possible, additional PGF library modules have been exposed, even
  though they should probably be considered for internal use only. They could
  be collected in a PGF.Internal module, or marked as "unstable", to make
  this explicit.

+ Also, by using the -fwarn-unused-imports flag, ~220 redundant imports were
  found and removed, reducing the total number of imports by ~15%.
2013-11-05 13:11:10 +00:00
kr.angelov
620e880155 linref is now used by the linearizer. The visible change is that the 'l' command in the shell now can linearize discontinuous phrases 2013-10-30 14:42:29 +00:00
hallgren
ad0e67530b Functions merge trees into tries in the GF Shell and the PGF web service
* In the shell, the new command tt (to_trie) merges a list of trees into a
  trie and prints it in a readable way, where unique subtrees are marked with
  a "*" and alternative subtrees are marked with numbers.
* In the PGF web service, adding the parameter trie=yes to the parse and
  translate commands augments the JSON output with a trie.

Example to try in the shell:

	Phrasebook> p -lang=Eng "your son waits for you" | tt
2013-10-24 17:29:02 +00:00
hallgren
1fcae658ac Commands.hs: fix a copy-paste error in the documentation of put_tree 2013-10-24 14:32:11 +00:00
kr.angelov
23bf85e023 the option -old for the vp command is now redundant 2013-04-19 11:15:18 +00:00
kr.angelov
d6d4ae3a6b remove the dead code left behind by Peter Ljunglöf in VisualizeTree 2013-04-19 11:13:07 +00:00
kr.angelov
b4374a6a52 fix the command options for the vd command in the shell 2013-04-19 11:11:57 +00:00
hallgren
0667311adf PGF.hs: export function missingLins
Also in Commands.hs: be explicit about things imported from the PGF library
that are not in the public API.
Also a couple of haddock documentation fixes.
2013-04-08 15:38:11 +00:00
aarne
28c59faf29 pg -lexc now writes a list of multichar symbols and a title ("Root") for the lexicon, as required by Xerox lexc 2013-02-03 10:03:15 +00:00
peter.ljunglof
595c475c70 better visualization of parse trees 2012-11-22 08:50:37 +00:00
hallgren
eff4d46fba GF.Command.Command: turn CommandOutput into a newtype
The output from commands is represented as ([Expr],String), where the [Expr] is
used when data is piped between commands and the String is used for the final
output. The String can represent the same list of trees as the [Expr] and/or
contain diagnostic information.

Sometimes the data that is piped between commands is not a list of trees, but
e.g. a string or a list of strings. In those cases, functions like fromStrings
and toStrings are used to encode the data as a [Expr].

This patch introduces a newtype for CommandOutput and collects the functions
dealing with command output in one place to make it clearer what is going on.
It also makes it easier to change to a more direct representation of piped
data, and make pipes more "type safe", if desired.
2012-10-16 13:01:03 +00:00
hallgren
7c65cd4073 Use the SIO monad in the GF shell
+ The restrictions on arbitrary IO when GF is running in restricted mode is now
  enforced in the types.
+ This hopefully also solves an intermittent problem when accessing the GF
  shell through the web API provided by gf -server. This was visible in the
  Simple Translation Tool and probably caused by some low-level bug in the
  GHC IO libraries.
2012-09-25 19:08:33 +00:00
hallgren
31ac2add1f GF.Command.Commands: allCommands is now a constant
The dependency on PGFEnv has been moved from the list to the exec function of
the commands in the list. This means that the help command no longer needs
to generate a new list of commands and that the state of the shell
(type GF.Command.Interpreter.CommandEnv) no longer needs to contain the list
of commands.
2012-09-25 11:42:32 +00:00
kr.angelov
fd5220038d A basic infrastructure for generating Teyjus bytecode from the GF abstract syntax 2012-08-29 11:43:02 +00:00
aarne
8ef8af479f command option ma -known to drop unknown words 2012-06-10 10:43:57 +00:00
Nick Frolov
0baf0d4e4a Fixed a typo in the shell online help 2011-11-01 11:22:13 +00:00
aarne
9db9c49bd6 structured examples in help into pairs (command,explanation) 2011-09-25 08:42:27 +00:00
aarne
ac51d644fc the sd -size command now shows the size of all code needed for defining an oper 2011-09-22 12:11:03 +00:00
aarne
d97101154f documented the ss command 2011-09-22 07:40:19 +00:00
aarne
cdaf3dc2f4 commands ss to show source, and sd to show the dependencies of a constant 2011-09-21 08:12:14 +00:00
hallgren
4e35640bb8 Add a command name header to the 'help -t2t' output 2011-09-15 18:19:01 +00:00
hallgren
e837f072f4 Omit empty sections in gf help output 2011-09-14 20:26:22 +00:00
hallgren
ac0b6db821 GF shell command 'help -t2t' outputs help in txt2tags format 2011-09-14 19:40:28 +00:00
aarne
250c9f8d82 import command now gives priority to new abstract syntax, and discards the old concretes if they are for the old abstract; the new priority is implemented in PGF.Data.unionPGF 2011-08-28 10:35:55 +00:00
aarne
b5d04181ba reload command in shell 2011-08-25 15:58:38 +00:00
aarne
72b63e34bd transliteration via configuration file: ps -to=file or ps -from=file 2011-05-02 14:53:46 +00:00
hallgren
e10b11a1f0 GF shell restricted mode: found one more writeFile that should be restricted 2011-04-08 13:20:50 +00:00
gdetrez
5be1b5d493 Adding a basic lexicon-based tokenizer and the asociated command in gf shell 2011-02-10 15:00:06 +00:00
aarne
d782be6440 generalized pt -transfer so that it goes into subtrees (naive implementation in TreeOperations; using PGF.Expr.match would be better); example given in 'h pt' 2011-03-12 10:20:54 +00:00
aarne
603dc34b63 switched the upper and lower parts of lexc entries to their standard order 2011-03-04 17:25:53 +00:00