def get(): keywords = bottle.request.params.keywords.split() keywords_expanded = [[keyword] + [ synonym['term'] for synonym in dbpediaknowledge.get_synonyms(keyword) ] for keyword in keywords] results = indexer.search( # keywords=[[keyword] for keyword in keywords], keywords=keywords_expanded, ) return json.dumps(results, ensure_ascii=False)
def get(): name = bottle.request.params.name keywords = bottle.request.params.keywords.split() keywords_expanded = [[keyword] + [ synonym['term'] for synonym in dbpediaknowledge.get_synonyms(keyword) ] for keyword in keywords] if keywords_expanded != []: fl_keyword_pairs = [(name + '_txt_ja', keywords_expanded)] else: fl_keyword_pairs = [('name_s', [[name]])] results = indexer.search_annotation(fl_keyword_pairs) return json.dumps(results, ensure_ascii=False)
import json import dbpediaknowledge if __name__ == '__main__': synonyms = dbpediaknowledge.get_synonyms('アメリカ合衆国') print(json.dumps(synonyms, indent=4, ensure_ascii=False))
# -*- coding: utf-8 -*- import json import dbpediaknowledge import sys args = sys.argv word = args[1] if __name__ == '__main__': synonyms = dbpediaknowledge.get_synonyms(word) print(json.dumps(synonyms, indent=2, ensure_ascii=False))