473,659 Members | 2,680 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Typing tutor help script needed, please


G'day everyone!

I would like to design typing tutor exercises for Afrikaans (and other
languages possibly). This is for a GPL project. For this, I need a
script that can extract words from a long list of words, based on which
letters those words contain, and write then write output to a file.
Does anyone know of an existing script for this, or can anyone write me
one, please?

Preferably I must be able to extract words which contain only certain
letters (they need not contain all of those letters, but they may not
contain any other letters). It would be nice if I can also extract
words which do not contain certain letters.

Any help will be greatly appreciated. I'm on a Windows 2000 machine
with Perl, Python, Tcl/Tk and Java.

Thanks!
Samuel (throw aka voetleuce aka leuce)

Oct 28 '05 #1
4 2068
#---Input data

#List of words; every word or sentence on one line
#If from file: WORDS = open(fileName). readlines()
WORDS = """\
Afrikaans
Anna
Bread
red
word
bored
python""".split ('\n')

#---Main program
import re

PATTERN = ['[^(%s)]+','[%s]+']
FILENAME = ['not_%s.txt','% s.txt']

def filter(letters= 'bdeor',words=W ORDS,contain=Tr ue,ignoreCase=T rue):
pattern = PATTERN[contain]%'|'.join(list( letters))
if ignoreCase:
allowed = re.compile(patt ern,re.IGNORECA SE)
else:
allowed = re.compile(patt ern)
result = []
for word in words:
match = allowed.match(w ord)
if match and match.group(0) == word: result.append(w ord)
print result
output = open(FILENAME[contain]%letters,'w')
output.write('\ n'.join(result) )
output.close()

if __name__ == '__main__':
filter()

---------------
This should do it.

Stani
--
http://pythonide.stani.be
http://pythonide.stani.be/manual/html/manual.html

Oct 28 '05 #2
"Throw" <th***@workmail .co.za> writes:
G'day everyone!

I would like to design typing tutor exercises for Afrikaans (and other
languages possibly). This is for a GPL project. For this, I need a
script that can extract words from a long list of words, based on which
letters those words contain, and write then write output to a file.
Does anyone know of an existing script for this, or can anyone write me
one, please?
This sounds nearly trivial in Python. More specifics would help.
Preferably I must be able to extract words which contain only certain
letters (they need not contain all of those letters, but they may not
contain any other letters). It would be nice if I can also extract
words which do not contain certain letters.


Again, this sounds nearly trivial in Python.

For instance. to get a list of all words that don't contain 'a', you'd
do something like:

f = open(textfile)
words = f.read().split( )
f.close()
selected = [word for word in words if 'a' not in word]

and then selected has the list of words that don't have an 'a' in
them. Tweaking the test the other way - to select words with an 'a',
remove the 'not'. You can combine the tests with 'and' and 'or'.

But without a UI, that's pretty much useless - and you haven't said
what you want the UI to be.

<mike
--
Mike Meyer <mw*@mired.or g> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Oct 28 '05 #3
Throw <th***@workmail .co.za> wrote in comp.lang.perl. misc:

G'day everyone!

I would like to design typing tutor exercises for Afrikaans (and other
languages possibly). This is for a GPL project. For this, I need a
script that can extract words from a long list of words, based on which
letters those words contain, and write then write output to a file.
Does anyone know of an existing script for this, or can anyone write me
one, please?


For the letters a, d, f and g:

perl -ne 'print if /^[adfg]+$/' < /list/of/words > words_with_adfg

For other combinations, change both occurrences of "adfg".

Anno
--
If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
Oct 28 '05 #4
<reinstated the context that was omitted by SPE>
Throw wrote:
I must be able to extract words which contain only
certain letters (they need not contain all of those letters,
but they may not contain any other letters).

SPE - Stani's Python Editor wrote: #---Input data

#List of words; every word or sentence on one line
#If from file: WORDS = open(fileName). readlines()
WORDS = """\
Afrikaans
Anna
Bread
red
word
bored
python""".split ('\n')

#---Main program
import re

PATTERN = ['[^(%s)]+','[%s]+']
FILENAME = ['not_%s.txt','% s.txt']

def filter(letters= 'bdeor',words=W ORDS,contain=Tr ue,ignoreCase=T rue):
pattern = PATTERN[contain]%'|'.join(list( letters))
if ignoreCase:
allowed = re.compile(patt ern,re.IGNORECA SE)
else:
allowed = re.compile(patt ern)
result = []
for word in words:
match = allowed.match(w ord)
if match and match.group(0) == word: result.append(w ord)
print result
output = open(FILENAME[contain]%letters,'w')
output.write('\ n'.join(result) )
output.close()

if __name__ == '__main__':
filter()

---------------
This should do it.


Am I underestimating the task, it looks simple enough for the simplest grep?

# perl -n -e "print if /^[bdeor]+$/i" words.txt
red
bored
Oct 28 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
1229
by: administrata | last post by:
i'm using tutor maling... i e-mail some questions to tutor and get answers. but, i frequently get mails which aren't related with my question. how should i stop it?
2
3513
by: zheenma | last post by:
There is a program that speed up your typing and avoid spelling errors. My friends use it ,their averege is more than 100 wpm. You can download it from www.wamasoft.com. And It has a library for c++. I hope that it can help you!
0
1545
by: Marian Heddesheimer | last post by:
Rent-a-Tutor.com is in search for testers as online-courses students. As operators of rent-a-tutor.com we are proud to offer high quality online courses over the internet at reasonable prices. At the moment, our courses are all available in German. These courses have proven themselves to be very user-friendly and understandable on the German market. So starting January 2006, we will provide them in English as well. All of my courses...
0
1008
by: eric_berlin | last post by:
This probably isn't the best venue for this message, but I am out of ideas. I am looking ASAP for a tutor knowledgable in C# multithreading code to help me with a project I'm working on. $45/hr or more DOE.
0
3121
by: pixtudio | last post by:
I have a problem making a typing tutor program in c.. im using djgpp and running on a windows xp. my problem is that, how can i be able to let the letters/number fall at the same time. example: the rand() function generated the letter a and is now falling on gotoxy(5,1).. now what i want is that while it is falling on (5,1) i want to have another fall at the same time on for example on gotoxy (12,1).. how will i be able to do that?...
2
1342
by: Dameon99 | last post by:
Hi all, I desperately need a C programming tutor to go through some concepts with me live, but preferrably face-to-face. Does anyone know of any tutors in Perth, WA that can go through C programming with me?? --or any other solutions?
2
2071
by: tavspamnofwd | last post by:
Referred here from the tutor list. ---------- Forwarded message ---------- From: Evert Rol Hi Tom, Ok, I wasn't on the list last year, but I was a few days ago, so persistence pays off; partly, as I don't have a full answer.
3
1348
by: biran | last post by:
Hi all, i am realy new in this forum. I need some help please do faver me! actualy, I want to develop typeing tutor software but there is some problem these problems are spelling check if spelling is mistake then immidiatly red color and timer. like: TextBox1 value is "Computer is good" these words will be type on textbox2 please help me out and if some body have c# example or source please help me. your sin...
1
1671
by: eddwinpaz | last post by:
Hi every one and thanks for reading and taking the time to answer this post. my question is how can i make something similar to Gmail Chat does. example Eddwin is typing a message so Michael gets a little text that says myemail@gmail.com is typing a message... how can i do that using ajax and PHP ? so far so good i had user this script and modify it to my requirements. i would like to apply that new feature onto my script. ...
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8525
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8627
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.