コード例 #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
ファイル: test_search.py プロジェクト: cornchz/ecogwiki
 def test_single_title(self):
     expected = {
         'pos': [u'Hello'],
         'neg': [],
     }
     actual = search.parse_expression(u'+Hello')
     self.assertEqual(expected, actual)
コード例 #3
0
ファイル: test_search.py プロジェクト: cornchz/ecogwiki
 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
ファイル: test_search.py プロジェクト: cornchz/ecogwiki
 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
ファイル: models.py プロジェクト: 0hoo/django-ecogwiki
    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
ファイル: resources.py プロジェクト: gcmcom/ecogwiki
 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
ファイル: resources.py プロジェクト: 0hoo/django-ecogwiki
 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
ファイル: test_search.py プロジェクト: gcmcom/ecogwiki
 def test_single_title(self):
     expected = {"pos": [u"Hello"], "neg": []}
     actual = search.parse_expression(u"+Hello")
     self.assertEqual(expected, actual)
コード例 #15
0
ファイル: test_search.py プロジェクト: gcmcom/ecogwiki
 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
ファイル: test_search.py プロジェクト: gcmcom/ecogwiki
 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)