Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # We need this for the cross-product we'll use later
- import itertools
- class Language:
- lang = {}
- def __init__(self):
- pass
- # Input: A meaning, can be any Python object
- # Output: The symbol chosen by the language to represent the meaning
- # The symbol will not overlap with any other symbol in the language
- def learn(self, meaning):
- pass
- # Input: A meaning
- # Output: The symbol associated with that meaning
- def speak(self, meaning):
- pass
- # Input: A symbol
- # Output: The meaning associated with that symbol
- def hear(self, symbol):
- pass
- def perturb(self):
- pass
- class MoreNumbers(Language):
- # Example: A0, B000, D0
- valid_letters =
- pass
- class NumberFirst(Language):
- # Example: 0a, 8f, 1s
- pass
- class NumberLast(Language):
- # Example: a0, g7, t1
- pass
- # Instantiate some languages
- langs = [ MoreNumbers(), NumberFirst(), NumberLast() ]
- # Here, our 'meanings' are arbitrary, as long as they are common, and each language knows them
- # We can just use integers
- meanings = range(100)
- # Now, teach the languages some stuff
- for m in meanings:
- for l in langs:
- l.learn(m)
- # Now we want to do a quick check that for each meaning, there's no overlap
- # If we've build out languages properly, that should be true.
- for m in meanings:
- for l1, l2 in itertools.product(lang):
- # If it's the same language for both the speaker and listener, we expect it
- # to work out
- if l1 == l2:
- heard_meaning = l2.hear(l1.speak(m))
- if heard_meaning != meaning:
- print "Language %s didn't understand %s properly" % (str(type(l1)), str(m))
- # If it's different languages, this should fail
- else:
- heard_meaning = l2.hear(l1.speak(m))
- if heard_meaning != None:
- print "Language %s successfully heard %s spoken by %s" (str(type(l2)), str(m), str(type(l1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement