コード例 #1
0
ファイル: bigwheel.py プロジェクト: BrandonCline/wheeler
def load_prelude():

	for line in open( os.path.dirname(os.path.abspath(__file__)) + "/prelude.w", "r"):
		line = line.strip()
		# Comment stripper. Fragile!
		line = line[:line.find('#')] if '#' in line else line

		# Ignore blank lines
		if line:
			evaluate( parse(line, ROOT), ROOT )
コード例 #2
0
	def test_evaluate_simple_expression(self):

		root = Category('*')

		expression = "foo bar baz"

		evaluate(parse(expression, root), root)  # Don't forget that at this point there are a bunch of meta-categories.

		connections = root.comprehend("baz", "foo", "bar")

		self.assertEqual(len(connections), 1) # Should just have the expression.
コード例 #3
0
ファイル: bigwheel.py プロジェクト: BrandonCline/wheeler
def load_file(filename):
	try:
		for line in open( os.path.dirname(os.path.abspath(__file__)) + "/%s.w" % filename, "r"):
			line = line.strip()
			# Comment stripper. Fragile!
			line = line[:line.find('#')] if '#' in line else line

			# Ignore blank lines
			if line:
				evaluate( parse( expand_arrows(line), ROOT), ROOT )
	except:
		print "Can't load that file for some damned reason or another."
コード例 #4
0
	def test_evaluate_different_atoms(self):

		rootA = Category('*')
		rootB = Category('*')

		expressionA = "foo"
		expressionB = "(foo)"

		evaluate(parse(expressionA, rootA), rootA)
		evaluate(parse(expressionB, rootB), rootB)
		category_delta = len(rootB.contents) - len(rootA.contents)

		self.assertTrue(category_delta > 0, "Second expression should generate different numbers of categories")
コード例 #5
0
    def test_simple_interaction(self):

        root = Category('*')

        expression = "foo bar"

        evaluate(parse(expression, root), root)

        self.assertTrue(root.has("foo"))

        self.assertTrue(isinstance(root.contents["foo"], Category))

        foo = root.contents["foo"]
        bar = root.contents["bar"]

        self.assertTrue(bar.related(set([foo])), "no double relation?")
コード例 #6
0
ファイル: interaction_tests.py プロジェクト: built/wheeler
	def test_simple_interaction(self):

		root = Category('*')

		expression = "foo bar"

		evaluate(parse(expression, root), root)

		self.assertTrue( root.has("foo") )

		self.assertTrue( isinstance( root.contents["foo"], Category) )

		foo = root.contents["foo"]
		bar = root.contents["bar"]

		self.assertTrue(bar.related(set([foo])), "no double relation?")
コード例 #7
0
ファイル: interaction_tests.py プロジェクト: built/wheeler
	def test_getting_a_thingy_between_two_other_thingies(self):

		root = Category('*')

		expression = "apple tasty red"

		evaluate(parse(expression, root), root)

		apple	= root.contents["apple"]
		tasty	= root.contents["tasty"]
		red		= root.contents["red"]

		related = root.comprehend("apple", "red")

		self.assertTrue(len(related) > 0, "We should have received some results back.")

		self.assertTrue( root.comprehend("apple", "red")[0].related( set([tasty]) ), "Can't find a relationship?")
コード例 #8
0
ファイル: interaction_tests.py プロジェクト: built/wheeler
	def test_getting_a_thingy_between_two_other_thingies2(self):

		root = Category('*')

		expression = "apple tasty red"

		evaluate(parse(expression, root), root)

		apple	= root.contents["apple"]
		tasty	= root.contents["tasty"]
		red		= root.contents["red"]

		relation = root.comprehend("apple", "red")

		self.assertTrue(len(relation) > 0, "We should have received some results back.")

		# TODO: Make this test less crude and more direct.
		self.assertTrue( tasty in relation[0].contents.values(), "Can't find a relationship?")
コード例 #9
0
    def test_getting_a_thingy_between_two_other_thingies(self):

        root = Category('*')

        expression = "apple tasty red"

        evaluate(parse(expression, root), root)

        apple = root.contents["apple"]
        tasty = root.contents["tasty"]
        red = root.contents["red"]

        related = root.comprehend("apple", "red")

        self.assertTrue(
            len(related) > 0, "We should have received some results back.")

        self.assertTrue(
            root.comprehend("apple", "red")[0].related(set([tasty])),
            "Can't find a relationship?")
コード例 #10
0
    def test_getting_a_thingy_between_two_other_thingies2(self):

        root = Category('*')

        expression = "apple tasty red"

        evaluate(parse(expression, root), root)

        apple = root.contents["apple"]
        tasty = root.contents["tasty"]
        red = root.contents["red"]

        relation = root.comprehend("apple", "red")

        self.assertTrue(
            len(relation) > 0, "We should have received some results back.")

        # TODO: Make this test less crude and more direct.
        self.assertTrue(tasty in relation[0].contents.values(),
                        "Can't find a relationship?")
コード例 #11
0
    def test_another_interaction(self):

        root = Category('*')

        expression = "apple tasty red"

        evaluate(parse(expression, root), root)

        apple = root.contents["apple"]
        tasty = root.contents["tasty"]
        red = root.contents["red"]

        # TODO: Make #related not suck.
        self.assertTrue(apple.related(set([tasty])), "no relation?")
        self.assertTrue(apple.related(set([red])), "no relation?")

        self.assertTrue(tasty.related(set([red])), "no relation?")
        self.assertTrue(tasty.related(set([apple])), "no relation?")

        self.assertTrue(red.related(set([tasty])), "no relation?")
        self.assertTrue(red.related(set([apple])), "no relation?")
コード例 #12
0
ファイル: interaction_tests.py プロジェクト: built/wheeler
	def test_another_interaction(self):

		root = Category('*')

		expression = "apple tasty red"

		evaluate(parse(expression, root), root)

		apple	= root.contents["apple"]
		tasty	= root.contents["tasty"]
		red		= root.contents["red"]

		# TODO: Make #related not suck.
		self.assertTrue(apple.related( set([tasty]) ), "no relation?")
		self.assertTrue(apple.related( set([red]) ), "no relation?")

		self.assertTrue(tasty.related( set([red]) ), "no relation?")
		self.assertTrue(tasty.related( set([apple]) ), "no relation?")

		self.assertTrue(red.related( set([tasty]) ) , "no relation?")
		self.assertTrue(red.related( set([apple]) ), "no relation?")
コード例 #13
0
    def test_simultaneous_transitions(self):
        root = Category('*')

        setup_expressions = [
            "foo A",
            "bar B",
            "transition (pattern (A)) (action B)",
            "transition (pattern (Y)) (action Z)",
        ]

        # Setup the world
        for expression in setup_expressions:
            evaluate(parse(expression, root), root)

        expression = "foo bar"

        # After evaluation the following relationships should exist:
        # foo B
        # bar Z
        # foo bar
        expected_relationships = ["foo B", "bar Z", "foo bar"]

        relationships = list(
            chain.from_iterable(
                [root.comprehend(*r.split()) for r in expected_relationships]))

        # Verify those relationships do not yet exist.
        self.assertFalse(any(relationships),
                         "None of those relationships should exist yet.")

        evaluate(parse(expression, root), root)

        # Now, ALL of those relationships should exist.

        relationships = list(
            chain.from_iterable(
                [root.comprehend(*r.split()) for r in expected_relationships]))
        self.assertTrue(all(relationships),
                        "All of those relationships should exist.")
コード例 #14
0
ファイル: execution_tests.py プロジェクト: built/wheeler
	def test_simultaneous_transitions(self):
		root = Category('*')

		setup_expressions = [
			"foo A",
			"bar B",
			"transition (pattern (A)) (action B)",
			"transition (pattern (Y)) (action Z)",
		]

		# Setup the world
		for expression in setup_expressions:
			evaluate(parse(expression, root), root)

		expression = "foo bar"

		# After evaluation the following relationships should exist:
		# foo B
		# bar Z
		# foo bar
		expected_relationships = [
			"foo B",
			"bar Z",
			"foo bar"
		]

		relationships = list(chain.from_iterable([ root.comprehend(*r.split()) for r in expected_relationships ]))

		# Verify those relationships do not yet exist.
		self.assertFalse(any(relationships), "None of those relationships should exist yet.")

		evaluate(parse(expression, root), root)

		# Now, ALL of those relationships should exist.

		relationships = list(chain.from_iterable([ root.comprehend(*r.split()) for r in expected_relationships ]))
		self.assertTrue(all(relationships), "All of those relationships should exist.")
コード例 #15
0
	def test_evaluate_atom(self):

		root = Category('*')
		root.create("relation") # Housekeeping

		expression = "foo"

		parsed = parse(expression, root)

		evaluate(parsed, root)

		# After an evaluation we should be able to see a relation which represents the result
		# of this particular evaluation. It will relate to a timestamp and the given expression.
		# In this way you should be able to see a history of evaluations.

		self.assertTrue( "foo" in root.contents.keys() )

		self.assertTrue( root.has("foo") )

		self.assertTrue( isinstance( root.contents["foo"], Category) )

		foo = root.contents["foo"]

		self.assertFalse(foo.has("relation")) # Should not connect directly to <<relation>>
コード例 #16
0
ファイル: wheeler.py プロジェクト: BrandonCline/wheeler
from interpreter.tools import parse, evaluate, expand_arrows
from common import *
import os

def load_prelude():

	for line in open(os.path.dirname(os.path.abspath(__file__)) + "/prelude.w", "r"):
		line = line.strip()
		# Comment stripper. Fragile!
		line = line[:line.find('#')] if '#' in line else line

		# Ignore blank lines
		if line:
			evaluate( parse( expand_arrows(line), ROOT), ROOT )

load_prelude()

tokenized_lines = []

line_number = 1

for line in fileinput.input():

	line = line.strip()
	# Comment stripper. Fragile!
	line = line[:line.find('#')] if '#' in line else line

	# Ignore blank lines
	if line:
		evaluate( parse(line, ROOT), ROOT )
コード例 #17
0
ファイル: bigwheel.py プロジェクト: BrandonCline/wheeler
	if command in ('reset',):
		ROOT = Category("*")
		ROOT.add(ROOT)
		load_prelude()
		print "* was reset"
		continue

	if command.split() and command.split()[0] == "load":
		args = command.split()
		if len(args) != 2:
			print "This didn't make sense for loading: ", args
		else:
			load_file(args[1])
		continue

	# Ignore blank lines
	if line:
		evaluate( parse( expand_arrows(line), ROOT), ROOT )