Commit Graph

125 Commits

Author SHA1 Message Date
Inari Listenmaa
3e0c0fa463 define default depths for shell and server only once 2025-08-02 21:46:13 +02:00
Hans Leiss
5776b567a2 Reactivate the gf-shell command 'pt -transfer' 2025-02-19 12:59:43 +01:00
Inari Listenmaa
2f31bbab23 Apply gt to all arguments when piped 2024-03-15 12:43:17 +01:00
Krasimir Angelov
b7672b67a3 adjust the -view command depending on the OS 2022-05-31 10:15:50 +02:00
Andreas Källberg
2c37e7dfad Fix build for ghc-7.10.3 2021-06-16 14:54:36 +08:00
Andreas Källberg
b1ed63b089 Don't print stack traces in Command.hs
They don't provide useful info anyways and they are needlessly verbose.
2021-06-16 14:26:22 +08:00
Andreas Källberg
57ce76dbc1 Add two more missing MonadFail imports 2020-09-05 20:57:30 +02:00
Andreas Källberg
0581d6827e Fix most build errors 2020-08-05 18:48:24 +02:00
Aarne Ranta
8787b56def option rf -paragraphs 2018-09-21 10:40:39 +02:00
Thomas Hallgren
820d2d503f Fixes for GHC 8.4.1 compatibility
* In GHC 8.4.1, the operator <> has become a method of the Semigroup class
  and is exported from the Prelude. This is unfortunate, since <> is also
  exported from the standard library module Text.PrettyPrint, so in any
  module that defines a pretty printer, there is likely to be an ambiguity.

  This affects ~18 modules in GF. Solution:

    import Prelude hiding (<>)

  This works also in older versions of GHC, since GHC does't complain if
  you hide something that doesn't exists.

* In GHC 8.4.1, Semigroup has become a superclass of Monoid. This means
  that anywhere you define an instance of the Monoid class you also have to
  define an instance in the Semigroup class.

  This affects Data.Binary.Builder in GF. Solution: conditionally define
  a Semigroup instance if compiling with base>=4.11 (ghc>=8.4.1)
2018-04-18 19:18:10 +02:00
Aarne Ranta
79feeaf5b8 new option linerize -tabtreebank for tab-separated treebank generation 2017-12-06 17:37:12 +01:00
Krasimir Angelov
c3297dd2e9 update documentation for command pt 2017-09-05 10:33:53 +02:00
aarne
ee2f3d085e vd command now reads local concrete configurations to deal with syncat words; TODO: dissolve clustered multiwords bound with + 2017-04-06 11:55:21 +00:00
hallgren
096b4cfcee PGF service & minibar: only show dependency diagrams if the labels are known
+ The PGF service now reads and caches dependency label configuration files.
+ The grammar info returned by command=grammar has a new boolean field 
  'hasDependencyLabels' to indicate if dependency labels were found for
  the grammar. Also, command=deptree will now fail if no labels are present.
+ The minibar only shows word dependency trees if labels are present.
+ Also changed the type of getDepLabels from [String] -> Labels to
  String -> Labels, since all uses were in the form "getDepLabels . lines".
2016-06-09 13:12:14 +00:00
hallgren
649ab21cec Changes for compatibility with GHC 8.0.1 2016-05-22 20:15:31 +00:00
hallgren
ab3cc77656 GF shell: fix a parsing problem with the cc command
This patch fixes a problem introduced last year when the GF shell was
refactored to allow more commands to be treated uniformly and be part
of pipes. The cc command was one of those commands, but unfortunately this
introduced a parsing problem, e.g.

	> cc "last"
	constant not found: last

	> cc "last"++"year"
	command not parsed: cc "last"++"year"

This happened because the generic command line parser in
GF.Command.{Abstract,Parse} assumes that all commands have an argument of
type PGF.Expr. Commands that expect other types of arguments have to
use PGF.showExpr combined with other conversion to the argument type they
expect. The cc command excpets a GF.Grammar.Term, and unfortunately not 
all terms survice the roundtrip through PGF.Expr, in part because of
an additional hack to allow strings to be roundtripped through PGF.Expr
without adding superfluous double quotes.

To solve the problem, this patch

 + makes room for arguments of type Term in the Argument type in
   GF.Command.Abstract.
   
 + makes a special case for the cc command in GF.Command.Parse, by
   calling the partial parser 'runPartial pTerm' recently added in
   GF.Grammar.Lexer and GF.Grammar.Parser. Care was taken so that
   that "|" and ";" can be used both inside terms and as separators between
   commands in the shell, e.g. things like the following now work:

       > cc ("a"|"b") | ps -lexcode
       variants { "a" ; "b" }

 + introduces a type CommandArgument that replaces [Expr] as the
   type of values passed between commands in pipes. It has room for
   values of type [Expr], [String] and Term, thus eliminating the need
   to roundtrip through the Expr type all the time.
   The hack to avoid adding superfluous quotes when strings are
   roundtripped through Expr has been left in place for now,
   but can probably be removed.
2016-04-07 13:40:05 +00:00
aarne
0a38e137b6 vd -conll2latex now converts conll to latex. Without going through GF trees, but as a service to the dependency parser community. 2015-11-23 10:43:03 +00:00
aarne
d6a505169a added -output=latex to visialize_dependencies. This generates more familiar-looking output than the default graphviz, which can moreover be pasted into LaTeX documents. Some more work is needed to make long sentences look nice and fit on a page; a constant word length is now used to simplify computing the coordinates. 2015-11-17 09:11:10 +00:00
aarne
ce6557f1f2 the visualization commands (aw,vd,vp,vt) can now show multiple trees. Previously they only showed one tree even if there were for instance after ambiguous parsing. The reason was that dot (graphviz) ignored all graphs but the first one. Now the graphs are put into separate files. The 'convert' command from ImageMagick package is used to combine them to one pdf. If this is a problem, the old behaviour can be restored by the -number=1 option to the tree-generating command, which cuts away all trees but the one and doesn't require ImageMagick. 2015-11-05 16:47:41 +00:00
aarne
eb49b6ab56 improved documentation of vp -showdep 2015-11-05 08:23:33 +00:00
aarne
0786dc6f42 dependency labels in parse trees now with the -deps flag, -file=labels_file for configuration. With -nocat option this shows reasonable dep trees, more familiar looking than the vd command. With -showfun flag, the tree gives a rather complete picture of the analysis of the sentence. 2015-11-04 20:36:47 +00:00
aarne
e39787ab88 prepared visualize_parse for showing dependency labels 2015-11-04 17:28:09 +00:00
hallgren
128236eab9 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
c25705519a 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
87e64a804c 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
6fff2def39 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
e50f92c41d GF shell: make environment types abstract, comment out some dead code 2015-08-11 16:14:38 +00:00
hallgren
10e7bacbfd 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
d38efbaa6a 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
8c697b72a4 drop the dependency to FST 2015-04-20 11:56:13 +00:00
aarne
84bce336fd (un)lexmixed: added the other math environments than $ used in latex 2014-10-19 17:43:39 +00:00
aarne
6c2e0d5ce2 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
584d589041 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
30cda51516 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
d6252d1c16 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
d6974a4065 GF shell: fix help text for generate_trees
Trees are not generated with increasing depth.
2013-12-06 13:45:12 +00:00
hallgren
ddac5f9e5a 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
fa4c327463 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
48660c219a 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
2483dc7728 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
e4c6ca41a7 added a -treebank option to the lc command 2013-11-05 20:42:22 +00:00
aarne
aba666c5bc 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
3814841d7d 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
a4194501fe 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
9410c6b141 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
c2e977c67a Commands.hs: fix a copy-paste error in the documentation of put_tree 2013-10-24 14:32:11 +00:00
kr.angelov
09c1bd662d the option -old for the vp command is now redundant 2013-04-19 11:15:18 +00:00
kr.angelov
4e2044ab99 remove the dead code left behind by Peter Ljunglöf in VisualizeTree 2013-04-19 11:13:07 +00:00
kr.angelov
a591160b94 fix the command options for the vd command in the shell 2013-04-19 11:11:57 +00:00
hallgren
b8ce5ef5b3 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