def setup(dbhost='localhost', dbport=7474, dburl=None, querypath=None): ''' Program to set up for running our REST server. We do these things: - Attach to the database - Initialize our type objects so things like ClientQuery will work... - Load the queries into the database from flat files Not sure if doing this here makes the best sense, but it works, and currently we're the only one who cares about them so it seems reasonable -- at the moment ;-) Also we're most likely to iterate changing on those relating to the REST server, so fixing them just by restarting the REST server seems to make a lot of sense (at the moment) - Remember the set of queries in the 'allqueries' hash table ''' if dburl is None: dburl = ('http://%s:%d/db/data/' % (dbhost, dbport)) print >> sys.stderr, 'CREATING Graph("%s")' % dburl neodb = neo4j.Graph(dburl) qstore = Store(neodb, None, None) print GraphNode.classmap for classname in GraphNode.classmap: GraphNode.initclasstypeobj(qstore, classname) print "LOADING TREE!" if querypath is None: querypath = "/home/alanr/monitor/src/queries" queries = ClientQuery.load_tree(qstore, querypath) for q in queries: allqueries[q.queryname] = q qstore.commit() for q in allqueries: allqueries[q].bind_store(qstore)
def import_rutez(): store = Store() store.ensure_thesaurus('rutez', u'РуТез') store.select('rutez') conn = sqlite3.connect('/home/petr/ownCloud/projects/rutez/rutez.db') c = conn.cursor() memd = {} c.execute("""select w1.name, w2.name, rel.name from rel join sinset w1 on w1.id = rel.id join sinset w2 on w2.id = rel.link """) store.set_autocommit(False) for row in c.fetchall(): store.ensure_link(row[0], row[1], row[2]) #print row[0], row[1], row[2] c.execute("""select s.name, w.name from sinset s join word w on w.id = s.id """) for row in c.fetchall(): store.ensure_word(row[0], row[1]) store.commit()
Neo4jCreds().authenticate() neodb = neo4j.Graph() neodb.delete_all() umap = {'ClientQuery': True} ckmap = {'ClientQuery': {'index': 'ClientQuery', 'kattr':'queryname', 'value':'None'}} qstore = Store(neodb, uniqueindexmap=umap, classkeymap=ckmap) for classname in GraphNode.classmap: GraphNode.initclasstypeobj(qstore, classname) print "LOADING TREE!" queries = ClientQuery.load_tree(qstore, "%s/../queries" % (os.path.dirname(sys.argv[0]))) qlist = [q for q in queries] qstore.commit() print "%d node TREE LOADED!" % len(qlist) qe2 = qstore.load_or_create(ClientQuery, queryname='list') qe2.bind_store(qstore) testresult = '' for s in qe2.execute(None, idsonly=False, expandJSON=True): testresult += s print 'RESULT', testresult # Test out a command line query for s in qe2.cmdline_exec(None): if re.match(s, '[ ]unknown$'): raise RuntimeError('Search result contains unknown: %s' % s) print s print "All done!"
umap = {'ClientQuery': True} ckmap = { 'ClientQuery': { 'index': 'ClientQuery', 'kattr': 'queryname', 'value': 'None' } } qstore = Store(neodb, uniqueindexmap=umap, classkeymap=ckmap) for classname in GraphNode.classmap: GraphNode.initclasstypeobj(qstore, classname) print "LOADING TREE!" queries = ClientQuery.load_tree(qstore, "/home/alanr/monitor/src/queries") qlist = [q for q in queries] qstore.commit() print "%d node TREE LOADED!" % len(qlist) qe2 = qstore.load_or_create(ClientQuery, queryname='list') qe2.bind_store(qstore) testresult = '' for s in qe2.execute(None, idsonly=False, expandJSON=True): testresult += s print testresult # Test out a command line query for s in qe2.cmdline_exec(None): print s print "All done!"