• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

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