#!/bin/bash
# Query the AtomSpace matrix learning daemon
# Usage: ./ask-matrix.sh "what is keypair"
# ./ask-matrix.sh /stats
# ./ask-matrix.sh # interactive mode
SOCK="/tmp/atomspace-matrix-learner.sock"
if [ ! -S "$SOCK" ]; then
echo "Matrix daemon not running. Start with: ./start-matrix-learner.sh"
exit 1
fi
send_query() {
python3 -c "
import socket, sys
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect('$SOCK')
s.sendall((sys.argv[1] + '\n').encode())
s.shutdown(socket.SHUT_WR)
data = b''
while True:
chunk = s.recv(4096)
if not chunk: break
data += chunk
print(data.decode(), end='')
s.close()
" "$1"
}
if [ $# -eq 0 ]; then
echo "AtomSpace Matrix Learner (type /help for commands, Ctrl+D to quit)"
echo ""
while IFS= read -r -p "> " line; do
send_query "$line"
echo ""
done
else
send_query "$*"
fi