本文整理汇总了Python中scinet3.model.Document.get方法的典型用法代码示例。如果您正苦于以下问题:Python Document.get方法的具体用法?Python Document.get怎么用?Python Document.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scinet3.model.Document
的用法示例。
在下文中一共展示了Document.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document 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)
示例2: receive_feedbacks
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document 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"
示例3: test_doc_fb_threshold_filter
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
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)
示例4: test_affected_docs
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
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))
示例5: test_document_centroid
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
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)
示例6: test_rec_fb_from_dockw
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document 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)
示例7: test_fb_weighted_sum_dockw_only
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
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))
示例8: test_rec_fb_from_doc
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
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)
示例9: test_fb_weighted_sum_mixed_source
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
def test_fb_weighted_sum_mixed_source(self):
"""
test if the weighted sum is correct
feedback include all three sources
"""
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)
kw.rec_fb_from_kw(kw, .5, self.session)
self.assertEqual(.3 * (1 / 2. + 1 / 4.) + .7 * .5,
kw.fb_weighted_sum(self.session))
示例10: test_loop_done
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
def test_loop_done(self):
"""
test if things are cleaned when the loop is done
"""
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)
kw.rec_fb_from_kw(kw, .5, self.session)
# terminate the loop
# everything feedback stuff cleaned
kw.loop_done(self.session)
self.assertEqual(kw.fb_weighted_sum(self.session), 0)
示例11: test_rec_from_doc
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
def test_rec_from_doc(self):
"""
getter/setting for receiving feedback from document
"""
doc = Document.get(1)
doc.rec_fb_from_doc(doc, 1, self.session)
self.assertEqual(1, doc.fb_from_doc(self.session))
doc.rec_fb_from_doc(doc, .5, self.session)
self.assertEqual(.5, doc.fb_from_doc(self.session))
#is not the right document
self.assertRaises(AssertionError, doc.rec_fb_from_doc, Document.get(2), 1, self.session)
#test the weighted sum
self.assertEqual(.5 * .7, doc.fb_weighted_sum(self.session))
示例12: test_update_doc_fb
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
def test_update_doc_fb(self):
"""update document feedback"""
doc = Document.get(1)
self.session.update_doc_feedback(doc, 1)
self.assertEqual(self.session.doc_feedbacks, {doc: 1})
self.assertEqual(doc.fb(self.session), 1)
示例13: test_kw_fb_filter
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document 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)
示例14: test_rec_fb_from_dockw
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
def test_rec_fb_from_dockw(self):
"""
getter/setting for receiving feedback from in-document keyword
"""
doc = Document.get(1)
doc.rec_fb_from_dockw(Keyword.get("redis"), doc, 1, self.session)
doc.rec_fb_from_dockw(Keyword.get("database"), doc, .5, self.session)
self.assertEqual(doc.fb_from_kw(self.session), {Keyword.get("redis"): 1, Keyword.get("database"): .5})
#not the right document
self.assertRaises(AssertionError, doc.rec_fb_from_dockw, Document.get(2), Keyword.get("redis"), 1, self.session)
#python is not a keyword for document#1, error should be raised
self.assertRaises(AssertionError, doc.rec_fb_from_dockw, doc, 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))
示例15: test_doc_fb_filter
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get [as 别名]
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)