Ejemplo n.º 1
0
def gather_topics(addresslist, site):
	"""Downloads, parses and pickles all the topics from a list of addresses.
	
	addresslist	- a list of web addresses
	site		- site name (for bundling topics)
	"""
	for address in addresslist:
		parsed = parse(address, True)
		with open(os.path.join(train_path,site,re.findall('[^/]*$',address)[0]), 'w') as file:
			pickle.dump(parsed, file)
Ejemplo n.º 2
0
def search(request):
    requestDict = request.POST
    template = loader.get_template('search.html')

    if 'question' not in requestDict:
        return HttpResponse(template.render(
            RequestContext(request,
                           {'title': 'No question',
                            'question': 'Please write the question URL first'
                            })))
    questionURL = requestDict['question']

    parsed = tparser.parse(questionURL)

    if 'drupal' in questionURL:
        posts = choose_answers('ent-sam-dru', parsed)
        bestpost = choose_answer('ent-sam-dru', parsed)
    elif 'ubuntu' in questionURL:
        posts = choose_answers('ent-sam-ubu', parsed)
        bestpost = choose_answer('ent-sam-ubu', parsed)
    else:
        posts = choose_answers('ent-sam-mix', parsed)
        bestpost = choose_answer('ent-sam-mix', parsed)
    #pdb.set_trace()

    #Do some NLP magic here...
    #vimpdb.set_trace()
    #posts = nlpsort.magic(posts)
    #response = ['good response', 'not so good response']
    #response = test.post(0)

    context = RequestContext(request,
                             {'title': 'Natural language search engine',
                              'question': questionURL,
                              'response': bestpost,
                              'others': posts,
                              'link': bestpost.link})
    return HttpResponse(template.render(context))