python代码没有在Jupyter笔记本上运行

时间:2016-11-23 15:18:19

标签: python jupyter-notebook attributeerror gensim

我已经运行了document similarity server

的python代码

代码在命令行中运行良好,但是当我尝试从Jupyter笔记本运行时,我收到以下错误(您可以在下面找到代码)

  

AttributeError Traceback(最近一次调用最后一次)
   in()
  ----> 1 simServer.queryIndex('National Intergroup Inc表示计划提交注册声明')

<ipython-input-2-81df834abc60> in queryIndex(self, queryText)
     58         print "Querying the INDEX"
     59         doc = {'tokens': utils.simple_preprocess(queryText)}
---> 60         print(self.service.find_similar(doc, min_score=0.4, max_results=50))

起初我得到了一个不同的错误消息,其中解决方案是使用命令!pip install --upgrade simserver在jupyter笔记本中安装simserver库..但是现在我认为没有丢失的库需要下载

来自jupyter笔记本的相关代码:

发生问题的行

simServer.queryIndex('National Intergroup Inc said it plans to file a registration statement')

#!/usr/bin/env python
import pickle
import os
import re
import glob
import pprint
import json

from gensim import utils
from simserver import SessionServer

import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

class SimilarityServer(object):
    def __init__(self):
        print "Openning sesesion and setting it to true"
        self.service = SessionServer('tmp/my_server/')
        self.service.open_session()
        self.service.set_autosession(True)

    def indexDocs(self):
        print "Docs indexing and training"
        #train and index
        print "Training"
        self.service.session.train(None,method='lsi',clear_buffer=False)
        print "Indexing"
        self.service.session.index(None)

    def queryIndex(self,queryText):
        print "Querying the INDEX"
        doc = {'tokens': utils.simple_preprocess(queryText)}
        print(self.service.find_similar(doc, min_score=0.4, max_results=50))

simServer = SimilarityServer()
simServer.queryIndex('National Intergroup Inc said it plans to file a registration statement')

0 个答案:

没有答案