From grossd@ibm.net  Tue Mar  7 16:03:18 2000
Received: from mail2.rdc3.on.home.com (mail2.rdc3.on.home.com [24.2.9.41])
	by swi.psy.uva.nl (8.9.3/8.9.3) with ESMTP id QAA22146
	for <prolog@swi.psy.uva.nl>; Tue, 7 Mar 2000 16:03:14 +0100 (MET)
Received: from cr889345-a.yec1.on.wave.home.com ([24.114.56.22])
          by mail2.rdc3.on.home.com (InterMail v4.01.01.00 201-229-111)
          with SMTP
          id <20000307150328.TPVT11289.mail2.rdc3.on.home.com@cr889345-a.yec1.on.wave.home.com>
          for <prolog@swi.psy.uva.nl>; Tue, 7 Mar 2000 07:03:28 -0800
Received: by localhost with Microsoft MAPI; Tue, 7 Mar 2000 09:59:49 -0800
Message-ID: <01BF881B.E05318E0.grossd@ibm.net>
From: Daniel Gross <grossd@ibm.net>
Reply-To: "gross@fis.utoronto.ca" <gross@fis.utoronto.ca>
To: "'Prolog list'" <prolog@swi.psy.uva.nl>
Subject: parsing a file ...
Date: Tue, 7 Mar 2000 09:59:48 -0800
X-Mailer: Microsoft Internet E-mail/MAPI - 8.0.0.4211
Encoding: 57 TEXT

Hi all,

The soution i've come up with in order to parse an atom made out of a comma 
list of items is the following:

It is assumed that after each comma there is a space. e.g. 'one, two, 
three, four''


parseAtoms(Atom,List) :-
        splitAtom(Atom,Atom1,Atom2),
        Atom2 \== '',
        parseAtoms(Atom2,List2),
        append([Atom1],List2,List).

parseAtoms(Atom,[Atom]).

splitAtom(Atom1,Atom2,Atom3) :-
        name(Atom1,List),
        nth1(P,List,44),
        P1 is P - 1,
        P2 is P + 2,
        string_length(List,Length),
        P3 is Length - P2 + 1,
        substring(List,1,P1,Atom2S),
        substring(List,P2,P3,Atom3S),
        string_to_atom(Atom2S,Atom2),
        string_to_atom(Atom3S,Atom3).

an interesting "feature" of the solution is that it produces a set of 
solutions:

parseAtoms('one, two, three', List).

List = [one, two, three] ;

List = [one, 'two, three'] ;

List = ['one, two', three] ;

List = ['one, two, three'] ;


Its quite a "brute force" way -- to convert the atom to a string and search 
for comma occurences, but i havent' seen a different approach to parse 
atoms. This parsing is used as the basis for parsing such comma lists in 
the text file of "frames" mentioned in the previous posting, into prolog 
facts.


commens are naturally appreciated

Daniel

ps. Is there a way to compose an input stream of characters into facts of 
words, phrases and sentences (i.e. a grammar represented as facts of list 
items ).

