示例#1
0
class Neo4jGraph(object):
    """
    The primary interface to graph databases on the Rexster REST server.

    Instantiates the database :class:`~bulbs.rest.Resource` object using 
    the specified database URL and sets up proxy objects to the database.

    :keyword root_uri: The URI to Neo4j Server. 
    
    Example::

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create({'name':'James'})
    >>> julie = g.vertices.create({'name':'Julie'})
    >>> g.edges.create(james,"knows",julie)
    >>> g.vertices.index.lookup(name="James")

    """

    
    def __init__(self,root_uri=NEO4J_URI):
        self.config = Config(root_uri)
        self.resource = Neo4jResource(self.config)

        self.gremlin = Gremlin(self.resource)

        self.indicesV = VertexIndexProxy(ExactIndex,self.resource)
        self.indicesE = EdgeIndexProxy(ExactIndex,self.resource)
        
        # What happens if these REST calls error on Heroku?

        self.vertices = VertexProxy(Vertex,self.resource)
        self.vertices.index = self.indicesV.get_or_create("vertices")
 
        self.edges = EdgeProxy(Edge,self.resource)
        self.edges.index = self.indicesE.get_or_create("edges")

    def load_graphml(self,uri):
        """Loads a GraphML file into the database and returns the response."""
        script = self.resource.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.execute(script,params)
        
    def save_graphml(self):
        """Returns a GraphML file representing the entire database."""
        script = self.resource.scripts.get('save_graphml')
        results = self.gremlin.execute(script,params=None)
        return results[0]

    def clear(self):
        """Deletes all the elements in the graph.

        .. admonition:: WARNING 

           g.clear() will delete all your data!

        """
        return self.resource.clear()
示例#2
0
class Neo4jGraph(object):
    """
    The primary interface to graph databases on the Rexster REST server.

    Instantiates the database :class:`~bulbs.rest.Resource` object using 
    the specified database URL and sets up proxy objects to the database.

    :keyword root_uri: The URI to Neo4j Server. 
    
    Example::

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create({'name':'James'})
    >>> julie = g.vertices.create({'name':'Julie'})
    >>> g.edges.create(james,"knows",julie)
    >>> g.vertices.index.lookup(name="James")

    """
    def __init__(self, root_uri=NEO4J_URI):
        self.config = Config(root_uri)
        self.resource = Neo4jResource(self.config)

        self.gremlin = Gremlin(self.resource)

        self.indicesV = VertexIndexProxy(ExactIndex, self.resource)
        self.indicesE = EdgeIndexProxy(ExactIndex, self.resource)

        # What happens if these REST calls error on Heroku?

        self.vertices = VertexProxy(Vertex, self.resource)
        self.vertices.index = self.indicesV.get_or_create("vertices")

        self.edges = EdgeProxy(Edge, self.resource)
        self.edges.index = self.indicesE.get_or_create("edges")

    def load_graphml(self, uri):
        """Loads a GraphML file into the database and returns the response."""
        script = self.resource.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.execute(script, params)

    def save_graphml(self):
        """Returns a GraphML file representing the entire database."""
        script = self.resource.scripts.get('save_graphml')
        results = self.gremlin.execute(script, params=None)
        return results[0]

    def clear(self):
        """Deletes all the elements in the graph.

        .. admonition:: WARNING 

           g.clear() will delete all your data!

        """
        return self.resource.clear()
示例#3
0
    def __init__(self, config=None):
        # What happens if these REST init calls error on Heroku?    
        super(Graph, self).__init__(config)

        # Neo4j Server supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts    # for convienience 

        # Cypher; TODO: Cypher Queries library object
        self.cypher = Cypher(self.client)
示例#4
0
    def __init__(self, root_uri=REXSTER_URI):
        self.config = Config(root_uri)
        self.resource = RexsterResource(self.config)

        self.gremlin = Gremlin(self.resource)
        self.indices = IndexProxy(RexsterIndex, resource)

        self.vertices = VertexProxy(Vertex, self.resource)
        self.vertices.index = self.indices.get("vertices", Vertex)

        self.edges = EdgeProxy(Edge, self.resource)
        self.edges.index = self.indices.get("edges", Edge)
示例#5
0
    def __init__(self, root_uri=NEO4J_URI):
        self.config = Config(root_uri)
        self.resource = Neo4jResource(self.config)

        self.gremlin = Gremlin(self.resource)

        self.indicesV = VertexIndexProxy(ExactIndex, self.resource)
        self.indicesE = EdgeIndexProxy(ExactIndex, self.resource)

        # What happens if these REST calls error on Heroku?

        self.vertices = VertexProxy(Vertex, self.resource)
        self.vertices.index = self.indicesV.get_or_create("vertices")

        self.edges = EdgeProxy(Edge, self.resource)
        self.edges.index = self.indicesE.get_or_create("edges")
示例#6
0
文件: graph.py 项目: nicholsn/bulbs
    def __init__(self, config=None):
        # What happens if these REST init calls error on Heroku?    
        super(Graph, self).__init__(config)

        # Neo4j Server supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts    # for convienience 
示例#7
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)
示例#8
0
文件: graph.py 项目: nicholsn/bulbs
class Graph(object):

    def __init__(self,root_uri=REXSTER_URI):
        self.config = Config(root_uri)
        self.client = RexsterClient(self.config)

        self.gremlin = Gremlin(self.client)
        self.indices = IndexProxy(RexsterIndex,client)

        self.vertices = VertexProxy(Vertex,self.client)
        self.vertices.index = self.indices.get("vertices",Vertex)
 
        self.edges = EdgeProxy(Edge,self.client)
        self.edges.index = self.indices.get("edges",Edge)

    def load_graphml(self,uri):
        """Loads a GraphML file into the database and returns the response."""
        script = self.client.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.execute(script,params)
        
    def save_graphml(self):
        """Returns a GraphML file representing the entire database."""
        script = self.client.scripts.get('save_graphml')
        results = self.gremlin.execute(script,params=None)
        return results[0]

    def clear(self):
        """
        Deletes all the elements in the graph.

        Example::

        >>> g = Graph()
        >>> g.clear()

        .. admonition:: WARNING 

           g.clear() will delete all your data!

        """
        return self.client.clear()
示例#9
0
class Graph(object):
    def __init__(self, root_uri=REXSTER_URI):
        self.config = Config(root_uri)
        self.resource = RexsterResource(self.config)

        self.gremlin = Gremlin(self.resource)
        self.indices = IndexProxy(RexsterIndex, resource)

        self.vertices = VertexProxy(Vertex, self.resource)
        self.vertices.index = self.indices.get("vertices", Vertex)

        self.edges = EdgeProxy(Edge, self.resource)
        self.edges.index = self.indices.get("edges", Edge)

    def load_graphml(self, uri):
        """Loads a GraphML file into the database and returns the response."""
        script = self.resource.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.execute(script, params)

    def save_graphml(self):
        """Returns a GraphML file representing the entire database."""
        script = self.resource.scripts.get('save_graphml')
        results = self.gremlin.execute(script, params=None)
        return results[0]

    def clear(self):
        """
        Deletes all the elements in the graph.

        Example::

        >>> g = Graph()
        >>> g.clear()

        .. admonition:: WARNING 

           g.clear() will delete all your data!

        """
        return self.resource.clear()
示例#10
0
    def __init__(self, root_uri=REXSTER_URI):
        self.config = Config(root_uri)
        self.resource = RexsterResource(self.config)

        self.gremlin = Gremlin(self.resource)
        self.indices = IndexProxy(RexsterIndex, resource)

        self.vertices = VertexProxy(Vertex, self.resource)
        self.vertices.index = self.indices.get("vertices", Vertex)

        self.edges = EdgeProxy(Edge, self.resource)
        self.edges.index = self.indices.get("edges", Edge)
示例#11
0
    def __init__(self,root_uri=NEO4J_URI):
        self.config = Config(root_uri)
        self.resource = Neo4jResource(self.config)

        self.gremlin = Gremlin(self.resource)

        self.indicesV = VertexIndexProxy(ExactIndex,self.resource)
        self.indicesE = EdgeIndexProxy(ExactIndex,self.resource)
        
        # What happens if these REST calls error on Heroku?

        self.vertices = VertexProxy(Vertex,self.resource)
        self.vertices.index = self.indicesV.get_or_create("vertices")
 
        self.edges = EdgeProxy(Edge,self.resource)
        self.edges.index = self.indicesE.get_or_create("edges")
示例#12
0
class Graph(BaseGraph):
    """
    The primary interface to Rexster.

    Instantiates the database :class:`~bulbs.rexster.client.Client` object using 
    the specified Config and sets up proxy objects to the database.

    :param config: Optional. Defaults to the default config.
    :type config: bulbs.config.Config

    :cvar client_class: RexsterClient class.
    :cvar default_index: Default index class.

    :ivar client: RexsterClient object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.
    :ivar config: Config object.
    :ivar gremlin: Gremlin object.
    :ivar scripts: GroovyScripts object.
    
    Example:

    >>> from bulbs.rexster import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """
    client_class = TitanClient
    default_index = KeyIndex

    def __init__(self, config=None):
        super(Graph, self).__init__(config)

        # Rexster supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts  # for convienience

    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file to load.
        :type uri: str

        :rtype: RexsterResult

        """
        script = self.client.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.command(script, params)

    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: RexsterResult

        """
        script = self.client.scripts.get('save_graphml')
        return self.gremlin.command(script, params=None)

    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: RexsterResult

        """
        script = self.scripts.get('warm_cache')
        return self.gremlin.command(script, params=None)

    def clear(self):
        """
        Deletes all the elements in the graph.

        :rtype: RexsterResult

        .. admonition:: WARNING 

           This will delete all your data!

        """
        script = self.client.scripts.get('clear')
        return self.gremlin.command(script, params=None)
示例#13
0
文件: graph.py 项目: 747project/bulbs
    def __init__(self, config=None):
        super(Graph, self).__init__(config)

        # Rexster supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts    # for convienience 
示例#14
0
class Graph(BaseGraph):
    """
    The primary interface to Neo4j Server.

    Instantiates the database :class:`~bulbs.neo4jserver.client.Client` object using 
    the specified Config and sets up proxy objects to the database.

    :param config: Optional. Defaults to the default config.
    :type config: bulbs.config.Config

    :cvar client_class: Neo4jClient class.
    :cvar default_index: Default index class.

    :ivar client: Neo4jClient object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.
    :ivar config: Config object.
    :ivar gremlin: Gremlin object.
    :ivar scripts: GroovyScripts object.
    
    Example:

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """
    client_class = Neo4jClient
    default_index = ExactIndex

    def __init__(self, config=None):
        # What happens if these REST init calls error on Heroku?    
        super(Graph, self).__init__(config)

        # Neo4j Server supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts    # for convienience 

        # Cypher; TODO: Cypher Queries library object
        self.cypher = Cypher(self.client)

    def set_metadata(self, key, value):
        """
        Sets the metadata key to the supplied value.

        :param key: Metadata key
        :type key: str

        :param value: Metadata value.
        :type value: str, int, or list

        :rtype: Neo4jResponse
        
        """
        return self.client.set_metadata(key, value).one()

    def get_metadata(self, key, default_value=None):
        """
        Returns the value of metadata for the key.

        :param key: Metadata key
        :type key: str

        :param default_value: Default value to return if the key is not found.
        :type default_value: str, int, or list

        :rtype: Neo4jResult
        
        """
        return self.client.get_metadata(key, default_value).one()

    def remove_metadata(self, key):
        """
        Removes the metadata key and value.

        :param key: Metadata key
        :type key: str

        :rtype: Neo4jResponse
        
        """
        return self.client.remove_metadata(key)
        
    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file to load.
        :type uri: str

        :rtype: Neo4jResult

        """
        script = self.client.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.command(script, params)
        
    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: Neo4jResult

        """
        script = self.client.scripts.get('save_graphml')
        return self.gremlin.command(script, params=None)
        
    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: Neo4jResult

        """
        script = self.scripts.get('warm_cache')
        return self.gremlin.command(script, params=None)

    def clear(self):
        """
        Deletes all the elements in the graph.

        :rtype: Neo4jResult

        .. admonition:: WARNING 

           This will delete all your data!

        """
        script = self.client.scripts.get('clear')
        return self.gremlin.command(script, params=None)
示例#15
0
文件: graph.py 项目: 747project/bulbs
class Graph(BaseGraph):
    """
    The primary interface to Rexster.

    Instantiates the database :class:`~bulbs.rexster.client.Client` object using 
    the specified Config and sets up proxy objects to the database.

    :param config: Optional. Defaults to the default config.
    :type config: bulbs.config.Config

    :cvar client_class: RexsterClient class.
    :cvar default_index: Default index class.

    :ivar client: RexsterClient object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.
    :ivar config: Config object.
    :ivar gremlin: Gremlin object.
    :ivar scripts: GroovyScripts object.
    
    Example:

    >>> from bulbs.rexster import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """
    client_class = TitanClient
    default_index = KeyIndex
    
    def __init__(self, config=None):
        super(Graph, self).__init__(config)

        # Rexster supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts    # for convienience 


    def load_graphml(self,uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file to load.
        :type uri: str

        :rtype: RexsterResult

        """
        script = self.client.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.command(script, params)
        
    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: RexsterResult

        """
        script = self.client.scripts.get('save_graphml')
        return self.gremlin.command(script, params=None)
        
    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: RexsterResult

        """
        script = self.scripts.get('warm_cache')
        return self.gremlin.command(script, params=None)

    def clear(self):
        """
        Deletes all the elements in the graph.

        :rtype: RexsterResult

        .. admonition:: WARNING 

           This will delete all your data!

        """
        script = self.client.scripts.get('clear')
        return self.gremlin.command(script,params=None)
示例#16
0
    def __init__(self, config=None):
        super(Graph, self).__init__(config)

        # Rexster supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts  # for convienience
示例#17
0
class Graph(BaseGraph):
    """
    The primary interface to Rexster.

    Instantiates the database :class:`~bulbs.rexster.client.Client` object using 
    the specified Config and sets up proxy objects to the database.

    :param config: Optional. Defaults to the default config.
    :type config: bulbs.config.Config

    :cvar client_class: RexsterClient class.
    :cvar default_index: Default index class.

    :ivar client: RexsterClient object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.
    :ivar config: Config object.
    :ivar gremlin: Gremlin object.
    :ivar scripts: GroovyScripts object.
    
    Example:

    >>> from bulbs.rexster import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """
    client_class = RexsterClient
    default_index = ManualIndex

    def __init__(self, config=None):
        super(Graph, self).__init__(config)

        # Rexster supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts  # for convienience

    def make_script_files(self, out_dir=None):
        """
        Generates a server-side scripts file.

        """
        out_dir = out_dir or os.getcwd()
        for namespace in self.scripts.namespace_map:
            # building script content from stored methods
            # instead of sourcing files directly to filter out overridden methods
            methods = self.scripts.namespace_map[namespace]
            scripts_file = os.path.join(out_dir, "%s.groovy" % namespace)
            method_defs = []
            for method_name in methods:
                method = methods[method_name]
                method_defs.append(method.definition)
            content = "\n\n".join(method_defs)
            with io.open(scripts_file, "w", encoding='utf-8') as fout:
                fout.write(content + "\n")

    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file to load.
        :type uri: str

        :rtype: RexsterResult

        """
        script = self.client.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.command(script, params)

    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: RexsterResult

        """
        script = self.client.scripts.get('save_graphml')
        return self.gremlin.command(script, params=None)

    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: RexsterResult

        """
        script = self.scripts.get('warm_cache')
        return self.gremlin.command(script, params=None)

    def clear(self):
        """
        Deletes all the elements in the graph.

        :rtype: RexsterResult

        .. admonition:: WARNING 

           This will delete all your data!

        """
        script = self.client.scripts.get('clear')
        return self.gremlin.command(script, params=None)
示例#18
0
class Graph(BaseGraph):
    """
    The primary interface to Rexster.

    Instantiates the database :class:`~bulbs.rexster.client.Client` object using 
    the specified Config and sets up proxy objects to the database.

    :param config: Optional. Defaults to the default config.
    :type config: bulbs.config.Config

    :cvar client_class: RexsterClient class.
    :cvar default_index: Default index class.

    :ivar client: RexsterClient object.
    :ivar vertices: VertexProxy object.
    :ivar edges: EdgeProxy object.
    :ivar config: Config object.
    :ivar gremlin: Gremlin object.
    :ivar scripts: GroovyScripts object.
    
    Example:

    >>> from bulbs.rexster import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """

    client_class = RexsterClient
    default_index = ManualIndex

    def __init__(self, config=None):
        super(Graph, self).__init__(config)

        # Rexster supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts  # for convienience

    def make_script_files(self, out_dir=None):
        """
        Generates a server-side scripts file.

        """
        out_dir = out_dir or os.getcwd()
        for namespace in self.scripts.namespace_map:
            # building script content from stored methods
            # instead of sourcing files directly to filter out overridden methods
            methods = self.scripts.namespace_map[namespace]
            scripts_file = os.path.join(out_dir, "%s.groovy" % namespace)
            method_defs = []
            for method_name in methods:
                method = methods[method_name]
                method_defs.append(method.definition)
            content = "\n\n".join(method_defs)
            with io.open(scripts_file, "w", encoding="utf-8") as fout:
                fout.write(content + "\n")

    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file to load.
        :type uri: str

        :rtype: RexsterResult

        """
        script = self.client.scripts.get("load_graphml")
        params = dict(uri=uri)
        return self.gremlin.command(script, params)

    def get_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: RexsterResult

        """
        script = self.client.scripts.get("save_graphml")
        return self.gremlin.command(script, params=None)

    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: RexsterResult

        """
        script = self.scripts.get("warm_cache")
        return self.gremlin.command(script, params=None)

    def clear(self):
        """
        Deletes all the elements in the graph.

        :rtype: RexsterResult

        .. admonition:: WARNING 

           This will delete all your data!

        """
        script = self.client.scripts.get("clear")
        return self.gremlin.command(script, params=None)
示例#19
0
文件: graph.py 项目: nicholsn/bulbs
class Graph(BaseGraph):
    """
    The primary interface to graph databases on Neo4j Server.

    Instantiates the database :class:`~bulbs.neo4jserver.client.Client` object using 
    the specified database URL and sets up proxy objects to the database.

    :param config: Optional. Defaults to the default config.
    :type config: bulbs.config.Config
    
    Example:

    >>> from bulbs.neo4jserver import Graph
    >>> g = Graph()
    >>> james = g.vertices.create(name="James")
    >>> julie = g.vertices.create(name="Julie")
    >>> g.edges.create(james, "knows", julie)

    """
    #: The client class
    client_class = Neo4jClient

    #: The default Index class.
    default_index = ExactIndex

    def __init__(self, config=None):
        # What happens if these REST init calls error on Heroku?    
        super(Graph, self).__init__(config)

        # Neo4j Server supports Gremlin
        self.gremlin = Gremlin(self.client)
        self.scripts = self.client.scripts    # for convienience 

    def set_metadata(self, key, value):
        return self.client.set_metadata(key, value).one()

    def get_metadata(self, key, default_value=None):
        return self.client.get_metadata(key, default_value).one()

    def remove_metadata(self, key):
        return self.client.remove_metadata(key)
        
    def load_graphml(self, uri):
        """
        Loads a GraphML file into the database and returns the response.

        :param uri: URI of the GraphML file to load.
        :type uri: str

        :rtype: Neo4jResult

        """
        script = self.client.scripts.get('load_graphml')
        params = dict(uri=uri)
        return self.gremlin.command(script,params)
        
    def save_graphml(self):
        """
        Returns a GraphML file representing the entire database.

        :rtype: Neo4jResult

        """
        script = self.client.scripts.get('save_graphml')
        return self.gremlin.command(script,params=None)
        
    def warm_cache(self):
        """
        Warms the server cache by loading elements into memory.

        :rtype: Neo4jResult

        """
        script = self.scripts.get('warm_cache')
        return self.gremlin.command(script,params=None)

    def clear(self):
        """Deletes all the elements in the graph.

        :rtype: Neo4jResult

        .. admonition:: WARNING 

           This will delete all your data!

        """
        script = self.client.scripts.get('clear')
        return self.gremlin.command(script,params=None)