예제 #1
0
파일: parse.py 프로젝트: Sheyne/comprehend
def main():
    # load a graph from a mindnode type graph
    dictionary = mindnode.mindmap('resources/dictionary.mindnode')

    # dump the graph into 'dictionary.edgepairgraph'
    dictionary.dump(open("resources/dictionary.edgepairgraph","w"))

    # load another graph from a mindnode type graph. 
    enviroment = mindnode.mindmap('resources/enviroment.mindnode')

    # merge dictionary into the enviroment
    enviroment.mutate(dictionary)

    # load another graph from a mindnode type graph. 
    query_dictionary = mindnode.mindmap('resources/queries/test1.mindnode')
    # this graph will be used as a query. 

    # run the query on the envieroment
    keep_it_up = True
    for result in enviroment.query(query_dictionary):
        # print out result dictionaries. 
        for key in result:
            print "%s is %s." % ((key.replace("?", "") or "Your answer"), result[key])
        keep_it_up = False
    if keep_it_up:
        print "No results found. "
예제 #2
0
import Tkinter as tk
import tkMessageBox
from PIL import Image, ImageTk
from StringIO import StringIO
from binary_sentence_parse import parse_sentence, WordNotFound
import graph as graphmodule
import mindnode
from magicate import shorten

dictionary = mindnode.mindmap('resources/dictionary.mindnode')

database = graphmodule.Graph()
database.mutate(dictionary)

def withoutdictionary():
	return shorten(database.combine(dictionary, set.difference))
root = tk.Tk()
root.title('Sentence Graph')
root.geometry("500x500")
panel1 = tk.Label(root, image=None)
panel1.pack(side='top', fill='both', expand='yes')
 
def sentence_caller(arg):
	try:
		g = parse_sentence(sentence.get().lower().replace(".", ""))
	except WordNotFound as w:
		tkMessageBox.showerror("Word Not Found", "I do not know the word \"%s\"" % str(w.args[0]))
	else:
		g.mutate(dictionary)
		database.add_info(g)
		buffer = withoutdictionary()
예제 #3
0
from binary_sentence_parse import parse_sentence, WordNotFound
import graph as graphmodule

import mindnode
from magicate import prettify

dictionary = mindnode.mindmap("resources/dictionary.mindnode")

database = graphmodule.Graph()
database.mutate(dictionary)


def withoutdictionary():
    return database.combine(dictionary, set.difference)


last_query = None

while True:
    command = raw_input(": ").lower()
    if "?" == command:
        query = graphmodule.Graph()
        while True:
            line = raw_input("? ")
            if line == "":
                break
            else:
                query.add(*line.split(" "))
        print database.query(query)
    elif command.endswith(".png"):
        withoutdictionary().as_pydot_graph().write_png(command)