本文整理汇总了Python中scinet3.model.Document.get_many方法的典型用法代码示例。如果您正苦于以下问题:Python Document.get_many方法的具体用法?Python Document.get_many怎么用?Python Document.get_many使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scinet3.model.Document
的用法示例。
在下文中一共展示了Document.get_many方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_one
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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])
示例2: test_get_many
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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))
示例3: test_associated_keywords_from_documents
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [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))
示例4: test_two
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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])
示例5: test_filter_objs
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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])))
示例6: test_doc_hashable
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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)
示例7: test_modellist2modellist_similarity
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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))
示例8: sample_documents_associated_with_keywords
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
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)
示例9: test_equality_same_type
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def test_equality_same_type(self):
kwlist1 = Keyword.get_many(["redis", "a", "the"])
kwlist2 = Keyword.get_many(["a", "the", "redis"])
kwlist3 = Keyword.get_many(["a", "the", "python"])
self.assertEqual(kwlist1, kwlist2)
self.assertNotEqual(kwlist3, kwlist2)
doclist1 = Document.get_many([1,2,3])
doclist2 = Document.get_many([2,3,1])
doclist3 = Document.get_many([4,5,6])
self.assertEqual(doclist1, doclist2)
self.assertNotEqual(doclist3, doclist2)
示例10: test_add_docs
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def test_add_docs(self):
"""
as well as last_recom_docs
"""
iter1 = Document.get_many([1, 2, 3])
iter2 = Document.get_many([2, 3, 4])
self.session.add_doc_recom_list(iter1)
self.assertEqual([iter1], self.session.recom_docs)
self.session.add_doc_recom_list(iter2)
self.assertEqual([iter1, iter2], self.session.recom_docs)
self.assertEqual(iter2, self.session.last_recom_docs)
示例11: setUp
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def setUp(self):
doc_goal = Document.get_many([1,2])
kw_goal = Keyword.get_many(["redis", "database"])
self.e = GoalBasedEvaluator()
self.e.setGoal(doc_goal, kw_goal)
示例12: setUp
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def setUp(self):
init_recommender = QueryBasedRecommender(3, 2,
3, 2,
**fmim.__dict__)
main_recommender = LinRelRecommender(3, 3,
1., .5,
1., .5,
None,None,
None,None,
**fmim.__dict__)
self.app = CmdApp(OnePassPropagator, OverrideUpdater,
init_recommender, main_recommender)
self.session = get_session()
#add recommended list
self.session.add_doc_recom_list(Document.get_many([1,2,3]))
self.session.add_kw_recom_list(Keyword.get_many(["a", "redis", "database"]))
self.fb = {
"docs": [[1, .5]],
"kws": [["redis", .5]],
"dockws": [["redis", 1, .5]]
}
random.seed(123456)
示例13: test_recommend
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def test_recommend(self):
docs, kws = self.r.recommend(self.session,
4, 4,
1, .5,
1., .5)
self.assertEqual(Document.get_many([1,8,2,6]), docs)
self.assertEqual(Keyword.get_many(["redis", "database", "the", "mysql", "a", "python"]), kws)
示例14: test_recommend_documents_sensible_query
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def test_recommend_documents_sensible_query(self):
"""
query that has keywords existing in the documents' keyword list
"""
query = "database, python, redis"
matched_docs, query_keywords = self.r.recommend_documents(query, 4)
self.assertEqual(Document.get_many([6,1,2,5]), matched_docs)
self.assertEqual(Keyword.get_many(["database", "python", "redis"]), query_keywords)
示例15: test_recommend_main
# 需要导入模块: from scinet3.model import Document [as 别名]
# 或者: from scinet3.model.Document import get_many [as 别名]
def test_recommend_main(self):
#receive the feedback first
self.app.receive_feedbacks(self.session, self.fb)
docs , kws = self.app.recommend(start = False, session = self.session)
self.assertEqual(Document.get_many([1,2,6]),
docs)
self.assertEqual(Keyword.get_many(["redis", "database", "a", "python", "the"]),
kws)