Skip to content

Commit

Permalink
Merge pull request #353 from delph-in/release-1.7.0
Browse files Browse the repository at this point in the history
Release 1.7.0
  • Loading branch information
goodmami authored Oct 14, 2022
2 parents 9902750 + 8437127 commit b5c7094
Show file tree
Hide file tree
Showing 75 changed files with 1,376 additions and 226 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: ["3.7", "3.8", "3.9", "3.10"]

steps:
- uses: actions/checkout@v2
Expand Down
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
# Change Log

## [v1.7.0]

**Release date: 2022-10-13**

Updates Python support to currently active releases. Includes
`delphin.highlight` (adds a dependency on Pygments), `delphin.edm`,
and `delphin.codecs.dmrstikz` directly instead of as separate plugins.

### Python Versions

* Removed Python 3.6 support ([#343])
* Added Python 3.10 support ([#343])

### Added

* `delphin.highlight` for syntax highlighting; it is no longer
necessary to install this as a plugin ([#344])
* `delphin.edm` for elementary dependency matching; it is no longer
necessary to install this as a plugin ([#344])
* `delphin.codecs.dmrstikz` for exporting DMRS with tikz-dependency;
it is no longer necessary to install this as a plugin ([#344])
* `executable` parameter to `delphin.commands.process()` ([#352])
* `--executable` option to `delphin process` command ([#352])

### Fixed

* The `mkprof` command no longer raises an error on an empty sentence ([#335])
* EDS conversion in `delphin.edm` now more robustly handles errors


## [v1.6.0]

**Release date: 2021-09-30**
Expand Down Expand Up @@ -1346,6 +1376,7 @@ There was no CHANGELOG file prior to this release, so I don't have much
information about changes, except for
[commit messages](../../commits/v0.2).

[v1.7.0]: ../../releases/tag/v1.7.0
[v1.6.0]: ../../releases/tag/v1.6.0
[v1.5.1]: ../../releases/tag/v1.5.1
[v1.5.0]: ../../releases/tag/v1.5.0
Expand Down Expand Up @@ -1521,3 +1552,7 @@ information about changes, except for
[#331]: https://github.com/delph-in/pydelphin/issues/331
[#333]: https://github.com/delph-in/pydelphin/issues/333
[#334]: https://github.com/delph-in/pydelphin/issues/334
[#335]: https://github.com/delph-in/pydelphin/issues/335
[#343]: https://github.com/delph-in/pydelphin/issues/343
[#344]: https://github.com/delph-in/pydelphin/issues/344
[#352]: https://github.com/delph-in/pydelphin/issues/352
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ For bug requests, please provide the following, if possible:
```python
>>> from delphin.__about__ import __version__
>>> __version__ # distribution version
'1.6.0'
'1.7.0'
>>> from delphin import mrs
>>> mrs.__version__ # package version
'1.6.0'
'1.7.0'
```
* Python version (e.g. 3.6, 3.7, etc.)
* Python version (e.g. 3.7, 3.8, etc.)

For feature requests, please provide a use case for the feature.

Expand Down
2 changes: 1 addition & 1 deletion delphin/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# the warehouse project:
# https://github.com/pypa/warehouse/blob/master/warehouse/__about__.py

__version__ = '1.6.0'
__version__ = '1.7.0'
__version_info__ = __version__.replace('.', ' ').replace('-', ' ').split()

__title__ = 'PyDelphin'
Expand Down
11 changes: 0 additions & 11 deletions delphin/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,6 @@ def call_convert(args):
else:
color = (args.color == 'always'
or (args.color == 'auto' and sys.stdout.isatty()))
if color:
try:
import delphin.highlight # noqa: F401
except ImportError:
# don't warn if color=auto
if args.color == 'always':
warnings.warn(
'delphin.highlight must be installed for '
'syntax highlighting',
PyDelphinWarning)
color = False
if args.indent and args.indent is not True:
if args.indent.lower() in ('no', 'none'):
args.indent = None
Expand Down
152 changes: 152 additions & 0 deletions delphin/cli/edm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@

"""
Compute the EDM (Elementary Dependency Match) score for two collections.
The collections, GOLD and TEST, may be files containing semantic
representations, decoded using '--format'; or an [incr tsdb()] test
suite directory, selecting MRSs using '-p' for the parse result
number. GOLD and TEST should contain the same number of items. MRS
representations will be converted to EDS for comparison.
"""

from typing import Optional, Iterator, Union
import argparse
from pathlib import Path
import warnings
import logging

from delphin import util
from delphin import tsdb
from delphin import itsdb
from delphin import edm
from delphin import mrs
from delphin import eds
from delphin import dmrs


logger = logging.getLogger(__name__)

_SemanticRepresentation = Union[eds.EDS, dmrs.DMRS]

parser = argparse.ArgumentParser(add_help=False)

COMMAND_INFO = {
'name': 'edm',
'help': 'Evaluate with Elementary Dependency Match',
'description': __doc__,
'parser': parser,
}


def call_compute(args):
golds = _iter_representations(args.GOLD, args.format, args.p)
tests = _iter_representations(args.TEST, args.format, args.p)
p, r, f = edm.compute(
golds,
tests,
name_weight=args.N,
argument_weight=args.A,
property_weight=args.P,
constant_weight=args.C,
top_weight=args.T,
ignore_missing_gold=args.ignore_missing in ('gold', 'both'),
ignore_missing_test=args.ignore_missing in ('test', 'both'))
print(f'Precision:\t{p}')
print(f' Recall:\t{r}')
print(f' F-score:\t{f}')


def _iter_representations(
path: Path,
fmt: str,
p: int
) -> Iterator[Optional[_SemanticRepresentation]]:
if tsdb.is_database_directory(path):
logger.debug('reading MRSs from profile: %s', (path,))
ts = itsdb.TestSuite(path)
for response in ts.processed_items():
try:
result = response.result(p)
except IndexError:
yield None
else:
yield _eds_from_mrs(result.mrs(), predicate_modifiers=True)

elif path.is_file():
logger.debug('reading %s from file: %s', (fmt, path,))
codec = util.import_codec(fmt)
rep = codec.CODEC_INFO.get('representation', '').lower()
if rep == 'mrs':
for sr in codec.load(path):
yield _eds_from_mrs(sr, predicate_modifiers=True)
elif rep in ('dmrs', 'eds'):
for sr in codec.load(path):
yield sr
else:
raise ValueError(f'unsupported representation: {rep}')

else:
raise ValueError(f'not a file or TSDB database: {path}')


def _eds_from_mrs(
m: mrs.MRS,
predicate_modifiers: bool,
errors: str = 'warn',
) -> Optional[eds.EDS]:
try:
e = eds.from_mrs(m, predicate_modifiers=predicate_modifiers)
except Exception:
logger.debug('could not convert MRS to EDS')
if errors == 'warn':
warnings.warn("error in EDS conversion; skipping entry")
elif errors == 'strict':
raise
e = None
return e


parser.set_defaults(func=call_compute)
# data selection
parser.add_argument(
'GOLD',
type=Path,
help='corpus of gold semantic representations')
parser.add_argument(
'TEST',
type=Path,
help='corpus of test semantic representations')
parser.add_argument(
'-f',
'--format',
metavar='FMT',
default='eds',
help='semantic representation format (default: eds)')
parser.add_argument(
'-p',
metavar='N',
type=int,
default=0,
help='parse result number (default: 0)')
parser.add_argument(
'--ignore-missing',
metavar='X',
choices=('gold', 'test', 'both', 'none'),
default='none',
help='do not treat missing Xs as a mismatch (default: none)')
# comparison configuration
parser.add_argument(
'-A', metavar='WEIGHT', type=float, default=1.0,
help='weight for argument triples (default: 1.0)')
parser.add_argument(
'-N', metavar='WEIGHT', type=float, default=1.0,
help='weight for name (predicate) triples (default: 1.0)')
parser.add_argument(
'-P', metavar='WEIGHT', type=float, default=1.0,
help='weight for property triples (default: 1.0)')
parser.add_argument(
'-C', metavar='WEIGHT', type=float, default=1.0,
help='weight for constant triples (default: 1.0)')
parser.add_argument(
'-T', metavar='WEIGHT', type=float, default=1.0,
help='weight for matching top triples (default: 1.0)')
6 changes: 5 additions & 1 deletion delphin/cli/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def call_process(args):
options=shlex.split(args.options),
all_items=args.all_items,
result_id=args.p,
gzip=args.gzip)
gzip=args.gzip,
executable=args.executable)


# process subparser
Expand Down Expand Up @@ -92,3 +93,6 @@ def call_process(args):
)
parser.add_argument(
'-z', '--gzip', action='store_true', help='compress table files with gzip')
parser.add_argument(
'--executable', metavar='PATH', default='ace',
help='path to ACE executable (default: ace)')
10 changes: 0 additions & 10 deletions delphin/cli/repp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@
def call_repp(args):
color = (args.color == 'always'
or (args.color == 'auto' and sys.stdout.isatty()))
if color:
try:
import pygments # noqa: F401
except ImportError:
# don't warn if color=auto
if args.color == 'always':
warnings.warn(
'Pygments must be installed for diff highlighting',
PyDelphinWarning)
color = False
return repp(
args.FILE or sys.stdin,
config=args.config,
Expand Down
2 changes: 0 additions & 2 deletions delphin/codecs/ace.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
Deserialization of MRSs in ACE's stdout protocols.
"""
Expand Down
2 changes: 0 additions & 2 deletions delphin/codecs/dmrsjson.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
DMRS-JSON serialization and deserialization.
"""
Expand Down
2 changes: 0 additions & 2 deletions delphin/codecs/dmrspenman.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

"""
DMRS-PENMAN serialization and deserialization.
"""
Expand Down
Loading

0 comments on commit b5c7094

Please sign in to comment.