本文整理汇总了Python中scinet3.model.Document类的典型用法代码示例。如果您正苦于以下问题:Python Document类的具体用法?Python Document怎么用?Python Document使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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"
示例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)
示例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()
示例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))
示例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])
示例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)
示例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])))
示例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))
示例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)
示例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])
示例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)
示例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))
示例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)
示例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))
示例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))