本文整理汇总了Python中scinet3.model.Keyword.get_many方法的典型用法代码示例。如果您正苦于以下问题:Python Keyword.get_many方法的具体用法?Python Keyword.get_many怎么用?Python Keyword.get_many使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scinet3.model.Keyword
的用法示例。
在下文中一共展示了Keyword.get_many方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_one
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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 Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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_add_kws
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get_many [as 别名]
def test_add_kws(self):
iter1 = Keyword.get_many(["redis", "database", "mysql"])
iter2 = Keyword.get_many(["redis", "database", "python"])
self.session.add_kw_recom_list(iter1)
self.assertEqual([iter1], self.session.recom_kws)
self.session.add_kw_recom_list(iter2)
self.assertEqual([iter1, iter2], self.session.recom_kws)
示例4: test_associated_keywords_from_documents
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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))
示例5: test_two
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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])
示例6: test_kw_hashable
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get_many [as 别名]
def test_kw_hashable(self):
d = {}
kwlist1 = Keyword.get_many(["redis", "a", "the"])
kwlist2 = Keyword.get_many(["a", "the", "redis"])
kwlist3 = Keyword.get_many(["redis", "a", "python"])
d[kwlist1] = 1
d[kwlist2] = 2 #override
d[kwlist3] = 3
self.assertEqual({kwlist1:2, kwlist3: 3}, d)
示例7: test_modellist2modellist_similarity
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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: test_equality_same_type
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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)
示例9: setUp
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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)
示例10: recommend_keywords
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get_many [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
示例11: setUp
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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)
示例12: test_recommend
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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)
示例13: test_recommend_keywords
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword import get_many [as 别名]
def test_recommend_keywords(self):
kws = self.r.recommend_keywords(Document.get_many([6, 1]), 5, 3,
query_keywords = Keyword.get_many(["python", "redis",
"non-existing"]))
kw_from_recom_docs = kws[:3]
kw_from_assoc_docs = kws[3:]
self.assertEqual(5, len(kws))
self.assertEqual(list(Keyword.get_many(["python", "redis"])), kw_from_recom_docs[:2]) #the first two should be python and redis
for kw in kw_from_recom_docs:
self.assertTrue(kw["recommended"])
for kw in kw_from_assoc_docs:
self.assertFalse(kw["recommended"])
#no easy way to further test the elements of the kws
pass
示例14: test_recommend_documents_sensible_query
# 需要导入模块: from scinet3.model import Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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 Keyword [as 别名]
# 或者: from scinet3.model.Keyword 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)