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

Python model.Document类代码示例

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

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



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

示例1: receive_feedbacks

    def receive_feedbacks(self, session, feedbacks):
        """
        Receive feedbacks from user
        
        The format of feedback is:
        {
        "docs": [[doc_id, feedback_value], ...],
        "kws": [[keyword_id, feedback_value], ...],
        "dockws": [[keyword_id, doc_id, feedback_value], ...]
        }
        """
        print "propagation started..."
        for doc_fb in feedbacks.get("docs", []):
            doc_id, fb = doc_fb
            doc = Document.get(doc_id)
            
            self.ppgt.fb_from_doc(doc, fb, session)

        for kw_fb in feedbacks.get("kws", []):
            kw_id, fb = kw_fb
            kw = Keyword.get(kw_id)
            
            self.ppgt.fb_from_kw(kw, fb, session)

        for dockw_fb in feedbacks.get("dockws", []):
            kw_id, doc_id, fb = dockw_fb
            doc = Document.get(doc_id)
            kw = Keyword.get(kw_id)
            
            self.ppgt.fb_from_dockw(kw, doc, fb, session)

        # propagation is done
        # updates the feedback value 
        self.upd.update(session)
        print "propagation finished"
开发者ID:samim23,项目名称:rl-search,代码行数:35,代码来源:cmdapp.py


示例2: setUp

    def setUp(self):
                #make the fmim
        kw_filters = [self.my_kw_filter]
        doc_filters = [self.kw_count_filter, self.has_database_filter]
        
        
        self.r = LinRelRecommender(2, 2, 
                                   1.0, 0.1, 1.0, 0.1,
                                   #the default configuration
                                   kw_filters = None, doc_filters = [self.kw_count_filter, self.has_database_filter],
                                   **fmim.__dict__)
        
        self.session = get_session()
        
        self.session.update_kw_feedback(Keyword.get("redis"), .7)
        self.session.update_kw_feedback(Keyword.get("database"), .6)
        
        self.session.update_doc_feedback(Document.get(1), .7)
        self.session.update_doc_feedback(Document.get(2), .7)
        self.session.update_doc_feedback(Document.get(8), .7)

        filtered_kws = self.r._filter_objs(kw_filters, kws = Keyword.all_kws)
        filtered_docs = self.r._filter_objs(doc_filters, docs = Document.all_docs)
        
        kw2doc_submat, kw_ind_map, kw_ind_map_r = self.r._submatrix_and_indexing(filtered_kws, filtered_docs, fmim.kw2doc_m, fmim.kw_ind, fmim.doc_ind)
        doc2kw_submat, doc_ind_map, doc_ind_map_r = self.r._submatrix_and_indexing(filtered_docs, filtered_kws, fmim.doc2kw_m, fmim.doc_ind, fmim.kw_ind)
        
        self.fmim = FeatureMatrixAndIndexMapping(kw_ind_map, doc_ind_map, kw2doc_submat, doc2kw_submat, kw_ind_map_r, doc_ind_map_r)
开发者ID:samim23,项目名称:rl-search,代码行数:28,代码来源:linrel_recommender_test.py


示例3: __init__

 def __init__(self, **kwargs):
     for k, v in kwargs.items():
         setattr(self, k, v)
     
     if not Document.all_docs_loaded:
         print "loading docs from db..."
         Document.load_all_from_db()
开发者ID:samim23,项目名称:rl-search,代码行数:7,代码来源:base.py


示例4: test_get_many

    def test_get_many(self):
        doc_ids = [1,2]
        kw_ids = ["a", "the"]
        
        self.assertEqual(Document.get_many([1,2]), 
                         Document.get_many(doc_ids))

        self.assertEqual(Keyword.get_many(["a", "the"]), 
                         Keyword.get_many(kw_ids))
开发者ID:samim23,项目名称:rl-search,代码行数:9,代码来源:model_test.py


示例5: test_one

    def test_one(self):
        docs = [Document.get_many([1,2]), Document.get_many([1,2]), Document.get_many([2,1])]
        kws = [Keyword.get_many(["redis", "database"]), Keyword.get_many(["redis", "database"]), Keyword.get_many(["redis", "database"])]

        scores = self.e.evaluate(docs, kws)
        expected = ([1,1,1], [1,1,1])
        
        self.assertArrayAlmostEqual(expected[0], scores[0])
        self.assertArrayAlmostEqual(expected[1], scores[1])
开发者ID:samim23,项目名称:rl-search,代码行数:9,代码来源:ir_eval_test.py


示例6: test_doc_fb_threshold_filter

    def test_doc_fb_threshold_filter(self):
        #change the feedback
        self.session.update_doc_feedback(Document.get(1), .2)
        self.session.update_doc_feedback(Document.get(2), .0999999)
        
        actual = doc_fb_threshold_filter(0.1, self.session, 
                                         docs = Document.all_docs, with_fb = False)
        expected = Document.get_many([1])

        self.assertEqual(expected, actual)
开发者ID:samim23,项目名称:rl-search,代码行数:10,代码来源:filters_test.py


示例7: test_filter_objs

    def test_filter_objs(self):
        def has_redis_filter(objs = None):
            return filter(lambda obj: Keyword.get("redis") in obj.keywords,  objs)

        def has_database_filter(objs = None):
            return filter(lambda obj: Keyword.get("database") in obj.keywords,  objs)

        self.assertEqual(list(Document.get_many([1, 7])),
                         self.r._filter_objs([has_redis_filter, has_database_filter], 
                                             objs = Document.get_many([1, 7, 8])))
开发者ID:samim23,项目名称:rl-search,代码行数:10,代码来源:linrel_recommender_test.py


示例8: test_associated_keywords_from_documents

 def test_associated_keywords_from_documents(self):
     kws = self.r.associated_keywords_from_docs(Document.get_many([1,2]))
     self.assertEqual(set(Keyword.get_many(["a", "database", "redis", "the"])),
                      set(kws))
     
     exclude_kws = [Keyword.get("redis")]
     kws = self.r.associated_keywords_from_docs(Document.get_many([1,2]), exclude_kws)
     
     self.assertEqual(set(Keyword.get_many(["a", "database", "the"])), 
                      set(kws))
开发者ID:samim23,项目名称:rl-search,代码行数:10,代码来源:linrel_recommender_test.py


示例9: test_kw_fb_filter

    def test_kw_fb_filter(self):
        kw = Keyword.get("redis")
        kw.rec_fb_from_doc(Document.get(1), 1, self.session)
        self.session.add_doc_recom_list(Document.get_many([1, 2, 6]))
        self.session.update_kw_feedback(kw, kw.fb_weighted_sum(self.session))

        actual = FilterRepository.filters["kw_fb"]([kw])
        expected = Keyword.get_many(["redis"])

        self.assertEqual(expected, actual)
开发者ID:samim23,项目名称:rl-search,代码行数:10,代码来源:filters_test.py


示例10: test_two

    def test_two(self):
        docs = [Document.get_many([8,10]), Document.get_many([3,4]), Document.get_many([2,1])]
        kws = [Keyword.get_many(["a", "the"]), Keyword.get_many(["python", "database"]), Keyword.get_many(["database", "redis"])]

        scores = self.e.evaluate(docs, kws)
        expected = ([0.34491169135422844, 0.1726882003112921, 1.0],
                    [0.4834283906452939, 0.759679156743632, 0.9999999999999999])

        self.assertArrayAlmostEqual(expected[0], scores[0])
        self.assertArrayAlmostEqual(expected[1], scores[1])
开发者ID:samim23,项目名称:rl-search,代码行数:10,代码来源:ir_eval_test.py


示例11: test_doc_fb_filter

 def test_doc_fb_filter(self):
     doc = Document.get(1)
     doc.rec_fb_from_kw(Keyword.get("redis"), 1, self.session)
     self.session.update_doc_feedback(doc, doc.fb_weighted_sum(self.session))
     
     print "doc.fb(self.session)=", doc.fb(self.session)
     actual = FilterRepository.filters["doc_fb"]([doc])
     expected = Document.get_many([])
     
     print doc.fb(self.session)
     self.assertEqual(expected, actual)                            
开发者ID:samim23,项目名称:rl-search,代码行数:11,代码来源:filters_test.py


示例12: test_affected_docs

    def test_affected_docs(self):
        docs = [Document.get(1), Document.get(2)]
        
        self.session.add_affected_docs(*docs)
        self.assertEqual(docs, self.session.affected_docs)

        doc3 = Document.get(3)
        docs.append(doc3)
        self.session.add_affected_docs(doc3)
        self.assertEqual(set(docs), 
                         set(self.session.affected_docs))
开发者ID:samim23,项目名称:rl-search,代码行数:11,代码来源:session_test.py


示例13: test_doc_hashable

    def test_doc_hashable(self):
        d = {}
        doclist1 = Document.get_many([1,2,3])
        doclist2 = Document.get_many([2,1,3])
        doclist3 = Document.get_many([4,5,6])

        d[doclist1] = 1
        d[doclist2] = 2 #override
        d[doclist3] = 3 

        self.assertEqual({doclist1:2, doclist3: 3}, d)
开发者ID:samim23,项目名称:rl-search,代码行数:11,代码来源:modellist_test.py


示例14: test_model2modellist_similarity

    def test_model2modellist_similarity(self):
        #for keywords
        kw = Keyword.get("redis")
        kwlist = Keyword.get_many(["database", "mysql"])

        self.assertAlmostEqual(0.3754029265429976, kw.similarity_to(kwlist))
        
        #for documents
        doc = Document.get(6)
        doclist = Document.get_many([1, 2])
        
        self.assertAlmostEqual(0.7382455893131392, doc.similarity_to(doclist))
开发者ID:samim23,项目名称:rl-search,代码行数:12,代码来源:modellist_test.py


示例15: test_modellist2modellist_similarity

    def test_modellist2modellist_similarity(self):
        #for keywords
        kwlist1 = Keyword.get_many(["redis", "a"])
        kwlist2 = Keyword.get_many(["database", "the"])

        self.assertAlmostEqual(0.42205423035497763, kwlist1.similarity_to(kwlist2))
        
        #for documents
        doclist1 = Document.get_many([3,5])
        doclist2 = Document.get_many([4,6])
        
        self.assertAlmostEqual(0.6990609119502719, doclist1.similarity_to(doclist2))
开发者ID:samim23,项目名称:rl-search,代码行数:12,代码来源:modellist_test.py


示例16: test_rec_fb_from_dockw

    def test_rec_fb_from_dockw(self):
        """
        getter/setting for receiving feedback from in-document keyword
        """
        kw = Keyword.get("redis")
        
        kw.rec_fb_from_dockw(kw, Document.get(2), .5, self.session)
        kw.rec_fb_from_dockw(kw, Document.get(1), 1, self.session)
        
        self.assertEqual(kw.fb_from_doc(self.session), {Document.get(1): 1, Document.get(2): .5})

        #is not the right keyword
        self.assertRaises(AssertionError, kw.rec_fb_from_dockw, Keyword.get("the"), Document.get(1), 1, self.session)
开发者ID:samim23,项目名称:rl-search,代码行数:13,代码来源:kw_fb_receiver_test.py


示例17: test_fb_weighted_sum_dockw_only

    def test_fb_weighted_sum_dockw_only(self):
        """
        test if the weighted sum is correct
        
        only feedback from dockw/doc
        """
        kw = Keyword.get("redis")
        
        kw.rec_fb_from_dockw(kw, Document.get(1), 1, self.session)
        kw.rec_fb_from_doc(Document.get(2), .5, self.session)

        self.assertEqual((1 + .5) / 2,
                         kw.fb_weighted_sum(self.session))
开发者ID:samim23,项目名称:rl-search,代码行数:13,代码来源:kw_fb_receiver_test.py


示例18: test_document_centroid

    def test_document_centroid(self):
        doc = Document.get(1)
        doclist1 = DocumentList([doc])
        
        self.assertArrayAlmostEqual(matrix2array(doclist1.centroid), doc.vec.toarray()[0])

        doc1 = Document.get(1)
        doc2 = Document.get(2)
        
        doclist2 = Document.get_many([1, 2])
        
        self.assertArrayAlmostEqual(matrix2array(doclist2.centroid), 
                                    (doc1.vec.toarray()[0] + doc2.vec.toarray()[0]) / 2)        
开发者ID:samim23,项目名称:rl-search,代码行数:13,代码来源:modellist_test.py


示例19: test_rec_fb_from_doc

    def test_rec_fb_from_doc(self):
        """
        getter/setting for receiving feedback from document
        """
        kw = Keyword.get("redis")
        
        kw.rec_fb_from_doc(Document.get(1), 1, self.session)
        kw.rec_fb_from_doc(Document.get(2), .5, self.session)
        
        self.assertEqual(kw.fb_from_doc(self.session), {Document.get(1): 1, Document.get(2): .5})        

        #does not contain redis, error should be raised
        self.assertRaises(AssertionError, kw.rec_fb_from_doc, Document.get(3), 1, self.session)
开发者ID:samim23,项目名称:rl-search,代码行数:13,代码来源:kw_fb_receiver_test.py


示例20: sample_documents_associated_with_keywords

 def sample_documents_associated_with_keywords(self, keywords, n):
      """
      sample n documents from all documents that contain any of the keywords
      """
      assert type(keywords) in (KeywordList, ListType) , "keywords should be KeywordList, but is %r" %(keywords)
      
      #get all doc ids of which the document contains any of the keywords
      doc_ids = self._doc_ids_that_contain_keywords([kw.id for kw in keywords])
      
      #sample it
      try:
          return Document.get_many(random.sample(doc_ids, n))
      except ValueError: #sample size larger than population
          return Document.get_many(doc_ids)
开发者ID:samim23,项目名称:rl-search,代码行数:14,代码来源:query.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python model.Keyword类代码示例发布时间:2022-05-27
下一篇:
Python misc.query_yes_no函数代码示例发布时间: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