delphin.commands

PyDelphin API counterparts to the delphin commands.

The public functions in this module largely mirror the front-end subcommands provided by the delphin command, with some small changes to argument names or values to be better-suited to being called from within Python.

delphin.commands.compare(testsuite, gold, select='i-id i-input mrs')[source]

Compare two [incr tsdb()] profiles.

Parameters:
  • testsuite (str, TestSuite) – path to the test [incr tsdb()] testsuite or a TestSuite object
  • gold (str, TestSuite) – path to the gold [incr tsdb()] testsuite or a TestSuite object
  • select – TSQL query to select (id, input, mrs) triples (default: i-id i-input mrs)
Yields:

dict

Comparison results as:

{"id": "item identifier",
 "input": "input sentence",
 "test": number_of_unique_results_in_test,
 "shared": number_of_shared_results,
 "gold": number_of_unique_results_in_gold}
delphin.commands.convert(path, source_fmt, target_fmt, select='result:mrs', properties=True, show_status=False, predicate_modifiers=False, color=False, pretty_print=False, indent=None)[source]

Convert between various DELPH-IN Semantics representations.

Parameters:
  • path (str, file) – filename, testsuite directory, open file, or stream of input representations
  • source_fmt (str) – convert from this format
  • target_fmt (str) – convert to this format
  • select (str) – TSQL query for selecting data (ignored if path is not a testsuite directory; default: “result:mrs”)
  • properties (bool) – include morphosemantic properties if True (default: True)
  • show_status (bool) – show disconnected EDS nodes (ignored if target_fmt is not “eds”; default: False)
  • predicate_modifiers (bool) – apply EDS predicate modification for certain kinds of patterns (ignored if target_fmt is not an EDS format; default: False)
  • color (bool) – apply syntax highlighting if True and target_fmt is “simplemrs” (default: False)
  • pretty_print (bool) – if True, format the output with newlines and default indentation (default: False)
  • indent (int, optional) – specifies an explicit number of spaces for indentation (implies pretty_print)
Returns:

str – the converted representation

delphin.commands.mkprof(destination, source=None, relations=None, where=None, in_place=False, skeleton=False, full=False, gzip=False)[source]

Create [incr tsdb()] profiles or skeletons.

Data for the testsuite may come from an existing testsuite or from a list of sentences. There are four main usage patterns:

  • source=”testsuite/” – read data from testsuite/
  • source=None, in_place=True – read data from destination
  • source=None, in_place=False – read sentences from stdin
  • source=”sents.txt” – read sentences from sents.txt

For the latter two, the relations parameter must be specified.

Parameters:
  • destination (str) – path of the new testsuite
  • source (str) – path to a source testsuite or a file containing sentences; if not given and in_place is False, sentences are read from stdin
  • relations (str) – path to a relations file to use for the created testsuite; if None and source is given, the relations file of the source testsuite is used
  • where (str) – TSQL condition to filter records by; ignored if source is not a testsuite
  • in_place (bool) – if True and source is not given, use destination as the source for data (default: False)
  • skeleton (bool) – if True, only write tsdb-core files (default: False)
  • full (bool) – if True, copy all data from the source testsuite (requires source to be a testsuite path; default: False)
  • gzip (bool) – if True, non-empty tables will be compressed with gzip
delphin.commands.process(grammar, testsuite, source=None, select=None, generate=False, transfer=False, options=None, all_items=False, result_id=None, gzip=False)[source]

Process (e.g., parse) a [incr tsdb()] profile.

Results are written to directly to testsuite.

If select is None, the defaults depend on the task:

Task Default value of select
Parsing item:i-input
Transfer result:mrs
Generation result:mrs
Parameters:
  • grammar (str) – path to a compiled grammar image
  • testsuite (str) – path to a [incr tsdb()] testsuite where data will be read from (see source) and written to
  • source (str) – path to a [incr tsdb()] testsuite; if None, testsuite is used as the source of data
  • select (str) – TSQL query for selecting processor inputs (default depends on the processor type)
  • generate (bool) – if True, generate instead of parse (default: False)
  • transfer (bool) – if True, transfer instead of parse (default: False)
  • options (list) – list of ACE command-line options to use when invoking the ACE subprocess; unsupported options will give an error message
  • all_items (bool) – if True, don’t exclude ignored items (those with i-wf==2) when parsing
  • result_id (int) – if given, only keep items with the specified result-id
  • gzip (bool) – if True, non-empty tables will be compressed with gzip
delphin.commands.repp(file, config=None, module=None, active=None, format=None, trace_level=0)[source]

Tokenize with a Regular Expression PreProcessor (REPP).

Results are printed directly to stdout. If more programmatic access is desired, the delphin.repp module provides a similar interface.

Parameters:
  • file (str, file) – filename, open file, or stream of sentence inputs
  • config (str) – path to a PET REPP configuration (.set) file
  • module (str) – path to a top-level REPP module; other modules are found by external group calls
  • active (list) – select which modules are active; if None, all are used; incompatible with config (default: None)
  • format (str) – the output format (“yy”, “string”, “line”, or “triple”; default: “yy”)
  • trace_level (int) – if 0 no trace info is printed; if 1, applied rules are printed, if greather than 1, both applied and unapplied rules (in order) are printed (default: 0)
delphin.commands.select(dataspec, testsuite, mode='list', cast=True)[source]

Select data from [incr tsdb()] profiles.

Parameters:
  • query (str) – TSQL select query (e.g., ‘i-id i-input mrs’ or ‘* from item where readings > 0’)
  • testsuite (str, TestSuite) – testsuite or path to testsuite containing data to select
  • mode (str) – see delphin.itsdb.select_rows() for a description of the mode parameter (default: list)
  • cast (bool) – if True, cast column values to their datatype according to the relations file (default: True)
Returns:

a generator that yields selected data