Esempio n. 1
0
    def search(self):
        c.service = "search"
        query = request.params['query']
        if request.params.has_key('start'):
          start = request.params['start']
        else:
          start = 0

        if query.strip() == "":
          return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab data from Solr
        params = {'q': sanitize(query), 'rows' : 10, 'start': start}
        results = conn.query(**(params))
        conn.close()


        if len(results) == 0:
          c.query = query
          return render('/noresults.mako')

        # Send params to context
        c.start = start
        c.results = results
        c.query = query

        return render('/results.mako')
Esempio n. 2
0
    def custom(self):
        c.service = "custom"
        query = request.params['query']

        if request.params.has_key('start'):
          start = float(request.params['start'])
        else:
          start = -1.0

        if request.params.has_key('end'):
          end = float(request.params['end'])
        else:
          end = 1.0

        if query.strip() == "":
          return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab data from Solr
        params = {'q': sanitize(query) + " sentiment:[%f TO %f]" % (start, end),
                  'rows' : 10}
        results = conn.query(**(params))
        conn.close()

        c.query = query

        if len(results) == 0:
          return render('/noresults.mako')

        c.results = results
        c.start = start
        c.end = end

        return render('/custom.mako')
Esempio n. 3
0
    def search(self):
        c.service = "search"
        query = request.params['query']
        if request.params.has_key('start'):
            start = request.params['start']
        else:
            start = 0

        if query.strip() == "":
            return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab data from Solr
        params = {'q': sanitize(query), 'rows': 10, 'start': start}
        results = conn.query(**(params))
        conn.close()

        if len(results) == 0:
            c.query = query
            return render('/noresults.mako')

        # Send params to context
        c.start = start
        c.results = results
        c.query = query

        return render('/results.mako')
Esempio n. 4
0
    def polarize(self):
        c.service = "polarize"
        c.query = request.params['query']

        if c.query.strip() == "":
            return render('/index.mako')

        self.startAsyncSearch(c.query)
        return render('/polarize.mako')
Esempio n. 5
0
  def polarize(self):
    c.service = "polarize"
    c.query = request.params['query']

    if c.query.strip() == "":
      return render('/index.mako')

    self.startAsyncSearch(c.query)
    return render('/polarize.mako')
Esempio n. 6
0
    def custom(self):
        c.service = "search"
        c.query = request.params['query']

        if c.query.strip() == "":
            return render('/index.mako')

        self.startAsyncSearch(c.query)
        return render('/custom.mako')
Esempio n. 7
0
  def custom(self):
    c.service = "search"
    c.query = request.params['query']

    if c.query.strip() == "":
      return render('/index.mako')

    self.startAsyncSearch(c.query)
    return render('/custom.mako')
Esempio n. 8
0
    def analysis(self):
        query = request.params['query']

        if query.strip() == "":
            return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab polarized data from Solr
        params = {'q': sanitize(query) + " sentiment:[0.0 TO 1.0]", 'rows': 10}
        good_results = conn.query(**(params))
        params = {
            'q': sanitize(query) + " sentiment:[-1.0 TO 0.0]",
            'rows': 10
        }
        bad_results = conn.query(**(params))

        # Grab data from Solr
        params = {'q': sanitize(query), 'rows': 500, 'start': 0}
        results = conn.query(**(params))
        conn.close()

        # Do ngrams analysis
        goodText = ''.join(hit['content'] for hit in good_results.results)
        badText = ''.join(hit['content'] for hit in bad_results.results)
        c.goodTerms, c.badTerms = ngrams.main(goodText, badText,
                                              ngrams.getWordsForDisplay)

        c.goodCount = good_results.numFound
        c.badCount = bad_results.numFound

        c.goodResults = good_results
        c.badResults = bad_results

        c.query = query

        if len(results) == 0:
            return render('/noresults.mako')

        c.results = results
        c.service = "analysis"
        return render('/analysis.mako')
Esempio n. 9
0
    def polarize(self):
        c.service = "polarize"

        query = request.params['query']

        if query.strip() == "":
            return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab data from Solr
        params = {'q': sanitize(query) + " sentiment:[0.0 TO 1.0]", 'rows': 10}
        good_results = conn.query(**(params))
        params = {
            'q': sanitize(query) + " sentiment:[-1.0 TO 0.0]",
            'rows': 10
        }
        bad_results = conn.query(**(params))
        conn.close()

        if not (good_results or bad_results):
            c.query = query
            return render('/noresults.mako')

        # Do ngrams analysis
        goodText = ''.join(hit['content'] for hit in good_results.results)
        badText = ''.join(hit['content'] for hit in bad_results.results)
        q, p = ngrams.main(goodText, badText, ngrams.getWordsForDisplay)

        # Send params to context
        c.goodTerms = q  #[i[0] for i in q]
        c.badTerms = p  #[i[0] for i in p]

        c.goodResults = good_results
        c.badResults = bad_results

        c.query = query

        return render('/polarize.mako')
Esempio n. 10
0
    def analysis(self):
        query = request.params['query']

        if query.strip() == "":
          return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab polarized data from Solr
        params = {'q': sanitize(query) + " sentiment:[0.0 TO 1.0]", 'rows' : 10}
        good_results = conn.query(**(params))
        params = {'q': sanitize(query) + " sentiment:[-1.0 TO 0.0]", 'rows' : 10}
        bad_results = conn.query(**(params))

        # Grab data from Solr
        params = {'q': sanitize(query), 'rows' : 500, 'start': 0}
        results = conn.query(**(params))
        conn.close()

        # Do ngrams analysis
        goodText = ''.join(hit['content'] for hit in good_results.results)
        badText = ''.join(hit['content'] for hit in bad_results.results)
        c.goodTerms, c.badTerms = ngrams.main(goodText, badText, ngrams.getWordsForDisplay)

        c.goodCount = good_results.numFound
        c.badCount = bad_results.numFound

        c.goodResults = good_results
        c.badResults = bad_results

        c.query = query

        if len(results) == 0:
          return render('/noresults.mako')

        c.results = results
        c.service = "analysis"
        return render('/analysis.mako')
Esempio n. 11
0
    def custom(self):
        c.service = "custom"
        query = request.params['query']

        if request.params.has_key('start'):
            start = float(request.params['start'])
        else:
            start = -1.0

        if request.params.has_key('end'):
            end = float(request.params['end'])
        else:
            end = 1.0

        if query.strip() == "":
            return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab data from Solr
        params = {
            'q': sanitize(query) + " sentiment:[%f TO %f]" % (start, end),
            'rows': 10
        }
        results = conn.query(**(params))
        conn.close()

        c.query = query

        if len(results) == 0:
            return render('/noresults.mako')

        c.results = results
        c.start = start
        c.end = end

        return render('/custom.mako')
Esempio n. 12
0
    def polarize(self):
        c.service = "polarize"

        query = request.params['query']

        if query.strip() == "":
          return render('/index.mako')

        conn = solr.SolrConnection('http://localhost:8983/solr')

        # Grab data from Solr
        params = {'q': sanitize(query) + " sentiment:[0.0 TO 1.0]", 'rows' : 10}
        good_results = conn.query(**(params))
        params = {'q': sanitize(query) + " sentiment:[-1.0 TO 0.0]", 'rows' : 10}
        bad_results = conn.query(**(params))
        conn.close()

        if not (good_results or bad_results):
          c.query = query
          return render('/noresults.mako')

        # Do ngrams analysis
        goodText = ''.join(hit['content'] for hit in good_results.results)
        badText = ''.join(hit['content'] for hit in bad_results.results)
        q, p = ngrams.main(goodText, badText, ngrams.getWordsForDisplay)

        # Send params to context
        c.goodTerms = q #[i[0] for i in q]
        c.badTerms = p #[i[0] for i in p]

        c.goodResults = good_results
        c.badResults = bad_results

        c.query = query

        return render('/polarize.mako')
Esempio n. 13
0
  def analysis(self):
    c.service = "analysis"
    c.query = request.params['query']

    if c.query.strip() == "":
      return render('/index.mako')

    c.results = self.getAllResults(c.query)

    c.categories = {}
    for r in c.results:
      if r['parser'] not in c.categories:
        c.categories[r['parser']] = []
      if r['product'] not in c.categories[r['parser']]:
        c.categories[r['parser']].append(r['product'])

    narrowparsers = None
    narrowproducts = None

    if "narrow" in request.params:
      newresults = []
      narrowparsers = request.params['sources'].split(",")
      narrowparsers = [s[8:] for s in narrowparsers]
      narrowproducts = request.params['products'].split(",")
      narrowproducts = [s[7:] for s in narrowproducts]

      for r in c.results:
        if (fix(r['product']) in narrowproducts and
            r['parser'] in narrowparsers):
          newresults.append(r)

      c.results = newresults
    c.narrowparsers = narrowparsers
    c.narrowproducts = narrowproducts

    if len(c.results) == 0:
      return render('/noresults.mako')

    good_results = [hit for hit in c.results if hit['sentiment'] >= positive_cutoff]
    neutral_results = [hit for hit in c.results 
        if hit['sentiment'] < positive_cutoff and hit['sentiment'] >= negative_cutoff]
    bad_results = [hit for hit in c.results if hit['sentiment'] < negative_cutoff]

    sent_sum = 0.0
    for hit in c.results:
      sent_sum += hit['sentiment']

    c.mean = sent_sum / len(c.results)
    c.std_dev = 0
    for hit in c.results:
      c.std_dev += (hit['sentiment'] - c.mean)**2

    c.std_dev = (c.std_dev/len(c.results))**(1.0/2)

    c.verdict = ""
    if c.std_dev < 0.20:
      c.verdict = "Universal "
    elif c.std_dev < 0.35:
      c.verdict = "Disputed "
    else:
      c.verdict = "Hotly contested "

    if c.mean < 0.35:
      c.verdict += "disapproval"
    elif c.mean < 0.65:
      c.verdict += "mediocre reviews"
    else:
      c.verdict += "approval"

    goodText = ''
    badText = ''
    for hit in good_results:
        try:
            goodText += hit['content']
        except Exception , e:
            print 'good_results error', e
            pass
Esempio n. 14
0
 def index(self):
     # Return a rendered template
     c.service = "search"
     return render('/index.mako')
Esempio n. 15
0
 def index(self):
   # Return a rendered template
   #return render('/metasearch.mako')
   # or, return a string
   c.service = "polarize"
   return render('/index.mako')
Esempio n. 16
0
    for hit in bad_results:
        try:
            badText += hit['content']
        except Exception , e:
            print 'bad_results error', e
            pass

    #goodText = ''.join(hit['content'] for hit in good_results)
    #badText = ''.join(hit['content'] for hit in bad_results)

    c.goodTerms, c.badTerms = ngrams.main(goodText, badText,
        ngrams.getWordsForDisplay)

    c.goodResults = good_results
    c.neutralResults = neutral_results
    c.badResults = bad_results

    return render('/analysis.mako')

  def custom(self):
    c.service = "search"
    c.query = request.params['query']

    if c.query.strip() == "":
      return render('/index.mako')

    self.startAsyncSearch(c.query)
    return render('/custom.mako')

# vi: set ts=2 sts=2 sw=2:
Esempio n. 17
0
            try:
                badText += hit['content']
            except Exception, e:
                print 'bad_results error', e
                pass

        #goodText = ''.join(hit['content'] for hit in good_results)
        #badText = ''.join(hit['content'] for hit in bad_results)

        c.goodTerms, c.badTerms = ngrams.main(goodText, badText,
                                              ngrams.getWordsForDisplay)

        c.goodResults = good_results
        c.neutralResults = neutral_results
        c.badResults = bad_results

        return render('/analysis.mako')

    def custom(self):
        c.service = "search"
        c.query = request.params['query']

        if c.query.strip() == "":
            return render('/index.mako')

        self.startAsyncSearch(c.query)
        return render('/custom.mako')


# vi: set ts=2 sts=2 sw=2:
Esempio n. 18
0
 def index(self):
     # Return a rendered template
     c.service = "search"
     return render('/index.mako')
Esempio n. 19
0
 def index(self):
     # Return a rendered template
     #return render('/metasearch.mako')
     # or, return a string
     c.service = "polarize"
     return render('/index.mako')
Esempio n. 20
0
    def analysis(self):
        c.service = "analysis"
        c.query = request.params['query']

        if c.query.strip() == "":
            return render('/index.mako')

        c.results = self.getAllResults(c.query)

        c.categories = {}
        for r in c.results:
            if r['parser'] not in c.categories:
                c.categories[r['parser']] = []
            if r['product'] not in c.categories[r['parser']]:
                c.categories[r['parser']].append(r['product'])

        narrowparsers = None
        narrowproducts = None

        if "narrow" in request.params:
            newresults = []
            narrowparsers = request.params['sources'].split(",")
            narrowparsers = [s[8:] for s in narrowparsers]
            narrowproducts = request.params['products'].split(",")
            narrowproducts = [s[7:] for s in narrowproducts]

            for r in c.results:
                if (fix(r['product']) in narrowproducts
                        and r['parser'] in narrowparsers):
                    newresults.append(r)

            c.results = newresults
        c.narrowparsers = narrowparsers
        c.narrowproducts = narrowproducts

        if len(c.results) == 0:
            return render('/noresults.mako')

        good_results = [
            hit for hit in c.results if hit['sentiment'] >= positive_cutoff
        ]
        neutral_results = [
            hit for hit in c.results if hit['sentiment'] < positive_cutoff
            and hit['sentiment'] >= negative_cutoff
        ]
        bad_results = [
            hit for hit in c.results if hit['sentiment'] < negative_cutoff
        ]

        sent_sum = 0.0
        for hit in c.results:
            sent_sum += hit['sentiment']

        c.mean = sent_sum / len(c.results)
        c.std_dev = 0
        for hit in c.results:
            c.std_dev += (hit['sentiment'] - c.mean)**2

        c.std_dev = (c.std_dev / len(c.results))**(1.0 / 2)

        c.verdict = ""
        if c.std_dev < 0.20:
            c.verdict = "Universal "
        elif c.std_dev < 0.35:
            c.verdict = "Disputed "
        else:
            c.verdict = "Hotly contested "

        if c.mean < 0.35:
            c.verdict += "disapproval"
        elif c.mean < 0.65:
            c.verdict += "mediocre reviews"
        else:
            c.verdict += "approval"

        goodText = ''
        badText = ''
        for hit in good_results:
            try:
                goodText += hit['content']
            except Exception, e:
                print 'good_results error', e
                pass