當前位置: 首頁>>代碼示例>>Python>>正文


Python ZCTextIndex.ZCTextIndex類代碼示例

本文整理匯總了Python中Products.ZCTextIndex.ZCTextIndex.ZCTextIndex的典型用法代碼示例。如果您正苦於以下問題:Python ZCTextIndex類的具體用法?Python ZCTextIndex怎麽用?Python ZCTextIndex使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ZCTextIndex類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_ZCTextIndex

 def test_ZCTextIndex(self):
     from xml.dom.minidom import parseString
     from Products.ZCTextIndex.ZCTextIndex import PLexicon
     from Products.ZCTextIndex.ZCTextIndex import ZCTextIndex
     from Products.GenericSetup.testing import DummySetupEnviron
     from Products.GenericSetup.ZCTextIndex.exportimport \
             import ZCTextIndexNodeAdapter
     _XML = """\
     <index name="foo_zctext" meta_type="ZCTextIndex">
     <indexed_attr value="bar"/>
     <extra name="index_type" value="Okapi BM25 Rank"/>
     <extra name="lexicon_id" value="foo_plexicon"/>
     </index>
     """
     environ = DummySetupEnviron()
     def _no_clear(*a):
         raise AssertionError("Don't clear me!")
     catalog = DummyCatalog()
     catalog.foo_plexicon = PLexicon('foo_plexicon')
     extra = _extra()
     extra.lexicon_id = 'foo_plexicon'
     extra.index_type='Okapi BM25 Rank'
     index = ZCTextIndex('foo_field', extra=extra, field_name='bar',
                         caller=catalog).__of__(catalog)
     index.clear = _no_clear 
     adapted = ZCTextIndexNodeAdapter(index, environ)
     adapted.node = parseString(_XML).documentElement # no raise
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:27,代碼來源:test_exportimport.py

示例2: QueryTestsBase

class QueryTestsBase(object):

    # Subclasses of QueryTestsBase must set a class variable IndexFactory
    # to the kind of index to be constructed.
    IndexFactory = None

    # The FauxIndex in testQueryEngine contains four documents.
    # docid 1: foo, bar, ham
    # docid 2: bar, ham
    # docid 3: foo, ham
    # docid 4: ham

    docs = ['foo bar ham', 'bar ham', 'foo ham', 'ham']

    def setUp(self):
        self.lexicon = PLexicon('lexicon', '',
                                Splitter(),
                                CaseNormalizer(),
                                StopWordRemover())
        caller = LexiconHolder(self.lexicon)

        self.zc_index = ZCTextIndex('name',
                                    None,
                                    caller,
                                    self.IndexFactory,
                                    'text',
                                    'lexicon')
        self.parser = QueryParser(self.lexicon)
        self.index = self.zc_index.index
        self.add_docs()

    def add_docs(self):
        for i in range(len(self.docs)):
            text = self.docs[i]
            obj = Indexable(text)
            self.zc_index.index_object(i + 1, obj)

    def compareSet(self, set, dict):
        # The FauxIndex and the real Index score documents very
        # differently.  The set comparison can't actually compare the
        # items, but it can compare the keys.  That will have to do for now.
        setkeys = list(set.keys())
        dictkeys = list(dict.keys())
        setkeys.sort()
        dictkeys.sort()
        self.assertEqual(setkeys, dictkeys)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:46,代碼來源:testZCTextIndex.py

示例3: getLexicon

 def getLexicon(self):
     """Get the lexicon for this index
     """
     try:
         return ZCTextIndex.getLexicon(self)
     except:
         lexicon = getattr(getToolByName(getSite(), 'portal_catalog'), self.lexicon_id)
         if not ILexicon.providedBy(lexicon):
             raise TypeError('Object "%s" is not a ZCTextIndex Lexicon'
                             % repr(lexicon))
         self._v_lexicon = lexicon
         return lexicon
開發者ID:gyst,項目名稱:raptus.multilanguagefields,代碼行數:12,代碼來源:ZCTextIndex.py

示例4: setUp

 def setUp(self):
     self.lexicon = PLexicon('lexicon', '',
                             Splitter(),
                             CaseNormalizer(),
                             StopWordRemover())
     caller = LexiconHolder(self.lexicon)
     self.zc_index = ZCTextIndex('name',
                                 None,
                                 caller,
                                 self.IndexFactory,
                                 'text',
                                 'lexicon')
     self.index = self.zc_index.index
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:13,代碼來源:testZCTextIndex.py

示例5: testMultipleAttributes

 def testMultipleAttributes(self):
     caller = LexiconHolder(self.lexicon)
     zc_index = ZCTextIndex('name',
                            None,
                            caller,
                            self.IndexFactory,
                            'text1,text2',
                            'lexicon')
     doc = Indexable2('foo bar', 'alpha omega')
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('foo')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('foo alpha')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('foo alpha gamma')
     self.assertEqual(len(nbest), 0)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:16,代碼來源:testZCTextIndex.py

示例6: testListAttributes

 def testListAttributes(self):
     caller = LexiconHolder(self.lexicon)
     zc_index = ZCTextIndex('name',
                            None,
                            caller,
                            self.IndexFactory,
                            'text1,text2',
                            'lexicon')
     doc = Indexable2('Hello Tim',
                      ['Now is the winter of our discontent',
                       'Made glorious summer by this sun of York', ])
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('glorious')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('York Tim')
     self.assertEqual(len(nbest), 1)
     nbest, total = zc_index.query('Tuesday Tim York')
     self.assertEqual(len(nbest), 0)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:18,代碼來源:testZCTextIndex.py

示例7: testReindex

 def testReindex(self):
     caller = LexiconHolder(self.lexicon)
     zc_index = ZCTextIndex('name',
                            None,
                            caller,
                            self.IndexFactory,
                            'text',
                            'lexicon')
     doc = Indexable('Hello Tim')
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('glorious')
     self.assertEqual(len(nbest), 0)
     nbest, total = zc_index.query('Tim')
     self.assertEqual(len(nbest), 1)
     # reindex with another value
     doc.text = 'Goodbye George'
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('Tim')
     self.assertEqual(len(nbest), 0)
     nbest, total = zc_index.query('Goodbye')
     self.assertEqual(len(nbest), 1)
     # reindex with an empty value
     doc.text = ''
     zc_index.index_object(1, doc)
     nbest, total = zc_index.query('George')
     self.assertEqual(len(nbest), 0)
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:26,代碼來源:testZCTextIndex.py

示例8: ZCIndexTestsBase

class ZCIndexTestsBase(object):

    def setUp(self):
        self.lexicon = PLexicon('lexicon', '',
                                Splitter(),
                                CaseNormalizer(),
                                StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        self.zc_index = ZCTextIndex('name',
                                    None,
                                    caller,
                                    self.IndexFactory,
                                    'text',
                                    'lexicon')
        self.index = self.zc_index.index

    def parserFailure(self, query):
        self.assertRaises(ParseError, self.zc_index.query, query)

    def parserSuccess(self, query, n):
        r, num = self.zc_index.query(query)
        self.assertEqual(num, n)
        if n:
            self.assertEqual(r[0][0], 1)

    def testMultipleAttributes(self):
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                               None,
                               caller,
                               self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('foo bar', 'alpha omega')
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('foo')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha gamma')
        self.assertEqual(len(nbest), 0)

    def testListAttributes(self):
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                               None,
                               caller,
                               self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('Hello Tim',
                         ['Now is the winter of our discontent',
                          'Made glorious summer by this sun of York', ])
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('glorious')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('York Tim')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('Tuesday Tim York')
        self.assertEqual(len(nbest), 0)

    def testReindex(self):
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                               None,
                               caller,
                               self.IndexFactory,
                               'text',
                               'lexicon')
        doc = Indexable('Hello Tim')
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('glorious')
        self.assertEqual(len(nbest), 0)
        nbest, total = zc_index.query('Tim')
        self.assertEqual(len(nbest), 1)
        # reindex with another value
        doc.text = 'Goodbye George'
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('Tim')
        self.assertEqual(len(nbest), 0)
        nbest, total = zc_index.query('Goodbye')
        self.assertEqual(len(nbest), 1)
        # reindex with an empty value
        doc.text = ''
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('George')
        self.assertEqual(len(nbest), 0)

    def testStopWords(self):
        # the only non-stopword is question
        text = ('to be or not to be '
                'that is the question')
        doc = Indexable(text)
        self.zc_index.index_object(1, doc)
        for word in text.split():
            if word != 'question':
                wids = self.lexicon.termToWordIds(word)
                self.assertEqual(wids, [])
        self.assertEqual(len(self.index.get_words(1)), 1)

#.........這裏部分代碼省略.........
開發者ID:zopefoundation,項目名稱:Products.ZCatalog,代碼行數:101,代碼來源:testZCTextIndex.py

示例9: setUp

class ZCIndexTestsBase:

    def setUp(self):
        self.lexicon = PLexicon('lexicon', '',
                                Splitter(),
                                CaseNormalizer(),
                                StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        self.zc_index = ZCTextIndex('name',
                                    None,
                                    caller,
                                    self.IndexFactory,
                                    'text',
                                    'lexicon')
        self.index = self.zc_index.index


    def parserFailure(self, query):
        self.assertRaises(ParseError, self.zc_index.query, query)

    def parserSuccess(self, query, n):
        r, num = self.zc_index.query(query)
        self.assertEqual(num, n)
        if n:
            self.assertEqual(r[0][0], 1)

    def testMultipleAttributes(self):
        lexicon = PLexicon('lexicon', '',
                            Splitter(),
                            CaseNormalizer(),
                            StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                                None,
                                caller,
                                self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('foo bar', 'alpha omega')
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('foo')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('foo alpha gamma')
        self.assertEqual(len(nbest), 0)

    def testListAttributes(self):
        lexicon = PLexicon('lexicon', '',
                            Splitter(),
                            CaseNormalizer(),
                            StopWordRemover())
        caller = LexiconHolder(self.lexicon)
        zc_index = ZCTextIndex('name',
                                None,
                                caller,
                                self.IndexFactory,
                               'text1,text2',
                               'lexicon')
        doc = Indexable2('Hello Tim', \
                         ['Now is the winter of our discontent',
                          'Made glorious summer by this sun of York', ])
        zc_index.index_object(1, doc)
        nbest, total = zc_index.query('glorious')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('York Tim')
        self.assertEqual(len(nbest), 1)
        nbest, total = zc_index.query('Tuesday Tim York')
        self.assertEqual(len(nbest), 0)

    def testStopWords(self):
        # the only non-stopword is question
        text = ("to be or not to be "
                "that is the question")
        doc = Indexable(text)
        self.zc_index.index_object(1, doc)
        for word in text.split():
            if word != "question":
                wids = self.lexicon.termToWordIds(word)
                self.assertEqual(wids, [])
        self.assertEqual(len(self.index.get_words(1)), 1)

        self.parserSuccess('question', 1)
        self.parserSuccess('question AND to AND be', 1)
        self.parserSuccess('to AND question AND be', 1)
        self.parserSuccess('question AND NOT gardenia', 1)
        self.parserSuccess('question AND gardenia', 0)
        self.parserSuccess('gardenia', 0)
        self.parserSuccess('question OR gardenia', 1)
        self.parserSuccess('question AND NOT to AND NOT be', 1)
        self.parserSuccess('question OR to OR be', 1)
        self.parserSuccess('question to be', 1)

        self.parserFailure('to be')
        self.parserFailure('to AND be')
        self.parserFailure('to OR be')
        self.parserFailure('to AND NOT be')
        self.parserFailure('to AND NOT question')
        self.parserFailure('to AND NOT gardenia')

#.........這裏部分代碼省略.........
開發者ID:nacho22martin,項目名稱:tesis,代碼行數:101,代碼來源:testZCTextIndex.py


注:本文中的Products.ZCTextIndex.ZCTextIndex.ZCTextIndex類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。