LGames
Class Rules2

java.lang.Object
  |
  +--LGames.Rules2

public class Rules2
extends java.lang.Object


Constructor Summary
Rules2()
          Empty constructor
Rules2(IntArray DCS, int cov, java.util.List g, java.util.List o, int mc, int ab)
          Constructor for inventing a holistic rule/expression
Rules2(int cHead, int cTail, IntArray mHead, IntArray mTail, java.util.List g, java.util.List o, int mc, int ab)
          Constructor for making a compositional rule
Rules2(int cov, java.lang.String f, IntArray DCS, java.util.List g, java.util.List o, int mc, int ab)
          Constructor for adopting/incorporating an expression in a terminal (possibly holistic) rule
Rules2(Rules2 r)
          Copy constructor
 
Method Summary
 void adapt(java.lang.String head, java.lang.String tail, IntArray mHead, IntArray mTail)
          Function to add the meanings of the head and tail the proposed chunk in case the function matches returned true.
 void addMeaning(IntArray m, int n)
          This function adds category features to the IntArray meanings, removes any doubles and sets initial values to scores and usage, and indicates to which constituent (group) the categories belong.
 int compositionality()
           
 boolean equals(Rules2 r1)
          Implementation of an alternative equals
 boolean exploit(java.lang.String f, int lg)
          This function exploits a partial parse to adopt a part of the utterance.
 void generalise(java.lang.String f, IntArray m, int c, int n)
          This function generalises the grammar by searching unexplored rules that can be generalised based on a new rule.
 boolean generaliseAndMerge(int rule)
          This function implements generalise and merge.
 IntArray getComposition()
          Returns the composition of the rule
 boolean getCompositional()
           
 java.lang.String getExpression()
          This function returns the expression of the rule.
 int getFrequency()
          Returns the frequency of the rule
 boolean getHolistic()
           
 double[][] getMeaning(java.lang.String l, java.lang.String l1, int dim)
          returns a matrix representation of the meaning.
 java.lang.String[] getParts()
          This function returns the words of the rule's composition as a string array
 double getScore()
          This function returns the score of the rule.
 double getScore(int[] f, int c)
          This function calculates the score of the composition.
 java.lang.String getString(java.lang.String l)
          Returns a string representation for the linguistic categories that make up this rule.
 int getTotalUse()
           
 double getWeight()
          This function returns the rule weight
 void initGame()
          Initialised the rule for a new language game.
 boolean isSentence()
           
 boolean match(IntArray DCS, int totCover)
          Function that calls itself with an additional argument (lg=-1)
 boolean match(IntArray DCS, int totCover, int lg)
          Function to check wether the semantics of the rule matches the meaning of the distinctive categories.
 boolean matches(int cHead, int cTail)
          Function to see if the rule is compositional, and if so, if its constituents coinside with cHead and cTail.
 java.lang.String niceString()
          a string form of the rule
 boolean parse(java.lang.String f, IntArray DCS, int totCover)
          The function that implements the parsing/decoding part for holistic or non-terminal nodes.
 boolean partialMatch(IntArray DCS, int totCover)
          This function checks if the topic's meaning (DCS) matches a part of the semantics of this rule
 boolean partialParse(java.lang.String f, IntArray DCS, int totCover)
          This function tries to parse a part of the speaker's utterance.
 java.lang.String printSH()
          Returns a string representation of the rule
 java.lang.String produceExpression()
          If we have a partial match, this function invents the non-covering part and produces and expression
 void setComposition(IntArray c)
          Sets the composition to the given composition
 boolean similar(java.util.List g)
          This function searches the grammar g if it has a rule that is similar to this one.
 java.lang.String toString()
          general string form
 void updateFrequency(int[] f, int c)
          This function updates the frequency with which it has been able to encode or decode an expression, irrespective of whether it was finally selected or not.
 void updateScore(boolean s)
          Updates all weights of this rule and their meanings.
 void updateScore(boolean s, IntArray d)
          Function that calls the function updateScore(boolean s) function, after the tmpMeanings array is initialised with the proper meanings specified in d
 boolean wordMatch(java.lang.String u, IntArray dcs)
          This function checks whether the utterance matches the rule's expression.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Rules2

public Rules2()
Empty constructor


Rules2

public Rules2(Rules2 r)
Copy constructor


Rules2

public Rules2(IntArray DCS,
              int cov,
              java.util.List g,
              java.util.List o,
              int mc,
              int ab)
Constructor for inventing a holistic rule/expression

Parameters:
DCS - the meaning of the new rule.
cov - the cover of the new rule (recall cover is a bit-representation for the conceptual space and acts as the terminal label of this rule)
g - a pointer to the agent's grammar (this helps for searching)
o - a pointer to the agent;s ontology (this helps for searching)
mc - the maximum cover, ie. the conceptual space of the sentence
ab - the alphabet size

Rules2

public Rules2(int cov,
              java.lang.String f,
              IntArray DCS,
              java.util.List g,
              java.util.List o,
              int mc,
              int ab)
Constructor for adopting/incorporating an expression in a terminal (possibly holistic) rule

Parameters:
cov - the cover of the new rule (recall cover is a bit-representation for the conceptual space and acts as the terminal label of this rule)
f - the expression
DCS - the meaning of the new rule.
g - a pointer to the agent's grammar (this helps for searching)
o - a pointer to the agent;s ontology (this helps for searching)
mc - the maximum cover, ie. the conceptual space of the sentence
ab - the alphabet size

Rules2

public Rules2(int cHead,
              int cTail,
              IntArray mHead,
              IntArray mTail,
              java.util.List g,
              java.util.List o,
              int mc,
              int ab)
Constructor for making a compositional rule

Parameters:
cHead - the cover of the first constituent
cTail - the cover of the second constituent
mHead - the possible meanings of the first constituent (this speeds up searching)
mTail - the possible meanings of the second constituent (this speeds up searching)
g - a pointer to the agent's grammar (this helps for searching)
o - a pointer to the agent;s ontology (this helps for searching)
mc - the maximum cover, ie. the conceptual space of the sentence
ab - the alphabet size
Method Detail

initGame

public void initGame()
Initialised the rule for a new language game.


addMeaning

public void addMeaning(IntArray m,
                       int n)
This function adds category features to the IntArray meanings, removes any doubles and sets initial values to scores and usage, and indicates to which constituent (group) the categories belong.

Parameters:
m - the IntArray of category features
n - the consituent to which these belong

matches

public boolean matches(int cHead,
                       int cTail)
Function to see if the rule is compositional, and if so, if its constituents coinside with cHead and cTail. This is used by the compositional agent in the chunking process (see addSplit())

Parameters:
cHead - the cover of the head (1st constituent)
cTail - the cover of the tail (2nd constituent)
Returns:
true in case this rule is compositional and starts with cHead and ends with cTail

adapt

public void adapt(java.lang.String head,
                  java.lang.String tail,
                  IntArray mHead,
                  IntArray mTail)
Function to add the meanings of the head and tail the proposed chunk in case the function matches returned true.

Parameters:
head - the string of the first constituent
tail - the string of the second constituent
mHead - the meanings of the first constituent
mTail - the meanings of the second constituent

match

public boolean match(IntArray DCS,
                     int totCover)
Function that calls itself with an additional argument (lg=-1)


match

public boolean match(IntArray DCS,
                     int totCover,
                     int lg)
Function to check wether the semantics of the rule matches the meaning of the distinctive categories.

Parameters:
DCS - the distinctive categories
totCover - the linguistic category that is currently searched
lg - language game number used as a time stamp
Returns:
true when this rule matches, false when not

partialMatch

public boolean partialMatch(IntArray DCS,
                            int totCover)
This function checks if the topic's meaning (DCS) matches a part of the semantics of this rule

Parameters:
DCS - the meaning of the topic
totCover - the linguistic category/conceptual space under consideration
Returns:
true if the rule partially matches, otherwise it returns false

produceExpression

public java.lang.String produceExpression()
If we have a partial match, this function invents the non-covering part and produces and expression

Returns:
the expression, or if something went wrong nonetheless it returns null

parse

public boolean parse(java.lang.String f,
                     IntArray DCS,
                     int totCover)
The function that implements the parsing/decoding part for holistic or non-terminal nodes.

Parameters:
f - the string to be parsed
DCS - the meaning of this string
totCover - the linguistic category of this string
Returns:
true if the parse is there.

partialParse

public boolean partialParse(java.lang.String f,
                            IntArray DCS,
                            int totCover)
This function tries to parse a part of the speaker's utterance.

Parameters:
f - the speaker's utterance
DCS - the meaning to be considered
totCover - the linguistic category
Returns:
true if a the string can be partially parsed

exploit

public boolean exploit(java.lang.String f,
                       int lg)
This function exploits a partial parse to adopt a part of the utterance.

Parameters:
f - the original expression, part of which is adopted here
lg - language game number return true if exploitation succeeds (should normally be the case)

generalise

public void generalise(java.lang.String f,
                       IntArray m,
                       int c,
                       int n)
This function generalises the grammar by searching unexplored rules that can be generalised based on a new rule.

Parameters:
f - the expression of the new rule
m - the meaning of the new rule
c - the cover/conceptual space/linguistic category of the new rule
n - the position/constituent of the new rule

getWeight

public double getWeight()
This function returns the rule weight


getScore

public double getScore()
This function returns the score of the rule. This is calculated as the rule weight times the meaning score


getScore

public double getScore(int[] f,
                       int c)
This function calculates the score of the composition.

Parameters:
f - not used at the moment
c - not used at the moment

updateFrequency

public void updateFrequency(int[] f,
                            int c)
This function updates the frequency with which it has been able to encode or decode an expression, irrespective of whether it was finally selected or not. This could be part of a probabilistic parser. And currently only used to inform us.


getParts

public java.lang.String[] getParts()
This function returns the words of the rule's composition as a string array


getExpression

public java.lang.String getExpression()
This function returns the expression of the rule.


getComposition

public IntArray getComposition()
Returns the composition of the rule

Returns:
the composition as an IntArray. If there is no composition, it returns an emty array

setComposition

public void setComposition(IntArray c)
Sets the composition to the given composition

Parameters:
c - the composition

getMeaning

public double[][] getMeaning(java.lang.String l,
                             java.lang.String l1,
                             int dim)
returns a matrix representation of the meaning. this representation is used for constructing the grammar in the UI


wordMatch

public boolean wordMatch(java.lang.String u,
                         IntArray dcs)
This function checks whether the utterance matches the rule's expression. If so, then it adds the meanings of the dcs to the rule's meaning.

Parameters:
u - the utterance
dcs - the distinctive category
Returns:
true if the word matches, false otherwise

generaliseAndMerge

public boolean generaliseAndMerge(int rule)
This function implements generalise and merge. Part of the generalisation is done with the function generalise(final String f,final IntArray m,final int c,final int n) that is defined and called elsewhere. Here the function compares this rule with another rule and sees if there are commonalities or ways to generalise the two rules.

Parameters:
rule - index to the rule to be compared.
Returns:
true if the rule can be merged.

toString

public java.lang.String toString()
general string form

Overrides:
toString in class java.lang.Object

niceString

public java.lang.String niceString()
a string form of the rule


printSH

public java.lang.String printSH()
Returns a string representation of the rule


getString

public java.lang.String getString(java.lang.String l)
Returns a string representation for the linguistic categories that make up this rule.

Parameters:
l - the string with labels of all features used in the simulation
Returns:
string of the conceptual space for a terminal node, or a string of the combination of of conceptual spaces of the compositional rule (e.g. "RGB ; S" if the rule is a composition of colour and shape)

equals

public boolean equals(Rules2 r1)
Implementation of an alternative equals

Parameters:
r1 - the rule to compare
Returns:
true if the rules are - apart from their semantics! - equal

updateScore

public void updateScore(boolean s)
Updates all weights of this rule and their meanings.

Parameters:
s - boolean indicating the success of the game

updateScore

public void updateScore(boolean s,
                        IntArray d)
Function that calls the function updateScore(boolean s) function, after the tmpMeanings array is initialised with the proper meanings specified in d

Parameters:
s - boolean indicating the success of the game
d - the IntArray containing the distinctive categories

getFrequency

public int getFrequency()
Returns the frequency of the rule


getCompositional

public boolean getCompositional()
Returns:
true if the rule has more than 1 constituent, false otherwise

compositionality

public int compositionality()
Returns:
1 if the rule has more than 1 constituent, 0 otherwise

getHolistic

public boolean getHolistic()
Returns:
true if the rule is holistic

isSentence

public boolean isSentence()
Returns:
true if the rule is a rewrite rule for a sentence (ie. it covers the entire conceptual space)

similar

public boolean similar(java.util.List g)
This function searches the grammar g if it has a rule that is similar to this one. A rule is considereed similar if:
1. the expressions are equal, or
2. the covers/linguistic categories are equal
For reasons of convenience, the semantics are not compared.

Parameters:
g - grammar of another agent
Returns:
true if the rule has a similar counterpart in g

getTotalUse

public int getTotalUse()
Returns:
the number of times the rule was used in the language games