Welcome Guest [Log In] [Register]
Add Reply
Good news!
Topic Started: Feb 2 2008, 06:12 PM (954 Views)
Jesin
Member Avatar
The Small Fish
[ * ]
Hey, I have some great news! I may actually have something decent to contribute by the end of next [IRL] year. I plan to test out of [IRL] so I can do something worthwhile and fun next year, like AI.

BTW, techwizrd edited this because of various IRL related things.
Edited by Jesin, Feb 3 2008, 11:54 AM.
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Jesin
Feb 2 2008, 06:12 PM
Hey, I have some great news! I may actually have something decent to contribute by the end of next [IRL] year. I plan to test out of [IRL] so I can do something worthwhile and fun next year, like AI.

BTW, techwizrd edited this because of various IRL related things.
Oh AI? I see. I actually recently wrote an intelligent chatbot that argues with you (like in the Argument Clinic sketch). I am using it to teach myself how to use the finer aspects of regex in Python.

BTW, BobTheFerret edited this because TechWizrd failed to edit out the IRL things in his quotation.
Edited by Jesin, Feb 3 2008, 11:55 AM.
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Oh yeah, I forgot. NO MENTIONING IRL-RELATED THINGS!
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
BobTheFerret
Member Avatar
It's The End Of The World As We Know It
[ *  * ]
Cool, Techy! Show me the [source|tutorial]!
It is dark. You are likely to be eaten by a grue.
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
BobTheFerret
Feb 3 2008, 09:07 AM
Cool, Techy! Show me the [source|tutorial]!
The source? Sure! BTW. I wrote this from scratch. It's not even done yet. I know the code for the regex is very bad, especially as I have never used regular expressions in python and have only had a small dealing with them in Perl. If you guys can suggest any fixes or any optimizations, I would be very happy.

ArgueBot.py :
Code:
 
#!/usr/bin/python

#This is a reasonably intelligent bot built to argue
#Inspired by Arguement Clinic sketch by Monty Python's Flying Circus

import re

def response(a):
print "Fray: " + a
a = raw_input("Me: ")
analyze(a)

def analyze(a):
a = re.compile(a)
if a.search(r'\bArgueBot\b'):
response("That is not my name!")
elif a.search(r'\bIt\b \bit\b +(?=\bis\b)'):
response("No it isn't!")
else: response("Sorry, my time is up. I am not allowed to argue anymore.\n You'll have to pay for another arguement")


print "Fray: Oh, hello! Welcome. My name is ArgueBot"
a = raw_input("Me: ")
analyze(a)
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
Come on. Am I really not allowed to say "I plan to test out of FOOBAZ"? A determined stalker could easily find out a lot about me just given that I use the name Jesin everywhere and that it is connected to my email address in some of those places.
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Jesin
Feb 3 2008, 12:00 PM
Come on. Am I really not allowed to say "I plan to test out of FOOBAZ"? A determined stalker could easily find out a lot about me just given that I use the name Jesin everywhere and that it is connected to my email address in some of those places.
Yarr, he might be able to. But, I still hold up the rules. If the Administrators don't follow them, the users won't. As they say in Mother Russia, "The fish rots from the head".

Anyway, how do make regular expressions only match if a certain word is after it. I am trying to use it(?=is) to match it is, but it is not working. Arghh!
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
What do you think re.compile does? You have it backwards. You don't compile a string and then search it with regexes, you compile a regex and use it to search strings.
You're doing the equivalent of this:
Code:
 
$ inputfile < program
instead of this:
Code:
 
$ program < inputfile
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
techwizrd
Feb 3 2008, 12:14 PM
Jesin
Feb 3 2008, 12:00 PM
Come on. Am I really not allowed to say "I plan to test out of FOOBAZ"? A determined stalker could easily find out a lot about me just given that I use the name Jesin everywhere and that it is connected to my email address in some of those places.
Yarr, he might be able to. But, I still hold up the rules. If the Administrators don't follow them, the users won't. As they say in Mother Russia, "The fish rots from the head".

Anyway, how do make regular expressions only match if a certain word is after it. I am trying to use it(?=is) to match it is, but it is not working. Arghh!
That matches itis but not it is.
Someadvice:neverforgetaboutwhitespace.
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Jesin
Feb 3 2008, 12:18 PM
techwizrd
Feb 3 2008, 12:14 PM
Jesin
Feb 3 2008, 12:00 PM
Come on. Am I really not allowed to say "I plan to test out of FOOBAZ"? A determined stalker could easily find out a lot about me just given that I use the name Jesin everywhere and that it is connected to my email address in some of those places.
Yarr, he might be able to. But, I still hold up the rules. If the Administrators don't follow them, the users won't. As they say in Mother Russia, "The fish rots from the head".

Anyway, how do make regular expressions only match if a certain word is after it. I am trying to use it(?=is) to match it is, but it is not working. Arghh!
That matches itis but not it is.
Someadvice:neverforgetaboutwhitespace.
OH! THX!

What if a I put in a \b meta character before and after it and is? Wouldn't that do it? According to what I remember, all strings end with a null value, and that might potentially screw it up...

Anyway, I'll try that and post back if it works.
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Okay. it does not work. Can anyone show me a regular expression that matches "it" only if "it" is followed by the word "is". Should I just try and let the program look for the entire pattern "it is", or what?
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
techwizrd
Feb 3 2008, 12:30 PM
Jesin
Feb 3 2008, 12:18 PM
techwizrd
Feb 3 2008, 12:14 PM
Jesin
Feb 3 2008, 12:00 PM
Come on. Am I really not allowed to say "I plan to test out of FOOBAZ"? A determined stalker could easily find out a lot about me just given that I use the name Jesin everywhere and that it is connected to my email address in some of those places.
Yarr, he might be able to. But, I still hold up the rules. If the Administrators don't follow them, the users won't. As they say in Mother Russia, "The fish rots from the head".

Anyway, how do make regular expressions only match if a certain word is after it. I am trying to use it(?=is) to match it is, but it is not working. Arghh!
That matches itis but not it is.
Someadvice:neverforgetaboutwhitespace.
OH! THX!

What if a I put in a \b meta character before and after it and is? Wouldn't that do it? According to what I remember, all strings end with a null value, and that might potentially screw it up...

Anyway, I'll try that and post back if it works.
No, you fool. You're thinking in C. When it says \b matches the null string, it means the empty string, as in ''. You don't worry about null values in Python strings unless you're extending it in C. What you're doing matches it if and only if there is a non-alphanumeric character after it and the next two characters after it are is. That means, match the string it if it is part of the string itis and i is a non-alphanumeric character. That won't match anything.
What you're looking for is this:
Code:
 
(it)\s+is
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Jesin
Feb 3 2008, 01:14 PM
]No, you fool. You're thinking in C. When it says \b matches the null string, it means the empty string, as in ''. You don't worry about null values in Python strings unless you're extending it in C. What you're doing matches it if and only if there is a non-alphanumeric character after it and the next two characters after it are is. That means, match the string it if it is part of the string itis and i is a non-alphanumeric character. That won't match anything.
What you're looking for is this:
Code:
 
(it)\s+is
Actually, the computer understands and divides strings like this:"|C| |i|s||a| |g|r|e|a|t| |l|a|n|g|u|a|g|e|\0". It divides every single character and has a null value at the end of a line. This is who the processor knows how the terminating point of a string. I am not thinking in C, I am thinking in terms of how computers parse strings and handle them from a dynamic standpoint. I suggest you go check your facts before you call me a fool.

Anyway, your solution is correct, and I am thankful.

BTW, I still think C is the one of best languages out there. When you need something powerful, portable, and speedy, you use C. I wrote a parser that reads and writes bytes from an EEPROM and executes commands based on custom built scripting language (by me). The processor is 8-bit and we are given 512 bytes of non-volatile memory to use. C is a language not be be underestimated.

On the other hand, if I actually want to be able to read my code, maintain it, and debug it easily, I go with lovely Python.

Now if I want horrible looking spaghetti code, ugly references, forced use of bad code, slow code, and horrible debugging, maintenance problems, I go with *shudder Java.
Edited by techwizrd, Feb 3 2008, 02:05 PM.
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
BobTheFerret
Member Avatar
It's The End Of The World As We Know It
[ *  * ]
techwizrd
Feb 3 2008, 02:00 PM
*shudder
You didn't close your expression. I can't parse that sentence.

Oh, and you also made a typo. Fixed that for you.

TechWizrd
 
On the other hand, if I actually want to be able to read my code, maintain it, and debug it easily, I go with lovely Java.

Now if I want horrible looking spaghetti code, ugly references, forced use of bad code, slow code, and horrible debugging, maintenance problems, I go with *shudder* Python.

For reference, Java is the one that actually *tells* you if you've gotten types incorrect or put arguments in the wrong order; Python is the one where you don't notice until it borks on you at runtime. I can see why you're so hard on Python's "debugging".
Edited by BobTheFerret, Feb 3 2008, 02:13 PM.
It is dark. You are likely to be eaten by a grue.
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
About checked exceptions: Let's say method foo throws the checked exception SomeException. You want to call foo from bar, bar from baz, and baz from qux. Then you want to call qux from barbaz and catch SomeException in barbaz. Here you have two options: add "throws SomeException" to bar, baz, qux, and any other method that calls them but doesn't catch SomeException, or put this in bar:
Code:
 
try { foo(); } catch (SomeException e) { throw new RuntimeException(e); }
This misses the point of exception handling. Exceptions exist so you don't have to check for errors everywhere they could possibly occur, but instead you can handle them wherever it makes the most sense. With checked exceptions, you have to toss it from method to method, instead of just throwing it to the method that knows how to catch it.
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
BobTheFerret
Feb 3 2008, 02:13 PM
techwizrd
Feb 3 2008, 02:00 PM
*shudder
Oh, and you also made a typo. Fixed that for you.

TechWizrd
 
On the other hand, if I actually want to be able to read my code, maintain it, and debug it easily, I go with lovely Java.

Now if I want horrible looking spaghetti code, ugly references, forced use of bad code, slow code, and horrible debugging, maintenance problems, I go with *shudder* Python.

For reference, Java is the one that actually *tells* you if you've gotten types incorrect or put arguments in the wrong order; Python is the one where you don't notice until it borks on you at runtime. I can see why you're so hard on Python's "debugging".
Stop misquoting people. It itches.
Edited by Jesin, Feb 3 2008, 04:49 PM.
Offline Profile Quote Post Goto Top
 
Jesin
Member Avatar
The Small Fish
[ * ]
techwizrd
Feb 3 2008, 02:00 PM
Jesin
Feb 3 2008, 01:14 PM
No, you fool. You're thinking in C. When it says \b matches the null string, it means the empty string, as in ''. You don't worry about null values in Python strings unless you're extending it in C. What you're doing matches it if and only if there is a non-alphanumeric character after it and the next two characters after it are is. That means, match the string it if it is part of the string itis and i is a non-alphanumeric character. That won't match anything.
What you're looking for is this:
Code:
 
(it)\s+is
Actually, the computer understands and divides strings like this:"|C| |i|s||a| |g|r|e|a|t| |l|a|n|g|u|a|g|e|\0". It divides every single character and has a null value at the end of a line. This is who the processor knows how the terminating point of a string. I am not thinking in C, I am thinking in terms of how computers parse strings and handle them from a dynamic standpoint. I suggest you go check your facts before you call me a fool.

Anyway, your solution is correct, and I am thankful.

BTW, I still think C is the one of best languages out there. When you need something powerful, portable, and speedy, you use C. I wrote a parser that reads and writes bytes from an EEPROM and executes commands based on custom built scripting language (by me). The processor is 8-bit and we are given 512 bytes of non-volatile memory to use. C is a language not be be underestimated.

On the other hand, if I actually want to be able to read my code, maintain it, and debug it easily, I go with lovely Python.

Now if I want horrible looking spaghetti code, ugly references, forced use of bad code, slow code, and horrible debugging, maintenance problems, I go with *shudder Java.
No, computers do not understand strings as 0-terminated character arrays. Computers do not understand strings at all. Computer programs understand strings.
In Python, you don't think about memory blocks. Also, Python strings are not null-terminated.
Code:
 
>>> 'foo\x00bar'
'foo\x00bar'
>>> 'foo\x00bar' == 'foo'
False
>>> print 'foo\x00bar'
foobar
>>> print 'foo'
foo
See? If you don't believe me, try it.
Yes, I know C is not to be underestimated. I'm just saying that when you see the term "null string" in Python, it doesn't mean what it does in C.
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
BobTheFerret
Feb 3 2008, 02:13 PM
techwizrd
Feb 3 2008, 02:00 PM
*shudder
You didn't close your expression. I can't parse that sentence.

Oh, and you also made a typo. Fixed that for you.

TechWizrd
 
On the other hand, if I actually want to be able to read my code, maintain it, and debug it easily, I go with lovely Python.

Now if I want horrible looking spaghetti code, ugly references, forced use of bad code, slow code, and horrible debugging, maintenance problems, I go with *shudder* Java.

For reference, Java is the one that actually *tells* you if you've gotten types incorrect or put arguments in the wrong order; Python is the one where you don't notice until it borks on you at runtime. I can see why you're so hard on Python's "debugging".
In Python, it does not matter in arguments are in the wrong order. In Python, you don't run into ambiguous situations because of constructors.

In Python:
Code:
 
w = Button(text="bob",fg="#007eff")

Produces the exact same output as:
Code:
 
w = Button(fg="#007eff",text="bob")


Not only is it easier to read, you don't have to define a constructor for each and every possibility.

In Java:

Code:
 
damnConstructor()
{
}
damnConstructor()
{
String text;
String fg;
}
damnConstructor()
{
String fg;
String text
}


Don't get me wrong. I love Java';s naming scheme with the functionName and the ClassName but I hate the syntax, declare and typecast, and the overloading of constructors and classes. It is CONFUSING.
Edited by techwizrd, Feb 3 2008, 06:34 PM.
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Jesin, computers store strings as character arrays that are terminated by null characters. Here is an example. How do text editors know where the lines ends. An EOL character (or CLRF of LF). Strings are terminated by null characters. It woudn't matter anyway, as the original implementation of Python was written in C
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Well, after modifying the source to my ArgueBot, here is the newer code:
BTW, the forum code does not display the indentation
Spoiler: click to toggle


Now, here is a pseudo-intelligent conversation I just had with it:
Spoiler: click to toggle
Edited by techwizrd, Feb 3 2008, 05:34 PM.
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
Go to Next Page
« Previous Topic · General Discussion · Next Topic »
Add Reply