[comp.lang.prolog] making a "call" to a text file

eiverson@nmsu.edu (Eric Iverson) (07/20/90)

I am working with a very large text file of dictionary definitions in
prolog format.  What I would like to do is write a routine that does a
virtual call without actually consulting the file.  That is to say, I
would like to somehow just get the term I want from the file and unify
it with a prolog variable.

This obvious thing to do is a simple: read(Stream,Functor(Var1,...VarN)).
However, while this works, it is far too slow for multiple queries.
Is there something that could be implemented under grep or sed or lex
that would do the same thing?

Below is a sample of what I am trying to call:

int(play(v,12),
     [[genera,
         [[ancestor, [perform(v,1)]]]],
      [differentia,
         [[source,
             [[preference,
                 [[agent, [human_being(n,1)]],
                  [object, [music(n,1)]]]],
              [assertion,[]]]],
          [target, []]]]]).

adjective(green,[green(aj,1),green(aj,2),green(aj,3)]).

int(green(aj,1),
     [[genera,
         [[superproperty, [coloured(aj,1)]],
          [property, [green(n,1)]]]],
      [differentia,
         [[source,
             [[preference,
                 [[object, 
                     [[bounds(n,1), [bounded(aj,1)]],
                      [extent(n,1), [[not(aj,1),zero_dimensional(aj,1)]]],
                      [composition(n,1), [physical(n,1)]],
                      [animacy(n,1), [nonliving(aj,1)]]]]]],
              [assertion,
                 [[object, 
                     [[colour(n,1), [green(aj,1)]]]]]]]],
          [target, []]]]]).
--
------------------------------------------------------------------------
Eric Iverson				Internet: eiverson@nmsu.edu
Computing Research Lab
Box 30001/3CRL				Life is something to do when
New Mexico State University		you can't get to sleep.
Las Cruces, NM 88003-0001			-Fran Lebowitz
(505) 646-5711

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (07/20/90)

In article <EIVERSON.90Jul19123922@aigyptos.nmsu.edu>, eiverson@nmsu.edu (Eric Iverson) writes:
> I am working with a very large text file of dictionary definitions in
> Prolog format.  What I would like to do is write a routine that does a
> virtual call without actually consulting the file.

> However, while [read] works, it is far too slow for multiple queries.
> Is there something that could be implemented under grep or sed or lex
> that would do the same thing?

I'm puzzled.  If you want to get the thing into Prolog, what good is
it going to do you to use grep?

Have you tried building an index
	term_at(Term, StreamPosition).
where the Term recorded in the index is an abstraction of the term in the
file?  You might even build a multi-level index.  If the terms in the file
look like
> int(play(v,12), ...

you might build an index like
	term_at(int(X,_), Pos) :-
		term_at_int(X, Pos).
	...
	term_at_int(play(X,_), Pos) :-
		term_at_int_play(X, Pos).
	...
	term_at_int_play(v, /* the position where the term 
				int(play(v,_),_) starts in the file */).

and you would do
	term_from_file(Term) :-
		file_stream(Stream),
		term_at(Term, Pos),
		stream_position(Stream, _, Pos),
		read(Stream, Term).

you *would* have to compile the index file, but that would presumably
be rather smaller than the file as a whole.

(By the way, the example shown looked as though it was over-using lists.)
-- 
Science is all about asking the right questions.  | ok@goanna.cs.rmit.oz.au
I'm afraid you just asked one of the wrong ones.  | (quote from Playfair)

lee@munnari.oz.au (Lee Naish) (07/23/90)

In article <EIVERSON.90Jul19123922@aigyptos.nmsu.edu> eiverson@nmsu.edu (Eric Iverson) writes:
>
>I am working with a very large text file of dictionary definitions in
>prolog format.  What I would like to do is write a routine that does a
>virtual call without actually consulting the file.
>
>Below is a sample of what I am trying to call:
>
>int(play(v,12),
>     [[genera,
>         [[ancestor, [perform(v,1)]]]], ....

Some Prolog systems (eg, NU-Prolog) allow you to store Prolog facts in
external databases, where they can be accessed reasonably efficiently
(by just calling the predicate).

The advantages, compared with the scheme outlined by Richard, are
less main memory is needed for large databases, the indexing is more
flexible, updates are supported, its more transparent, joins of
database relations might be much faster, ....

Disadvantages are its less portable, it requires more disk space, it may
be slower (depending on overheads, indexing schemes and cache strategies
used), it uses more main memory for small databases, ....

	lee