-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.scm
45 lines (38 loc) · 1.38 KB
/
cleanup.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
;;; -*- Mode: Scheme; Character-encoding: utf-8; -*-
;;; Copyright (C) 2005-2020 beingmeta, inc. All rights reserved.
;;; Copyright (C) 2020-2022 Kenneth Haase ([email protected]).
(in-module 'brico/cleanup)
;;; Looking up terms in BRICO
;;; This module provides utilities and end-user functions for mapping
;;; natural language terms into BRICO concepts.
(use-module 'brico)
(use-module '{texttools reflection engine})
(use-module '{varconfig logger})
(module-export! '{brico/cleanup!})
(define (cleanup-value value)
(cond ((string? value) (trim-spaces value))
((not (oid? value)) value)
((not (table? (oid-value value)))
(if (and (exists? (getpool value)) (getpool value))
(fail)
value))
((test value 'replacement) (get value 'replacement))
((or (test value '{type status} '{deleted deprecated})
(test value '{deleted deprecated replaced}))
(fail))
(else value)))
(define (cleanup-oid! oid (locked #f))
(do-choices (slotid {(getkeys oid) (get oid 'has)})
(let* ((v (get oid slotid))
(cv (cleanup-value v)))
(unless (identical? v cv)
(unless locked (lock-oid! oid))
(add! oid slotid (difference cv v))
(drop! oid slotid (difference v cv))))))
(define (brico/cleanup! arg)
(if (oid? arg)
(cleanup-oid! arg)
(if (pool? arg)
(engine/run cleanup-oid! (pool-elts arg)
[beforefn engine/lockoids])
(irritant arg |NotPoolOrOID|))))