示例#1
0
文件: base.py 项目: samim23/rl-search
 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()
示例#2
0
    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()
示例#3
0
 def setUp(self):
     #load all first
     self.docs = Document.load_all_from_db()
示例#4
0
##########################
# Test the evaluation module
##########################

from util import (config_doc_kw_model, NumericTestCase)

from scinet3.util.ir_eval import GoalBasedEvaluator
from scinet3.model import (Document, Keyword)

config_doc_kw_model()
Document.load_all_from_db()


class GoalBasedEvaluationTest(NumericTestCase):
    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)

    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"]),
示例#5
0
##########################
# Test the evaluation module
##########################

from util import (config_doc_kw_model, NumericTestCase)

from scinet3.util.ir_eval import GoalBasedEvaluator
from scinet3.model import (Document, Keyword)


config_doc_kw_model()
Document.load_all_from_db()

class GoalBasedEvaluationTest(NumericTestCase):
    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)

    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
0
# Test for document feedback receiver
##############################

import unittest

import torndb
import redis

from scinet3.model import Document, Keyword

from util import (config_doc_kw_model, get_session)

#config model,
#only done once
config_doc_kw_model()
docs = Document.load_all_from_db()


class DocumentFeedbackTest(unittest.TestCase):
    def setUp(self):
        #session
        self.session = get_session()

    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))
示例#7
0
 def setUp(self):
     #load all first
     self.docs = Document.load_all_from_db()
示例#8
0
# Test for document feedback receiver
##############################

import unittest

import torndb
import redis

from scinet3.model import Document, Keyword

from util import (config_doc_kw_model, get_session)

#config model, 
#only done once
config_doc_kw_model()
docs = Document.load_all_from_db()

class DocumentFeedbackTest(unittest.TestCase):
    def setUp(self):
        #session
        self.session = get_session()                

    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))