本文整理汇总了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;未经允许,请勿转载。 |
请发表评论