Skip to content

Commit 054dfcd

Browse files
authored
Merge pull request #439 from opennars/RC2PR
RC2 pr
2 parents dad202d + 2a7faf1 commit 054dfcd

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

src/main/java/org/opennars/main/Nar.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public Nar() throws IOException, InstantiationException, InvocationTargetExcepti
227227
* Reset the system with an empty memory and reset clock. Called locally.
228228
*/
229229
public void reset() {
230+
cycle = (long) 0;
230231
memory.reset();
231232
}
232233

@@ -380,12 +381,31 @@ public void addInputFile(final String s) {
380381
String line;
381382
while ((line = br.readLine()) != null) {
382383
if(!line.isEmpty()) {
383-
this.addInput(line);
384+
//Loading experience file lines, or else just normal input lines
385+
if(line.matches("([A-Za-z])+:(.*)")) {
386+
//Extract creation time:
387+
if(!line.startsWith("IN:")) {
388+
continue; //ignore
389+
}
390+
String[] spl = line.replace("IN:", "").split("\\{");
391+
int creationTime = Integer.parseInt(spl[spl.length-1].split(" :")[0].split("\\|")[0]);
392+
while(this.time() < creationTime) {
393+
this.cycles(1);
394+
}
395+
String lineReconstructed = ""; //the line but without the stamp info at the end
396+
for(int i=0; i<spl.length-1; i++) {
397+
lineReconstructed += spl[i] + "{";
398+
}
399+
lineReconstructed = lineReconstructed.substring(0, lineReconstructed.length()-1);
400+
this.addInput(lineReconstructed.trim());
401+
} else {
402+
this.addInput(line);
403+
}
384404
}
385405
}
386-
} catch (final IOException ex) {
406+
} catch (final Exception ex) {
387407
Logger.getLogger(Nar.class.getName()).log(Level.SEVERE, null, ex);
388-
throw new IllegalStateException("Could not open specified file", ex);
408+
throw new IllegalStateException("Loading experience file failed ", ex);
389409
}
390410
}
391411

0 commit comments

Comments
 (0)