(DEFINE-FUNCTION Score-per-model (query model background &KEY (use-boundary NIL)) "(SCORE-PER-MODEL query model background-model [USE-BOUNDARY t | NIL]) - Calculates the fit of a query string relative to the given Markov models - A positive score indicates that the first model predicts the query better - A negative score indicates that the second model predicts the query better - A score of zero indicates that both models are equally predictive - The model may be constructed using HAMLET - The background model may be constructed using BACKGROUND-MODEL - If USE-BOUNDARY is set to T then the boundaries of the training set texts are considered " (LET* ((order (ORDER-OF-MODEL model)) (boundary-char (CODE-CHAR 255)) (boundary (MAKE-STRING order :INITIAL-ELEMENT boundary-char)) (bounded-query (IF-TRUE use-boundary THEN (CONCATENATE 'STRING boundary query) ELSE query)) ) (FOR-EACH start FROM 1 TO (- (LENGTH bounded-query) order 1) WITH total-p = 1 AS end = ************** AS key = ************** AS target = (GET-STRING-ELEMENT (+ end 1) FROM bounded-query) AS p-markov = (VALUE-OF ************** AS p-bg = (VALUE-OF ************** AS ratio = NIL DO (IF-FALSE (NUMBERP p-markov) THEN (DISPLAY-LINE "'" key target "' not found.") (ASSIGN p-markov = 0)) (ASSIGN ratio = ************** (ASSIGN total-p = ************** FINALLY (RETURN (IF-TRUE (> total-p 0) THEN (LOG10 total-p) ELSE total-p)))))