コード例 #1
0
import os
import wp

try:
    os.remove("./data/index3.db")
except OSError:
    pass

collection = wp.WikipediaCollection("./data/wp.db")
index = wp.Index("./data/index4.db", collection)
index.generate()
index.generate_ngrams()
index.generateFromOpeningText()
コード例 #2
0
import bottle
import wp
import json
import os

collection = wp.WikipediaCollection("./data/wp.db")
index = wp.Index("./data/index2.db", collection)
indexOpeningText = wp.Index("./data/index3.db", collection)
analyse = wp.AnalyseQuery()


@bottle.route('/action')
def action():
    query = bottle.request.query.q
    terms = analyse.extractWords(query)
    table1 = index.sortSearchReturnTable(terms)
    table2 = indexOpeningText.sortSearchReturnTable(terms)
    title = index.returnBestFromTable(index.mergeTable(table1, table2))
    bottle.response.content_type = 'application/json'
    if title is None:
        return json.dums({'textToSpeech': 'はい残念みつからないよー'},
                         index=2,
                         separators=(',', ':'),
                         ensure_ascii=False)
    return json.dumps({'textToSpeech': title},
                      indent=2,
                      separators=(',', ': '),
                      ensure_ascii=False)


@bottle.route('/article/<title>')
コード例 #3
0
import os
import wp

try:
    # 過去のindexは削除する
    os.remove("data/index.db")
except OSError:
    pass
collection = wp.WikipediaCollection("data/wp.db")
index = wp.Index("data/index.db", collection)
index.generate()