FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log inLog in 


facts database in vp8

Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog
View previous topic :: View next topic  
Author Message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 10 Oct 2017 16:27    Post subject: facts database in vp8 Reply with quote

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

Inside the code the following facts database exists:

...
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
Back to top
View user's profile Send private message
Vitaly Markov



Krasnodar, Russia
Joined: 30 Nov 2003
Posts: 75

PostPosted: 10 Oct 2017 19:07    Post subject: Reply with quote

It is not necessary to specify the database end:

implement backend
% open fileSelector, core
class facts - backend_dbase
...

clauses

Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 11 Oct 2017 16:53    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 11 Oct 2017 18:07    Post subject: Reply with quote

for example in my program I have the following structure:

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

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
Back to top
View user's profile Send private message
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3124

PostPosted: 12 Oct 2017 11:20    Post subject: Reply with quote

The domain

domains
    local_object  = (string, integer, ..., value).

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:

domains
    local_object  = functorName(string, integer, ..., value).

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:

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:

assert(local_object_fact(local_object("Val", 17, ...)))


_________________
Regards Thomas Linder Puls
Prolog Development Center
Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 13 Oct 2017 5:55    Post subject: Reply with quote

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

Michael

_________________
PrologUser
Back to top
View user's profile Send private message
Thomas Linder Puls



Copenhagen, Denmark
Joined: 28 Feb 2000
Posts: 3124

PostPosted: 13 Oct 2017 8:03    Post subject: Reply with quote

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
Prolog Development Center
Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 20 Oct 2017 18:28    Post subject: Reply with quote

Hi,
as with your previous instructions I have:

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
Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 21 Oct 2017 17:24    Post subject: Reply with quote

Dear all,

I have been using the call:

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
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 316

PostPosted: 21 Oct 2017 22:55    Post subject: Reply with quote

How big is your file ITF_FACT.DBA ?
Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 22 Oct 2017 12:13    Post subject: Reply with quote

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

Michael

_________________
PrologUser
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 316

PostPosted: 22 Oct 2017 17:28    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 316

PostPosted: 22 Oct 2017 18:26    Post subject: Reply with quote

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.

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 ).

Back to top
View user's profile Send private message
mdosnov2016



Greece
Joined: 19 Nov 2016
Posts: 34

PostPosted: 22 Oct 2017 21:25    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Harrison Pratt



Des Moines, Iowa USA
Joined: 05 Nov 2000
Posts: 316

PostPosted: 22 Oct 2017 21:57    Post subject: Reply with quote

It doesn't seem to matter how many or what variety of facts you have in the database. Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    discuss.visual-prolog.com Forum Index -> Visual Prolog All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum