def __init__(self, uri, database, logger=None, model_paths=[]): """ Connects to the database instance through a Rexster client, and initializes a session and identity map. :param uri: The URI to the database. :type uri: str :param database: The database name. :type database: str :param logger: A logger instance. :type logger: logging :param model_paths: The fully qualified path to your models. :type model_paths: list """ self.logger = logger # Init connection from bulbs.config import Config # config = Config(uri) from bulbs.titan import TitanClient self.client = TitanClient(db_name=database) from bulbs.titan import Graph self.graph = Graph(self.client.config) # Init identity map self.session_delete = [] self.session_add = [] self._repositorys = {} self.model_paths = model_paths
def get_sliced_data(query, fields, with_header=False): """ Returns a query result. The result can be cleaned, removing duplicates In case of error it raises a ValueError """ from urllib2 import HTTPError from tempfile import mkstemp # from webui.cnmain.utils import get_virtuoso # virtuoso = get_virtuoso(instance='master') from bulbs.titan import Graph from bulbs.config import Config header = [field.strip() for field in fields.split(',')] handle_, path = mkstemp(text=True) with open(path, 'w') as f: f.write(query) c = Config('http://localhost:8182/graphs/graph') g = Graph(c) g.scripts.update(path) try: nodes_fun = g.scripts.get('nodes') except KeyError: raise ValueError("Malformed query: missing nodes() function") nodes_id = g.gremlin.execute(nodes_fun, {}).content['results'] if with_header: yield header block_size = 100 has_results = False for i in range(len(nodes_id) / block_size + 1): start = i * block_size block = nodes_id[start:start + block_size] try: slice_fun = g.scripts.get('slice') content = g.gremlin.execute(slice_fun, {'nodes_id': block}).content except HTTPError, e: raise ValueError("Malformed query: {}".format(e.read())) for result in content['results']: has_results = True yield result
def test_suite(): # pass in a db_name to test a specific database client = TitanClient(db_name=db_name) BulbsTestCase.client = client BulbsTestCase.vertex_index_proxy = VertexIndexProxy BulbsTestCase.edge_index_proxy = EdgeIndexProxy BulbsTestCase.index_class = KeyIndex BulbsTestCase.graph = Graph(client.config) suite = bulbs_test_suite() #suite.addTest(unittest.makeSuite(RestTestCase)) suite.addTest(unittest.makeSuite(GremlinTestCase)) return suite
def __init__(self, restUrl): self.url = restUrl self.config = Config(self.url) self.graph = Graph(self.config)
# Not able to use bulbs to program Titan GraphDB/Rexster >>> from bulbs.titan import Graph >>> g = Graph()
from bulbs.titan import Graph, Config config = Config("http://localhost:8182/graphs/yourdatabasename/") g = Graph(config) g.gremlin.command(""" v1 = g.addVertex([account_id: 1]) v2 = g.addVertex([account_id: 2]) g.addEdge(v1, v2, 'follow') """) vertex = g.gremlin.query("g.V().has('account_id', 1).out('follow')") assert vertex.next().get('account_id') == 2
#Run these commands in the terminal. #http://bulbflow.com/quickstart/ #It looks like we can write Gremlin code in and execute it: #http://stackoverflow.com/questions/16954378/bulb-flow-how-to-get-a-range-of-vertices #stack tag: http://stackoverflow.com/questions/tagged/bulbs?page=1&sort=newest&pagesize=15 from people import Person, Knows from bulbs.titan import Graph import requests import json g = Graph() g.add_proxy("people", Person) g.add_proxy("knows", Knows) james = g.people.create(name="James") julie = g.people.create(name="Julie") nodes = g.people.index.lookup(name="James") vertices = list(nodes) vertex = vertices[1] knows = vertex.bothV("knows") for k in knows: print k.data() nodes = g.people.index.lookup(name="mark") vertices = list(nodes)
# -*- coding: utf-8 -*- """ Created on Fri Jun 20 15:00:48 2014 @author: turbosnail9 """ # # Imports # from graphelements import User, Chooses, Sport, Location, Budget, Has, LivesIn from bulbs.titan import Graph import requests import json g = Graph() g.add_proxy("user", User) g.add_proxy("chooses", Chooses) g.add_proxy("has", Has) g.add_proxy("sport", Sport) g.add_proxy("location", Location) g.add_proxy("lives_in", LivesIn) g.add_proxy("budget", Budget) # # Method definitions # def GetOrCreateUser(p_name, p_age, p_gender, p_email, p_sportList): #Create a new person node and pass in the properties