Mnemonic app. for remembering a lot of phone numbers

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
dhomi
User
Beiträge: 5
Registriert: Freitag 22. September 2006, 14:59

writing a app. for remembering a lot of phone numbers
I want to ask for help on this item:
I want to remember numbers through a system called pseudonumerology, its a mnemonic system to remember numbers through converting the to words (words are easier to remember). It replaces numbers to consonants, and then adds vowels to make real words from it
(look www.pseudonumerology.com)

The system does this:
Convert given number (example: 526) to corresponding letters from the 'Conversion list' below.
The reslut of 526 would be LNX
Then look the LNX through words of a ascii dictionary file (dictionary ascii file which has normal words in it).
We would find the word LiNUX.

Conversion list:
1=t or d
2=n
3=m
4=r
5=l
6=g or x
7=j or k or q
8=v or f
9=p or b
0=s or z

Converting a number like '526' would result on a clean 'LNX',
and after looking in the (ascii) dictionary, we would find words like 'LINUX' to be a good conversion example.

---
About the dictionary:
1. the Ascii Dictionary contains any word (if not all words in a selected language). It doesn't matter how many words, and how many solutions; the user may choose itself which solution may suit him/her.
2. Words must contain all consonants; if not then no solution is showed, or the most close-to-it solution/word.
3. Dictionary will be loaded/read at the start of application (the user could choose which language, as it doesn't matter which language is shown, as long as it shows the result). It will be appreciated if user can add words to dictionary.

---
Well, GUI is always user-friendlier.



So please is there anybody who can do this? It would help me a lot
Thankssssss
Joghurt
User
Beiträge: 877
Registriert: Dienstag 15. Februar 2005, 15:07

dhomi hat geschrieben:So please is there anybody who can do this?
Probably.

What do you pay?
dhomi
User
Beiträge: 5
Registriert: Freitag 22. September 2006, 14:59

Joghurt hat geschrieben:
dhomi hat geschrieben:So please is there anybody who can do this?
Probably.

What do you pay?
No. i want to learn, i want to do this together, so i learn. not for money, it is for everybody GPL
BlackJack

Grab some plain text dictionaries from the net, learn about regular expressions and build a regular expression from the numbers to scan the word list.

Although doing a linear search in the word list might be not optimal, it is a quite easy to implement solution.

Faster would be stuffing the words into some sort of search tree.
CM
User
Beiträge: 2464
Registriert: Sonntag 29. August 2004, 19:47
Kontaktdaten:

dhomi, welcome to the forum, but let me be frank.

Joghurt's answer points in the right direction: All you want is feasible, but jaws lots of time to code. If you would have any idea of what it takes to hack all that together, you wouldn't have asked the way you did. You would have started, started with learning, and everytime you would have encountered a problem you might have taken that very chunk and enquired about that only.
So, why not take BlackJack's advice and start coding? (Though you might want to start with learning Python first, if that didn't happen already. Feel free to ask here in case of particular problems.)

Cheers
Christian
dhomi
User
Beiträge: 5
Registriert: Freitag 22. September 2006, 14:59

Well I did what you proposed.
I am learning the whole day, and doing tests with reg. expressions in Python. It is not so easy, but very very nice.

So far I came with this code, but it is still not working well. It should look vor words with t or d and n. Please help...

Code: Alles auswählen

#! /usr/bin/env python

import re

# Vars
mnemonics = 'tdnmrlgxjkqvfpbsz'
vowels = 'aeiouy'

# Reg. expr.
reg1 = re.compile('\
^([^tdnmrlgxjkqvfpbsz]{0,3}[aeiouy]{0,3}){0,9}\
[t|d]\
([^tdnmrlgxjkqvfpbsz]{0,3}[aeiouy]{0,3}){0,9}\
n\
([^tdnmrlgxjkqvfpbsz]{0,3}[aeiouy]{0,3}){0,9}\
$\
', re.IGNORECASE)

# open the dictionary to read from it
f1 = open("dictionary.txt", "r")

# Search the dict. with the search string
for searchstring in f1.xreadlines():
    search1 = reg1.match(searchstring)
    if search1:
        start1=search1.start()
        print searchstring

[/code]
BlackJack

I think that's a problem with the regular expression.

First and last character is okay, this assures that a whole word is matched and not just a part of the word.

Then there's a grouped expression that can be matched 0 to 9 time which contains 0 to 3 characters that are no mnenonics and 0 to 3 vovels. Can you explain the meaning of this? Or what you had in mind that would match or not match?

Next is ``[t|d]`` wich matches one of the three characters ``t``, ``|`` or ``d``. I'm quite sure you don't want the ``|`` in this character group.

Let's take your 526 example. One could describe a pattern in words this way: starts at beginning of line, zero or more vocals, ``l``, zero or more vocals, ``n``, zero or more vocals, ``g`` or ``x``, zero or more vocals and the end of the line. Zero or more can be expressed by appending a ``*`` to the construct that should be repeated. If you want to have a "one or more" reapeat use a ``+`` instead.

This pattern used on `/usr/share/dict/words` on my system yields:

Lang
Linux
Long
Loyang
ailing
along
laying
linage
lineage
lingo
long
lounge
lung
lunge
lying
lynx
oiling
dhomi
User
Beiträge: 5
Registriert: Freitag 22. September 2006, 14:59

well, that's it! Your 're' works!!! wow...

How did you do it? How does your reg.ex. looks like?
hen there's a grouped expression that can be matched 0 to 9 time which contains 0 to 3 characters that are no mnenonics and 0 to 3 vovels. Can you explain the meaning of this? Or what you had in mind that would match or not match?
OK: it must match any character which is not mnemonic, and as many times (i thought 9 is enough, becouse if used in foreign launguages, maybe it is handy 9, in english is enough 4). Clear?
Next is ``[t|d]`` wich matches one of the three characters ``t``, ``|`` or ``d``. I'm quite sure you don't want the ``|`` in this character group.
OK: it must match a 't' OR 'd' becouse that is one number: 1, which may be 't' or 'd'.


---
Can you help me with the code?
1. We have to ask the user to give a number
2. System will ask the user to choose which dictionary he wants to use (in folder dict)
3. The system will translate it to mnemonics
4. And then give the user the result
Y0Gi
User
Beiträge: 1454
Registriert: Freitag 22. September 2006, 23:05
Wohnort: ja

With Kodos, there is a nice tool to test out regex. Written in Python, of course ;)
Bernhard
User
Beiträge: 136
Registriert: Sonntag 15. Januar 2006, 20:31
Wohnort: Greifswald
Kontaktdaten:

The idea as such is neither bad nor very complicated to code. But what's the point in coding numbers in letters that are equally hard to code back to numbers? Will I have to remember, what letter equals what number?

Usual Phones and all cell phones have letters written on the keys - i. e. "abc" on "2" and "def" on "3" and so on.

I downloaded seven books from gutenberg.org, put them in a directory and called them 01.txt, 02.txt, etc. The following code than extracts suitable words. However, as translations of "1" and "0" are lacking, it doesn't really work out. Telephone-numbers tend to contain "0"s and "1"s Has anybody a good idea to fill that lack?

Code: Alles auswählen

import re

class Mnemo:
    def schaffeRe(self):
        global ausdruck
        schluessel = {
                "2" : "[a|b|c]",
                "3" : "[d|e|f]",
                "4" : "[g|h|i]",
                "5" : "[j|k|l]",
                "6" : "[m|n|o]",
                "7" : "[p|q|r|s]",
                "8" : "[t|u|v]",
                "9" : "[w|x|y|z]"
            }
        eingabe = raw_input("Telefonnummer: ")
        ausdruck = "(?i\A)"
        for ziffer in eingabe:
            if ziffer in schluessel:
                ausdruck += schluessel[ziffer]
        ausdruck += ".*?[\W|\s]"
        print ausdruck
    
    def dateiLesen(self, dateiname):
        global zeilen
        wb = file(dateiname)
        zeilen = wb.readlines()
        wb.close()

    def vergleicheReUndWoerter(self):
        for zeile in zeilen:
            fund=re.findall(ausdruck, zeile)
            if fund <>[]:
                print fund
    
    def __init__(self):
        self.schaffeRe()
        dat =["wb/01.txt","wb/02.txt","wb/03.txt","wb/04.txt",
              "wb/05.txt","wb/06.txt","wb/07.txt"]
        for item in dat:
            self.dateiLesen(item)
            self.vergleicheReUndWoerter()
            print "--"
        print "---"
    
Instanz=Mnemo()
(Ja, ich habe natürlich verstanden, dass Ihr ihm keinen fertigen Code geben wollt. Das habe ich ja auch nicht getan: Er muss noch die Vokale hinzufügen, wenn er den Code für seine Pseudonumerologie verwenden will. )
Gruß,
Bernhard
Y0Gi
User
Beiträge: 1454
Registriert: Freitag 22. September 2006, 23:05
Wohnort: ja

OT: Die deutschsprachigen Bezeichner helfen unserem Englisch schreibenden Threadersteller sicher viel ;)

Oder, um es mit den Worten von PEP 8 zu sagen:
Python coders from non-English speaking countries: please write your comments in English, unless you are 120% sure that the code will never be read by people who don't speak your language.
Daraus lässt sich (ausnahmsweise implizit) entnehmen, dass das erst recht für den eigentlichen Code gilt.
dhomi
User
Beiträge: 5
Registriert: Freitag 22. September 2006, 14:59

Bernhard hat geschrieben:The idea as such is neither bad nor very complicated to code. But what's the point in coding numbers in letters that are equally hard to code back to numbers? Will I have to remember, what letter equals what number?

Usual Phones and all cell phones have letters written on the keys - i. e. "abc" on "2" and "def" on "3" and so on.

I downloaded seven books from gutenberg.org, put them in a directory and called them 01.txt, 02.txt, etc. The following code than extracts suitable words. However, as translations of "1" and "0" are lacking, it doesn't really work out. Telephone-numbers tend to contain "0"s and "1"s Has anybody a good idea to fill that lack?

Code: Alles auswählen

import re

class Mnemo:
    def schaffeRe(self):
        global ausdruck
        schluessel = {
                "2" : "[a|b|c]",
                "3" : "[d|e|f]",
                "4" : "[g|h|i]",
                "5" : "[j|k|l]",
                "6" : "[m|n|o]",
                "7" : "[p|q|r|s]",
                "8" : "[t|u|v]",
                "9" : "[w|x|y|z]"
            }
        eingabe = raw_input("Telefonnummer: ")
        ausdruck = "(?i\A)"
        for ziffer in eingabe:
            if ziffer in schluessel:
                ausdruck += schluessel[ziffer]
        ausdruck += ".*?[\W|\s]"
        print ausdruck
    
    def dateiLesen(self, dateiname):
        global zeilen
        wb = file(dateiname)
        zeilen = wb.readlines()
        wb.close()

    def vergleicheReUndWoerter(self):
        for zeile in zeilen:
            fund=re.findall(ausdruck, zeile)
            if fund <>[]:
                print fund
    
    def __init__(self):
        self.schaffeRe()
        dat =["wb/01.txt","wb/02.txt","wb/03.txt","wb/04.txt",
              "wb/05.txt","wb/06.txt","wb/07.txt"]
        for item in dat:
            self.dateiLesen(item)
            self.vergleicheReUndWoerter()
            print "--"
        print "---"
    
Instanz=Mnemo()
(Ja, ich habe natürlich verstanden, dass Ihr ihm keinen fertigen Code geben wollt. Das habe ich ja auch nicht getan: Er muss noch die Vokale hinzufügen, wenn er den Code für seine Pseudonumerologie verwenden will. )
Gruß,
Bernhard
but this is not what I mean, this is another thing. It is not ok.
Antworten