!752

!include #1002461 // Source

static Relationship<S, Source> isA;

p {
  load("isA");
}

answer {
  L<S> tok = nlTok(s);
  int i = findCodeTokens(tok, true, "is", "a");
  if (i > 0) {
    
  }
}

// This is about (directed) pair relationships: A * A -> V
// For example, "A is a B" with V being a value type
static class Relationship<A, V> {
  Map<A, Map<A, V>> forward = new TreeMap;
  Map<A, Map<A, V>> backward = new TreeMap;
  
  V get(A a, A b) {
    Map<A, V> map = forward.get(a);
    ret map == null ? null : map.get(b);
  }
  
  void put(A a, A b, V v) {
    put1(forward, a, b, v);
    put1(backward, b, a, v);
  }
  
  void put1(Map<A, Map<A, V>> x, A a, A b, V v) {
    Map<A, V> map = x.get(a);
    if (map == null) x.put(a, map = new TreeMap);
    map.put(b, v);
  }
}