Pattern matching psuedocode for multiple patterns
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Pattern matching psuedocode for multiple patterns

  1. #1
    Join Date
    Nov 2017
    Posts
    3

    Pattern matching psuedocode for multiple patterns

    Hi,
    I am trying to write a psuedocode for finding five words in a list from a text pattern that whether they exist in the text or not and if they do write their count and occurrences. I have written a psuedocode based on na´ve pattern search algo but the problem is it only finds single pattern in a string not a list of words. how can I do that?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    18,995

    Re: Pattern matching psuedocode for multiple patterns

    Could you show your pseudocode together with the text pattern so we could see how it works with a single pattern in a string but not with a list of words?
    Victor Nijegorodov

  3. #3
    Join Date
    Nov 2017
    Posts
    3

    Re: Pattern matching psuedocode for multiple patterns

    Option 2: Word Search Algorithm

    Initialize a List of five patterns (3-6 max characters) to be matched As string:
    List= {p1, p2, p3, p4, p5}
    P1= “red”
    P2= “blue”
    P3= “white”
    P4= “grey”
    P5= “green”
    Initialize a Long Text string (30 max characters) from which patterns to be matched As string:
    T =“vuvyefdarednnjpinkvhsgree”

    BEGIN WordSearch (T, list)
    Set n to length of T ​ //Length of Long Text
    Set s to shift_index //When mismatch occurs, shift moves position right
    Select first pattern p1 from list
    While (list is not full)
    ​Set m to length of pattern P
    For s= 0 to n-m //Iterate n-m number of times
    ​​​​//Initialize a counter up to length of pattern m
    ​​​Set counter to 0
    ​ ​​//Initialize an occurrence of each pattern for total number of times
    ​​​Set occurrence to 0
    ​​​For i = 0 to m //iterate to the length of the pattern word
    //match corresponding characters of two strings
    If (P [i] == T [s+i]) then
    ​​​​increment counter
    ​​​​end if
    ​​​If counter == m then //All characters of a pattern word are matched
    Print “String contains the pattern at location” + s
    increment occurrence
    end if
    ​​next s
    Print “No of times pattern occurs” + occurrence
    move to next pattern
    ​end while
    END.

  4. #4
    Join Date
    Nov 2017
    Posts
    3

    Re: Pattern matching psuedocode for multiple patterns

    Thats what i have made, does it make sense?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)