[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 385
  • Last Modified:

parsing in prolog

I am having a difficult time to create a parser in prolog that will allow me to do this:

say I have a database of vowels:

vowel(a).
vowel(i).
vowel(u).
vowel(e).
vowel(o).

I want to create a function called match([vowel], [.....]). The dotted lines means that it's a  list of characters that will be tested if they are vowels or not. The function will return true if the entire character list contains one or more vowels found in the database. An example of an complex expression:

match([vowel], [e,e,e])

will result in:

true?;
true?;
true?;
no

notice that it returns true three times as vowel can match one or more vowels.. it can match [e]. [e,e] and [e,e,e]. I am having a difficult time coding it... can someone please help me out?

another example to make it much clear:

match([vowel], [e,e,k])

results in:

true?;
true?;
no

one other thing to consider is that I will have another patttern as well besides vowel, one of them is called cons1, which matches exactly one consonant.. we can combine both patterns, vowel and cons1. As an example:

match([vowel, cons1], [a,e,e,k]), will return:

true?;
no


that's the part where I am confused at... so far my code is

which works if pattern is only vowel, but if you put vowel and cons1 (i.e. like the example above) it doesn't work.. that's where I need help I think..
prefix_match([vowel|T], [H|_] ) :- vowel(H).
prefix_match([vowel|T], [H|T1] ) :- vowel(H), prefix_match([vowel|T], T1).

Open in new window

0
kuntilanak
Asked:
kuntilanak
1 Solution

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now