Re: Detecting the presence of a pattern in an atom

Boris Vassilev <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <CAFw8osKyQPXb-0G7vYnYa3gqYL8BOHMn5_68VBj+SLZ9LUcr5Q@mail.gmail.com>
Not the most experienced programmer here, but anyway:

You can already get quite far with `sub_atom/5` and
`atomic_list_concat/3` (analyzing
and constructing atoms<http://www.swi-prolog.org/pldoc/man?section=manipatom>).
But at the end you will probably need to use DCGs, which is not bad, partly
because they are so explicit.

Once you go that way you would probably end up using `char_type/2` and DCGs
like those defined in
library('dcg/basics')<http://www.swi-prolog.org/pldoc/doc/swi/library/dcg/basics.pl?show=src>.
The library at the moment is quite incomplete but it shows how to approach
something like "a string of upper case letters (chars) up to a delimiter",
for example.

Cheers,
Boris


On Tue, Oct 15, 2013 at 8:18 AM, Steve Prior <[email protected]> wrote:

> This is not a homework problem.
>
> I've been writing code which retrieves a list of titles from a web page
> source and need to do a little pattern matching on each title.  A title
> might look like:
>
> Some name and some business name (ABC)
>
> I'm trying to get the "ABC".
>
> The titles don't have any formal grammar to them, but for starters I need
> to see if there is a substring which starts with '(' contains all upper
> case letters and ends with ')'.  I suppose it's possible that the title
> might contain multiple open/close parens, but I'd expect only one set to
> fit the all upper case criterion.
>
> It seems a bit much to do a DCG grammar for this and I know that a regex
> isn't the Prolog way of doing things, but don't remember what a better
> option would be.  I'm a bit rusty in Prolog, I picked it for this project
> because of SWI's html parsing abilities which I've already put to good use.
>
> Any pointers?
>
> Steve
> ______________________________**_________________
> SWI-Prolog mailing list
> [email protected].**de <[email protected]>
> https://lists.iai.uni-bonn.de/**mailman/listinfo.cgi/swi-**prolog<https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog>
>
-------------- next part --------------
HTML attachment scrubbed and removed
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.