コード例 #1
0
ファイル: download.py プロジェクト: JamieMoon/spaCy
def main(data_size='all', force=False):
    if force:
        sputnik.purge(about.__name__, about.__version__)

    try:
        sputnik.package(about.__name__, about.__version__, about.__default_model__)
        print("Model already installed. Please run 'python -m "
              "spacy.en.download --force' to reinstall.", file=sys.stderr)
        sys.exit(1)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__name__, about.__version__, about.__default_model__)

    try:
        sputnik.package(about.__name__, about.__version__, about.__default_model__)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run 'python -m "
              "spacy.en.download --force'.", file=sys.stderr)
        sys.exit(1)

    # FIXME clean up old-style packages
    migrate(os.path.dirname(os.path.abspath(__file__)))

    print("Model successfully installed.", file=sys.stderr)
コード例 #2
0
ファイル: download.py プロジェクト: adamhadani/spaCy
def download(lang, force=False, fail_on_exist=True, data_path=None):
    if not data_path:
        data_path = util.get_data_path()

    # spaCy uses pathlib, and util.get_data_path returns a pathlib.Path object,
    # but sputnik (which we're using below) doesn't use pathlib and requires
    # its data_path parameters to be strings, so we coerce the data_path to a
    # str here.
    data_path = str(data_path)

    try:
        pkg = sputnik.package(about.__title__, about.__version__,
                        about.__models__.get(lang, lang), data_path)
        if force:
            shutil.rmtree(pkg.path)
        elif fail_on_exist:
            print("Model already installed. Please run 'python -m "
                  "spacy.%s.download --force' to reinstall." % lang, file=sys.stderr)
            sys.exit(0)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__title__, about.__version__,
                              about.__models__.get(lang, lang), data_path)

    try:
        sputnik.package(about.__title__, about.__version__,
                        about.__models__.get(lang, lang), data_path)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run 'python -m "
              "spacy.%s.download --force'." % lang, file=sys.stderr)
        sys.exit(1)

    print("Model successfully installed to %s" % data_path, file=sys.stderr)
コード例 #3
0
ファイル: download.py プロジェクト: paolodedios/spaCy
def download(lang, force=False, fail_on_exist=True):
    try:
        pkg = sputnik.package(about.__title__, about.__version__,
                        about.__models__.get(lang, lang))
        if force:
            shutil.rmtree(pkg.path)
        elif fail_on_exist:
            print("Model already installed. Please run 'python -m "
                  "spacy.%s.download --force' to reinstall." % lang, file=sys.stderr)
            sys.exit(0)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__title__, about.__version__,
                              about.__models__.get(lang, lang))

    try:
        sputnik.package(about.__title__, about.__version__,
                        about.__models__.get(lang, lang))
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run 'python -m "
              "spacy.%s.download --force'." % lang, file=sys.stderr)
        sys.exit(1)

    data_path = util.get_data_path()
    print("Model successfully installed to %s" % data_path, file=sys.stderr)
コード例 #4
0
ファイル: download.py プロジェクト: xfcold/spaCy
def download(lang, force=False, fail_on_exist=True):
    if force:
        sputnik.purge(about.__title__, about.__version__)

    try:
        sputnik.package(about.__title__, about.__version__,
                        about.__models__.get(lang, lang))
        if fail_on_exist:
            print("Model already installed. Please run 'python -m "
                  "spacy.%s.download --force' to reinstall." % lang,
                  file=sys.stderr)
            sys.exit(0)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__title__, about.__version__,
                              about.__models__.get(lang, lang))

    try:
        sputnik.package(about.__title__, about.__version__,
                        about.__models__.get(lang, lang))
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run 'python -m "
              "spacy.%s.download --force'." % lang,
              file=sys.stderr)
        sys.exit(1)

    data_path = util.get_data_path()
    print("Model successfully installed to %s" % data_path, file=sys.stderr)
コード例 #5
0
ファイル: download.py プロジェクト: henningpeters/sense2vec
def main(force=False):
    if force:
        sputnik.purge(about.__name__, about.__version__)

    try:
        sputnik.package(about.__name__, about.__version__, about.__default_model__)
        print("Model already installed. Please run '%s --force to reinstall." % sys.argv[0], file=sys.stderr)
        sys.exit(1)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__name__, about.__version__, about.__default_model__)

    try:
        sputnik.package(about.__name__, about.__version__, about.__default_model__)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run '%s --force." % sys.argv[0], file=sys.stderr)
        sys.exit(1)

    print("Model successfully installed.", file=sys.stderr)
コード例 #6
0
ファイル: util.py プロジェクト: StevenLOL/spaCy
def get_package_by_name(name=None, via=None):
    try:
        return sputnik.package(about.__title__, about.__version__,
                               name or about.__default_model__, data_path=via)
    except PackageNotFoundException as e:
        raise RuntimeError("Model %s not installed. Please run 'python -m "
                           "spacy.en.download' to install latest compatible "
                           "model." % name)
    except CompatiblePackageNotFoundException as e:
        raise RuntimeError("Installed model is not compatible with spaCy "
                           "version. Please run 'python -m spacy.en.download "
                           "--force' to install latest compatible model.")
コード例 #7
0
ファイル: util.py プロジェクト: spacy-io/sense2vec
def get_package_by_name(name=None, via=None):
    try:
        return sputnik.package(about.title, about.version,
                               name or about.default_model, data_path=via)
    except PackageNotFoundException as e:
        raise RuntimeError("Model not installed. Please run 'python -m "
                           "sense2vec.download' to install latest compatible "
                           "model.")
    except CompatiblePackageNotFoundException as e:
        raise RuntimeError("Installed model is not compatible with sense2vec "
                           "version. Please run 'python -m sense2vec.download "
                           "--force' to install latest compatible model.")
コード例 #8
0
ファイル: download.py プロジェクト: anish9208/spaCy
def download(lang, force=False):
    if force:
        sputnik.purge(about.__title__, about.__version__)

    try:
        sputnik.package(about.__title__, about.__version__, about.__models__[lang])
        print("Model already installed. Please run 'python -m "
              "spacy.%s.download --force' to reinstall." % lang, file=sys.stderr)
        sys.exit(0)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__title__, about.__version__, about.__models__[lang])

    try:
        sputnik.package(about.__title__, about.__version__, about.__models__[lang])
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run 'python -m "
              "spacy.%s.download --force'." % lang, file=sys.stderr)
        sys.exit(1)

    print("Model successfully installed.", file=sys.stderr)
コード例 #9
0
ファイル: util.py プロジェクト: yocheah/sense2vec
def get_package_by_name(name=None, via=None):
    try:
        return sputnik.package(about.title,
                               about.version,
                               name or about.default_model,
                               data_path=via)
    except PackageNotFoundException as e:
        raise RuntimeError("Model not installed. Please run 'python -m "
                           "sense2vec.download' to install latest compatible "
                           "model.")
    except CompatiblePackageNotFoundException as e:
        raise RuntimeError("Installed model is not compatible with sense2vec "
                           "version. Please run 'python -m sense2vec.download "
                           "--force' to install latest compatible model.")
コード例 #10
0
ファイル: util.py プロジェクト: anukat2015/spaCy
def get_package_by_name(name=None, via=None):
    try:
        return sputnik.package(about.__title__,
                               about.__version__,
                               name or about.__default_model__,
                               data_path=via)
    except PackageNotFoundException as e:
        raise RuntimeError("Model %s not installed. Please run 'python -m "
                           "spacy.en.download' to install latest compatible "
                           "model." % name)
    except CompatiblePackageNotFoundException as e:
        raise RuntimeError("Installed model is not compatible with spaCy "
                           "version. Please run 'python -m spacy.en.download "
                           "--force' to install latest compatible model.")
コード例 #11
0
def main(force=False):
    about.__title__ = about.title
    about.__version__ = about.version
    about.__default_model__ = about.default_model
    if force:
        sputnik.purge(about.__title__, about.__version__)

    try:
        sputnik.package(about.__title__, about.__version__, about.__default_model__)
        print("Model already installed. Please run '%s --force to reinstall." % sys.argv[0], file=sys.stderr)
        sys.exit(1)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        pass

    package = sputnik.install(about.__title__, about.__version__, about.__default_model__)

    try:
        sputnik.package(about.__title__, about.__version__, about.__default_model__)
    except (PackageNotFoundException, CompatiblePackageNotFoundException):
        print("Model failed to install. Please run '%s --force." % sys.argv[0], file=sys.stderr)
        sys.exit(1)

    print("Model successfully installed.", file=sys.stderr)
コード例 #12
0
ファイル: util.py プロジェクト: Develer/spaCy
def get_package_by_name(name=None, via=None):
    package_name = name or about.__models__[about.__default_lang__]
    lang = get_lang_class(package_name)
    try:
        return sputnik.package(about.__title__, about.__version__,
            package_name, data_path=via)
    except PackageNotFoundException as e:
        raise RuntimeError("Model '%s' not installed. Please run 'python -m "
                           "%s.download' to install latest compatible "
                           "model." % (name, lang.__module__))
    except CompatiblePackageNotFoundException as e:
        raise RuntimeError("Installed model is not compatible with spaCy "
                           "version. Please run 'python -m %s.download "
                           "--force' to install latest compatible model." %
                           (lang.__module__))
コード例 #13
0
def get_package_by_name(name=None, via=None):
    package_name = name or about.__models__[about.__default_lang__]
    lang = get_lang_class(package_name)
    try:
        return sputnik.package(about.__title__,
                               about.__version__,
                               package_name,
                               data_path=via)
    except PackageNotFoundException as e:
        raise RuntimeError("Model '%s' not installed. Please run 'python -m "
                           "%s.download' to install latest compatible "
                           "model." % (name, lang.__module__))
    except CompatiblePackageNotFoundException as e:
        raise RuntimeError("Installed model is not compatible with spaCy "
                           "version. Please run 'python -m %s.download "
                           "--force' to install latest compatible model." %
                           (lang.__module__))
コード例 #14
0
def _import_spacy():
    min_supported_spacy_version = '0.100.6'
    max_supported_spacy_version = '0.100.7'
    try:
        import spacy
    except:
        _logging.getLogger(__name__).error(
            ("spaCy version {} or greater is required. Please" +
             " install spaCy via pip or conda. See https://spacy.io/" +
             " for more information.").format(min_supported_spacy_version))
        raise

    try:
        spacy_version = spacy.about.__version__
        if LooseVersion(spacy_version) < LooseVersion(
                min_supported_spacy_version):
            raise RuntimeError((
                "spaCy version is less than {}. Please upgrade to {}.").format(
                    min_supported_spacy_version, min_supported_spacy_version))
        if LooseVersion(spacy_version) > LooseVersion(
                max_supported_spacy_version):
            _logging.getLogger(__name__).warn((
                "spaCy version is greater than {}. This version has not been tested and may not work"
            ).format(max_supported_spacy_version))

    # If the version attribute doesn't exist, the spaCy version is too old.
    except:
        raise RuntimeError(
            ("spaCy version is less than {}. Please upgrade to {}.").format(
                min_supported_spacy_version, min_supported_spacy_version))

    try:
        nlp = spacy.en.English()

    except:
        data_path = _os.path.join(_os.path.expanduser("~"), ".graphlab",
                                  "spacy_data")
        import sputnik
        if LooseVersion(spacy_version) > LooseVersion(
                min_supported_spacy_version):
            model = spacy.about.__models__['en']
        else:
            model = spacy.about.__default_model__

        try:
            p = sputnik.package(spacy.about.__title__,
                                spacy.about.__version__,
                                model,
                                data_path=_os.path.join(data_path, ""))
            nlp = spacy.en.English(package=p, load_vectors=False)
        except:
            _logging.getLogger(__name__).info(
                "Downloading data for spacy to ~/.graphlab directory")
            sputnik.install(spacy.about.__title__,
                            spacy.about.__version__,
                            model,
                            data_path=data_path)
            p = sputnik.package(spacy.about.__title__,
                                spacy.about.__version__,
                                model,
                                data_path=_os.path.join(data_path, ""))
            nlp = spacy.en.English(package=p, load_vectors=False)

    return nlp