home » user manual » knowledge representation

Nuin knowledge representation language

The knowledge representation language provided by Nuin is modelled on first order predicate calculus, with some extensions. In general, we take the view that agents may require different KR capabilities in different circumstances. Some applications require relatively simple knowledge processing, while other applications are much more complex. The Nuin KR language is therefore a set of abstract interfaces, which may be instantiated in different ways, or used with different reasoners

Each element of the KR language is principally represented as a Java interface. In addition, it has a string serialisation that is used in Nuinscript scripts, and may be used to generate Java objects corresponding to the appropriate interfaces directly from a factory object. We first summarise the values and sentences that have representations in the KR language, together with their serialisation form, then show how to create them in Java programs.

KR Values

Values in the Nuin knowledge representation are represented by interfaces in the org.nuin.ks.values package. The available values are:

Java interface Meaning Example script syntax
KsInt Integer scalar values 42
-34
KsDouble Double precision floating point values 42.34
-3.5e6
KsBoolean Boolean true of false true
false
KsString Character string "to be or not to be"
KsSymbol Symbolic constant, represented as a URI. Can use a known prefix to shorten to a readable form. Undecorated symbols are given the default namespace: http://www.nuin.org/ns#. aSymbol
lib:round
<http://example.org/foo#bar>
<urn:uuid:890809f-29243734-39300>
KsConst Super-interface for all of the above constant terms. n/a
KsVar A single-assignment variable (when unbound may be bound to any value, but will not be re-assigned unless unbound by backtracking) ?x
?customerID
KsTerm Term representing a compound value as a function term (functor) applied to zero or more arguments. Note that a zero-argument term is considered the same as a symbol. ex:horse( "missy",
     hands( 13, 2 ),
     colour:dappleGrey )
KsList Value representing an ordered list of ks values. []
[a, b, 17, "foo"]
[?head | ?tail]
KsEvent Term representing an event occurrence. event ex:alarm( 101 )
event ex:alarm {ex:source=ex:alarm101}
KsMessage Term representing an message; a specialisation of event. message( a, b, "help" )
message () {acl:sender=ex:a}
KsAction Term representing an action. action ex:openDoor( door17 )
action ex:openDoor {ex:target=door17}
KsField Expression that extracts a named field from a compound value that accepts named parameters (e.g. messages). When evaluated at run time, it is replaced with the value of named field of the left-hand value, or bottom if that value is not defined. ?incomingMsg :: acl:sender
KsBottom Represents the impossible or meaningless value. bottom
KsIdentifier Interface that is implemented by all values that can be used for identification of objects or concepts, including symbols and terms and their sub-classes. n/a
KsObject Value that wraps an arbitrary Java object and lifts it to the Nuinscript level. This allows arbitrary Java objects to be exchanged between agent services via the agent script, if necessary. n/a
KsReification Value that represents a reified sentence, that is, a logical sentence treated as a value. Normally, sentences can contain values but not nice versa. This is inconvenient for representing messages, for example, since the content field of a message is typically a sentence. sentence( p(x) && q(y) )
KsIota Value that represents the single result of a reference expression. An example of an iota reference expression is "the x where x is the capital of France". When an iota expression is evaluated, it should (assuming appropriate resoning capabilities are available) evaluate to a single value, or to bottom if there is no known value corresponding to the reference. iota( ?x, capitalOf( country:France, ?x ) )
KsAll Value that represents the set of all results of a reference expression. An example of an all reference expression is "all x where x is is a single digit prime number". When an iota expression is evaluated, it should (assuming appropriate resoning capabilities are available) evaluate to a set of values (encoded as a list). all( ?x, prime( ?x ) && singleDigit( ?x ) )
KsAny Value that represents the set of some, but not necessarily all, results of a reference expression. NB Any is included in the KR values language for completeness, as it occurs in FIPA SL. It seems a difficult construct to define and use. any( ?x, prime( ?x ) && singleDigit( ?x ) )
KsReference Interface that is the super-class of the iota, any and all reference expressions. n/a
KsValue Interface that is the super-class of all of the value types listed above. n/a
Table 1: Nuin KR language value expressions

Using values from Java

Table 1 shows the syntax for denoting values in Nuinscript programs. To access the contents of the value objects, see the Javadoc (linked from each line of Table 1). To create a ks-value in Java, use an instance of KsValueFactory. The default such factory is available from the central factory registry The. For example, to create a new KsInt with the value 42, use:

 KsInt i = The.valueFactory().newInt( 42 );

Similar methods are available for each of the value types listed above; details in the javadoc. In addition, a ks-value may be created by directly parsing the script syntax from a string. For example:

 KsTerm t = (KsTerm) The.valueFactory()
                        .parse( "foo( 42, bar )" )
                        .next();

Note finally that Nuinscript is only one possible serialisation syntax that can be parsed into the KsValue sub-types listed above. It is quite possible to parse other syntaxes into the same representation. A particular case in point is the FIPA SL language, for which a parser is planned soon.

KR Sentences

Sentences in the Nuin knowledge representation are also represented by interfaces, this time in the org.nuin.ks.sentences package. While a value represents some actual data value, a sentence represents a logical formula to which a truth value could be assigned. Note that we are not claiming that any known or forseeable reasoner can process all of the sentence types described below. The class of logics that include every one of these sentences types is certainly undecidable. The reason for making the KR language this powerful is to provide a common formalism for recording, storing retrieving and trasmitting a wide range of sentential knowledge. It will be necessary for the agent designer to select a sub-set of this representation suitable to whichever reasoning resource is chosen for the agent to employ.

Java interface Meaning Example script syntax
Conjunction The conjunction (i.e. and) of two operand sentences. p(x) && p(y)
Disjunction The disjunction (i.e. or) of two operand sentences. p(x) || p(y)
Negation The negation (i.e. not) of an operand sentence. not p(y)
Predicate A predicate denotes the truth of some relationship among an ordered list of arguments. p(0)
father( brian, ian )
KsLiteral KsLiteral is an interface that provides a common super-class for a predicate or the negation of a predicate. n/a
Equality A statement of equality between two values. ?x == 42
Implication The material implication operator; the sentence is true just in case the left hand operand is false or the right hand operand is true. father(?x) -> male(?x)
UniversalQuantifier The universal quantifier denotes a sentence which is true for all values of a given variable. That is, the value of the sentence is universally true, no matter what the variable is bound to. For convenience, the Nuin universal quanitifier accepts one or more variables to range over. forall ?x, ?y : p(?x) && q(?y)
ExistentialQuantifier The existential quantifier denotes a sentence which is true for one or more values of a given variable. That is, some value exists for which the sentence is true. For convenience, the Nuin existential quanitifier accepts one or more variables to range over. exists ?x, ?y : p(?x) || q(?y)
KsQuantifier KsQuantifier is a Java interface that provides a common super-class for existential and universal quantifiers n/a
KsModality Allows a sentence to be placed in the scope of a modal operator. Modal operators are a very powerful extension to normal first-order logic, but they do raise the complexity of computing with the logic quite significantly. A typical use of modal operators is to encode mental attitudes, so "janet believes the sun is shining" might be encoded as shown in the example to the right. Note that, while this sentence type can encode arbitrary modalities in Java (by setting the modality symbol argument), the only modalities that are recognised by the Nuinscript parser are B (believes), I (intends) and D (desires). Each modality is followed by a single symbol or variable denoting the identity of the agent who has that mental attitude. If a variable, the variable is expected to be bound to a symbol by the time the sentence is evaluated. B janet : shining( sun )
 
D person:ian : purchse( cd( "Aion" ) )
KsSentence KsSentence is a Java interface that provides a common super-class for all of the above sentence types. n/a
Table 2: Nuin KR language sentences

Using KsSentences from Java

The various access methods to the contents of each sentence are documented in the Javadoc, linked from each class name above. Like values, instances of sentences are created in Java from a factory object, in this case the KsSentenceFactory. The default instantiation of this factory is also available from the central factory registry, The. Thus to create the negative literal "not p of 0", we can use:

  KsSentenceFactory ksf = The.sentenceFactory();
  KsInt zero = The.valueFactory().newInt( 0 );
  KsSymbol p = The.valueFactory().newSymbol( "p" );
  
  Predicate p0 = ksf.newPredicate( p, zero );
  Literal lit = ksf.newNegation( p0 );

As an alternative to constructing sentences using the factory methods, we can parse serialised representations of sentences into KsSentences, using an appropriate parser. While Nuinscript is the default KR language, we can also refer to it explicitly when parsing Nuinscript strings into sentences:

  Literal lit = (Literal) The.sentenceFactory()
                             .parse( "not p( 0 )", 
                                     ParsersVocab.NUINSCRIPT )
                             .next();

« prev: agent intentions & plans | knowledge representation | next: nuinscript »