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

Unread post by mdosnov2016 »

Thank you.
I just recall some statement from the old versions documentation that the facts need to be groupped.
But I had the same facts as now with the old 5.2x version and everything then was OK,
I don't understand why VP8 has a problem with these databases.

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

Unread post by Thomas Linder Puls »

There shouldn't be a problem if the file corresponds to the fact database declaration.

But perhaps the file has an endoding that is not handled correctly. Perhaps you can zip the file and attach it here?
Regards Thomas Linder Puls
PDC
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

I modified a little your code as follows, in order to increment the line counter and then just understand where the error is with my database, however this gives me syntax errors.
Can you please help me with my recursive predicates?

showBadTerms(FN, Line) :-
IS = inputStream_file::openFile(FN),
check_Bad_Terms(FN, Line, IS),
IS:close(),
!.

check_Bad_Terms(_FN, _, IS) :-
IS:endOfStream(), !.

check_Bad_Terms(FN, Line, IS) :-
not(IS:endOfStream()),
S = IS:readLine(),
NLine = Line + 1,
%string::lastChar(S,S2,_), % you must remove the trailing '.'
if Term = tryToTerm(backend_dbase, S) 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, "' line : ", Line)
end if,
check_Bad_Terms(FN, NLine, IS),
!.
PrologUser
Harrison Pratt
VIP Member
Posts: 439
Joined: 5 Nov 2000 0:01

Unread post by Harrison Pratt »

You can use a mutable variable for line counting. See LineNum below.

Remember that VP 5.x database files do NOT have a trailing '.', unlike the VP 7.5 and (I assume) 8.0.

Also, your code will be much easier to read if you use the Code button to format it before posting.

Code: Select all

class predicates     showBadTerms : ( string FileName ). clauses     showBadTerms( FN ):-         LineNum = varm::new(0),         IS = inputStream_file::openFile( FN ),         IS:repeatToEndOfStream(),             S = IS:readLine(),             LineNum:value := LineNum:value + 1,             string::lastChar(S,S2,_),  %  NOTE: there is NO trailing '.' in VP 5.x saved file             if Term = tryToTerm( testDB, S2 ) then                     assert( Term ),                     console::write("\nAsserted : ", Term )                 else                     console::write("\nFailed to assert line #", LineNum:value, "  '", 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, but your code doesn't seem to work.
It gives me the error from the first line of the databse.
I attach here the sample dbase (confidentially).
Michael
Attachments
ITF_FACT.zip
(26.79 KiB) Downloaded 310 times
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

the
S = IS:readLine(),

doesn't work,
further down I added:

console::write(" the fact I read is : ", S),

and I get the attached file terminal output:

Michael
Attachments
screen1.png
screen1.png (85.05 KiB) Viewed 8447 times
PrologUser
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

Your file in in ANSI so you should use
Regards Thomas Linder Puls
PDC
User avatar
Thomas Linder Puls
VIP Member
Posts: 1398
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls »

I can consult your file with this program:

Code: Select all

implement main   class facts - db     type_def : (integer, string, integer, string, integer, string, integer, integer, integer).     op_def : (integer, string, string, integer, integer, integer, integer).     hierarchy_part : (integer, string, integer, string, integer, integer, integer).     data_stmt : (string, string, integer, integer, string, ii).     local_object : (lo).     prog_stmt : (string, integer, integer, integer, integer, integer, integer, integer).     special_op : (string, integer, string, integer, integer, integer, string, integer, integer, integer).     special_dt : (string, integer, string, integer, string, string, ii).     state_node : (sn).     source_is_normal_dt : (string, integer, integer).     last_change_op_number : (string, integer, integer).     change_op_number : (string, integer, integer).     joint_stmt : (string, integer, integer, integer, integer, integer).     cessor : (string, integer, integer).     cessor_kind : (string, string, integer, integer, string, string, integer*).     guard_cond : (string, integer, integer, string).     guard_pair : (string, integer, integer, string).     op_guards : (string, integer, integer*, integer*).     predecessors : (string, integer, integer*).     rec_stmt : (string, integer, integer*).     var_guards : (string, integer, integer*, integer*).   domains     ii =         i(integer);         sym(string);         bit_wire(string).     lo = local_object(string, integer, string, string, integer, string, string, integer, ii).     sn = state_node(string, integer, cc).     cc =         dataflow(integer*, integer);         ifthen(integer*, integer*, integer*, integer, integer);         jump(integer*, integer).   clauses     run() :-         file::consult(@"..\ITF_FACT.DBA", db).   end implement main   goal     console::runUtf8(main::run).
Regards Thomas Linder Puls
PDC
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

Dear Thomas I am doing exactly the same as you,
and showBadTerms proceeds ok until the middle of local_object(local_object( facts (it asserts them ok)
but then sunddenly it interrupts and issues error: invalid handle.

I also tried the same dba file with fullstops (.) at the end of each line, and I get again the same
error.

I will send you confidentially the class facts portion and the goal portion of my project to look at,
and tell me if I am doing something wrong.
PrologUser
mdosnov2016
VIP Member
Posts: 73
Joined: 19 Nov 2016 7:58

Unread post by mdosnov2016 »

I did some restructuring and it seems that consult is working OK now.
thanks,
Michael
PrologUser
Post Reply