Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!samsung!munnari.oz.au!goanna!ok From: ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) Newsgroups: comp.lang.prolog Subject: Re: making a "call" to a text file Message-ID: <3447@goanna.cs.rmit.oz.au> Date: 20 Jul 90 09:09:32 GMT References: Distribution: comp Organization: Comp Sci, RMIT, Melbourne, Australia Lines: 43 In article , 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)