Skip to content

Commit

Permalink
positive => negate
Browse files Browse the repository at this point in the history
multiple fixes
  • Loading branch information
garfix committed Mar 26, 2021
1 parent 0517611 commit dd8b3c4
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 51 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

##
## 1.13 asynchronous execution - 26-03-2021

* asynchronous execution of mentalese code
* processing of input has been rewritten as a mentalese program
Expand Down
Binary file added doc/archive/blocksworld3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/archive/blocksworld4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions doc/remarks.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
## 2021-03-26

The rewrite I started on January 21 is done! Answering and execution are now separated. This is a major advancement and I will create a new release.

It is now possible to create a plan and execute that plan later, by creating a `goal` for it. This change shows itself most manifestly in the fact that the system answers "OK" directly after it has received the question, and before it starts executing the plan. This is an advancement even over SHRDLU, that says "OK" only after the execution is complete. To appreciate this difference it is only necessary to imagine that you want to tell the system to "Stop!" performing its current action.

The working representation of the blocks after all interactions now looks like this:

![Initial blocks world](archive/blocksworld3.png)

And here's a first impression of the web demo I am working on.

"Pick up a big red block."

![Initial blocks world](archive/blocksworld4.png)

It is still too brittle to release.

The system class now looks nothing like it did before. It used to contain all language processes. Now it just passes relational messages.

## 2021-03-25

Up until now, `go:list_foreach` only fails if all children fail. I need it to fail under certain circumstances. So I'm thinking about a
Expand Down
4 changes: 2 additions & 2 deletions lib/central/NameResolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func (resolver *NameResolver) Choose(messenger api.ProcessMessenger, nameInforma

// go:wait_for(go:user_select(['A', 'B', 'C'], Selection))
set := mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateWaitFor, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateWaitFor, []mentalese.Term{
mentalese.NewTermRelationSet(
mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateUserSelect, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateUserSelect, []mentalese.Term{
mentalese.NewTermList(names),
mentalese.NewTermVariable("Selection"),
}),
Expand Down
2 changes: 1 addition & 1 deletion lib/central/RelationMatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (matcher *RelationMatcher) MatchTwoRelations(needleRelation mentalese.Relat
// predicate
if needleRelation.Predicate != haystackRelation.Predicate {
match = false
} else if needleRelation.Positive != haystackRelation.Positive {
} else if needleRelation.Negate != haystackRelation.Negate {
match = false
} else if len(needleRelation.Arguments) != len(haystackRelation.Arguments) {
match = false
Expand Down
2 changes: 1 addition & 1 deletion lib/central/RelationTransformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (transformer *RelationTransformer) replaceRelations(transformations []menta
for _, relation := range relationSet {

// replace inside hierarchical relations
deepRelation := mentalese.NewRelation(true, relation.Predicate, relation.Arguments)
deepRelation := mentalese.NewRelation(false, relation.Predicate, relation.Arguments)

for i, argument := range deepRelation.Arguments {
if argument.IsRelationSet() {
Expand Down
25 changes: 16 additions & 9 deletions lib/global/System.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func (system *System) assert(relation mentalese.Relation) {

// go:assert(go:goal(go:respond(input, Id)))
set := mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateAssert, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateAssert, []mentalese.Term{
mentalese.NewTermRelationSet(mentalese.RelationSet{relation}),
}),
}
Expand All @@ -92,11 +92,11 @@ func (system *System) createAnswerGoal(input string) string {

// go:assert(go:goal(go:respond(input, Id)))
set := mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateAssert, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateAssert, []mentalese.Term{
mentalese.NewTermRelationSet(mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateGoal, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateGoal, []mentalese.Term{
mentalese.NewTermRelationSet(mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateRespond, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateRespond, []mentalese.Term{
mentalese.NewTermString(input),
}),
}),
Expand All @@ -110,10 +110,13 @@ func (system *System) createAnswerGoal(input string) string {
}

func (system *System) deleteGoal(goalId string) {

system.processList.RemoveProcess(goalId)

set := mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateRetract, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateRetract, []mentalese.Term{
mentalese.NewTermRelationSet(mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateGoal, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateGoal, []mentalese.Term{
mentalese.NewTermAnonymousVariable(),
mentalese.NewTermString(goalId),
})}),
Expand All @@ -131,13 +134,18 @@ func (system *System) Answer(input string) (string, *common.Options) {
done := false

// find or create a goal
system.getGoalId(input)
goalId := system.getGoalId(input)

for !done {

// execute all goals
system.Run()

if len(system.log.GetErrors()) > 0 {
system.deleteGoal(goalId)
break
}

// read answer action
anAnswer, someOptions, done = system.readAnswer()
if anAnswer != "" {
Expand Down Expand Up @@ -186,7 +194,7 @@ func (system *System) Run() {

// find all goals
set := mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateGoal, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateGoal, []mentalese.Term{
mentalese.NewTermVariable("Goal"),
mentalese.NewTermVariable("Id"),
}),
Expand All @@ -204,7 +212,6 @@ func (system *System) Run() {

// delete goal when done
if process.IsDone() {
system.processList.RemoveProcess(process.GoalId)
system.deleteGoal(goalId)
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/importer/InternalGrammarParserFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ func (parser *InternalGrammarParser) parseRelationTag(tokens []Token, startIndex
if found {
tag, startIndex, found = parser.parseSingleToken(tokens, startIndex, t_variable)
if found {
relation = mentalese.NewRelation(true, mentalese.PredicateIncludeRelations, []mentalese.Term{
relation = mentalese.NewRelation(false, mentalese.PredicateIncludeRelations, []mentalese.Term{
mentalese.NewTermVariable(tag),
})
_, startIndex, found = parser.parseSingleToken(tokens, startIndex, t_double_closing_brace)
Expand Down Expand Up @@ -469,15 +469,15 @@ func (parser *InternalGrammarParser) parseRelation(tokens []Token, startIndex in
arguments := []mentalese.Term{}
predicate := ""
newStartIndex := 0
positive := true
negate := false
relation := mentalese.Relation{}

_, startIndex, ok = parser.parseSingleToken(tokens, startIndex, t_negative)
if ok {
positive = false
negate = true
}

relation, newStartIndex, ok = parser.parsePlaceholder(tokens, startIndex, positive)
relation, newStartIndex, ok = parser.parsePlaceholder(tokens, startIndex, negate)
if ok {
startIndex = newStartIndex
} else {
Expand Down Expand Up @@ -537,7 +537,7 @@ func (parser *InternalGrammarParser) parseRelation(tokens []Token, startIndex in
}

}
relation = mentalese.NewRelation(positive, prefix + predicate, arguments)
relation = mentalese.NewRelation(negate, prefix + predicate, arguments)
}

return relation, startIndex, ok
Expand Down
6 changes: 3 additions & 3 deletions lib/knowledge/SystemMultiBindingBase.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,17 @@ func (base *SystemMultiBindingFunctionBase) makeAnd(messenger api.ProcessMesseng
if count == 0 {
return bindings
} else if count == 1 {
relation = mentalese.NewRelation(true, mentalese.PredicateAnd, []mentalese.Term{
relation = mentalese.NewRelation(false, mentalese.PredicateAnd, []mentalese.Term{
uniqueValues[0],
uniqueValues[0],
})
} else {
relation = mentalese.NewRelation(true, mentalese.PredicateAnd, []mentalese.Term{
relation = mentalese.NewRelation(false, mentalese.PredicateAnd, []mentalese.Term{
uniqueValues[count - 2],
uniqueValues[count - 1],
})
for i := len(uniqueValues)-3; i >= 0 ; i-- {
relation = mentalese.NewRelation(true, mentalese.PredicateAnd, []mentalese.Term{
relation = mentalese.NewRelation(false, mentalese.PredicateAnd, []mentalese.Term{
uniqueValues[i],
mentalese.NewTermRelationSet(mentalese.RelationSet{ relation }),
})
Expand Down
4 changes: 2 additions & 2 deletions lib/knowledge/function/grammar.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (base *SystemSolverFunctionBase) rangeIndexClarification(messenger api.Proc
if state == 0 {

set := mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateAssert, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateAssert, []mentalese.Term{
mentalese.NewTermRelationSet(mentalese.RelationSet{
mentalese.NewRelation(true, mentalese.PredicateOutput, []mentalese.Term{
mentalese.NewRelation(false, mentalese.PredicateOutput, []mentalese.Term{
mentalese.NewTermString("I don't understand which one you mean"),
})}),
}),
Expand Down
2 changes: 1 addition & 1 deletion lib/knowledge/function/quick-sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (base *SystemSolverFunctionBase) compare(messenger api.ProcessMessenger, id
return 0, false
}

relation := mentalese.NewRelation(true, orderFunction, []mentalese.Term{
relation := mentalese.NewRelation(false, orderFunction, []mentalese.Term{
mentalese.NewTermVariable("E1"),
mentalese.NewTermVariable("E2"),
mentalese.NewTermVariable("R"),
Expand Down
22 changes: 11 additions & 11 deletions lib/mentalese/Relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
)

type Relation struct {
Positive bool `json:"positive"`
Predicate string `json:"predicate"`
Arguments []Term `json:"arguments"`
Negate bool `json:"negate,omitempty"`
Predicate string `json:"predicate"`
Arguments []Term `json:"arguments"`
}

const ProcessInstructionLet = "let"
Expand Down Expand Up @@ -132,9 +132,9 @@ const SeqSecondOperandIndex = 1

const NotScopeIndex = 0

func NewRelation(positive bool, predicate string, arguments []Term) Relation {
func NewRelation(negate bool, predicate string, arguments []Term) Relation {
return Relation{
Positive: positive,
Negate: negate,
Predicate: predicate,
Arguments: arguments,
}
Expand All @@ -155,7 +155,7 @@ func (relation Relation) Equals(otherRelation Relation) bool {

equals := relation.Predicate == otherRelation.Predicate

equals = equals && relation.Positive == otherRelation.Positive
equals = equals && relation.Negate == otherRelation.Negate

for i, argument := range relation.Arguments {
equals = equals && argument.Equals(otherRelation.Arguments[i])
Expand All @@ -168,7 +168,7 @@ func (relation Relation) Copy() Relation {

newRelation := Relation{}
newRelation.Predicate = relation.Predicate
newRelation.Positive = relation.Positive
newRelation.Negate = relation.Negate
newRelation.Arguments = []Term{}
for _, argument := range relation.Arguments {
newRelation.Arguments = append(newRelation.Arguments, argument.Copy())
Expand All @@ -186,7 +186,7 @@ func (relation Relation) BindSingle(binding Binding) Relation {
boundArguments = append(boundArguments, arg)
}

return NewRelation(relation.Positive, relation.Predicate, boundArguments)
return NewRelation(relation.Negate, relation.Predicate, boundArguments)
}

// Returns multiple relations, that has all variables bound to bindings
Expand Down Expand Up @@ -233,7 +233,7 @@ func (relation Relation) ConvertVariablesToConstants() Relation {
newArguments = append(newArguments, newArgument)
}

return NewRelation(relation.Positive, relation.Predicate, newArguments)
return NewRelation(relation.Negate, relation.Predicate, newArguments)
}

func (relation Relation) String() string {
Expand All @@ -247,7 +247,7 @@ func (relation Relation) String() string {
}

sign := ""
if !relation.Positive {
if relation.Negate {
sign = "-"
}

Expand All @@ -272,7 +272,7 @@ func (relation Relation) IndentedString(indent string) string {
}

sign := ""
if !relation.Positive {
if relation.Negate {
sign = "-"
}

Expand Down
4 changes: 2 additions & 2 deletions lib/mentalese/RelationSet.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (relations RelationSet) ReplaceTerm(from Term, to Term) RelationSet {

arguments := []Term{}
predicate := relation.Predicate
positive := relation.Positive
negative := relation.Negate

for _, argument := range relation.Arguments {

Expand All @@ -179,7 +179,7 @@ func (relations RelationSet) ReplaceTerm(from Term, to Term) RelationSet {
arguments = append(arguments, relationArgument)
}

relation := NewRelation(positive, predicate, arguments)
relation := NewRelation(negative, predicate, arguments)
newRelations = append(newRelations, relation)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/parse/EarleyParser.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (parser *EarleyParser) Parse(words []string, rootCategory string, rootVaria
lastParsedWordIndex, nextWord := FindLastCompletedWordIndex(chart)

if nextWord != "" {
parser.log.AddError("Incomplete. Could not parse word: " + nextWord)
parser.log.AddError("Could not parse the word: " + nextWord)
} else if len(words) == 0 {
parser.log.AddError("No sentence given.")
} else if lastParsedWordIndex == len(words)-1 {
Expand Down
4 changes: 2 additions & 2 deletions lib/parse/Relationizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ func (relationizer Relationizer) includeChildSenses(parentRelation mentalese.Rel
childIndexes = append(childIndexes, index)
newParentRelationSet = childSets[index].Copy()
for i := range newParentRelationSet {
if !parentRelation.Positive {
newParentRelationSet[i].Positive = !newParentRelationSet[i].Positive
if parentRelation.Negate {
newParentRelationSet[i].Negate = !newParentRelationSet[i].Negate
}
}
} else {
Expand Down
Loading

0 comments on commit dd8b3c4

Please sign in to comment.