#
# KEHOME/bin/cycprint
# Sep/12/2003

# print OpenCyc answers to MKR questions and statements
# input format: one MKR proposition per line
#	subject predicate object;
# CycL output format: one bind list per line
#	(((?x . x1)) ((?x . x2)) ... )
# final output format: one concept per line, sorted
#	xi
#	...
#
# usage:
#	cycprint world
#	subject predicate object
#	...
#	EOF
#
# predicate ::=
#	MKR verb
#	CycL predicate
# MKR verb ::=  # see KEHOME/bin/mkr2cyc for complete list
#	isa	# CycL genls and isa
#	iss	# CycL genls
#	isu	# CycL isa
#	isc	# CycL specs and instances
#	isg	# CycL specs
#	isp	# CycL instances
#	genlmt	# CycL #$genlMt
#	specmt	# inverse #$genlMt
#
#	isa*	# CycL all-genls and all-isa
#	iss*	# CycL all-genls
#	isu*	# CycL all-isa
#	isc*	# CycL all-specs and all-instances
#	isg*	# CycL all-specs
#	isp*	# CycL all-instances
#	genlmt*	# CycL #$genlMt
#	specmt*	# inverse #$genlMt
#
#	...
#
# Notes:
#	input CycL constant '#$name' requires single quotes
#	to prevent shell from treating it as comment
#	and/or substituting for $name
#
# Examples:
#	'#$Microtheory' isg ?mt;
#	'#$Person' isa* ?genus;
#	?mt genlmt '#$BaseKB';

(
sleep 10				# wait for opencyc startup
while read subject predicate object; do
    echo "$subject $predicate $object"	# MKR proposition
done
echo 'exit;'				# exit opencyc
)			 |
mkr2cyc -q		 |  # translate MKR proposition to CycL expression
opencyc server "$1" 2>&1 |  # query/assert OpenCyc KB
#cat			    # for debugging
#cyclist2column		    # convert CycL list to sorted column
 cycbind2column		    # convert CycL bind list to sorted column

#