def create_db(usercol, refcol, start, end):
    '''
    try to generate relationships using a different example from the fundamentals page

    '''

    graph_db = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")

    rowlist = []

    #nodes first
    for i in range(11, 100):
        rowlist.append (node(user=usercol[i]))
        rowlist.append (node(ref = refcol[i]))

    #relationships second
    for i in range(11, 100):
        rowlist.append(rel(start[i], "RECOMMENDED", end[i]))

    incubate = graph_db.create(*rowlist) #asterisk expands the list & might work better?

    #gives an error Incomplete Read if you try to do the whole thing at once, but
    #looks like you can do this in pieces in order to get the whole thing (?)

    #not sure if this is really necessary, should try +/- the format=pretty part
    neo4j._add_header('X-Stream', 'true;format=pretty')
Beispiel #2
0
def graph_push(d):
    """
    Temporary way of pushing a dict of dicts to a neo4j database. Will be added
    to neo4j later.
    """
    neo4j._add_header('X-Stream', 'true;format=pretty')
    word_set = set(d.keys())
    for words in d.values():
        word_set = word_set.union(set(words.keys()))

    idx = {word: i for i, word in enumerate(word_set)}
    nodes = [{'word': word} for word in word_set]
    relations = []

    for from_word, edges in d.items():
        for to_word, p in edges.items():
            relations.append((idx[from_word], "SAME_SENTENCE", idx[to_word], {
                "Conditional Probability": p
            }))

    arguments = nodes + relations

    g = neo4j.GraphDatabaseService()
    g.clear()
    g.create(*arguments)
Beispiel #3
0
def insertIntoDb(filename1):
    print "Inserting into db"
    neo4j._add_header('X-Stream', 'true;format=pretty')
    characters_db1 = neo4j.GraphDatabaseService("http://localhost:7474/db/data/")
    characters_db1.clear()
    #nodes = unpickle.unpickle(filename1)
    num = 0
    batch = neo4j.WriteBatch(characters_db1)
    listOfNodeReferences = defaultdict()
    temp = ""
    #Nodes insertion
    try:
        for i in xrange(len(nodes)):
            dict1 = {}
            dict1['name'] = nodes[i]['name']
            temp = batch.create(node(dict1))
            
            batch.set_property(temp, 'gender',nodes[i]['gender'])
            try:
                batch.set_property(temp, 'image',nodes[i]['image']['thumb_url'])
            except:
                batch.set_property(temp, 'image','')
            batch.set_property(temp,'first_appeared_in_issue',nodes[i]['first_appeared_in_issue']['name'])
            batch.set_property(temp,'count_of_issue_appearances',nodes[i]['count_of_issue_appearances'])
            batch.set_property(temp,'publisher',nodes[i]['publisher']['name'])
            batch.set_property(temp,'creators',",".join([word[0] for word in nodes[i]['creators']]))

            listOfNodeReferences[i] = temp

        print "Inserted nodes"
        for i in xrange(len(edges)):
            for j in xrange(10):
                temp = batch.create(rel(listOfNodeReferences[i], 'Edge', listOfNodeReferences[edges[i]]))
        print "Inserted edges"
    except:
        print "interrupted"
    results = batch.submit()
    return results
Beispiel #4
0
def graph_push( d ):
    """
    Temporary way of pushing a dict of dicts to a neo4j database. Will be added
    to neo4j later.
    """
    neo4j._add_header('X-Stream', 'true;format=pretty')
    word_set = set( d.keys() )
    for words in d.values():
        word_set = word_set.union( set( words.keys() ) ) 

    idx = { word : i for i, word in enumerate( word_set ) }
    nodes = [ {'word':word} for word in word_set ]
    relations = []

    for from_word, edges in d.items():
        for to_word, p in edges.items():
            relations.append( ( idx[from_word], "SAME_SENTENCE", idx[to_word], {"Conditional Probability": p} ) )

    arguments = nodes + relations

    g = neo4j.GraphDatabaseService()
    g.clear()
    g.create( *arguments )
### GRAPH-BASED UTILITY FUNCTIONS
from py2neo import neo4j, node, rel
from django.conf import settings
from uuid import uuid4
import collections

neo4j._add_header('X-Stream', 'true;format=pretty')

#### labels ####
# -- nodes
BIOENTITY = 'Bioentity'
CHROMOSOME = 'chromosome'
GENE = 'gene'
TRANSCRIPT = 'transcript'
EXON = 'exon'
INTRON = 'intron'
BASE = 'base'
WILD_TYPE = 'wild_type'
REGION = 'region'
SEQUENCE_ALTERATION = 'sequence_alteration'
POINT_MUTATION = 'point_mutation'
DELETION = 'deletion'
INDEL = 'indel'
INSERTION = 'insertion'
INVERSION = 'inversion'
TRANSLOCATION = 'translocation'
COPY_NUMBER_VARIATION = 'copy_number_variation'
COPY_NUMBER_GAIN = 'copy_number_gain'
COPY_NUMBER_LOSS = 'copy_number_loss'
COPY_NUMBER_NEUTRAL = 'copy_number_neutral'
FEATURE_AMPLIFICATION = 'feature_amplification'