Example #1
0
    def __init__(self, config=None, db_name="GratefulDeadConcerts"):
        # This makes is easy to test different DBs
        #uri = self._get_uri(db_name) or self.default_uri

        self.configs = dict()
        self.request = dict()
        self.type_system = JSONTypeSystem()
        self.db_name = db_name

        for command in ['database', 'command']:
            uri = "%s/%s/%s" % (self.default_uri.rstrip("/"), command, db_name)
            print(uri)
            config = Config(uri, username="******", password="******")
            self.configs[command] = config
            self.registry = Registry(config)

            self.request[command] = self.request_class(
                config,
                self.type_system.content_type)

        self.config = self.configs['database']

        # OrientDB supports Gremlin so include the Gremlin-Groovy script library
        self.scripts = GroovyScripts(self.config)

        # Also include the OrientDB-specific Gremlin-Groovy scripts
        scripts_file = get_file_path(__file__, "gremlin.groovy")
        self.scripts.update(scripts_file)

        # Add it to the registry. This allows you to have more than one scripts
        # namespace.
        self.registry.add_scripts("gremlin", self.scripts)
Example #2
0
    def __init__(self, root_uri=SAIL_URI):
        self.config = Config(root_uri)
        self.client = RexsterClient(self.config)

        # No indices on sail graphs
        self.gremlin = Gremlin(self.client)

        self.vertices = VertexProxy(Vertex, self.client)
        self.edges = EdgeProxy(Edge, self.client)
Example #3
0
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
Example #4
0
    def __init__(self, config=None):
        self.config = config or Config(self.default_uri)
        self.registry = Registry(self.config)
        self.type_system = JSONTypeSystem()
        self.request = self.request_class(self.config,
                                          self.type_system.content_type)

        # Neo4j supports Gremlin so include the Gremlin-Groovy script library
        self.scripts = GroovyScripts(self.config)

        # Also include the Neo4j Server-specific Gremlin-Groovy scripts
        scripts_file = get_file_path(__file__, "gremlin.groovy")
        self.scripts.update(scripts_file)

        # Add it to the registry. This allows you to have more than one scripts namespace.
        self.registry.add_scripts("gremlin", self.scripts)
Example #5
0
    def __init__(self, config=None, db_name=None):
        # This makes is easy to test different DBs
        uri = self._get_uri(db_name) or self.default_uri

        self.config = config or Config(uri)
        self.registry = Registry(self.config)
        self.type_system = JSONTypeSystem()
        self.request = self.request_class(self.config,
                                          self.type_system.content_type)

        # Rexster supports Gremlin so include the Gremlin-Groovy script library
        self.scripts = GroovyScripts(self.config)

        # Also include the Rexster-specific Gremlin-Groovy scripts
        scripts_file = get_file_path(__file__, "gremlin.groovy")
        self.scripts.update(scripts_file)

        # Add it to the registry. This allows you to have more than one scripts namespace.
        self.registry.add_scripts("gremlin", self.scripts)
Example #6
0
import Test
from bulbs.config import Config
from bulbs.tests import BulbsTestCase, bulbs_test_suite
from bulbs.neo4jserver import Graph, Neo4jClient, NEO4J_URI, \
   VertexIndexProxy, EdgeIndexProxy, ExactIndex
from bulbs.tests import GremlinTestCase

config = Config(NEO4J_URI)
BulbsTestCase.client = Neo4jClient(config)
BulbsTestCase.vertex_index_proxy = VertexIndexProxy
BulbsTestCase.edge_index_proxy = EdgeIndexProxy
BulbsTestCase.index_class = ExactIndex
BulbsTestCase.graph = Graph(config)

def test_suite():
    suite = bulbs_test_suite()
    #suite.addTest(unittest.makeSuite(RestTestCase))
    suite.addTest(Test.makeSuite(GremlinTestCase))
    return suite

if __name__ == '__main__':
    Test.main(defaultTest='test_suite')

Example #7
0
# -*- coding: utf-8 -*-
#
# Copyright 2011 James Thornton (http://jamesthornton.com)
# BSD License (see LICENSE for details)
#
import unittest

from bulbs.tests.testcase import BulbsTestCase
from bulbs.element import Vertex, VertexProxy, Edge, EdgeProxy
from bulbs.config import Config

from bulbs.rexster import RexsterClient, REXSTER_URI
from bulbs.rexster.index import VertexIndexProxy, EdgeIndexProxy, ManualIndex

config = Config(REXSTER_URI)
BulbsTestCase.client = RexsterClient(config)
BulbsTestCase.index_class = ManualIndex

# is this being used anywhere? -- JT 10/22/2012


class IndexTestCase(BulbsTestCase):
    def setUp(self):
        self.indicesV = VertexIndexProxy(self.index_class, self.client)
        self.indicesE = EdgeIndexProxy(self.index_class, self.client)

        self.indicesV.delete("test_idxV")
        self.indicesE.delete("test_idxE")

        self.vertices = VertexProxy(Vertex, self.client)
        self.vertices.index = self.indicesV.get_or_create("test_idxV")
Example #8
0
 def setUp(self):
     config = Config(NEO4J_URI)
     self.client = Neo4jClient(config)
Example #9
0
 def setUp(self):
     #self.client = Client(config.DATABASE_URL)
     config = Config(root_uri=None)
     self.request = RexsterRequest(config)
Example #10
0
 def setUp(self):
     config = Config(REXSTER_URI)
     self.resource = RexsterResource(config)
     self.vertex_type = "vertex"
     self.edge_type = "edge"
Example #11
0
 def setUp(self):
     config = Config(NEO4J_URI)
     self.resource = Neo4jResource(config)
Example #12
0
# -*- coding: utf-8 -*-
'''
Created on 12 авг. 2014 г.

@author: feelosoff
'''

from bulbs.config import Config
from bulbs.rexster import Graph, Edge, Vertex
from bulbs.rexster.client import REXSTER_URI


Edge()
Vertex()
c = Config('http://localhost:8182/graphs/myorientgraph')
g = Graph(c)

james = g.vertices.create(name="James")
julie = g.vertices.create(name="Julie")
g.edges.create(james, "knows", julie)

if __name__ == '__main__':
    pass
Example #13
0
# -*- coding: utf-8 -*-
#
# Copyright 2012 James Thornton (http://jamesthornton.com)
# BSD License (see LICENSE for details)
#
from bulbs.neo4jserver import NEO4J_URI
from bulbs.config import Config as BulbsConfig, DEBUG

from lightbulb import Graph, Config
from lightbulb.utils import cache_author


#
# Bulbs Config
#

bulbs_config = BulbsConfig(NEO4J_URI)
bulbs_config.set_logger(DEBUG)
bulbs_config.set_neo4j_heroku()

graph = Graph(bulbs_config)


#
# Lightbulb Stuff
#

config = Config()
cache_author(graph, config)

Example #14
0
 def setUp(self):
     config = Config(REXSTER_URI)
     config.debug = True
     self.resource = RexsterResource(config)
Example #15
0
from bulbs.model import Node, Relationship
from bulbs.property import String, Integer, DateTime
from bulbs.utils import current_datetime


class Person(Node):

    element_type = "person"

    name = String(nullable=False)
    age = Integer()


class Knows(Relationship):

    label = "knows"

    created = DateTime(default=current_datetime, nullable=False)

from bulbs.titan import Graph

config = Config("http://titan:8182")
config.set_logger(DEBUG)
g = Graph(config)
g.add_proxy("people", Person)
g.add_proxy("knows", Knows)

james = g.people.create(name="James")
julie = g.people.create(name="Julie")
g.knows.create(james, julie)
Example #16
0
 def __init__(self, config=None):
     self.config = config or Config(self.default_uri)
     self.registry = Registry(self.config)
     self.type_system = TypeSystem()
     self.request = self.request_class(self.config,
                                       self.type_system.content_type)
Example #17
0
    def test_init(self):
        config = Config('http://localhost:8182/not-graphs/gratefulgraph')
        #res = Resource(config)

        print config.root_uri
        assert config.root_uri == 'http://localhost:8182/not-graphs/gratefulgraph'
Example #18
0
# -*- coding: utf-8 -*-
#
# Copyright 2011 James Thornton (http://jamesthornton.com)
# BSD License (see LICENSE for details)
#
import unittest

from bulbs.tests.testcase import BulbsTestCase
from bulbs.element import Vertex, VertexProxy, Edge, EdgeProxy
from bulbs.config import Config

from bulbs.orientdb import OrientDBClient, ORIENTDB_URI
from bulbs.orientdb.index import VertexIndexProxy, EdgeIndexProxy, ManualIndex

config = Config(ORIENTDB_URI)
db_name = "GratefulDeadConcerts"
BulbsTestCase.client = OrientDBClient(config=config, db_name=db_name)
BulbsTestCase.index_class = ManualIndex


# is this being used anywhere? -- JT 10/22/2012
class IndexTestCase(BulbsTestCase):
    def setUp(self):
        self.indicesV = VertexIndexProxy(self.index_class, self.client)
        self.indicesE = EdgeIndexProxy(self.index_class, self.client)

        self.indicesV.delete("test_idxV")
        self.indicesE.delete("test_idxE")

        self.vertices = VertexProxy(Vertex, self.client)
        self.vertices.index = self.indicesV.get_or_create("test_idxV")
Example #19
0
 def setUp(self):
     #self.resource = Resource(config.DATABASE_URL)
     config = Config(root_uri=None)
     self.request = RexsterRequest(config)
Example #20
0
 def setUp(self):
     config = Config(REXSTER_URI)
     self.resource = RexsterResource(config)
Example #21
0
 def setUp(self):
     config = Config(NEO4J_URI)
     self.client = Neo4jClient(config)
     self.factory = Factory(self.client)
Example #22
0
def run(host, port, graph, start_time=None, days=1, center=None, degree=None):
    response = {}

    # Bail with error if any of the required arguments is missing.
    missing = map(lambda x: x[0], filter(lambda x: x[1] is None, zip(["start_time", "days", "center", "degree"], [start_time, days, center, degree])))
    if len(missing) > 0:
        response["error"] = "missing required arguments: %s" % (", ".join(missing))
        return response

    # Cast the arguments to the right types.
    #
    # The degree is the degree of separation between the center element and the
    # retrieved nodes - an integer.
    try:
        degree = int(degree)
    except ValueError:
        response["error"] = "argument 'degree' must be an integer"
        return response

    # The start time is the number of milliseconds since the epoch (which is how
    # JavaScript dates are constructed, and therefore how dates are stored in
    # MongoDB) - an integer.
    try:
        start_time = datetime.datetime.strptime(start_time, "%Y-%m-%d")
    except ValueError:
        response["error"] = "argument 'start_time' must be in YYYY-MM-DD format"
        return response
    
    try:
        days = int(days)
    except ValueError:
        response["error"] = "argument 'days' must be an integer"
        return response
    
    dateList = [ start_time + datetime.timedelta(days=x) for x in range(0,days) ]

    config = Config("http://"+host+":"+port+"/graphs/"+graph)
    config.set_logger(DEBUG)
    #client = RexsterClient(config)
    g = Graph(config)

    # Start a set of all interlocutors we're interested in - that includes the
    # center emailer.
    talkers = set([center])

    # Also start a table of distances from the center.
    distance = {center: 0}
    current_talkers = list(talkers)
    
    center_vertex = g.vertices.index.lookup(email=center).next()

    edgeId = 0;
    edges = []
    for i in range(degree):
       
        new_talkers = []
        for day in dateList:
          dayString = day.strftime('%m/%d/%Y')
          
          for talker_email in current_talkers:
          
            current_vertex = g.vertices.index.lookup(email=talker_email).next()
            
            adjacent = current_vertex.bothV(dayString)
            if adjacent != None:
                adjacent_talkers = list(set(itertools.chain(*map(lambda x: [x.email], adjacent))))
                
                if '' in adjacent_talkers:
                    adjacent_talkers.remove('')
                
                for this_talker in adjacent_talkers:
                    newEdge = { "source": this_talker,
                    "target": talker_email,
                    "id": edgeId }
                    edges.append(newEdge)
                    edgeId += 1
                
                new_talkers.extend(adjacent_talkers)
               
            
        current_talkers.extend(new_talkers)
        current_talkers = list(set(current_talkers))
        
        talkers = talkers.union(current_talkers)

        # Compute updates to everyone's distance from center.
        for t in current_talkers:
            if t not in distance:
                distance[t] = i+1

    # Construct a canonical graph structure from the set of talkers and the list
    # of emails.
    #
    # Start with an index map of the talkers.
    talkers = list(set(talkers))
    talker_index = {name: index for (index, name) in enumerate(talkers)}

    for edge in edges:
        edge["source"] = talker_index[edge["source"]]
        edge["target"] = talker_index[edge["target"]]
    
    talkers = [{"email": n, "distance": distance[n]} for n in talkers]
    
    # Stuff the graph data into the response object, and return it.
    response["result"] = { "nodes": talkers,
                           "edges": edges }
    return response
Example #23
0
 def test_init(self):
     config = Config('http://localhost:8182/not-graphs/gratefulgraph')
     assert config.root_uri == 'http://localhost:8182/not-graphs/gratefulgraph'