Serializable
, Runnable
, Eventable
, InputFileConsumer
, Multistepable
, NarseseConsumer
, Pluggable
, Reasoner
, Resettable
, SensoryChannelConsumer
, TaskConsumer<Reasoner>
, Timable
, Plugin
public class Nar extends SensoryChannel implements Reasoner, Serializable, Runnable
Modifier and Type | Class | Description |
---|---|---|
class |
Nar.PluginState |
Modifier and Type | Field | Description |
---|---|---|
private Long |
cycle |
|
static String |
DEFAULTCONFIG_FILEPATH |
|
Memory |
memory |
The memory of the reasoner
|
(package private) long |
minCyclePeriodMS |
|
protected String |
name |
The name of the reasoner
|
static String |
NAME |
Name of the reasoner of the project
|
Parameters |
narParameters |
|
protected List<Nar.PluginState> |
plugins |
|
private boolean |
running |
Flag for running continuously
|
protected Map<Term,SensoryChannel> |
sensoryChannels |
|
private boolean |
stopped |
used by stop() to signal that a running loop should be interrupted
|
private Thread[] |
threads |
|
private boolean |
threadYield |
|
String |
usedConfigFilePath |
|
static String |
VERSION |
The information about the version of the project
|
static String |
WEBSITE |
The project web sites.
|
Constructor | Description |
---|---|
Nar() |
constructs the NAR and loads a config from the default filepath
Assigns a random id to the instance
|
Nar(long narId) |
constructs the NAR and loads a config from the default filepath
|
Nar(long narId,
String relativeConfigFilePath) |
constructs the NAR and loads a config from the filepath
|
Nar(long narId,
String relativeConfigFilePath,
Map<String,Object> parameterOverrides) |
constructs the NAR and loads a config from the filepath
|
Nar(String relativeConfigFilePath) |
constructs the NAR and loads a config from the filepath
|
Nar(String relativeConfigFilePath,
Map<String,Object> parameterOverrides) |
constructs the NAR and loads a config from the filepath
|
Nar(Map<String,Object> parameterOverrides) |
constructs the NAR and loads a config from the default filepath
Assigns a random id to the instance
|
Modifier and Type | Method | Description |
---|---|---|
private boolean |
addCommand(String text) |
|
void |
addInput(String text) |
feeds narsese input to the consumer
|
Nar |
addInput(Task t,
Timable time) |
consumes a task
|
void |
addInputFile(String s) |
consumes a file
|
private boolean |
addMultiLineInput(String text) |
Generally the text will consist of Task's to be parsed in Narsese, but
may contain other commands recognized by the system.
|
void |
addPlugin(Plugin p) |
adds/registers a plugin
|
void |
addSensoryChannel(String term,
SensoryChannel channel) |
registers a sensory channel by/for the term
|
Nar |
ask(String termString,
AnswerHandler answered) |
ask reasoner a eternal question
|
Nar |
askNow(String termString,
AnswerHandler answered) |
ask reasoner a now question
|
Concept |
concept(String concept) |
gets a concept if it exists, or returns null if it does not
|
void |
cycle() |
A frame, consisting of one or more Nar memory cycles
|
void |
cycles(int cycles) |
Execute a fixed number of cycles.
|
private boolean |
dispatchToSensoryChannel(Task task) |
dispatches the task to the sensory channel if necessary
|
void |
emit(Class c,
Object... o) |
|
void |
event(EventEmitter.EventObserver e,
boolean enabled,
Class... events) |
set an event handler.
|
long |
getMinCyclePeriodMS() |
returns the minimum delay of a cycle in milliseconds
|
List<Nar.PluginState> |
getPlugins() |
returns all plugins which were added
|
boolean |
isRunning() |
is the reasoner running?
|
static Nar |
LoadFromFile(String name) |
|
void |
off(Class c,
EventEmitter.EventObserver o) |
remove event handler
|
void |
on(Class c,
EventEmitter.EventObserver o) |
attach event handler
|
private static void |
overrideParameters(Parameters parameters,
Map<String,Object> overrides) |
overrides parameter values by name
|
void |
removePlugin(Nar.PluginState ps) |
removes a plugin
|
void |
reset() |
Reset the system with an empty memory and reset clock.
|
void |
run() |
Main loop executed by the Thread.
|
void |
SaveToFile(String name) |
|
void |
setThreadYield(boolean b) |
When b is true, Nar will call Thread.yield each run() iteration that minCyclePeriodMS==0 (no delay).
|
void |
start() |
|
void |
start(long minCyclePeriodMS) |
|
void |
stop() |
Stop the inference process, killing its thread.
|
long |
time() |
return the current time from the clock
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
name, setEnabled
addInput, getDuration, getHeight, getName, getWidth, priority, resetChannel, setDuration, setHeight, setName, setWidth, step_finished, step_start, topDownPriority
public Parameters narParameters
private Long cycle
public static final String VERSION
public static final String NAME
public static final String WEBSITE
private transient Thread[] threads
protected transient Map<Term,SensoryChannel> sensoryChannels
volatile long minCyclePeriodMS
protected String name
public final Memory memory
protected transient List<Nar.PluginState> plugins
private transient boolean running
private transient boolean stopped
private transient boolean threadYield
public static final String DEFAULTCONFIG_FILEPATH
public String usedConfigFilePath
public Nar(long narId) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, IllegalAccessException, SAXException, ClassNotFoundException, ParseException
narId
- inter NARS id of this NARS instanceIOException
InstantiationException
InvocationTargetException
NoSuchMethodException
ParserConfigurationException
IllegalAccessException
SAXException
ClassNotFoundException
ParseException
public Nar(long narId, String relativeConfigFilePath) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, SAXException, IllegalAccessException, ParseException, ClassNotFoundException
narId
- inter NARS id of this NARS instancerelativeConfigFilePath
- (relative) path of the XML encoded config fileIOException
InstantiationException
InvocationTargetException
NoSuchMethodException
ParserConfigurationException
SAXException
IllegalAccessException
ParseException
ClassNotFoundException
public Nar(long narId, String relativeConfigFilePath, Map<String,Object> parameterOverrides) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, SAXException, IllegalAccessException, ParseException, ClassNotFoundException
narId
- inter NARS id of this NARS instancerelativeConfigFilePath
- (relative) path of the XML encoded config fileparameterOverrides
- (overwritten) parameters of a ReasonerIOException
InstantiationException
InvocationTargetException
NoSuchMethodException
ParserConfigurationException
SAXException
IllegalAccessException
ParseException
ClassNotFoundException
public Nar(String relativeConfigFilePath) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, SAXException, IllegalAccessException, ParseException, ClassNotFoundException
relativeConfigFilePath
- (relative) path of the XML encoded config fileIOException
InstantiationException
InvocationTargetException
NoSuchMethodException
ParserConfigurationException
SAXException
IllegalAccessException
ParseException
ClassNotFoundException
public Nar(String relativeConfigFilePath, Map<String,Object> parameterOverrides) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, SAXException, IllegalAccessException, ParseException, ClassNotFoundException
relativeConfigFilePath
- (relative) path of the XML encoded config fileparameterOverrides
- (overwritten) parameters of a ReasonerIOException
InstantiationException
InvocationTargetException
NoSuchMethodException
ParserConfigurationException
SAXException
IllegalAccessException
ParseException
ClassNotFoundException
public Nar() throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, IllegalAccessException, SAXException, ClassNotFoundException, ParseException
public Nar(Map<String,Object> parameterOverrides) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, IllegalAccessException, SAXException, ClassNotFoundException, ParseException
parameterOverrides
- (overwritten) parameters of a ReasonerIOException
InstantiationException
InvocationTargetException
NoSuchMethodException
ParserConfigurationException
IllegalAccessException
SAXException
ClassNotFoundException
ParseException
public void addSensoryChannel(String term, SensoryChannel channel)
SensoryChannelConsumer
addSensoryChannel
in interface SensoryChannelConsumer
term
- term in narsesechannel
- the channel to be registeredpublic void SaveToFile(String name) throws IOException
IOException
public static Nar LoadFromFile(String name) throws IOException, ClassNotFoundException, IllegalAccessException, ParseException, ParserConfigurationException, SAXException, NoSuchMethodException, InstantiationException, InvocationTargetException
public void reset()
reset
in interface Resettable
private boolean addMultiLineInput(String text)
private boolean addCommand(String text) throws IOException
IOException
public void addInput(String text)
NarseseConsumer
addInput
in interface NarseseConsumer
text
- the narsese textprivate boolean dispatchToSensoryChannel(Task task)
task
- dispatched taskpublic void addInputFile(String s)
InputFileConsumer
addInputFile
in interface InputFileConsumer
s
- optional path followed by filenamepublic Concept concept(String concept) throws Parser.InvalidInputException
concept
in interface Reasoner
concept
- the name/term of the conceptParser.InvalidInputException
public Nar ask(String termString, AnswerHandler answered) throws Parser.InvalidInputException
Reasoner
ask
in interface Reasoner
termString
- narsese string with term of questionanswered
- handler which will be called when answeredParser.InvalidInputException
public Nar askNow(String termString, AnswerHandler answered) throws Parser.InvalidInputException
Reasoner
askNow
in interface Reasoner
termString
- narsese string with term of questionanswered
- handler which will be called when answeredParser.InvalidInputException
public Nar addInput(Task t, Timable time)
TaskConsumer
addInput
in interface TaskConsumer<Reasoner>
addInput
in class SensoryChannel
t
- task to be consumedtime
- used to retrieve the timepublic void on(Class c, EventEmitter.EventObserver o)
public void off(Class c, EventEmitter.EventObserver o)
public void event(EventEmitter.EventObserver e, boolean enabled, Class... events)
public void addPlugin(Plugin p)
Pluggable
public void removePlugin(Nar.PluginState ps)
Pluggable
removePlugin
in interface Pluggable
ps
- plugin to be removedpublic List<Nar.PluginState> getPlugins()
Pluggable
getPlugins
in interface Pluggable
public void start(long minCyclePeriodMS)
start
in interface Multistepable
public void start()
start
in interface Multistepable
public void stop()
stop
in interface Multistepable
public void cycles(int cycles)
cycles
in interface Multistepable
public void run()
public void cycle()
cycle
in interface Multistepable
public long time()
Reasoner
public boolean isRunning()
Reasoner
public long getMinCyclePeriodMS()
Reasoner
getMinCyclePeriodMS
in interface Reasoner
public void setThreadYield(boolean b)
setThreadYield
in interface Reasoner
b
- Nar will call Thread.yield each run()private static void overrideParameters(Parameters parameters, Map<String,Object> overrides)
parameters
- (overwritten) parameters of a Reasoneroverrides
- specific override values by parameter nameCopyright © 2020 OpenNARS. All rights reserved.