• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

nielstron / quantulum3 / 897

pending completion
897

push

travis-ci-com

web-flow
Merge pull request #218 from adhardydm/negative-ranges

Enhance parsing of ranges to better handle negative values

22 of 22 new or added lines in 2 files covered. (100.0%)

1513 of 1546 relevant lines covered (97.87%)

4.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/quantulum3/scripts/train.py
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
""" Train the disambiguator """
5✔
4

5
import argparse
5✔
6
import json
5✔
7
import logging
5✔
8
import time
5✔
9

10
from quantulum3.classifier import train_classifier
5✔
11

12
_LOGGER = logging.getLogger(__name__)
5✔
13

14

15
def main(args=None):
5✔
16
    logging.basicConfig(level=logging.INFO)
5✔
17
    parser = argparse.ArgumentParser(
5✔
18
        "train",
19
        description="Train unit disambiguator based on data in quantulum "
20
        "project folder",
21
    )
22
    parser.add_argument(
5✔
23
        "--store",
24
        "-s",
25
        help="store resulting classifier as a joblib file",
26
        action="store_true",
27
    )
28
    parser.add_argument(
5✔
29
        "--lang",
30
        "-l",
31
        help="language in which to train the classifier, default 'en_US'",
32
        type=str,
33
        default="en_US",
34
    )
35
    parser.add_argument(
5✔
36
        "--data",
37
        "-d",
38
        help=(
39
            "path to one or more json training files. If none are given, the default training "
40
            "data in the quantulum3 project folder is used. Multiple files can be given by "
41
            "specifying this argument multiple times (e.g. -d train1.json -d train2.json). "
42
            "See the project README for more information."
43
        ),
44
        type=str,
45
        action="append",
46
    )
47
    parser.add_argument(
5✔
48
        "--output",
49
        "-o",
50
        help=(
51
            "path to a folder where the resulting classifier is stored. If "
52
            "not given, the default location in the quantulum3 project folder "
53
            "is used"
54
        ),
55
        type=str,
56
        default=None,
57
    )
58

59
    args = parser.parse_args(args)
5✔
60

61
    if args.data is not None:
5✔
62
        training_set = []
5✔
63
        args.lang = None
5✔
64
        for file in args.data:
5✔
65
            training_set += json.load(open(file))
5✔
66
    else:
67
        training_set = None
5✔
68

69
    if args.output is not None:
5✔
70
        # override this option if an output file is given, feels intuitive to do
71
        args.store = True
5✔
72

73
    _LOGGER.info(
5✔
74
        "Start training for language {}, {}storing the classifier".format(
75
            args.lang, "" if args.store else "not "
76
        )
77
    )
78
    start = time.process_time()
5✔
79
    try:
5✔
80
        train_classifier(
5✔
81
            store=args.store,
82
            lang=args.lang,
83
            training_set=training_set,
84
            output_path=args.output,
85
        )
86
    except ImportError:
5✔
87
        _LOGGER.error(
5✔
88
            "Could not train the classifier. Make sure you have the "
89
            f"required dependencies installed. "
90
            "These can be installed in pip using the command "
91
            "'pip install quantulum3[classifier]'"
92
        )
93
    else:
94
        end = time.process_time()
5✔
95
        _LOGGER.info("Done in {} s".format(end - start))
5✔
96

97

98
if __name__ == "__main__":
5✔
99
    main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc