コード例 #1
0
ファイル: dal.py プロジェクト: PacificNorthwest/Litgraph
def get_graph_context(config):
    if config is None:
        return Graph(auth=('neo4j', 'pass'), host='localhost')

    login = config.get('NEO4J_LOGIN', 'neo4j')
    password = config.get('NEO4J_PASS', 'pass')
    host = config.get('NEO4J_HOST', 'localhost')

    return Graph(auth=(login, password), host=host)
コード例 #2
0
 def __init__(self):
     #watch("neo4j.bolt")
     self.graph = Graph(super().graph_url)
     tx = self.graph.begin()
     tx.run(SnomedConceptProcessor.create_index_concept_id)
     tx.run(SnomedConceptProcessor.create_index_term)
     tx.commit()
コード例 #3
0
    def connectGraph(self):
        # graph = Graph(user = self.user, password = self.password)
        authenticate(self.service_ip, self.user, self.password)
        graph = Graph('http://%s/db/data/' % self.service_ip)
        #         authenticate("localhost:7474", self.user, self.password)
        #         graph = Graph("http://localhost:7474/db/data/")

        return graph
コード例 #4
0
    def __init__(self, uri=None, **settings):
        self.output_file = settings.pop("file", None)
        verbose = settings.pop("verbose", False)
        connection_data = get_connection_data(uri, **settings)
        try:
            self.graph = Graph(uri, **settings)
        except ServiceUnavailable as error:
            raise ConsoleError("Could not connect to {} -- {}".format(
                connection_data["uri"], error))
        try:
            makedirs(HISTORY_FILE_DIR)
        except OSError:
            pass
        self.history = FileHistory(path_join(HISTORY_FILE_DIR, HISTORY_FILE))
        self.prompt_args = {
            "history":
            self.history,
            "lexer":
            PygmentsLexer(CypherLexer),
            "style":
            merge_styles([
                style_from_pygments_cls(NativeStyle),
                style_from_pygments_dict({
                    Token.Prompt:
                    "#ansi{}".format(self.prompt_colour.replace(
                        "cyan", "teal")),
                    Token.TxCounter:
                    "#ansi{} bold".format(
                        self.tx_colour.replace("cyan", "teal")),
                })
            ])
        }
        self.lexer = CypherLexer()
        self.result_writer = Table.write
        if verbose:
            from neobolt.diagnostics import watch
            self.watcher = watch("neo4j.%s" % connection_data["scheme"])

        self.commands = {
            "//": self.set_multi_line,
            "/e": self.edit,
            "/?": self.help,
            "/h": self.help,
            "/help": self.help,
            "/x": self.exit,
            "/exit": self.exit,
            "/play": self.play,
            "/csv": self.set_csv_result_writer,
            "/table": self.set_tabular_result_writer,
            "/tsv": self.set_tsv_result_writer,
            "/config": self.config,
            "/kernel": self.kernel,
        }
        self.tx = None
        self.tx_counter = 0
コード例 #5
0
def setup():
    author_nodes = []
    pmid_nodes = []
    written_by = []

    count = 0
    g = Graph(uri="bolt://localhost:7687", auth=("neo4j", "justjournals"))
    g.schema.create_uniqueness_constraint('PMID', 'name')
    g.schema.create_uniqueness_constraint('Person', 'title')
    g.schema.create_uniqueness_constraint('Factor', 'dID')
    g.schema.create_uniqueness_constraint('Qualifier', 'qID')
コード例 #6
0
def main(args):
    logger = log.getdebuglogger("dbmanager")
    graph = Graph(host=NEO4J_HOST,
                  user=NEO4J_USERNAME,
                  password=NEO4J_PASSWORD)
    args_obj = parse_args(args)

    if args_obj.verbose:
        logger.setLevel(log.LEVELS[-1])
    else:
        logger.setLevel(log.LEVELS[0])

    args_obj.func(args_obj, graph, logger)
コード例 #7
0
    def __init__(self, profile=None, *_, **settings):
        super(ClientConsole, self).__init__(__name__, verbosity=settings.get("verbosity", 0))
        self.output_file = settings.pop("file", None)

        welcome = settings.get("welcome", True)
        if welcome:
            self.write(TITLE)
            self.write()
            self.write(dedent(QUICK_HELP))
            self.write()

        self.profile = ConnectionProfile(profile, **settings)
        try:
            self.graph = Graph(self.profile)
        except OSError as error:
            self.critical("Could not connect to <%s> (%s)", self.profile.uri, " ".join(map(str, error.args)))
            raise
        else:
            self.debug("Connected to <%s>", self.graph.service.uri)
        try:
            makedirs(HISTORY_FILE_DIR)
        except OSError:
            pass
        self.history = FileHistory(path_join(HISTORY_FILE_DIR, HISTORY_FILE))
        self.lexer = CypherLexer()
        self.result_writer = Table.write

        self.commands = {

            "//": self.set_multi_line,
            "/e": self.edit,

            "/?": self.help,
            "/h": self.help,
            "/help": self.help,

            "/x": self.exit,
            "/exit": self.exit,

            "/play": self.play,

            "/csv": self.set_csv_result_writer,
            "/table": self.set_tabular_result_writer,
            "/tsv": self.set_tsv_result_writer,

            "/config": self.config,
            "/kernel": self.kernel,

        }
        self.tx = None
        self.qid = 0
コード例 #8
0
ファイル: index.py プロジェクト: thinks520/CodeRecord
 def __init__(self, content_type, uri, name=None):
     self._content_type = content_type
     key_value_pos = uri.find("/{key}/{value}")
     if key_value_pos >= 0:
         self._searcher = ResourceTemplate(uri)
         self.__remote__ = Resource(uri[:key_value_pos])
     else:
         self.__remote__ = Resource(uri)
         self._searcher = ResourceTemplate(uri.string + "/{key}/{value}")
     uri = remote(self).uri
     self._create_or_fail = Resource(
         uri.resolve("?uniqueness=create_or_fail"))
     self._get_or_create = Resource(
         uri.resolve("?uniqueness=get_or_create"))
     self._query_template = ResourceTemplate(uri.string + "{?query,order}")
     self._name = name or uri.path.segments[-1]
     self.__searcher_stem_cache = {}
     self.graph = Graph(uri.resolve("/db/data/").string)
コード例 #9
0
ファイル: orm_utils.py プロジェクト: yitzikc/nesta
def graph_session(yield_graph=False, *args, **kwargs):
    '''Generate a Neo4j graph transaction object with
    safe commit/rollback built-in.

    Args:
        {*args, **kwargs}: Any arguments for py2neo.database.Graph
    Yields:
        py2neo.database.Transaction
    '''
    graph = Graph(*args, **kwargs)
    transaction = graph.begin()
    try:
        if yield_graph:
            yield (graph, transaction)
        else:
            yield transaction
        transaction.commit()
    except:
        transaction.rollback()
        raise
    finally:
        del transaction
        del graph
コード例 #10
0
    def connectGraph(self):
        # graph = Graph(user = self.user, password = self.password)
        authenticate("localhost:7474", self.user, self.password)
        graph = Graph("http://localhost:7474/db/data/")

        return graph
コード例 #11
0
import os
import sys
import pytest

from py2neo.database import Graph
from py2neo.data import Node, Relationship

ROOT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(ROOT_PATH)

from schemes.graph import GraphNode, GraphRelation
from graph.graph import NLMGraph

nlmg = NLMGraph(graph=Graph(port=7688))
nlmg.graph.delete_all()


def test_graph_connected():
    assert nlmg.graph.database.name != None


@pytest.fixture
def make_node():
    props = {"age": 20, "sex": "female"}
    node = GraphNode("Person", "Alice", props)
    return node


@pytest.fixture
def make_node_no_props():
    return GraphNode("Person", "Alice")
コード例 #12
0
ファイル: test_nlm.py プロジェクト: yorick76ee/NLM
import os
import sys
import pytest

ROOT_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(ROOT_PATH)

from py2neo.database import Graph
from schemes.graph import GraphNode, GraphRelation
from schemes.extractor import Entity, ExtractorInput
from nlm import NLMLayer


graph = Graph(port=7688)
mem = NLMLayer(graph=graph)


def test_nlm_instance_call_graphnode():
    start = GraphNode("Person", "AliceThree")
    res = mem(start)
    query = res[0]
    assert isinstance(query, GraphNode) == True
    assert query.label == "Person"
    assert query.name == "AliceThree"
    assert query.props == {'age': 22, 'sex': 'male'}


def test_nlm_instance_call_graphrelation():
    start = GraphNode("Person", "AliceThree")
    end = GraphNode("Person", "AliceOne")
    relation = GraphRelation(start, end, "LOVES")
コード例 #13
0
ファイル: batch.py プロジェクト: yorick76ee/NLM
from dataclasses import dataclass
from pnlp import piop

from py2neo.database import Graph
from batch_scheme import (Disease, Department, Producer,
                          Symptom, Examination, Food, Drug)


graph = Graph(scheme="bolt", host="localhost", port=7687,
              user="******", password="******")


def create_node(item: dict):
    """
    One item of the given data to a node.
    """
    dise = Disease()
    dise.name = item.get("name", "")
    dise.description = item.get("desc", "")
    dise.prevent = item.get("prevent", "")
    dise.cause = item.get("cause", "")
    dise.susceptible = item.get("easy_get", "")
    dise.cause_prob = item.get("get_prob", "")
    dise.cured_prob = item.get("ured_prob", "")
    dise.method = item.get("cure_way", "")
    dise.cure_duration = item.get("cure_lasttime", "")
    return dise


@dataclass
class RelationUpdate:
コード例 #14
0
 def __init__(self, profile=None, name=None, **settings):
     self.graph = Graph(profile, name=name, **settings)
コード例 #15
0
import os

from py2neo.database import Graph

h = os.environ.get('GRAPHENEDB_HOST', 'localhost')
u = os.environ.get('NEO4J_USERNAME', 'neo4j')
p = os.environ.get('NEO4J_PASSWORD', '111111')

graph = Graph(host=h, user=u, password=p)


def query_on_constraint(constraint):
    matcher = NodeMatcher(graph)
    return graph.nodes.match('Label', Constraint=constraint).first()


def list_all():
    return list(graph.nodes.match('Label'))
コード例 #16
0
ファイル: neo4j_opt.py プロジェクト: chenhehong/TCM_KG
 def connectGraph(self):
     authenticate(self.service_ip, self.user, self.password)
     graph = Graph('http://%s/db/data/' % self.service_ip)
     return graph
コード例 #17
0
ファイル: kernel.py プロジェクト: PaulyB71/SVoO-Python
 def graph(self):
     if self._graph is None:
         self._graph = Graph(**self.server)
     return self._graph
コード例 #18
0
 def __init__(self):
     #watch("neo4j.bolt")
     self.graph = Graph(super().graph_url)
コード例 #19
0
    def gdb(self):
        """The graph database service instance as a property, for convenience.

        Note: The property will use these configuration variables
        ``CONNECTION_RETRY``
        ``RETRY_INTERVAL``

        :return: the graph database service as a property
        """
        retry = False
        if 'CONNECTION_RETRY' in self.app.config:
            retry = self.app.config['CONNECTION_RETRY']
        retry_interval = 5
        if 'RETRY_INTERVAL' in self.app.config:
            retry_interval = self.app.config['RETRY_INTERVAL']
        retry_count = 0
        try:
            log.info("flask.ext.Neo4j gdb trying to connect to DB")
            host_port = ''
            host_database = self.app.config['GRAPH_DATABASE']
            neo_user = self.app.config['GRAPH_USER']
            neo_pass = self.app.config['GRAPH_PASSWORD']

            host_port_idx = host_database.find('://')
            if host_port_idx >= 0:
                # extract the host and port from the host_database
                host_port_idx = host_port_idx + 3
                host_port = host_database[host_port_idx:]
                host_port = host_port[:host_port.find('/')]
        except Exception as e:
            log.error(
                "Error with database parameters, they may not have been specified in your config: {}"
                .format(e))
        try:
            #authenticate(
            #    host_port,
            #    self.app.config['GRAPH_USER'],
            #    self.app.config['GRAPH_PASSWORD']
            #)
            #v4:
            #"bolt://myserver:7687", auth=("neo4j", "psswrd")
            self.graph_db = Graph(host_database, auth=(neo_user, neo_pass))
        except Exception as se:
            log.error('SocketError: {0}'.format(se))
            if retry:
                while retry_count < 3:
                    log.debug(
                        'Waiting {0}secs before Connection Retry to GraphDatabaseService'
                        .format(retry_interval))
                    time.sleep(retry_interval)
                    #time.sleep(1)
                    retry_count += 1
                    try:
                        self.graph_db = Graph(host_database,
                                              auth=(neo_user, neo_pass))
                    except Exception as sse:
                        log.error('SocketError: {0}'.format(sse.message))

        if not hasattr(self, 'index'):
            self.index = {}
            # add all the indexes as app attributes
            if self._indexes is not None:
                for i, i_type in iter(list(self._indexes.items())):
                    log.debug('getting or creating graph index:{0} {1}'.format(
                        i, i_type))
                    self.index[i] = \
                        self.graph_db.legacy.get_or_create_index(i_type, i)

        return self.graph_db
コード例 #20
0
ファイル: server.py プロジェクト: yorick76ee/NLM
    If is, the props will never update.')
parser.add_argument('-ai',
                    dest='add_inexistence',
                    type=bool,
                    default=False,
                    help='Whether to add an inexistent Node or Relation.')
parser.add_argument('-up',
                    dest='update_props',
                    type=bool,
                    default=False,
                    help='Whether to update props of a Node or Relation.')
args = parser.parse_args()

graph = Graph(scheme=neo_sche,
              host=neo_host,
              port=neo_port,
              user=neo_user,
              password=neo_pass)
mem = NLMLayer(graph=graph,
               fuzzy_node=args.fuzzy_node,
               add_inexistence=args.add_inexistence,
               update_props=args.update_props)


class NLMService(nlm_pb2_grpc.NLMServicer):
    @raise_grpc_error(Exception, StatusCode.INTERNAL)
    @deco_log_error(logger)
    @convert_request_to(GraphNode)
    def NodeRecall(self, request, context):
        result = mem(request)
        gn = result[0] if result else request
コード例 #21
0
ファイル: vifi.py プロジェクト: sundhaug92/vifi
                        continue
                    existing_rels.append(job_value)
                    existing_rels = existing_rels[-100000:]
                    register_connection(get_connection(*job_value))
                elif job_type == 'update_rel':
                    pass
                else:
                    raise Exception('Unknown job_type', job_type)
            db_queue.task_done()
        except:
            pass


logger = logging.getLogger()
print('Connecting to graph')
graph = Graph(password='******')  # TODO: parameterize, don't hardcode password


def main():
    sniffer_count = min([cpu_count(), len(argv[1:])])
    sniffer_queue = JoinableQueue()
    db_queue = JoinableQueue()
    for filename in argv[1:]:
        if os.path.isfile(filename):
            print('Will be loading from file', filename)
        else:
            print('Will sniff from interface', filename)
        sniffer_queue.put(filename)
    if argv[1:] == []:
        sniffer_queue.put('*')
        if sniffer_count == 0:
コード例 #22
0
ファイル: __init__.py プロジェクト: Tas-Kit/platform
from flask import Flask
from py2neo.database import Graph
from settings import PLATFORM_DB, BLOWFISH_SECRET
from Crypto.Cipher import Blowfish

db = Graph(**PLATFORM_DB)
blowfish = Blowfish.new(BLOWFISH_SECRET)


def create_app():
    app = Flask('Platform')
    # Load common settings
    app.config.from_object('settings')

    # Register blueprints
    from .views import register_blueprints
    register_blueprints(app)

    @app.route('/healthcheck', methods=['GET'])
    def healthcheck():
        return 'HEALTHY'

    return app