DeleteLink

From OpenCog
Jump to: navigation, search

The DeleteLink is a kind of FreeLink that can never be fully grounded in the AtomSpace. Attempting to insert a fully grounded DeleteLink into the atomspace causes the body of link to be deleted. It is used during pattern matching to delete certain links if they are found.

There are several ways to use DeleteLink. One way is to combine it with PutLink (and use cog-execute!). Another way is to combine it the BindLink.

Formally, one would say that DeleteLinks can only ever be open sentences, or open terms; they can never be closed sentences.

A related concept is the StateLink, which allows only one closed term in the atomspace; adding a second one causes the earlier one to be automatically deleted.

Executing, with PutLink

Suppose one wanted to delete the statement that "Ben is a martian"

InheritanceLink
   ConceptNode "Ben"
   ConceptNode "martian"

from the atomspace. Of course, one could do this by explicitly calling cog-delete on it, but this requires scheme programming to accomplish. To stick to atomese, one would write:

PutLink
    DeleteLink
        InheritanceLink
            VariableNode $x
            ConceptNode "martian"
    ConceptNode "Ben"

When this is executed (for example, using cog-execute!) then the beta-reduction is performed, the variable $x is replaced by the node "Ben", and the resulting inheritance link is then deleted.

Note that only the InheritanceLink would be deleted; the ConceptNodes "Ben" and "Martian" would remain in the atomspace, untouched.

Searching, with the pattern matcher

To delete inheritance links between some set and "martians" from the atomspace, one can use either a GetLink or BindLink to find the members of the set, and then have the DeleteLink as the implicand to delete the inhertiance link. Thus, for example:

BindLink
    VariableNode $x
    AndLink
        <clauses that define some set, whose members are $x>
    DeleteLink
        InheritanceLink
            VariableNode $x
            ConceptNode "martian"

When evaluated by the pattern matcher, it would cause all inheritance links between $x and "martians" to be deleted from the AtomSpace. In the above example, only the InheritanceLink is deleted; the grounded values are not.

See also