From OpenCog
Jump to: navigation, search

Links are Atom types that connect other Atoms. A Link is uniquely defined by its type and its outgoing set, i.e., the set of Atoms linked by it. If a Link with the same type and outgoing set of a previously inserted Link is inserted in the AtomSpace, they are merged.

The type and outgoing set of the link cannot be changed after the link has been inserted into the AtomSpace: OpenCog atoms are immutable objects.

Scheme interface

Links can be created, manipulated and destroyed at the scheme shell command prompt. See scheme for details.

C++ programming interface

class Link : public Atom
       std::vector<Handle> _outgoing;
       Link(Type, const std::vector<Handle>&);
       const std::vector<Handle>& getOutgoingSet()
            { return _outgoing; }
       size_t getArity() const {return _outgoing.size(); }
       std::string toString() const;
       std::string toShortString() const;

toString() and toShortString() return string representations of the link.

getArity() returns the arity of the Link, i.e. the number of Atoms which participate in the relationship it represents.

getOutgoingSet() returns the outgoing set of the Atom.

Incoming and Outgoing Sets

These are easiest to understand by example. Consider an AtomSpace formed by four Nodes A, B, C and D and four Links:

L1 A -> B
L2 A -> C
L3 D -> B
L4 L1 -> A

In the following table we have the incoming and the outgoing sets of each Atom:

Atom Incoming set Outgoing set
A {L1,L2,L4} null
B {L1,L3} null
C {L2} null
D {L3} null
L1 {L4} {A,B}
L2 null {A,C}
L3 null {D,B}
L4 null {L1,A}

The incoming set is stored inside the Atom computed and represented as a single linked list while the outgoing set is stored in an array of Handles with 'arity' elements. The array and the linked list store the Handles and not the Atoms themselves.

Another way to explain this is by imagining an InheritanceLink between 'cat' and 'animal'. In this link, the outgoing set is defined as the nodes that are connected by the link, so 'cat' and 'animal'. If you would then imagine another link to define the fact that 'Bob knows a cat is an animal', that link would be in the incoming set of the previously defined 'cat' inherits from 'animal' link.

Alternative explanation

The outgoing set of relationship R is the list of arguments of that relation.

The incoming set of an entity E is the set of relationships that take E as an argument.