Ejemplo n.º 1
0
def read_yaml(path: str, repo: Repository):
    """
    Read a yaml file containing database/ontology description.

    :param path:
    :return:
    """

    with open(path, 'r') as stream:
        entry = yaml.safe_load(stream)

    if entry['type'] == 'database':
        d = Database()
        d.name = entry['name']

        for entity_name in entry['entities']:
            e = Entity(entity_name)

            repo.save(e)

            d.contains.update(e)

        repo.save(d)

    elif entry['type'] == 'ontology':
        o = Ontology()
        o.name = entry['name']
        for entity_name in entry['entities']:
            e = Entity(entity_name)
            repo.save(e)

            o.describes.update(e)
        repo.save(o)

    # relations
    if 'relations' in entry:
        for relation in entry['relations']:
            r = Relation()
            r.uid = str(uuid4())

            to_entity = relation['to']
            from_entity = relation['from']

            r.connects.update(Entity(to_entity))
            r.connects.update(Entity(from_entity))
            repo.save(r)
Ejemplo n.º 2
0
def main():
    repo_url = os.getenv("NEO4J_URL")
    password = os.getenv("NEO4J_PASSWORD")
    print("Neo4j: {0}".format(repo_url))
    repo = Repository(repo_url, password=password)
    print("Connected to Neo4j !")

    pool = concurrent.futures.ThreadPoolExecutor()

    processed_count = 0
    for root, dirs, files in os.walk("maildir"):
        pool.map(file_path_to_model,
                 [(os.path.join(root, filepath), repo) for filepath in files])
        computed_now = len(files)
        processed_count += computed_now
        print("Processed {0} (+{1}) files. Continuing ...".format(
            processed_count, computed_now))

    print("Done !")
Ejemplo n.º 3
0
def movie_repo(movie_graph):
    return Repository.wrap(movie_graph)
Ejemplo n.º 4
0
def repo(graph):
    graph.delete_all()
    yield Repository.wrap(graph)
    graph.delete_all()
Ejemplo n.º 5
0
def test_repo(uri, graph):
    repo = Repository(uri)
    assert repo.graph == graph
Ejemplo n.º 6
0
from .models import Movie, Person

HOME = dirname(__file__)
STATIC = path.join(HOME, "static")
VIEWS = path.join(HOME, "views")
CONFIG = path.join(HOME, "movies.ini")

# Update the template search path used by Bottle
TEMPLATE_PATH.append(VIEWS)

# Load the connection details from the config file
profile = ConnectionProfile.from_file(CONFIG, "Neo4j")

# Set up a link to the local graph database.
repo = Repository(profile)


@get("/static/<filename>")
def get_static(filename):
    """ Static file accessor.
    """
    return static_file(filename, root=STATIC)


@get("/")
def get_index():
    """ Index page.
    """
    return template("index")
Ejemplo n.º 7
0
from py2neo.ogm import Repository
from py2neo.ogm.models.movies import Movie, Person

HOME = dirname(__file__)
STATIC = path.join(HOME, "static")
VIEWS = path.join(HOME, "views")
CONFIG = path.join(HOME, "movies.ini")

# Update the template search path used by Bottle
TEMPLATE_PATH.append(VIEWS)

# Load the connection details from the config file
profile = ConnectionProfile.from_file(CONFIG, "Neo4j")

# Set up a link to the local graph database.
repo = Repository(profile)

if repo.match(Movie).count() == 0:
    print("No movie data found in repository %r" % repo)
    answer = input(
        "Would you like to automatically load the Neo4j movies data set [y/N]? "
    )
    if answer and answer[0].upper() == "Y":
        with open(path.join(HOME, "data", "movies.cypher")) as fin:
            query = fin.read()
        repo.graph.run(query)
        print("Movie data loaded - %d movies available" %
              repo.match(Movie).count())
    else:
        exit(1)
Ejemplo n.º 8
0
import csv

import containers
from py2neo.ogm import Repository

# TODO: Add Weapon Type links, Promotions, Marriages, and Children relationships

r = Repository("bolt://neo4j@localhost:7687", password="******")
print(r)


class MyGraph(Repository):
    uri: str = "bolt://neo4j@localhost:7687"
    password: str = "nick0709"

    def create_characters(self):
        file_path = "data/characters.csv"
        with open(file_path, mode="r", encoding="utf-8-sig") as f:
            csv_reader = csv.DictReader(f)
            for i, line in enumerate(csv_reader):
                if i == 0:
                    print(f'Column names are {", ".join(line)}')

                print(
                    f"{line['Name']}, {line['OptionsList']}, {line['Type']}, {line['Gender']}, {line['UnlockLvl']}"
                )
            print(f"Processed {i} lines.")

    def create_skills(self):
        file_path = "data/skills.csv"
        with open(file_path, mode="r", encoding="utf-8-sig") as f:
Ejemplo n.º 9
0
import os
import logging
from py2neo.ogm import Repository

from metagraph.read_yaml import read_yaml

logging.basicConfig(level=logging.DEBUG)
logging.getLogger('py2neo.client.bolt').setLevel(logging.WARNING)
logging.getLogger('py2neo.client').setLevel(logging.WARNING)

log = logging.getLogger(__name__)

repo = Repository(host='localhost',
                  user='******',
                  password='******',
                  name='metagraph')

datafiles = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')

for file in os.listdir(datafiles):
    filepath = os.path.join(datafiles, file)
    log.info(filepath)

    read_yaml(filepath, repo)