Commit d23407d7 authored by gijs's avatar gijs

Merge branch 'master' of activearchives.org:git/1943

parents bd575e2b 2cd3f8a7
......@@ -41,96 +41,103 @@ tiggy, rabbit, jemima, jeremy, robinson, pigling]
# functions
# random choice of tale
def select(texts):
txt = choice(texts)
return txt
item = choice(texts)
#print "selected txt", item
return item
# gets title from tale
def title(txt):
txt = open(txt).read().decode("utf-8")
nametxt = txt.splitlines()[0]
return nametxt
name = txt.splitlines()[0]
#print "name", name
return name
# gets url from tale
def source(txt):
txt = open(txt).read().decode("utf-8")
url = txt.splitlines()[1]
#print "url", url
return url
# splits text into list of words
def tokenize(txt):
txt = open(txt).read().decode("utf-8")
tokens = ' '.join(line.replace('\n', '') for line in txt)
basket = ' '.join(line.replace('\n', '') for line in txt)
#turn into wordlist
tokens = word_tokenize(txt)
return tokens
basket = word_tokenize(txt)
#print "tokens", basket
return basket
# splits text into list of sentences
def sentences(txt):
txt = ''.join(open(txt).readlines())
phrases = re.split(r' *[\.\?!][\'"\)\]]* *', txt)
return phrases
basket = re.split(r' *[\.\?!][\'"\)\]]* *', txt)
#print "sentences", basket
return basket
# Select sentences that contain keyword
def sentences_with_key(sentences, pick):
selected_sentences = []
def sentences_with_key(sentences, word):
basket = []
for sentence in sentences:
wordlist = sentence.split(" ")
if pick in wordlist:
if word in wordlist:
sentence = sentence+'.'
selected_sentences.append(sentence)
return selected_sentences
# replace vowels by numbers
def replace_all(text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text
basket.append(sentence)
print "sentences_with_key", basket
return basket
# Replacements
reps = {'a':'4', 'e':'3', 'i':'1', 'o':'0', 'u':'8'}
def frequency(msg):
# captures last line in chat
# picks a random tale
txt = select(texts)
#print "freq text", txt
# captures title of tale
nametxt = title(txt)
#print "freq titel", nametxt
# captures url of tale
url = source(txt)
urltxt = source(txt)
#print "freq url", urltxt
# transforms txt in wordlist
tokens = tokenize(txt)
#print "freq tokens", tokens
# transforms txt in list of sentences
phrases = sentences(txt)
#print " freq phrases", phrases
# turn list of tokenized words into nltk.Text
fin = nltk.Text(tokens)
# FreqDist
fdist1 = FreqDist(fin)
print(fdist1)
#print(fdist1)
# splits chat message in wordlist
words = msg.split()
# selects from chat message words between 2 and 10 characters
selected = []
selected = [x for x in words if len(x)>3 and len(x)<10 and x in fdist1]
selected = [x for x in words if len(x)>2 and len(x)<10 and x in fdist1]
print "freq selected words from msg", selected
if len(selected)>0:
pick = choice(selected)
print "pick", pick
# Counts the frequency of the selected word
amount = fdist1[pick]
print(amount)
print "amount", amount
# Selects sentences in which selected word appears
selected_sentences = sentences_with_key(phrases, pick)
print "selected sentences", selected_sentences
# Shuffles the selected sentences
shuffle(selected_sentences)
# Prints the results
examples = []
basket = []
if amount > 0:
pick = pick.upper()
message1 = "In " + nametxt + " I used " + str(amount) + " times the word " + pick + ". Like in here: "
print message1
examples.append(message1)
basket.append(message1)
for sentence in selected_sentences[:4]:
message = (sentence.replace("\n", " ").replace(pick, pick.upper()))
examples.append(message)
return examples
basket.append(message)
return basket
# print message 2
......
......@@ -41,71 +41,70 @@ tiggy, rabbit, jemima, jeremy, robinson, pigling]
# functions
# random choice of tale
def select(texts):
txt = choice(texts)
return txt
item = choice(texts)
#print "selected txt", item
return item
# gets title from tale
def title(txt):
txt = open(txt).read().decode("utf-8")
nametxt = txt.splitlines()[0]
return nametxt
name = txt.splitlines()[0]
#print "name", name
return name
# gets url from tale
def source(txt):
txt = open(txt).read().decode("utf-8")
url = txt.splitlines()[1]
#print "url", url
return url
# splits text into list of words
def tokenize(txt):
txt = open(txt).read().decode("utf-8")
tokens = ' '.join(line.replace('\n', '') for line in txt)
basket = ' '.join(line.replace('\n', '') for line in txt)
#turn into wordlist
tokens = word_tokenize(txt)
return tokens
basket = word_tokenize(txt)
#print "tokens", basket
return basket
# splits text into list of sentences
def sentences(txt):
txt = ''.join(open(txt).readlines())
phrases = re.split(r' *[\.\?!][\'"\)\]]* *', txt)
return phrases
basket = re.split(r' *[\.\?!][\'"\)\]]* *', txt)
#print "sentences", basket
return basket
# Select sentences that contain keyword
def sentences_with_pick(sentences, pick):
selected_sentences = []
def sentences_with_key(sentences, word):
basket = []
for sentence in sentences:
wordlist = sentence.split(" ")
if pick in wordlist:
if word in wordlist:
sentence = sentence+'.'
selected_sentences.append(sentence)
return selected_sentences
# replace vowels by numbers
def replace_all(text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text
# Replacements
reps = {'a':'4', 'e':'3', 'i':'1', 'o':'0', 'u':'8'}
basket.append(sentence)
print "sentences_with_key", basket
return basket
def length(msg):
# captures last line in chat
# splits chat message in wordlist
words = msg.split()
# selects from chat message words between 2 and 10 characters
selected = []
basket = []
for word in words:
if len(word) > 3 and len(word) < 10:
selected.append(word)
#print(selected)
if len(word) > 2 and len(word) < 12:
basket.append(word)
print "basket words message", basket
# picks a random word
w = choice(selected)
w = choice(basket)
print "length word", w
w = w.upper()
#print(w)
print "length word capitals", w
# define length keyword
length = len(w)
#print(length)
print "lenght", length
# picks a random tale
txt = select(texts)
# captures title of tale
......@@ -120,28 +119,31 @@ def length(msg):
fin = nltk.Text(tokens)
# selecteer op lengte van woorden
T = set(fin)
words = [x for x in T if len(x) == length]
sorted_words = sorted(words)
basket = [x for x in T if len(x) == length]
sorted_words = sorted(basket)
# picks word of sorted_words
pick = choice(sorted_words)
#print(pick)
print "picked word from tale with right lenght", pick
# Selects sentences in which selected word appears
selected_sentences = sentences_with_pick(phrases, pick)
selected_sentences = sentences_with_key(phrases, pick)
print "length selected sentences with key", selected_sentences
# Shuffles the selected sentences
shuffle(selected_sentences)
# Prints the results
basket = []
if len(selected_sentences) > 0:
pick = pick.upper()
message1 = "The word, " + w + ", counts " + str(length) + " characters. In " + nametxt + " I used the following words of " + str(length) + " characters each: " + ', '.join(sorted_words[:4])
#print(message1)
basket.append(message1)
printsentence = selected_sentences[0]
#print(printsentence)
pick = pick.upper()
message2 = "Take the word, " + pick + ", for example, I used it in this sentence: " + printsentence.replace(pick, pick.upper())
print(message2)
message3 = "Source: " + nametxt
print(message3)
return message1, message2, message3
#print(message2)
basket.append(message2)
#print(message3)
return basket
#msg = e.arguments[0]
......@@ -173,10 +175,9 @@ class MyBot(irc.bot.SingleServerIRCBot):
# captures last line in chat
print e.arguments
msg = e.arguments[0]
message1, message2, message3 = length(msg)
self.say(c, message1)
self.say(c, message2)
self.say(c, message3)
messages = length(msg)
for message in messages:
self.say(c, message)
# Launch bot
if __name__ == "__main__":
......
Throughout my life, I've invented many different kinds of motors. Many of my inventions were not patented, or patented by others. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_topic/USpatents_motor.gif
21 of my patents include the word magnet. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_topic/USpatents_magnet.gif
My first US patent includes the word dynamo, and many of them afterwards. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_topic/USpatents_dynamo.gif
Two of my patents include the word coil, but not the one which is referred today as the Tesla Coil. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_topic/USpatents_coil.gif
1886 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1886.gif
1887 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1887.gif
1888 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1888.gif
1889 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1889.gif
1890 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1890.gif
1891 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1891.gif
1892 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1892.gif
1893 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1893.gif
1894 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1894.gif
In 1886, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1886.gif
In 1887, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1887.gif
In 1888, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1888.gif
In 1889, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1889.gif
In 1890, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1890.gif
In 1891, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1891.gif
In 1892, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1892.gif
In 1893, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1893.gif
In 1894, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1894.gif
In 1895, I didn't get any patents published in the United States.
1896 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1896.gif
1897 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1897.gif
1898 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1898.gif
In 1896, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1896.gif
In 1897, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1897.gif
In 1898, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1898.gif
In 1899, I didn't get any patents published in the United States.
1900 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1900.gif
1901 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1901.gif
1902 In that year, I didn't get any patents published in the United States.
1903 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1903.gif
1904 In that year, I didn't get any patents published in the United States.
1905 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1905.gif
In 1900, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1900.gif
In 1901, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1901.gif
In 1902, I didn't get any patents published in the United States.
In 1903, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1903.gif
In 1904, I didn't get any patents published in the United States.
In 1905, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1905.gif
In 1906, I didn't get any patents published in the United States.
In 1907, I didn't get any patents published in the United States.
In 1908, I didn't get any patents published in the United States.
1909 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1909.gif
In 1909, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1909.gif
In 1910, I didn't get any patents published in the United States.
In 1911, I didn't get any patents published in the United States.
In 1912, I didn't get any patents published in the United States.
In 1913, I didn't get any patents published in the United States.
1914 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1914.gif
1915 In that year, I didn't get any patents published in the United States.
1916 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1916.gif
In 1914, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1914.gif
In 1915, I didn't get any patents published in the United States.
In 1916, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1916.gif
In 1917, I didn't get any patents published in the United States.
1918 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1918.gif
1919 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1919.gif
1920 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1920.gif
1921 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1921.gif
1922 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1922.gif
In 1923, I didn't get any patents published in the United States.
In 1918, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1918.gif
In 1919, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1919.gif
In 1920, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1920.gif
In 1921, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1921.gif
In 1922, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1922.gif
In 1923, I didn't get any patents published in the United States.
In 1924, I didn't get any patents published in the United States.
In 1925, I didn't get any patents published in the United States.
In 1926, I didn't get any patents published in the United States.
In 1927, I didn't get any patents published in the United States.
1928 http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1928.gif
In 1928, these patents were published by the United States Patent and Trademark Office. http://botopera.activearchives.org/NICKola_Tesla/USpatents_by_year/USpatents_1928.gif
In 1929, I didn't get any patents published in the United States.
In 1930, I didn't get any patents published in the United States.
In 1931, I didn't get any patents published in the United States.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment