Skip to content

Commit

Permalink
Merge branch 'bowen-xu:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ARCJ137442 authored Oct 27, 2023
2 parents 0f79406 + e0cc2c5 commit 42ffa5e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
13 changes: 13 additions & 0 deletions pynars/ConsolePlus.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,19 @@ def toggle_silent() -> None:
}.''')


@cmd_register(('volume'), (int, 100))
def volume(vol:int) -> None:
'''Format: volume [volume:int 0~100]
Set the Output Volume of the console to control its output (same as OpenNARS)'''
if 0 <= vol <= 100:
current_NARS_interface.volume_threshold = 1 - vol * 0.01 # same as `(100-vol)/100`
current_NARS_interface.print_output(
type=PrintType.INFO, content=f'''Volume is set to "*volume={vol}".''')
else:
current_NARS_interface.print_output(
type=PrintType.INFO, content=f'''Volume {vol} is out of range 0~100!''')


@cmd_register(('toggle-color', 'color'))
def toggle_color() -> None:
'''Toggle the color display of cmds (for terminals that do not support custom foreground/background colors)'''
Expand Down
40 changes: 32 additions & 8 deletions pynars/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,10 @@ def change_random_seed(seed: int) -> None:
f'Changing random seed={seed}...', comment_title='Setup')

silent_output: bool = False
'determines whether the output is hidden or not'

volume_threshold: float = 0.5
'determines the level (min threshold of total budget) of output (NARSOutput) generate, only affects the narsese output'

# reasoner
_NARS: Reasoner = None # ! internal
Expand Down Expand Up @@ -231,6 +235,7 @@ def __init__(self, seed=-1, NARS: reasoner = None, silent: bool = False) -> None

# config
self.silent_output: bool = silent
self.volume_threshold = 0

# reasoner
self.print_output(
Expand Down Expand Up @@ -375,18 +380,37 @@ def _handle_lines(self, lines: str) -> List[NARSOutput]:
for task_line in task_list:
tasks_derived, judgement_revised, goal_revised, answers_question, answers_quest,\
(task_operation_return, task_executed) = task_line
# * only the 'OUT' will be affected by silence level
for derived_task in tasks_derived:
outs.append(
NARSOutput(
PrintType.OUT, derived_task.sentence.repr(), *derived_task.budget)
)
'''
Ref. OpenNARS 3.1.0 Memory.java line 344~352
```
final float budget = t.budget.summary();
final float noiseLevel = 1.0f - (narParameters.VOLUME / 100.0f);
if (budget >= noiseLevel) { // only report significant derived Tasks
emit(OUT.class, t);
if (Debug.PARENTS) {
emit(DEBUG.class, "Parent Belief\t" + t.parentBelief);
emit(DEBUG.class, "Parent Task\t" + t.parentTask + "\n\n");
}
}
```
'''
if derived_task.budget.summary > self.volume_threshold:
outs.append(
NARSOutput(
PrintType.OUT, derived_task.sentence.repr(), *derived_task.budget)
)

if judgement_revised is not None:
outs.append(NARSOutput(PrintType.OUT, judgement_revised.sentence.repr(
), *judgement_revised.budget))
if judgement_revised.budget.summary > self.volume_threshold:
outs.append(NARSOutput(
PrintType.OUT, judgement_revised.sentence.repr(), *judgement_revised.budget))
if goal_revised is not None:
outs.append(NARSOutput(
PrintType.OUT, goal_revised.sentence.repr(), *goal_revised.budget))
if judgement_revised.budget.summary > self.volume_threshold:
outs.append(NARSOutput(
PrintType.OUT, goal_revised.sentence.repr(), *goal_revised.budget))
if answers_question is not None:
for answer in answers_question:
outs.append(
Expand Down

0 comments on commit 42ffa5e

Please sign in to comment.