当前位置: 首页>>代码示例>>Python>>正文


Python spacy.util方法代码示例

本文整理汇总了Python中spacy.util方法的典型用法代码示例。如果您正苦于以下问题:Python spacy.util方法的具体用法?Python spacy.util怎么用?Python spacy.util使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spacy的用法示例。


在下文中一共展示了spacy.util方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: model_installed

# 需要导入模块: import spacy [as 别名]
# 或者: from spacy import util [as 别名]
def model_installed(name: str) -> bool:
        """Check if spaCy language model is installed.

        From https://github.com/explosion/spaCy/blob/master/spacy/util.py

        :param name:
        :return:
        """
        data_path = util.get_data_path()
        if not data_path or not data_path.exists():
            raise IOError(f"Can't find spaCy data path: {data_path}")
        if name in {d.name for d in data_path.iterdir()}:
            return True
        if is_package(name):  # installed as package
            return True
        if Path(name).exists():  # path to model data directory
            return True
        return False 
开发者ID:HazyResearch,项目名称:fonduer,代码行数:20,代码来源:spacy_parser.py

示例2: is_package

# 需要导入模块: import spacy [as 别名]
# 或者: from spacy import util [as 别名]
def is_package(name: str):
        """Check if string maps to a package installed via pip.
        From https://github.com/explosion/spaCy/blob/master/spacy/util.py
        
        Arguments:
            name {str} -- Name of package
        
        Returns:
            [bool] -- True if installed package, False if not.
        """

        name = name.lower()  # compare package name against lowercase name
        packages = pkg_resources.working_set.by_key.keys()
        for package in packages:
            if package.lower().replace('-', '_') == name:
                return True
            return False 
开发者ID:uwdata,项目名称:errudite,代码行数:19,代码来源:spacy_annotator.py

示例3: model_installed

# 需要导入模块: import spacy [as 别名]
# 或者: from spacy import util [as 别名]
def model_installed(name: str):
        """Check if spaCy language model is installed
        From https://github.com/explosion/spaCy/blob/master/spacy/util.py
        
        Arguments:
            name {str} -- Name of package
        
        Returns:
            [bool] -- True if installed package, False if not.
        """
        data_path = util.get_data_path()
        if not data_path or not data_path.exists():
            raise IOError("Can't find spaCy data path: %s" % str(data_path))
        if name in set([d.name for d in data_path.iterdir()]):
            return True
        if SpacyAnnotator.is_package(name): # installed as package
            return True
        if Path(name).exists(): # path to model data directory
            return True
        return False 
开发者ID:uwdata,项目名称:errudite,代码行数:22,代码来源:spacy_annotator.py

示例4: load_lang_model

# 需要导入模块: import spacy [as 别名]
# 或者: from spacy import util [as 别名]
def load_lang_model(lang: str, disable: List[str]):
        """Load spaCy language model or download if
            model is available and not installed
        
        Arguments:
            lang {str} -- language
            disable {List[str]} -- If only using tokenizer, can disable ['parser', 'ner', 'textcat']
        
        Returns:
            [type] -- [description]
        """
        if 'coref' in lang:
            try:
                return spacy.load(lang, disable=disable) # 
            except Exception as e:
                return SpacyAnnotator.load_lang_model(lang.split('_')[0], disable=disable)
        try:
            return spacy.load(lang, disable=disable)
        except OSError:
            logger.warning(f"Spacy models '{lang}' not found.  Downloading and installing.")
            spacy_download(lang)
            # NOTE(mattg): The following four lines are a workaround suggested by Ines for spacy
            # 2.1.0, which removed the linking that was done in spacy 2.0.  importlib doesn't find
            # packages that were installed in the same python session, so the way `spacy_download`
            # works in 2.1.0 is broken for this use case.  These four lines can probably be removed
            # at some point in the future, once spacy has figured out a better way to handle this.
            # See https://github.com/explosion/spaCy/issues/3435.
            from spacy.cli import link
            from spacy.util import get_package_path
            package_path = get_package_path(lang)
            link(lang, lang, model_path=package_path)
            return spacy.load(lang, disable=disable) 
开发者ID:uwdata,项目名称:errudite,代码行数:34,代码来源:spacy_annotator.py


注:本文中的spacy.util方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。