def _make_mock_learner(**kwargs): ## Specify ontology. types = log.TypeSystem(["object", "location", "boolean", "action"]) functions = [ types.new_function("go", ("location", "action"), lambda x: ("go", x)), ] constants = [ types.new_constant("there", "location"), types.new_constant("here", "location"), types.new_constant("away", "location"), ] ont = log.Ontology(types, functions, constants) ## Specify initial lexicon. lexicon = lex.Lexicon.fromstring(r""" :- S, N goto => S/N {\x.go(x)} go => S/N {\x.go(x)} there => N {there} away => N {away} """, ontology=ont, include_semantics=True) return WordLearner(lexicon, **kwargs)
def _make_complex_mock_ontology(): def fn_unique(xs): true_xs = [x for x, matches in xs.items() if matches] assert len(true_xs) == 1 return true_xs[0] types = log.TypeSystem(["obj", "num", "ax", "boolean"]) functions = [ types.new_function( "cmp_pos", ("ax", "obj", "obj", "num"), lambda ax, a, b: a["3d_coords"][ax()] - b["3d_coords"][ax()]), types.new_function("ltzero", ("num", "boolean"), lambda x: x < 0), types.new_function("ax_x", ("ax", ), lambda: 0), types.new_function("ax_y", ("ax", ), lambda: 1), types.new_function("ax_z", ("ax", ), lambda: 2), types.new_function("unique", (("obj", "boolean"), "obj"), fn_unique), types.new_function("cube", ("obj", "boolean"), lambda x: x["shape"] == "cube"), types.new_function("sphere", ("obj", "boolean"), lambda x: x["shape"] == "sphere"), types.new_function("and_", ("boolean", "boolean", "boolean"), lambda x, y: x and y), ] constants = [ types.new_constant("one", "num"), types.new_constant("two", "num") ] ontology = log.Ontology(types, functions, constants, variable_weight=0.1) return ontology
def _make_simple_mock_ontology(): types = l.TypeSystem(["boolean", "obj"]) functions = [ types.new_function("and_", ("boolean", "boolean", "boolean"), lambda x, y: x and y), types.new_function("foo", ("obj", "boolean"), lambda x: True), types.new_function("bar", ("obj", "boolean"), lambda x: True), types.new_function("not_", ("boolean", "boolean"), lambda x: not x), types.new_function("invented_1", (("obj", "boolean"), "obj", "boolean"), lambda f, x: x is not None and f(x)), types.new_function("threeplace", ("obj", "obj", "boolean", "boolean"), lambda x, y, o: True), ] constants = [types.new_constant("baz", "boolean"), types.new_constant("qux", "obj"), types.new_constant("quz", "obj"),] ontology = l.Ontology(types, functions, constants, variable_weight=0.1) return ontology