abstraction of the column names (classes)

Discussion in 'Python' started by Wiebke Pätzold, Aug 5, 2003.

  1. 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
     
    Wiebke Pätzold, Aug 5, 2003
    #1
    1. Advertising

  2. Wiebke Pätzold

    Peter Abel Guest

    Wiebke Pätzold <> wrote in message news:<>...
    > 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
     
    Peter Abel, Aug 5, 2003
    #2
    1. Advertising

  3. On 5 Aug 2003 14:00:23 -0700, (Peter Abel) wrote:

    >Wiebke Pätzold <> wrote in message news:<>...
    >> 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.
     
    Wiebke Pätzold, Aug 6, 2003
    #3
  4. On 5 Aug 2003 14:00:23 -0700, (Peter Abel) wrote:

    >Wiebke Pätzold <> wrote in message news:<>...
    >> 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.
     
    Wiebke Pätzold, Aug 6, 2003
    #4
  5. On 5 Aug 2003 14:00:23 -0700, (Peter Abel) wrote:

    >Wiebke Pätzold <> wrote in message news:<>...
    >> 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.
     
    Wiebke Pätzold, Aug 6, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    2
    Views:
    568
  2. Ben
    Replies:
    4
    Views:
    377
  3. Stefano
    Replies:
    0
    Views:
    318
    Stefano
    Oct 13, 2003
  4. Martin Burger
    Replies:
    0
    Views:
    856
    Martin Burger
    Jul 18, 2005
  5. JanJaap

    Abstraction levels in xsd

    JanJaap, Jun 7, 2004, in forum: XML
    Replies:
    0
    Views:
    390
    JanJaap
    Jun 7, 2004
Loading...

Share This Page