Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

87
LINES

< > BotCompany Repo | #1006464 // Concept Graphs [dev.]

JavaX source code [tags: use-pretranspiled] - run with: x30.jar

Libraryless. Click here for Pure Java version (7142L/48K/158K).

!7

concept AIConcept {
  S globalID = aGlobalID();
  S name;
  S comment;
}

concept C {
  S globalID = aGlobalID();
  S name;
  S comment;
  new Ref<C> type;
  new LinkedHashMap<C, C> slots;
  
  public S toString() {
    ret name;
  }
}

static C findCOpt(S name) {
  ret findConcept(C, +name);
}

static C findC(S name) {
  C c = findCOpt(name);
  assertNotNull(name, c);
  ret c;
}

static C intC(int i) {
  C c = findCOpt(str(i));
  if (c == null) {
    c = instance("Integer");
    cset(c, name := str(i));
  }
  ret c;
}

static C instance(S name) {
  ret cnew(C, type := findC(name));
}

static C getC(C parent, C slot) {
  ret parent == null ? null : parent.slots.get(slot);
}

static C getC(C parent, S slot) {
  ret parent == null ? null : parent.slots.get(findC(slot));
}

static void setC(C parent, C slot, C value) {
  parent.slots.put(slot, value);
}

static void setC(C parent, S slot, C value) {
  setC(parent, findC(slot), value);
}

p {
  conceptsAndBot();
  Concepts in = new Concepts(#1006463).load(); // load AIConcept's
  
  L<AIConcept> imported = list(in, AIConcept);
  print("Have AI concepts: " + struct(collect(imported, "name")));
  for (AIConcept c : imported) {
    C cc = findConcept(C, globalID := c.globalID);
    if (cc == null) {
      print("Importing " + c.name);
      uniq(C, globalID := c.globalID, name := c.name, comment := c.comment);
    }
  }
  
  C img = findConcept(C, type := findC("RGB Image"));
  if (img == null) {
    print("Making image.");
    img = instance("RGB Image");
  }
  C width = getC(img, "Width");
  print("Width: " + width);
  if (width == null)
    setC(img, "Width", intC(200));
  C height = getC(img, "Height");
  print("Height: " + height);
  if (height == null)
    setC(img, "Height", intC(100));
}

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, sawdedvomwva, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1006464
Snippet name: Concept Graphs [dev.]
Eternal ID of this version: #1006464/1
Text MD5: 2ccd1c8158a29d4da1c5811cd332000a
Transpilation MD5: 7c5def958e07afd087113fb13fb8b66a
Author: stefan
Category: javax / gui / concepts
Type: JavaX source code
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-01-05 21:23:51
Source code size: 1858 bytes / 87 lines
Pitched / IR pitched: No / No
Views / Downloads: 452 / 547
Referenced in: [show references]