;;;; -*- Mode: LISP; Syntax: Common-Lisp; Base: 10 -*- ;;;; --------------------------------------------------------------------------- ;;;; File name: reify-gizmo.lsp ;;;; System: FIRE ;;;; Version: 1.0 ;;;; Author: Jin Yan ;;;; Created: March 8, 2003 18:21:17 ;;;; Purpose: Reification of SME results ;;;; --------------------------------------------------------------------------- ;;;; Modified: Tuesday, August 26, 2003 at 12:11:47 by jinyan ;;;; --------------------------------------------------------------------------- (in-package :fire) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Reifying Gizmo properties into the working memory (defun reify-gizmo (gizmo qp-source) (with-kb (kb qp-source) (let* ((r (reasoner qp-source))) (tell (declare-QpAnalysis gizmo) r :qp :all)))) ;;;(defun make-states-result (source query response context states) ;;; (let* ((binding-list (list (cons (fourth query) ;;; (mapcar 'make-state-reference states)))) ;;; (bound-result (sublis binding-list query))) ;;; ;; Cache result in reasoner ;;; (tell bound-result (reasoner source) :qp-source context) ;;; (list (case response ;;; (:bindings binding-list) ;;; (:pattern (sublis binding-list query)) ;;; (t (sublis binding-list response)))))) ;;;(dolist (state (gizmo::gizmo-states gizmo)) ;;; (reify-state state gizmo qp-source)) (defun reify-states (states qp-source) (with-kb (kb qp-source) (let ((r (reasoner qp-source))) (dolist (state states) (tell (declare-QpState state) r :qp :all) (tell (declare-gizmo-state state) r :qp :all) (tell (declare-state-vs state) r :qp :all) (tell (declare-state-ps state) r :qp :all) (tell (declare-state-ds-values state) r :qp :all) (tell (declare-state-quantities state) r :qp :all) (tell (declare-state-ineqls state) r :qp :all) ;;Ordinal Relations (tell (declare-state-influences state) r :qp :all) ;;; (tell (declare-state-influence-resolution state) r :qp :all) (tell (declare-state-continuity-constraints state) r :qp :all) (tell (declare-state-assumptions state) r :qp :all) (tell (declare-state-status state) r :qp :all))))) (defun reify-transition-states (state qp-source) (with-kb (kb qp-source) (let ((r (reasoner qp-source))) (tell (make-transition-states state) r :qp :all)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Checking syntax of forms (defun QpAnalysisFn? (form &optional (kb *kb*)) (car-is form (if (mixed-case? kb) 'data::QpAnalysisFn 'data::Qp-analysis-fn))) (defun state-fn? (form &optional (kb *kb*)) (car-is form (if (mixed-case? kb) 'data::QpStateFn 'data::Qp-state-fn))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Retrieving Gizmo datastructures (defgeneric gizmo-referent (form reasoner-or-qp-source) (:documentation "Given an expression representing some kind of Gizmo-related entity (such as (QpAnalysisFn 25)), returns the actual Gizmo object that the form refers to. Returns nil if none can be found.")) (defmethod gizmo-referent (form source) ;; default method -- just returns nil (declare (ignore form source)) nil) (defmethod gizmo-referent (form (reasoner reasoner)) (do ((sources (sources reasoner) (cdr sources)) (result nil)) ((or result (null sources)) result) (setq result (gizmo-referent form (car sources))))) (defmethod gizmo-referent (form (qp-source qp-source)) (with-kb (kb qp-source) (cond ((qpAnalysis-fn? form) (lookup-gizmo (cadr form) qp-source)) ((state-fn? form) (lookup-state (cadr form) (third form) qp-source)) (t nil)))) (defun lookup-gizmo (id qp-source) (find id (gizmos qp-source) :key 'gizmo::id)) (defun lookup-state (state-id gizmo-id qp-source) (let ((gizmo (lookup-gizmo gizmo-id qp-source))) (when (typep gizmo 'gizmo::gizmo) (find state-id (gizmo::gizmo-states gizmo) :key 'gizmo::id))))