Ejemplo n.º 1
0
                    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:
                    from json import loads
                    entity = loads(line.strip()[:-1])
                except:
                    pass
                else: