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


Python Keyword.get方法代码示例

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


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

示例1: receive_feedbacks

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    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,代码行数:37,代码来源:cmdapp.py

示例2: setUp

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    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,代码行数:30,代码来源:linrel_recommender_test.py

示例3: test_kw_fb_threshold_filter

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_kw_fb_threshold_filter(self):
        #change the feedback
        self.session.update_kw_feedback(Keyword.get("python"), .2)
        self.session.update_kw_feedback(Keyword.get("a"), .0999999)
        
        actual = kw_fb_threshold_filter(0.1, self.session, 
                                        kws = Keyword.all_kws, with_fb = False)
        expected = Keyword.get_many(["python"])

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

示例4: test_affected_kws

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_affected_kws(self):
        kws = [Keyword.get("python"), Keyword.get("redis")]
        
        self.session.add_affected_kws(*kws)
        self.assertEqual(kws, self.session.affected_kws)

        kw3 = Keyword.get("a")
        kws.append(kw3)
        self.session.add_affected_kws(kw3)
        self.assertEqual(set(kws), 
                         set(self.session.affected_kws))
开发者ID:samim23,项目名称:rl-search,代码行数:13,代码来源:session_test.py

示例5: test_sample_documents_associated_with_keywords

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_sample_documents_associated_with_keywords(self):
        """
        normal case
        """
        docs = self.r.sample_documents_associated_with_keywords(Keyword.get_many(["python", "redis"]), 2)

        self.assertEqual(2, len(docs))

        for doc in docs:
            self.assertTrue((Keyword.get("python") in doc.keywords) or \
                            (Keyword.get("redis") in doc.keywords))
开发者ID:samim23,项目名称:rl-search,代码行数:13,代码来源:query_recommender_test.py

示例6: test_rec_fb_from_dockw

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    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,代码行数:15,代码来源:kw_fb_receiver_test.py

示例7: test_keyword_centroid

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_keyword_centroid(self):
        kw = Keyword.get("a")
        kwlist1 = KeywordList([kw])
        
        self.assertArrayAlmostEqual(matrix2array(kwlist1.centroid), kw.vec.toarray()[0])

        kw1 = Keyword.get("a")
        kw2 = Keyword.get("the")
        
        kwlist2 = Keyword.get_many(["a", "the"])
        
        self.assertArrayAlmostEqual(matrix2array(kwlist2.centroid), 
                                    (kw1.vec.toarray()[0] + kw2.vec.toarray()[0]) / 2)
开发者ID:samim23,项目名称:rl-search,代码行数:15,代码来源:modellist_test.py

示例8: test_rec_fb_from_kw

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_rec_fb_from_kw(self):
        """
        getter/setting for receiving feedback from keyword
        """
        kw = Keyword.get("redis")
        kw.rec_fb_from_kw(kw, 1, self.session)
        self.assertEqual(1, 
                         kw.fb_from_kw(self.session))
        
        kw.rec_fb_from_kw(kw, .5, self.session)
        self.assertEqual(.5, 
                         kw.fb_from_kw(self.session))

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

示例9: test_loop_done

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_loop_done(self):
        """
        test if things are cleaned when the loop is done
        """
        doc = Document.get(1)

        doc.rec_fb_from_dockw(Keyword.get("redis"), doc, 1, self.session)
        doc.rec_fb_from_kw(Keyword.get("database"), .5, self.session)

        doc.rec_fb_from_doc(doc, .5, self.session)

        # terminate the loop
        # everything feedback stuff cleaned
        doc.loop_done(self.session)

        self.assertEqual(doc.fb_weighted_sum(self.session), 0)
开发者ID:samim23,项目名称:rl-search,代码行数:18,代码来源:doc_fb_receiver_test.py

示例10: recommend_keywords

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
 def recommend_keywords(self, fmim,
                        session, top_n, mu, c, 
                        sampler=None):
     """
     fmim: FeatureMatrixAndIndexMapping, the fmim for the sub-matrix        
     session: Session,
     top_n: how many kws are returned
     mu,c: float, the parameters for LinRel algorithm
     
     Return
     KeywordList: a list of keyword ids as well as their scores
     """        
     kws = Keyword.get_many(fmim.kw_ind.keys())
     fbs = dict([(kw.id, kw.fb(session)) for kw in kws])
     
     id_with_scores, id_with_explt_scores, id_with_explr_scores = self.generic_rank(fmim.kw2doc_m, fbs, 
                                                                                    fmim.kw_ind, fmim.kw_ind_r,
                                                                                    mu, c)
     
     kws = []
     for kw_id, score in id_with_scores.items()[:top_n]:
         kw = Keyword.get(kw_id)
         kw['score'] = score
         kw['recommended'] = True
         kws.append(kw)
         
     return kws
开发者ID:samim23,项目名称:rl-search,代码行数:29,代码来源:linrel.py

示例11: test_update_kw_fb

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
 def test_update_kw_fb(self):
     """update keyword feedback"""
     kw = Keyword.get('redis')
     self.session.update_kw_feedback(kw, 1)
     
     self.assertEqual(self.session.kw_feedbacks, {kw: 1})
     
     self.assertEqual(kw.fb(self.session), 1)
开发者ID:samim23,项目名称:rl-search,代码行数:10,代码来源:session_test.py

示例12: test_rec_fb_from_kw

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_rec_fb_from_kw(self):
        """
        getter/setting for receiving feedback from keyword
        """
        doc = Document.get(1)

        doc.rec_fb_from_kw(Keyword.get("redis"), 1, self.session)
        doc.rec_fb_from_kw(Keyword.get("database"), .5, self.session)
        
        self.assertEqual(doc.fb_from_kw(self.session), {Keyword.get("redis"): 1, Keyword.get("database"): .5})

        #does not contain redis, error should be raised
        self.assertRaises(AssertionError, doc.rec_fb_from_kw, Keyword.get("python"), 1, self.session)
                

        #test the weighted sum
        weights = [0.62981539329519109, 0.45460437826405437, 0.62981539329519109]                
        self.assertEqual((weights[0] * 1 + weights[1] * .5) / sum(weights), doc.fb_weighted_sum(self.session))
开发者ID:samim23,项目名称:rl-search,代码行数:20,代码来源:doc_fb_receiver_test.py

示例13: test_associated_keywords_from_documents

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
 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,代码行数:12,代码来源:linrel_recommender_test.py

示例14: test_kw_fb_filter

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    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,代码行数:12,代码来源:filters_test.py

示例15: test_all_together

# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get [as 别名]
    def test_all_together(self):
        """
        All three sources of feedbacks are involved
        """
        doc = Document.get(1)
        
        doc.rec_fb_from_dockw(Keyword.get("redis"), doc, 1, self.session)
        doc.rec_fb_from_kw(Keyword.get("database"), .5, self.session)

        doc.rec_fb_from_doc(doc, .5, self.session)
        
        redis = Keyword.get("redis")
        db = Keyword.get("database")
        weights = {redis: 0.62981539329519109, 
                   db: 0.45460437826405437, 
                   Keyword.get("a"): 0.62981539329519109
        }
        
        self.assertAlmostEqual(.5 * .7 + .3 * (weights[redis] * 1 + weights[db] * .5) / sum(weights.values()),
                               doc.fb_weighted_sum(self.session))
开发者ID:samim23,项目名称:rl-search,代码行数:22,代码来源:doc_fb_receiver_test.py


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