Serializable, Runnable, Eventable, InputFileConsumer, Multistepable, NarseseConsumer, Pluggable, Reasoner, Resettable, SensoryChannelConsumer, TaskConsumer<Reasoner>, Timable, Pluginpublic 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, waitname, setEnabledaddInput, getDuration, getHeight, getName, getWidth, priority, resetChannel, setDuration, setHeight, setName, setWidth, step_finished, step_start, topDownPrioritypublic 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 instanceIOExceptionInstantiationExceptionInvocationTargetExceptionNoSuchMethodExceptionParserConfigurationExceptionIllegalAccessExceptionSAXExceptionClassNotFoundExceptionParseExceptionpublic 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 fileIOExceptionInstantiationExceptionInvocationTargetExceptionNoSuchMethodExceptionParserConfigurationExceptionSAXExceptionIllegalAccessExceptionParseExceptionClassNotFoundExceptionpublic 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 ReasonerIOExceptionInstantiationExceptionInvocationTargetExceptionNoSuchMethodExceptionParserConfigurationExceptionSAXExceptionIllegalAccessExceptionParseExceptionClassNotFoundExceptionpublic Nar(String relativeConfigFilePath) throws IOException, InstantiationException, InvocationTargetException, NoSuchMethodException, ParserConfigurationException, SAXException, IllegalAccessException, ParseException, ClassNotFoundException
relativeConfigFilePath - (relative) path of the XML encoded config fileIOExceptionInstantiationExceptionInvocationTargetExceptionNoSuchMethodExceptionParserConfigurationExceptionSAXExceptionIllegalAccessExceptionParseExceptionClassNotFoundExceptionpublic 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 ReasonerIOExceptionInstantiationExceptionInvocationTargetExceptionNoSuchMethodExceptionParserConfigurationExceptionSAXExceptionIllegalAccessExceptionParseExceptionClassNotFoundExceptionpublic 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 ReasonerIOExceptionInstantiationExceptionInvocationTargetExceptionNoSuchMethodExceptionParserConfigurationExceptionIllegalAccessExceptionSAXExceptionClassNotFoundExceptionParseExceptionpublic void addSensoryChannel(String term, SensoryChannel channel)
SensoryChannelConsumeraddSensoryChannel in interface SensoryChannelConsumerterm - term in narsesechannel - the channel to be registeredpublic void SaveToFile(String name) throws IOException
IOExceptionpublic static Nar LoadFromFile(String name) throws IOException, ClassNotFoundException, IllegalAccessException, ParseException, ParserConfigurationException, SAXException, NoSuchMethodException, InstantiationException, InvocationTargetException
public void reset()
reset in interface Resettableprivate boolean addMultiLineInput(String text)
private boolean addCommand(String text) throws IOException
IOExceptionpublic void addInput(String text)
NarseseConsumeraddInput in interface NarseseConsumertext - the narsese textprivate boolean dispatchToSensoryChannel(Task task)
task - dispatched taskpublic void addInputFile(String s)
InputFileConsumeraddInputFile in interface InputFileConsumers - optional path followed by filenamepublic Concept concept(String concept) throws Parser.InvalidInputException
concept in interface Reasonerconcept - the name/term of the conceptParser.InvalidInputExceptionpublic Nar ask(String termString, AnswerHandler answered) throws Parser.InvalidInputException
Reasonerask in interface ReasonertermString - narsese string with term of questionanswered - handler which will be called when answeredParser.InvalidInputExceptionpublic Nar askNow(String termString, AnswerHandler answered) throws Parser.InvalidInputException
ReasoneraskNow in interface ReasonertermString - narsese string with term of questionanswered - handler which will be called when answeredParser.InvalidInputExceptionpublic Nar addInput(Task t, Timable time)
TaskConsumeraddInput in interface TaskConsumer<Reasoner>addInput in class SensoryChannelt - 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)
Pluggablepublic void removePlugin(Nar.PluginState ps)
PluggableremovePlugin in interface Pluggableps - plugin to be removedpublic List<Nar.PluginState> getPlugins()
PluggablegetPlugins in interface Pluggablepublic void start(long minCyclePeriodMS)
start in interface Multistepablepublic void start()
start in interface Multistepablepublic void stop()
stop in interface Multistepablepublic void cycles(int cycles)
cycles in interface Multistepablepublic void run()
public void cycle()
cycle in interface Multistepablepublic long time()
Reasonerpublic boolean isRunning()
Reasonerpublic long getMinCyclePeriodMS()
ReasonergetMinCyclePeriodMS in interface Reasonerpublic void setThreadYield(boolean b)
setThreadYield in interface Reasonerb - 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.