Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; TODO: model the semantic network below as a list of nodes, that refer to each other by name
- ; example semantic network:
- ; the Toyota Prius is a a japanese hybrid car
- ; cars have a mean power of 120hp
- ; a hybrid car is a combination of an electric car with a gasoline car
- ; japanese cars have about 160hp
- ; however, japanese electric cars have about 130 hp
- ; Chevrolet Volt is an american electric car
- ; most electric cars have a power of 150hp
- (define db
- '((Car (power 120))
- (Electric (aka Car) (power 150))
- (Gasoline (aka Car))
- (Hybrid (aka Electric) (aka Gasoline))
- (Japanese (aka Car) (power 160))
- (American (aka Car))
- (AE (aka American) (aka Electric))
- (JE (aka Japanese) (aka Electric) (power 130))
- (JH (aka Japanese) (aka Hybrid))
- (TP (isa JH))
- (CV (isa AE))
- ))
- ; TODO: implement the functions below to determine the power of the Toyota Prius and the Chevrolet Volt
- ; in: name of the searched node; the semantic network
- ; returns: node in the semantic net with the specified name
- (define (find-node name net)
- (if (null? net)
- '()
- (if (equal? (caar net) name)
- (car net)
- (find-node name (cdr net)))
- ))
- (find-node 'TP db)
- ; in: node; attribute name
- ; returns: the value of the attribute for the node, if defined (not inferred)
- (define (get-attr node attr-name)
- (map
- (lambda (x)
- (cadr x)
- )
- (filter
- (lambda (x)
- (equal? (car x) attr-name)
- )
- (cdr node)
- )))
- (get-attr (find-node 'Electric db) 'power)
- ; in: node
- ; returns: the list of nodes to which the node is related by ISA relations (for instances (objects))
- (define (make-isa-ancestor-list node)
- (map
- (lambda (x)
- (cadr x)
- )
- (filter
- (lambda (x)
- (equal? (car x) 'isa)
- )
- (cdr node)
- )))
- (make-isa-ancestor-list (find-node 'TP db))
- ; in: node
- ; returns: the list of nodes to which the node is related by AKO relations (for classes (concepts))
- (define (make-ako-ancestor-list node)
- (map
- (lambda (x)
- (cadr x)
- )
- (filter
- (lambda (x)
- (equal? (car x) 'aka)
- )
- (cdr node)
- )))
- (make-ako-ancestor-list (find-node 'JH db))
- ; in: node; attribute name
- ; returns: the value of the attribute for the node, inferred from the semantic network
- ; note: one inheritance path mandatory; bonus for multiple inheritance paths
- (define (infer-attr node attr-name)
- (if (null? node)
- '()
- (if (null? (car (get-attr (find-node node db) attr-name)))
- (infer-attr (car (make-ako-ancestor-list (find-node node db)) attr-name))
- (car (get-attr (find-node node db) attr-name)))))
- (infer-attr 'Electric 'power)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement