Advertisement
Guest User

Untitled

a guest
Jul 9th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 2.64 KB | None | 0 0
  1.  
  2. ; TODO: model the semantic network below as a list of nodes, that refer to each other by name
  3.  
  4. ; example semantic network:
  5. ; the Toyota Prius is a a japanese hybrid car
  6. ; cars have a mean power of 120hp
  7. ; a hybrid car is a combination of an electric car with a gasoline car
  8. ; japanese cars have about 160hp
  9. ; however, japanese electric cars have about 130 hp
  10. ; Chevrolet Volt is an american electric car
  11. ; most electric cars have a power of 150hp
  12. (define db
  13.   '((Car (power 120))
  14.   (Electric (aka Car) (power 150))
  15.   (Gasoline (aka Car))
  16.   (Hybrid (aka Electric) (aka Gasoline))
  17.   (Japanese (aka Car) (power 160))
  18.   (American (aka Car))
  19.   (AE (aka American) (aka Electric))
  20.   (JE (aka Japanese) (aka Electric) (power 130))
  21.   (JH (aka Japanese) (aka Hybrid))
  22.   (TP (isa JH))
  23.   (CV (isa AE))
  24.   ))
  25. ; TODO: implement the functions below to determine the power of the Toyota Prius and the Chevrolet Volt
  26.  
  27.  
  28. ; in: name of the searched node; the semantic network
  29. ; returns: node in the semantic net with the specified name
  30. (define (find-node name net)
  31.   (if (null? net)
  32.       '()
  33.       (if (equal? (caar net) name)
  34.           (car net)
  35.           (find-node name (cdr net)))
  36.  
  37.   ))
  38.  
  39.  
  40. (find-node 'TP db)
  41. ; in: node; attribute name
  42. ; returns: the value of the attribute for the node, if defined (not inferred)
  43. (define (get-attr node attr-name)
  44.  (map
  45.   (lambda (x)
  46.     (cadr x)
  47.   )
  48.   (filter
  49.    (lambda (x)
  50.     (equal? (car x) attr-name)
  51.   )
  52.   (cdr node)
  53. )))
  54.  
  55.  
  56. (get-attr (find-node 'Electric db) 'power)
  57. ; in: node
  58. ; returns: the list of nodes to which the node is related by ISA relations (for instances (objects))
  59.  
  60. (define (make-isa-ancestor-list node)
  61.  (map
  62.   (lambda (x)
  63.     (cadr x)
  64.   )
  65.   (filter
  66.    (lambda (x)
  67.     (equal? (car x) 'isa)
  68.   )
  69.   (cdr node)
  70. )))
  71.  
  72. (make-isa-ancestor-list (find-node 'TP db))
  73. ; in: node
  74. ; returns: the list of nodes to which the node is related by AKO relations (for classes (concepts))
  75. (define (make-ako-ancestor-list node)
  76.  (map
  77.   (lambda (x)
  78.     (cadr x)
  79.   )
  80.   (filter
  81.    (lambda (x)
  82.     (equal? (car x) 'aka)
  83.   )
  84.   (cdr node)
  85. )))
  86.  
  87. (make-ako-ancestor-list (find-node 'JH db))
  88. ; in: node; attribute name
  89. ; returns: the value of the attribute for the node, inferred from the semantic network
  90. ; note: one inheritance path mandatory; bonus for multiple inheritance paths
  91.  
  92. (define (infer-attr node attr-name)
  93.   (if (null? node)
  94.       '()
  95.       (if (null? (car (get-attr (find-node node db) attr-name)))
  96.           (infer-attr (car (make-ako-ancestor-list (find-node node db)) attr-name))
  97.           (car (get-attr (find-node node db) attr-name)))))
  98.  
  99. (infer-attr 'Electric 'power)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement