read file and construct facts in prolog

后端 未结 3 749
北荒
北荒 2021-01-23 00:34

I would like to construct a mechanism that constructs different facts depending from txt file, imported in prolog. I already have found some examples where they directly assert

3条回答
  •  醉话见心
    2021-01-23 01:10

    yes - you need to do what you'd do in any other language.

    Open and read the file, parse the contents, and convert into terms that you can then assert.

    Fortunately, you're in prolog, so 'parse the contents' is a task the language does for breakfast.

    It turns out I've been writing a tutorial on how to do pretty much this exact task. It's not quite finished, but is online at

    http://www.pathwayslms.com/swipltuts/dcg/

    If your files are large, use the method described in the tutorial to read them. Otherwise, just bring the file into a 'codes' style string and go on with life.

提交回复
热议问题