Skip to content

Commit

Permalink
Merge 6bfaeab into 892101d
Browse files Browse the repository at this point in the history
  • Loading branch information
nielstron committed Oct 7, 2020
2 parents 892101d + 6bfaeab commit a21c655
Show file tree
Hide file tree
Showing 26 changed files with 84 additions and 98 deletions.
8 changes: 8 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[settings]
# ensure compatability with black
multi_line_output=3
include_trailing_comma = True
force_grid_wrap = 0
use_parentheses = True
ensure_newline_before_comments = True
line_length = 88
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
repos:
- repo: https://github.com/psf/black
rev: '20.8b1'
hooks:
- id: black
- repo: https://github.com/pycqa/isort
rev: '5.5.4'
hooks:
- id: isort
20 changes: 11 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
language: python

python:
- "3.4"
- "3.5"
- "3.6"
- "3.7"
dist: xenial
sudo: true

matrix:
include:
- python: '3.5'
- python: '3.6'
- python: '3.7'
- python: '3.8'
env: PRE_COMMIT=1
fast_finish: true
dist: xenial
sudo: true

install:
- test ! "$PRE_COMMIT" || pip install pre-commit
- pip install pylint
- pip install coverage
- pip install coveralls
# Check if installing works
- pip install -e .

script:
- test ! "$PRE_COMMIT" || pre-commit run --all-files
# Check for import errors
- coverage run --source=quantulum3 scripts/test_import_error.py
# Build common words
Expand All @@ -44,7 +46,7 @@ deploy:
provider: pypi
on:
branch: master
python: "3.7"
python: "3.8"
distributions: "sdist bdist_wheel"
skip_existing: true
# Keep the generated classifier
Expand Down
1 change: 0 additions & 1 deletion quantulum3/_lang/en_US/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Standard library
from pathlib import Path

lang = Path(__file__).parent.name
1 change: 0 additions & 1 deletion quantulum3/_lang/en_US/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
:mod:`Quantulum` classifier functions.
"""

# Standard library
import re
import string

Expand Down
8 changes: 2 additions & 6 deletions quantulum3/_lang/en_US/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
:mod:`Quantulum` unit and entity loading functions.
"""

from builtins import open

# Standard library
import os
import json
import os
from builtins import open
from collections import defaultdict

# Dependencies
import inflect

# Quantulum
from ... import load
from . import lang

Expand Down
22 changes: 10 additions & 12 deletions quantulum3/_lang/en_US/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
:mod:`Quantulum` parser.
"""

from . import lang

# Standard library
import re
import logging
import re

# Quantulum
from ... import load
from ... import regex as reg
from ... import classes as cls
from ... import parser
from ... import load, parser
from ... import regex as reg
from . import lang
from .load import COMMON_WORDS

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -203,10 +199,12 @@ def build_quantity(orig_text, text, item, values, unit, surface, span, uncert):
# When it comes to currencies, some users prefer the format ($99.99) instead of -$99.99
try:
if (
len(values) == 1 and unit.entity.name == "currency"
and orig_text[span[0]-1] == "(" and orig_text[span[1]] == ")"
and values[0] >= 0
):
len(values) == 1
and unit.entity.name == "currency"
and orig_text[span[0] - 1] == "("
and orig_text[span[1]] == ")"
and values[0] >= 0
):
span = (span[0] - 1, span[1] + 1)
surface = "({})".format(surface)
values[0] = -values[0]
Expand Down
4 changes: 1 addition & 3 deletions quantulum3/_lang/en_US/speak.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
:mod:`Quantulum` class to spoken conversion.
"""

# Quantulum
from ... import load
from ... import parser
from ... import load, parser
from . import lang


Expand Down
1 change: 0 additions & 1 deletion quantulum3/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
:mod:`Quantulum` classes.
"""

# Quantulum
from . import speak

###############################################################################
Expand Down
17 changes: 8 additions & 9 deletions quantulum3/classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
:mod:`Quantulum` classifier functions.
"""

# Standard library
import json
import logging
import pkg_resources
import os
import multiprocessing
import os

import pkg_resources

from . import language, load
from .load import cached

# Semi-dependencies
try:
from sklearn.linear_model import SGDClassifier
from sklearn.feature_extraction.text import TfidfVectorizer
import joblib
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import SGDClassifier

USE_CLF = True
except ImportError:
Expand All @@ -26,10 +29,6 @@
except ImportError:
wikipedia = None

# Quantulum
from . import load
from .load import cached
from . import language

_LOGGER = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions quantulum3/disambiguate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
:mod:`Quantulum` disambiguation functions.
"""

# Quantulum
from . import classifier as clf
from . import no_classifier as no_clf
from . import load
from . import no_classifier as no_clf


###############################################################################
Expand Down
3 changes: 1 addition & 2 deletions quantulum3/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
:mod:`Quantulum` parser.
"""

# Standard library
import re
from importlib import import_module
from pathlib import Path
import re

TOPDIR = Path(__file__).parent or Path(".")

Expand Down
2 changes: 0 additions & 2 deletions quantulum3/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
:mod:`Quantulum` unit and entity loading functions.
"""

# Standard library
import json
from collections import defaultdict
from pathlib import Path

# Quantulum
from . import classes as c
from . import language

Expand Down
1 change: 0 additions & 1 deletion quantulum3/no_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""
from __future__ import division

# Quantulum
from . import load


Expand Down
11 changes: 4 additions & 7 deletions quantulum3/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
:mod:`Quantulum` parser.
"""

# Standard library
import re
import logging
from fractions import Fraction
import re
from collections import defaultdict
from fractions import Fraction

# Quantulum
from . import load
from . import regex as reg
from . import classes as cls
from . import disambiguate as dis
from . import language
from . import language, load
from . import regex as reg

_LOGGER = logging.getLogger(__name__)

Expand Down
5 changes: 1 addition & 4 deletions quantulum3/regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
:mod:`Quantulum` regex functions.
"""

# Standard library
import re

# Quantulum
from . import load
from . import language, load
from .load import cached
from . import language


###############################################################################
Expand Down
2 changes: 0 additions & 2 deletions quantulum3/speak.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
:mod:`Quantulum` classes.
"""

# Dependencies
import num2words

# Quantulum
from . import language


Expand Down
20 changes: 8 additions & 12 deletions quantulum3/tests/test_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,24 @@

from __future__ import division

# Standard library
import os
import json
import urllib.request
import os
import unittest
import urllib.request

import joblib
import wikipedia

# Quantulum
from .. import load
from .. import parser as p
from .. import classifier as clf
from .. import language
from .. import language, load
from .. import parser as p
from .test_setup import (
add_type_equalities,
load_expand_tests,
load_quantity_tests,
multilang,
add_type_equalities,
)

# Dependencies
import joblib
import wikipedia

COLOR1 = "\033[94m%s\033[0m"
COLOR2 = "\033[91m%s\033[0m"
TOPDIR = os.path.dirname(__file__) or "."
Expand Down
6 changes: 2 additions & 4 deletions quantulum3/tests/test_no_classifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
:mod:`Quantulum` tests.
"""

# Standard library
import os
import unittest

# Quantulum
from .. import parser as p
from .. import classifier as clf
from .test_setup import load_quantity_tests, multilang, add_type_equalities
from .. import parser as p
from .test_setup import add_type_equalities, load_quantity_tests, multilang

COLOR1 = "\033[94m%s\033[0m"
COLOR2 = "\033[91m%s\033[0m"
Expand Down
13 changes: 5 additions & 8 deletions quantulum3/tests/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@
:mod:`Quantulum` tests.
"""

# Standard library
import json
import os
import re
import json
import unittest

# Dependencies
from .. import classes as cls
from .. import language, load
from .. import parser as p

try:
import wikipedia
except ImportError:
wikipedia = None

# Quantulum
from .. import load
from .. import parser as p
from .. import classes as cls
from .. import language

COLOR1 = "\033[94m%s\033[0m"
COLOR2 = "\033[91m%s\033[0m"
Expand Down
2 changes: 1 addition & 1 deletion scripts/build.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import os
from io import open
import json

from quantulum3._lang.en_US import load

Expand Down
4 changes: 2 additions & 2 deletions scripts/download_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# -*- coding: utf-8 -*-
""" Download new WikiPedia pages """

from quantulum3.classifier import download_wiki

import argparse

from quantulum3.classifier import download_wiki

arguments = [
{
"dest": "store",
Expand Down

0 comments on commit a21c655

Please sign in to comment.