Exemplo n.º 1
0
            # 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']
            print msg % (uid, score, concept)

    if args['wikidata'] and args['load']:
        with open(args['FILENAME']) as f:
            lines = iter(f)
            next(lines)  # drop first line
            for line in lines:
                try: