예제 #1
0
파일: views.py 프로젝트: namongk/ecogwiki
    def get(self, path, head=False):
        cache.create_prc()
        expression = WikiPage.path_to_title(path)
        parsed_expression = search.parse_expression(expression)
        scoretable = WikiPage.search(expression)

        positives = dict([(k, v) for k, v in scoretable.items() if v >= 0.0])
        positives = OrderedDict(
            sorted(positives.iteritems(),
                   key=operator.itemgetter(1),
                   reverse=True)[:20])
        negatives = dict([(k, abs(v)) for k, v in scoretable.items()
                          if v < 0.0])
        negatives = OrderedDict(
            sorted(negatives.iteritems(),
                   key=operator.itemgetter(1),
                   reverse=True)[:20])

        self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
        html = template(
            self.request, 'search.html', {
                'expression': expression,
                'parsed_expression': parsed_expression,
                'positives': positives,
                'negatives': negatives
            })
        set_response_body(self.response, html, head)
예제 #2
0
 def test_single_title(self):
     expected = {
         'pos': [u'Hello'],
         'neg': [],
     }
     actual = search.parse_expression(u'+Hello')
     self.assertEqual(expected, actual)
예제 #3
0
 def test_multiple_titles(self):
     expected = {
         'pos': [u'What the', u'Is it'],
         'neg': [u'Fun'],
     }
     actual = search.parse_expression(u'+What the -Fun +Is it')
     self.assertEqual(expected, actual)
예제 #4
0
 def test_no_space(self):
     expected = {
         'pos': [u'User-centered design'],
         'neg': [],
     }
     actual = search.parse_expression(u'+User-centered design')
     self.assertEqual(expected, actual)
예제 #5
0
 def test_no_space(self):
     expected = {
         'pos': [u'User-centered design'],
         'neg': [],
     }
     actual = search.parse_expression(u'+User-centered design')
     self.assertEqual(expected, actual)
예제 #6
0
 def test_single_title(self):
     expected = {
         'pos': [u'Hello'],
         'neg': [],
     }
     actual = search.parse_expression(u'+Hello')
     self.assertEqual(expected, actual)
예제 #7
0
 def test_multiple_titles(self):
     expected = {
         'pos': [u'What the', u'Is it'],
         'neg': [u'Fun'],
     }
     actual = search.parse_expression(u'+What the -Fun +Is it')
     self.assertEqual(expected, actual)
예제 #8
0
    def search(cls, expression):
        # parse
        parsed = search.parse_expression(expression)

        # evaluate
        pos, neg = parsed['pos'], parsed['neg']
        pos_pages = [cls.get_by_title(t, True) for t in pos]
        neg_pages = [cls.get_by_title(t, True) for t in neg]
        scoretable = search.evaluate(
            dict((page.title, page.link_scoretable) for page in pos_pages),
            dict((page.title, page.link_scoretable) for page in neg_pages)
        )
        return scoretable
예제 #9
0
    def search(cls, expression):
        # parse
        parsed = search.parse_expression(expression)

        # evaluate
        pos, neg = parsed['pos'], parsed['neg']
        pos_pages = [cls.get_by_title(t, True) for t in pos]
        neg_pages = [cls.get_by_title(t, True) for t in neg]
        scoretable = search.evaluate(
            dict((page.title, page.link_scoretable) for page in pos_pages),
            dict((page.title, page.link_scoretable) for page in neg_pages))

        return scoretable
예제 #10
0
 def load(self):
     expression = WikiPage.path_to_title(self.path)
     scoretable = WikiPage.search(expression)
     parsed_expression = search.parse_expression(expression)
     positives = dict([(k, v) for k, v in scoretable.items() if v >= 0.0])
     positives = OrderedDict(sorted(positives.iteritems(), key=operator.itemgetter(1), reverse=True)[:20])
     negatives = dict([(k, abs(v)) for k, v in scoretable.items() if v < 0.0])
     negatives = OrderedDict(sorted(negatives.iteritems(), key=operator.itemgetter(1), reverse=True)[:20])
     return {
         "expression": expression,
         "parsed_expression": parsed_expression,
         "positives": positives,
         "negatives": negatives,
     }
예제 #11
0
파일: views.py 프로젝트: ledzpl/ecogwiki
    def get_search_result(self, path, head):
        expression = WikiPage.path_to_title(path)
        parsed_expression = search.parse_expression(expression)
        scoretable = WikiPage.search(expression)

        positives = dict([(k, v) for k, v in scoretable.items() if v >= 0.0])
        positives = OrderedDict(sorted(positives.iteritems(),
                                       key=operator.itemgetter(1),
                                       reverse=True)[:20])
        negatives = dict([(k, abs(v)) for k, v in scoretable.items() if v < 0.0])
        negatives = OrderedDict(sorted(negatives.iteritems(),
                                       key=operator.itemgetter(1),
                                       reverse=True)[:20])

        self.response.headers['Content-Type'] = 'text/html; charset=utf-8'
        html = self._template('search.html', {'expression': expression,
                                              'parsed_expression': parsed_expression,
                                              'positives': positives,
                                              'negatives': negatives})
        self._set_response_body(html, head)
예제 #12
0
 def load(self):
     expression = WikiPage.path_to_title(self.path)
     scoretable = WikiPage.search(expression)
     parsed_expression = search.parse_expression(expression)
     positives = dict([(k, v) for k, v in scoretable.items() if v >= 0.0])
     positives = OrderedDict(
         sorted(positives.iteritems(),
                key=operator.itemgetter(1),
                reverse=True)[:20])
     negatives = dict([(k, abs(v)) for k, v in scoretable.items()
                       if v < 0.0])
     negatives = OrderedDict(
         sorted(negatives.iteritems(),
                key=operator.itemgetter(1),
                reverse=True)[:20])
     return {
         'expression': expression,
         'parsed_expression': parsed_expression,
         'positives': positives,
         'negatives': negatives,
     }
예제 #13
0
 def load(self):
     expression = WikiPage.path_to_title(self.path)
     scoretable = WikiPage.search(expression)
     parsed_expression = search.parse_expression(expression)
     positives = dict([(k, v) for k, v in scoretable.items() if v >= 0.0])
     positives = OrderedDict(sorted(positives.iteritems(),
                                    key=operator.itemgetter(1),
                                    reverse=True)[:20])
     negatives = dict([(k, abs(v)) for k, v in scoretable.items() if v < 0.0])
     negatives = OrderedDict(sorted(negatives.iteritems(),
                                    key=operator.itemgetter(1),
                                    reverse=True)[:20])
     context =  {
         'expression': expression,
         'parsed_expression': parsed_expression,
         'positives': positives,
         'negatives': negatives,
     }
     if positives:
         context['positive_items'] = positives.items()
     if negatives:
         context['negative_items'] = negatives.items()
     return context
예제 #14
0
 def test_single_title(self):
     expected = {"pos": [u"Hello"], "neg": []}
     actual = search.parse_expression(u"+Hello")
     self.assertEqual(expected, actual)
예제 #15
0
 def test_no_space(self):
     expected = {"pos": [u"User-centered design"], "neg": []}
     actual = search.parse_expression(u"+User-centered design")
     self.assertEqual(expected, actual)
예제 #16
0
 def test_multiple_titles(self):
     expected = {"pos": [u"What the", u"Is it"], "neg": [u"Fun"]}
     actual = search.parse_expression(u"+What the -Fun +Is it")
     self.assertEqual(expected, actual)