abstraction of the column names (classes)

  • Thread starter Wiebke Pätzold
  • Start date
W

Wiebke Pätzold

Hi all!

I create a database that contains a table. 'Nachname' is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in 'Nachname'. 'ra' takes place within a word. This is solved with
regular expression. So that I can limit my search.
For example: I can search for 'ra' and it is not relevant wich letters
follow or wich letters are in front of 'ra'.
Now I want to abstract the column name 'Nachname'. So I search in an
unknown column. Only the user of the program should determine in wich
class the search takes place. This input should happen in the view
lines of testing the class.
My task is it to change the program that a abstraction of the column
names takes place.
Please give me a detailed answer. If it is possible the changed
program because I am very new in Python and I am orientationless.

This is the program

import sys
import Mk4py
import re

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

class PatternFilter:
def __init__(self, pattern):
self.pattern = re.compile(pattern)

def __call__(self, row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return self.pattern.search(nachname)is not None

vf = vw.filter(PatternFilter("ra.*"))

for r in vf:
print vw[r.index].Nachname
 
P

Peter Abel

Wiebke Pätzold said:
Hi all!

I create a database that contains a table. 'Nachname' is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in 'Nachname'. 'ra' takes place within a word. This is solved with
regular expression. So that I can limit my search.
For example: I can search for 'ra' and it is not relevant wich letters
follow or wich letters are in front of 'ra'.
Now I want to abstract the column name 'Nachname'. So I search in an
unknown column. Only the user of the program should determine in wich
class the search takes place. This input should happen in the view
lines of testing the class.
My task is it to change the program that a abstraction of the column
names takes place.
Please give me a detailed answer. If it is possible the changed
program because I am very new in Python and I am orientationless.

This is the program

import sys
import Mk4py
import re

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

class PatternFilter:
def __init__(self, pattern):
self.pattern = re.compile(pattern)

def __call__(self, row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return self.pattern.search(nachname)is not None

vf = vw.filter(PatternFilter("ra.*"))

for r in vf:
print vw[r.index].Nachname

RegEx are really great and there are a lot of problems you can
only solve with them. But if I understand you right your problem
is to find a string where a substring is to be in, the simple
string operation does the work:
if String.find(substring) > -1:

**find** will give you the position in String where substring
will occure the 1rst time and -1 if substring doesn't occur.

e.g.
nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller']
for name in nameList:
.... if name.find('er')>-1:
.... print name
....
Meyer
Mueller
So if you can get your columns contents in **ColumnList**
and your searchpattern in **SearchPattern** so the following
function could do the work:

def getPatternMatches(ColumnList,SearchPattern):
foundList=[]
for n in ColumnList:
if n.find(SearchPattern) > -1:
foundList.append(n)
return foundList

Regards
Peter
 
W

Wiebke Pätzold

Wiebke Pätzold said:
Hi all!

I create a database that contains a table. 'Nachname' is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in 'Nachname'. 'ra' takes place within a word. This is solved with
regular expression. So that I can limit my search.
For example: I can search for 'ra' and it is not relevant wich letters
follow or wich letters are in front of 'ra'.
Now I want to abstract the column name 'Nachname'. So I search in an
unknown column. Only the user of the program should determine in wich
class the search takes place. This input should happen in the view
lines of testing the class.
My task is it to change the program that a abstraction of the column
names takes place.
Please give me a detailed answer. If it is possible the changed
program because I am very new in Python and I am orientationless.

This is the program

import sys
import Mk4py
import re

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

class PatternFilter:
def __init__(self, pattern):
self.pattern = re.compile(pattern)

def __call__(self, row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return self.pattern.search(nachname)is not None

vf = vw.filter(PatternFilter("ra.*"))

for r in vf:
print vw[r.index].Nachname

RegEx are really great and there are a lot of problems you can
only solve with them. But if I understand you right your problem
is to find a string where a substring is to be in, the simple
string operation does the work:
if String.find(substring) > -1:

**find** will give you the position in String where substring
will occure the 1rst time and -1 if substring doesn't occur.

e.g.
nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller']
for name in nameList:
... if name.find('er')>-1:
... print name
...
Meyer
Mueller
So if you can get your columns contents in **ColumnList**
and your searchpattern in **SearchPattern** so the following
function could do the work:

def getPatternMatches(ColumnList,SearchPattern):
foundList=[]
for n in ColumnList:
if n.find(SearchPattern) > -1:
foundList.append(n)
return foundList

Regards
Peter

I think you didn't understand me. My task is:
I have a database that consists of a tabla with different columns. The
program should have two possibilities to search for regular
expressions. The firat one possibility is in this program. Here I can
look for a certain expression. In my example I can look for 'ra' and
it is not relevant wich letters follow or wich letters are in front of
'ra'. But this search can ONLY takes place in the column 'Nachname'.
'Nachname is fixed by the programmer.
The second possibility is that the user and NOT the programmer
determine the column name in which the user want to look for a regular
expression. And so I think there must be anything with a print. Only
like that the user can enterin what column the search takes place.
 
W

Wiebke Pätzold

Wiebke Pätzold said:
Hi all!

I create a database that contains a table. 'Nachname' is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in 'Nachname'. 'ra' takes place within a word. This is solved with
regular expression. So that I can limit my search.
For example: I can search for 'ra' and it is not relevant wich letters
follow or wich letters are in front of 'ra'.
Now I want to abstract the column name 'Nachname'. So I search in an
unknown column. Only the user of the program should determine in wich
class the search takes place. This input should happen in the view
lines of testing the class.
My task is it to change the program that a abstraction of the column
names takes place.
Please give me a detailed answer. If it is possible the changed
program because I am very new in Python and I am orientationless.

This is the program

import sys
import Mk4py
import re

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

class PatternFilter:
def __init__(self, pattern):
self.pattern = re.compile(pattern)

def __call__(self, row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return self.pattern.search(nachname)is not None

vf = vw.filter(PatternFilter("ra.*"))

for r in vf:
print vw[r.index].Nachname

RegEx are really great and there are a lot of problems you can
only solve with them. But if I understand you right your problem
is to find a string where a substring is to be in, the simple
string operation does the work:
if String.find(substring) > -1:

**find** will give you the position in String where substring
will occure the 1rst time and -1 if substring doesn't occur.

e.g.
nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller']
for name in nameList:
... if name.find('er')>-1:
... print name
...
Meyer
Mueller
So if you can get your columns contents in **ColumnList**
and your searchpattern in **SearchPattern** so the following
function could do the work:

def getPatternMatches(ColumnList,SearchPattern):
foundList=[]
for n in ColumnList:
if n.find(SearchPattern) > -1:
foundList.append(n)
return foundList

Regards
Peter

I forgot something:
The user must have the choice between a special search in a concrete
split and a search in all columns. The user have to determine wich
search method is used.
 
W

Wiebke Pätzold

Wiebke Pätzold said:
Hi all!

I create a database that contains a table. 'Nachname' is one of 13
column names. This program can search for
a special letter. In my example it is 'ra'. and the search takes place
in 'Nachname'. 'ra' takes place within a word. This is solved with
regular expression. So that I can limit my search.
For example: I can search for 'ra' and it is not relevant wich letters
follow or wich letters are in front of 'ra'.
Now I want to abstract the column name 'Nachname'. So I search in an
unknown column. Only the user of the program should determine in wich
class the search takes place. This input should happen in the view
lines of testing the class.
My task is it to change the program that a abstraction of the column
names takes place.
Please give me a detailed answer. If it is possible the changed
program because I am very new in Python and I am orientationless.

This is the program

import sys
import Mk4py
import re

db = Mk4py.storage("c:\\datafile.mk",1)
vw = db.view("people")

class PatternFilter:
def __init__(self, pattern):
self.pattern = re.compile(pattern)

def __call__(self, row):
try:
nachname = row.Nachname
except AttributeError:
return 0
return self.pattern.search(nachname)is not None

vf = vw.filter(PatternFilter("ra.*"))

for r in vf:
print vw[r.index].Nachname

RegEx are really great and there are a lot of problems you can
only solve with them. But if I understand you right your problem
is to find a string where a substring is to be in, the simple
string operation does the work:
if String.find(substring) > -1:

**find** will give you the position in String where substring
will occure the 1rst time and -1 if substring doesn't occur.

e.g.
nameList=['Meyer', 'Maxon', 'Johnson', 'Mueller']
for name in nameList:
... if name.find('er')>-1:
... print name
...
Meyer
Mueller
So if you can get your columns contents in **ColumnList**
and your searchpattern in **SearchPattern** so the following
function could do the work:

def getPatternMatches(ColumnList,SearchPattern):
foundList=[]
for n in ColumnList:
if n.find(SearchPattern) > -1:
foundList.append(n)
return foundList

Regards
Peter

there is another problem too. I have NOT a string. Ihave a TABLE.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top