#!/usr/bin/env python import sys from the_semantic_db_code import * from the_semantic_db_functions import * from the_semantic_db_processor import * C = context_list("play with words") # the idea: # |x> => "x" # |x> + |y> => "x and y" # |x> + |y> + |z> => "x, y and z" # |x> + |y> + |z> + |p> => "x, y, z and p" one = ket("x") two = ket("x") + ket("y") three = ket("x") + ket("y") + ket("z") four = ket("x") + ket("y") + ket("z") + ket("p") def first_sp_to_words(one): one = superposition() + one # convert one to sp if ket. There is probably a better way to do this! labels = [x.label for x in one.data] if len(labels) == 0: return ket("",0) # maybe something else instead of this? if len(labels) == 1: result = labels[0] else: head = ", ".join(labels[:-1]) tail = labels[-1] result = head + " and " + tail return ket("text: " + result) print("one: ",one) print("words one:",sp_to_words(one)) print() print("two: ",two) print("words two:",sp_to_words(two)) print() print("three: ",three) print("words three:",sp_to_words(three)) print() print("four: ",four) print("words four:",sp_to_words(four))