• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python en.SearchEnglish类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sphinx.search.en.SearchEnglish的典型用法代码示例。如果您正苦于以下问题:Python SearchEnglish类的具体用法?Python SearchEnglish怎么用?Python SearchEnglish使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: __init__

    def __init__(self, env, lang, options, scoring):
        self.env = env
        # filename -> title
        self._titles = {}
        # stemmed word -> set(filenames)
        self._mapping = {}
        # stemmed words in titles -> set(filenames)
        self._title_mapping = {}
        # word -> stemmed word
        self._stem_cache = {}
        # objtype -> index
        self._objtypes = {}
        # objtype index -> (domain, type, objname (localized))
        self._objnames = {}
        # add language-specific SearchLanguage instance
        lang_class = languages.get(lang)
        if lang_class is None:
            self.lang = SearchEnglish(options)
        elif isinstance(lang_class, str):
            module, classname = lang_class.rsplit('.', 1)
            lang_class = getattr(__import__(module, None, None, [classname]),
                                 classname)
            self.lang = lang_class(options)
        else:
            # it's directly a class (e.g. added by app.add_search_language)
            self.lang = lang_class(options)

        if scoring:
            with open(scoring, 'rb') as fp:
                self.js_scorer_code = fp.read().decode('utf-8')
        else:
            self.js_scorer_code = u''
开发者ID:jschueller,项目名称:sphinx,代码行数:32,代码来源:__init__.py


示例2: __init__

    def __init__(self, env, lang, options, scoring):
        # type: (BuildEnvironment, unicode, Dict, unicode) -> None
        self.env = env
        self._titles = {}           # type: Dict[unicode, unicode]
                                    # docname -> title
        self._filenames = {}        # type: Dict[unicode, unicode]
                                    # docname -> filename
        self._mapping = {}          # type: Dict[unicode, Set[unicode]]
                                    # stemmed word -> set(docname)
        self._title_mapping = {}    # type: Dict[unicode, Set[unicode]]
                                    # stemmed words in titles -> set(docname)
        self._stem_cache = {}       # type: Dict[unicode, unicode]
                                    # word -> stemmed word
        self._objtypes = {}         # type: Dict[Tuple[unicode, unicode], int]
                                    # objtype -> index
        self._objnames = {}         # type: Dict[int, Tuple[unicode, unicode, unicode]]
                                    # objtype index -> (domain, type, objname (localized))
        lang_class = languages.get(lang)    # type: Type[SearchLanguage]
                                            # add language-specific SearchLanguage instance

        # fallback; try again with language-code
        if lang_class is None and '_' in lang:
            lang_class = languages.get(lang.split('_')[0])

        if lang_class is None:
            self.lang = SearchEnglish(options)  # type: SearchLanguage
        elif isinstance(lang_class, str):
            module, classname = lang_class.rsplit('.', 1)
            lang_class = getattr(__import__(module, None, None, [classname]),
                                 classname)
            self.lang = lang_class(options)
        else:
            # it's directly a class (e.g. added by app.add_search_language)
            self.lang = lang_class(options)

        if scoring:
            with open(scoring, 'rb') as fp:
                self.js_scorer_code = fp.read().decode('utf-8')
        else:
            self.js_scorer_code = u''
        self.js_splitter_code = splitter_code
开发者ID:nvmanh,项目名称:plant,代码行数:41,代码来源:__init__.py


示例3: IndexBuilder

class IndexBuilder(object):
    """
    Helper class that creates a searchindex based on the doctrees
    passed to the `feed` method.
    """
    formats = {
        'jsdump':   jsdump,
        'pickle':   pickle
    }   # type: Dict[unicode, Any]

    def __init__(self, env, lang, options, scoring):
        # type: (BuildEnvironment, unicode, Dict, unicode) -> None
        self.env = env
        self._titles = {}           # type: Dict[unicode, unicode]
                                    # docname -> title
        self._filenames = {}        # type: Dict[unicode, unicode]
                                    # docname -> filename
        self._mapping = {}          # type: Dict[unicode, Set[unicode]]
                                    # stemmed word -> set(docname)
        self._title_mapping = {}    # type: Dict[unicode, Set[unicode]]
                                    # stemmed words in titles -> set(docname)
        self._stem_cache = {}       # type: Dict[unicode, unicode]
                                    # word -> stemmed word
        self._objtypes = {}         # type: Dict[Tuple[unicode, unicode], int]
                                    # objtype -> index
        self._objnames = {}         # type: Dict[int, Tuple[unicode, unicode, unicode]]
                                    # objtype index -> (domain, type, objname (localized))
        lang_class = languages.get(lang)    # type: Type[SearchLanguage]
                                            # add language-specific SearchLanguage instance
        if lang_class is None:
            self.lang = SearchEnglish(options)  # type: SearchLanguage
        elif isinstance(lang_class, str):
            module, classname = lang_class.rsplit('.', 1)
            lang_class = getattr(__import__(module, None, None, [classname]),
                                 classname)
            self.lang = lang_class(options)
        else:
            # it's directly a class (e.g. added by app.add_search_language)
            self.lang = lang_class(options)

        if scoring:
            with open(scoring, 'rb') as fp:
                self.js_scorer_code = fp.read().decode('utf-8')
        else:
            self.js_scorer_code = u''
        self.js_splitter_code = splitter_code

    def load(self, stream, format):
        # type: (IO, Any) -> None
        """Reconstruct from frozen data."""
        if isinstance(format, string_types):
            format = self.formats[format]
        frozen = format.load(stream)
        # if an old index is present, we treat it as not existing.
        if not isinstance(frozen, dict) or \
           frozen.get('envversion') != self.env.version:
            raise ValueError('old format')
        index2fn = frozen['docnames']
        self._filenames = dict(zip(index2fn, frozen['filenames']))
        self._titles = dict(zip(index2fn, frozen['titles']))

        def load_terms(mapping):
            # type: (Dict[unicode, Any]) -> Dict[unicode, Set[unicode]]
            rv = {}
            for k, v in iteritems(mapping):
                if isinstance(v, int):
                    rv[k] = set([index2fn[v]])
                else:
                    rv[k] = set(index2fn[i] for i in v)
            return rv

        self._mapping = load_terms(frozen['terms'])
        self._title_mapping = load_terms(frozen['titleterms'])
        # no need to load keywords/objtypes

    def dump(self, stream, format):
        # type: (IO, Any) -> None
        """Dump the frozen index to a stream."""
        if isinstance(format, string_types):
            format = self.formats[format]
        format.dump(self.freeze(), stream)

    def get_objects(self, fn2index):
        # type: (Dict[unicode, int]) -> Dict[unicode, Dict[unicode, Tuple[int, int, int, unicode]]]  # NOQA
        rv = {}  # type: Dict[unicode, Dict[unicode, Tuple[int, int, int, unicode]]]
        otypes = self._objtypes
        onames = self._objnames
        for domainname, domain in sorted(iteritems(self.env.domains)):
            for fullname, dispname, type, docname, anchor, prio in \
                    sorted(domain.get_objects()):
                # XXX use dispname?
                if docname not in fn2index:
                    continue
                if prio < 0:
                    continue
                fullname = htmlescape(fullname)
                prefix, name = rpartition(fullname, '.')
                pdict = rv.setdefault(prefix, {})
                try:
                    typeindex = otypes[domainname, type]
#.........这里部分代码省略.........
开发者ID:hagenw,项目名称:sphinx,代码行数:101,代码来源:__init__.py


示例4: IndexBuilder

class IndexBuilder(object):
    """
    Helper class that creates a searchindex based on the doctrees
    passed to the `feed` method.
    """
    formats = {
        'jsdump':   jsdump,
        'pickle':   pickle
    }

    def __init__(self, env, lang, options, scoring):
        self.env = env
        # filename -> title
        self._titles = {}
        # stemmed word -> set(filenames)
        self._mapping = {}
        # stemmed words in titles -> set(filenames)
        self._title_mapping = {}
        # word -> stemmed word
        self._stem_cache = {}
        # objtype -> index
        self._objtypes = {}
        # objtype index -> (domain, type, objname (localized))
        self._objnames = {}
        # add language-specific SearchLanguage instance
        lang_class = languages.get(lang)
        if lang_class is None:
            self.lang = SearchEnglish(options)
        elif isinstance(lang_class, str):
            module, classname = lang_class.rsplit('.', 1)
            lang_class = getattr(__import__(module, None, None, [classname]),
                                 classname)
            self.lang = lang_class(options)
        else:
            # it's directly a class (e.g. added by app.add_search_language)
            self.lang = lang_class(options)

        if scoring:
            with open(scoring, 'rb') as fp:
                self.js_scorer_code = fp.read().decode('utf-8')
        else:
            self.js_scorer_code = u''

    def load(self, stream, format):
        """Reconstruct from frozen data."""
        if isinstance(format, string_types):
            format = self.formats[format]
        frozen = format.load(stream)
        # if an old index is present, we treat it as not existing.
        if not isinstance(frozen, dict) or \
           frozen.get('envversion') != self.env.version:
            raise ValueError('old format')
        index2fn = frozen['filenames']
        self._titles = dict(zip(index2fn, frozen['titles']))

        def load_terms(mapping):
            rv = {}
            for k, v in iteritems(mapping):
                if isinstance(v, int):
                    rv[k] = set([index2fn[v]])
                else:
                    rv[k] = set(index2fn[i] for i in v)
            return rv

        self._mapping = load_terms(frozen['terms'])
        self._title_mapping = load_terms(frozen['titleterms'])
        # no need to load keywords/objtypes

    def dump(self, stream, format):
        """Dump the frozen index to a stream."""
        if isinstance(format, string_types):
            format = self.formats[format]
        format.dump(self.freeze(), stream)

    def get_objects(self, fn2index):
        rv = {}
        otypes = self._objtypes
        onames = self._objnames
        for domainname, domain in iteritems(self.env.domains):
            for fullname, dispname, type, docname, anchor, prio in \
                    domain.get_objects():
                # XXX use dispname?
                if docname not in fn2index:
                    continue
                if prio < 0:
                    continue
                prefix, name = rpartition(fullname, '.')
                pdict = rv.setdefault(prefix, {})
                try:
                    typeindex = otypes[domainname, type]
                except KeyError:
                    typeindex = len(otypes)
                    otypes[domainname, type] = typeindex
                    otype = domain.object_types.get(type)
                    if otype:
                        # use unicode() to fire translation proxies
                        onames[typeindex] = (domainname, type,
                            text_type(domain.get_type_name(otype)))
                    else:
                        onames[typeindex] = (domainname, type, type)
#.........这里部分代码省略.........
开发者ID:lehmannro,项目名称:sphinx-mirror,代码行数:101,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python setup_command.BuildDoc类代码示例发布时间:2022-05-27
下一篇:
Python search.IndexBuilder类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap