示例#1
0
if __name__ == '__main__':
    args = docopt(__doc__)
    graph = AjguDB(args['--database'], logging=True)
    if args['conceptnet'] and args['load']:
        edges = chunks_to_rows(gzip_to_chunks(args['FILENAME']))
        for edge in edges:
            _, relation, start, end, _ = edge
            # index only cool concepts
            if COOL.search(start) and COOL.search(end):
                with graph.transaction():
                    # get or create start
                    start = Vertex(ref=start, concept=wordify(start))
                    new, start = graph.get_or_create(start)
                    if new:
                        graph.index(start, start['concept'])
                    # get or create end
                    end = Vertex(ref=end, concept=wordify(end))
                    new, end = graph.get_or_create(end)
                    if new:
                        graph.index(end, end['concept'])

                    edge = start.link(end, relation=relation)
                    graph.save(edge)

    if args['conceptnet'] and args['search']:
        query = args['QUERY']
        query = ' '.join(query)
        for uid, score in graph.like(query):
            msg = '(uid: %s)\t(score: %s)\t%s'
            concept = graph.get(uid)['concept']