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

70
LINES

< > BotCompany Repo | #1012068 // ai_solveQuestionInSubSpace_noTimeOut

JavaX fragment (include)

static int ai_solveQuestionInSubSpace_limit = 10000;
static bool ai_solveQuestionInSubSpace_saveIfSuccessful = true;

static S ai_solveQuestionInSubSpace_noTimeOut(L<T3<S>> seeds, L<T3<S>> lookingFor) {
  ret pairB(ai_solveQuestionInSubSpace_noTimeOut2(seeds, lookingFor));
}

static Pair<AI_SubSpace, S> ai_solveQuestionInSubSpace_noTimeOut2(L<T3<S>> seeds, L<T3<S>> lookingFor) {
  ret ai_solveQuestionInSubSpace_noTimeOut2(seeds, lookingFor, f ai_solveQuestionInSubSpace_defaultStep);
}

static Pair<AI_SubSpace, S> ai_solveQuestionInSubSpace_noTimeOut2(L<T3<S>> seeds, L<T3<S>> lookingFor, O stepFunction) {
  AI_SubSpace subSpace = new(ai_solveQuestionInSubSpace_limit);
  ai_setSubSpace(subSpace);
  try {
    for (T3<S> seed : seeds)
      subSpace.postTriple(seed); // force it to be posted in SubSpace even if it exists already in main space
    for (T3<S> t : lookingFor)
      subSpace.postTriple(t3("_goal", "is", ai_renderTriple(t)));
    
    int step = 0;
    while (!subSpace.limitReached()) {
      ++step;
      int n = l(subSpace.webs);
      print("Solving question: " + allToString(lookingFor) + " (step " + step + ", " + n + "/" + subSpace.limit + ")");
      
      pcall-short {
        callF(stepFunction);
      }
      
      L<Web> newWebs = cloneSubList(subSpace.webs, n);
      ai_spec_possiblyToActually(newWebs);
      
      for (T3<S> t : lookingFor) {
        S a = ai_text(t);
        if (a != null) {
          if (ai_solveQuestionInSubSpace_saveIfSuccessful)
            saveGZStructure(countTillNewFile(programFile("logged-subspaces/subspace"), ".gz"), subSpace);
          ret pair(subSpace, a);
        }
      }
  
      if (l(subSpace.webs) == n) {
        print("Got " + nWeb(n) + ". No new webs made");
        break;
      }
    }
    
    if (subSpace.limitReached()) print("Subspace limit reached");
    ret pair(subSpace, null);
  } finally {
    ai_setSubSpace(null);
  }
}

static Pair<AI_SubSpace, S> ai_solveQuestionInSubSpace_noTimeOut2(S q) {
  Pair<L<T3<S>>> p = ai_solveQuestion_seedAndLookingFor(q);
  ret ai_solveQuestionInSubSpace_noTimeOut2(p.a, p.b);
}

svoid ai_solveQuestionInSubSpace_defaultStep {
  AI_SubSpace subSpace = ai_currentSubSpace();
  for (S term : concatLists(keys(subSpace.index), allToString(keys(subSpace.websByID))))
    ai_speculate(term);
  
  // Random stuff!
  
  ai_spec_answerPattern();
  ai_spec_daysOld();
}

Author comment

Began life as a copy of #1012064

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012068
Snippet name: ai_solveQuestionInSubSpace_noTimeOut
Eternal ID of this version: #1012068/29
Text MD5: db9e68d205fa7023c316d7baeac3b87e
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-12-13 01:47:15
Source code size: 2466 bytes / 70 lines
Pitched / IR pitched: No / No
Views / Downloads: 548 / 551
Version history: 28 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1012070 - ai_solveQuestionInSubSpace