Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from neo4jrestclient.client import GraphDatabase
- gdb = GraphDatabase("http://localhost:7474/")
- #Defining the functions:
- def create_entity():
- entities = gdb.labels.create('Entity')
- enter = raw_input('New Entry: ')
- entry = gdb.nodes.create(e = enter)
- entities.add(entry)
- return entry
- def add_character(entity):
- characters = gdb.labels.create('Character')
- name = raw_input ('Character name: ')
- gender = raw_input ('Character gender: ')
- status = raw_input ('Is the character alive or dead? ')
- char = gdb.nodes.create(name=name, gender=gender, status=status)
- characters.add(char)
- char.relationships.create('hasCharacter', entity)
- return char
- def display_existing_characters():
- existing_characters = gdb.labels.get('Character').get()
- for existing in existing_characters:
- print str(existing.id) + " " + existing['name']
- def choose_existing_character(entity, question='Type the id number of the existing character: '): #allows to choose from existing characters.
- display_existing_characters()
- name = raw_input (question)
- character = gdb.node[name] #to link this entry to the one already there.
- character.relationships.create('hasCharacter', entity)
- return character
- def add_location(entity):
- location = gdb.labels.create('Place')
- pl = raw_input ('place: ')
- gran = raw_input ('Granularity: ')
- coor = raw_input ('Coordinates (as follows: lat, long): ')
- place = gdb.nodes.create(pl=pl, Granularity=gran, Coordinates=coor)
- location.add(place)
- place.relationships.create('inPlace', entity)
- return place
- def display_existing_location():
- existing_location = gdb.labels.get('Place').get()
- for existing in existing_location:
- print str(existing.id) + " " + existing['pl']
- def choose_existing_location(entity, question='Type the id number of the existing location: '): #allows to chose from existing locations.
- display_existing_location()
- pl = raw_input(question)
- local = gdb.node[pl]
- local.relationships.create('inPlace', entity)
- return local
- def add_emotion(entity, Character):
- emotions = gdb.labels.create('Emotions')
- List_of_emotions = ["Acceptance", "Anger", "Anticipation", "Anxiety", "Aversion", "Contempt", "Courage", "Dejection", "Desire", "Despair", "Disgust", "Distress", "Elation", "Expectancy", "Fear", "Guilt", "Grief", "Happiness", "Hate", "Hope", "Interest", "Joy", "Love", "Pain", "Panic", "Pleasure", "Rage", "Sadness", "Shame", "Sorrow", "Subjection", "Surprise", "Tender-Emotion", "Terror", "Wonder"]
- print List_of_emotions
- Emotion = raw_input ('Emotion (choose from list): ')
- while Emotion not in List_of_emotions:
- print 'Please choose from available list.'
- Emotion = raw_input ('Emotion: ')
- emotion = gdb.nodes.create(em = Emotion)
- emotions.add(emotion)
- emotion.relationships.create('isEmotion', entity)
- emotion.relationships.create('hasCharacter', character)
- emotion.relationships.create('Spatial_Emotion', place)
- return emotion
- def add_time(entity):
- times = gdb.labels.create('Time')
- temporal = raw_input('Time: ')
- gran = raw_input ('Granularity: ')
- time = gdb.nodes.create(t = temporal, Granularity=gran)
- times.add(time)
- time.relationships.create('atTime', entity)
- time.relationships.create('Spatial_Time', place)
- return time
- #Program starts, user inputs data:
- #Fetch character information:
- ans = raw_input ('Entry? (1 for yes, 0 for no)')
- while ans != '0': # 0 stops the program.
- entity = create_entity() # Numbering the entries
- #New character Vs. Existing:
- addition = raw_input ("New character? (yes/no)")
- if addition == "yes":
- character = add_character(entity)
- else:
- display_existing_characters()
- character = choose_existing_character(entity)
- #Fetch relationship information:
- connections = raw_input ('Does the character have a relationship with another character, in this specific instance? (yes/no)')
- if connections == "yes":
- is_new = raw_input ('New character? (yes/no)')
- if is_new == "yes":
- related_char = add_character(entity)
- else:
- related_char = choose_existing_character(entity)
- rel = raw_input ('What is the type of the relationship? ') #define the types and unify them; state them in this command
- related_char.relationships.create(rel, character)
- #New location Vs. Existing:
- new_place = raw_input ('New Place? (yes/no)')
- if new_place == "yes":
- place = add_location(entity)
- else:
- display_existing_location()
- place = choose_existing_location(entity)
- #Fetch emotion information:
- emotional = raw_input (character.get('name') + ' Emotion? (yes/no)')
- if emotional == "yes":
- add_emotion(entity, character)
- if connections == "yes":
- emotional_related = raw_input (related_char.get('name') + ' Emotion? (yes/no)')
- if emotional_related == "yes":
- add_emotion(entity, related_char)
- #Fetch time information:
- temporal = add_time(entity)
- #See if user wants to continue and act accordingly:
- ans = raw_input ('Entry? (1 for yes, 0 for no)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement