Discussions related to Visual Prolog
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

facts database in vp8

Unread post by mdosnov2016 »

hi all.
I have migrated project which I am trying to compile with version 8.

Inside the code the following facts database exists:

Code: Select all

implement backend %    open fileSelector, core     class facts - backend_dbase ...    end backend_dbase clauses
where I get a syntax error: error c150 : Syntax error

how do I declare in vp8 the ending of my facts database?
Have I used the wrong facts header?

Best regards,
Michael Dossis
PrologUser
Vitaly Markov
Active Member
Posts: 40
Joined: 30 Nov 2003 0:01

Unread post by Vitaly Markov »

It is not necessary to specify the database end:

Code: Select all

implement backend % open fileSelector, core class facts - backend_dbase ...   clauses
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

how do we implement external database fact loading (with consult) in vp8?

I tried with class facts ... but it doens't work.
I need a way to specify the syntax of the external file facts and a mechanism to refer to them
internally in my program.

Michael Dossis
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

for example in my program I have the following structure:

Code: Select all

class backend       open resourceIdentifiers  domains      file = input; output; specials_file; scr;             keyboard();%standard functor             screen();  %standard functor             stdin();   %standard functor             stdout();  %standard functor             stderr().  %standard functor    hdlform = string.  tool = string.         local_object  = (string,                                    integer,                                  string,                                string,                                    integer,                                  string,                                string,                                                                          integer,                                  value).       ...   predicates    ...   append_local : (local_list, local_object, local_list)  % i, i, o  determ (i,i,o)  nondeterm(i,i,i).   ...     end class backend

Code: Select all

implement backend     class facts - backend_dbase          local_object : (string,           % module name           integer,           % object's order number in DATA_TABLE, or special data list           string,           % local_kind ...: signal, variable, constant, par_in, par_out, par_inout           string,           % object's name           integer,           % order number in the tables (0 if none)           string,           % local_type: object's type           string,           % type_kind: standard library, or user-defined           % array or user-defined record           integer,           % object's size in bits           value).       local_list : backend::local_object*.   ...   clauses   ...    add_local(In_llist, Local_object, Out_llist) :-   Local_object = local_object(_,_,_,Name,_,_,_,_,_),   not(name_member_local(Name, In_llist)),   append_local(In_llist, Local_object, Out_llist), !. ...   <and some other predicates that use local_object>
with the above structure I get errors like:

Type Action Description Filename Path
e504 The expression has type 'backend::backend_dbase', which is incompatible with the type '(::string, ::integer, ::string, ::string, ::integer, ::string, ::string, ::integer, backend::value) procedure' backend.pack

--------------------------------------------------------------------------

what I am doing wrong?

I declare the types (domains) then the predicates that use them
and then in the implementation (as vp8 recommends) the facts database and
the predicate clauses.

What is wrong with that?

How else can I declare the facts' domains and later the facts to be loaded from external
database file?

Michael Dossis
PrologUser
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

The domain

Code: Select all

 
Defines a predicate domain: values of type local_object are predicates, not functor values/records.

If you want to define a functor domain you must add a functor name:

Code: Select all

 
It will however not be the same kind of funtor-values that you have in the fact database.

If your intension is to store "elements" in the local_object fact and have the same kind of "elements" in the local_list.

Then this is the structure for it:

Code: Select all

class backend ... domains     local_object = local_object(string, integer, ..., value). ... end class backend   implement backend ... class facts - backend_dbase     local_object_fact : (local_object LocalObject).     local_list : local_object* := []. ... end implement backend
I have called the fact local_object_fact to avoid confusion with the local_object functor from the domain. They do not have to be different, but since they are different things intended to be used in the same context I will suggest different names.

The asserts will now have to levels:

Code: Select all

assert(local_object_fact(local_object("Val", 17, ...)))
Regards Thomas Linder Puls
PDC
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

thank you Thomas,
and what is the correct syntax of the consult call to load these facts from external file database?

Michael
PrologUser
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

A fact database can be saved to any outputStream, and consulted from any inputStream.

So there are many possible ways to do this. But you will most likely want to use file::consult. You can see it used in the Fundamental Visual Prolog tutorial (which is currently being discussed in another thread).
Regards Thomas Linder Puls
PDC
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

Hi,
as with your previous instructions I have:

Code: Select all

implement backend ...   class facts - backend_dbase ...   and later towards the global goal, I have the call:   ...   file::consult("ITF_FACT.DBA", backend_dbase), ...
and when I debug and/or run I get at this point:

error: invalid handle

can anybody give me the correct format for this call?

thanks,
Michael
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

Dear all,

I have been using the call:

Code: Select all

file::consult("ITF_FACT.DBA", backend_dbase),
with various ITF_FACT.DBA files from different applications but coherent all to the facts database declarations.

I 've notice that for some, relatively small applications there is no problem with this consult predicate
call, but for larger files I receive a strange:

...bad handle ...

error message.

when I experiment with the facts files and cut them short then they pass without any problems.
I am suspecting that there is a file size limit with the file::consult version.

Does anybody know of any other calls that can do the same with file::consult and without the
database size limit?

thank you,
Michael
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

How big is your file ITF_FACT.DBA ?
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

the biggest I tried with is 500 Kbytes text with 5000 lines of facts (1 fact per line).

Michael
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Then it's certainly not just the size of your file -- that is not beyond the capacity of VIP.

If an edited truncated file can be consulted then probably there is a problem in the structure of the larger file.

I can't explain the error message unless you are trying to consult some sort of handle into the database.
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

Here is an approach you might try to see if you have ill-formed facts in your data file. I don't know about VP 8.0, but it works in 7.5.

Below is a tiny console application that (optionally) creates a tiny data file and then tries to read it back into the database.

* Run the application and enter Y to Create new database file?.
* Next edit MyTestFile.txt with Notepad. Change one of the lines to an invalid form, for example, change i(22). to i("22").
* Then run the program again, answering N to creating a new database and you'll see the bad lines displayed. You will notice that "clauses" is always displayed, as is the leading UTF byte-order mark header which looks line an empty line.

Code: Select all

class facts - testDB     i : ( integer ). clauses     run() :-         TestDbName = "MyTestFile.txt",         console::write("Create new database file? (y/n):"),         if string::toUpperCase(console::readLine()) = "Y"  then             retractFactDb( testDB ),             assert( i(1) ),             assert( i(22) ),             assert( i(333) ),             file::save( TestDbName, testDB ),             console::write("\nCreated new database file named: ", TestDbName )         end if,         retractFactDb( testDB ),         console::write("\nReading database file: ", TestDbName ),         showBadTerms( TestDbName ),         console::write("\nTest completed"),         console::readChar() = _C.           class predicates             showBadTerms : ( string FileName ).         clauses             showBadTerms( FN ):-                 IS = inputStream_file::openFile( FN ),                 IS:repeatToEndOfStream(),                     S = IS:readLine(),                     string::lastChar(S,S2,_),  % you must remove the trailing '.'                     if Term = tryToTerm( testDB, S2 ) then                             % NOTE: you can try to convert a string to ANY fact term                             % in the database and then assert it                             assert( Term ),                             console::write("\nAsserted : ", Term )                         else                             console::write("\nFailed to assert line '", S , "'")                     end if,                     IS:endOfStream(),                 IS:close(), !.             showBadTerms( FN ):-                 stdio::write("\nAbnormal exit in ", predicate_fullname(), " reading ", FN ).
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

thank you Harrison,

what about if I have multiple different types of facts (and not just i(integer))?
can they be intermixed in order in the database file?

Michael
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

It doesn't seem to matter how many or what variety of facts you have in the database. :-)
Post Reply