Beispiel #1
0
    def link_connect_impl(self, decided_atoms, new_blended_atom, config_base):
        check_type_str = BlendConfig().get_str(self.a, "connect-check-type",
                                               config_base)
        strength_diff_threshold = BlendConfig().get_str(
            self.a, "connect-strength-diff-limit", config_base)
        confidence_above_threshold = BlendConfig().get_str(
            self.a, "connect-confidence-above-limit", config_base)
        viable_atoms_count_threshold = BlendConfig().get_str(
            self.a, "connect-viable-atoms-count-limit", config_base)

        self.check_type = get_type(check_type_str)

        if check_type_str != get_type_name(self.check_type):
            raise UserWarning("Can't resolve type" + str(check_type_str))

        try:
            self.strength_diff_limit = \
                float(strength_diff_threshold)
            self.confidence_above_limit = \
                float(confidence_above_threshold)
        except (TypeError, ValueError):
            raise UserWarning(
                "Can't parse threshold value:: "
                "{strength: {0}, confidence: {1}, count: {2}}".format(
                    str(strength_diff_threshold),
                    str(confidence_above_threshold),
                    str(viable_atoms_count_threshold)))

        try:
            self.viable_atoms_count_threshold = \
                int(viable_atoms_count_threshold)
        except ValueError:
            self.viable_atoms_count_threshold = None

        self.__connect_links_simple(decided_atoms, new_blended_atom)
Beispiel #2
0
 def _get_atoms_by_type(self, type):
     type_name = get_type_name(type)
     return execute_atom(
         self.space,
         GetLink(
             VariableList(
                 TypedVariableLink(VariableNode("X"), TypeNode(type_name))),
             AndLink(VariableNode("X"))))
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()

        Rule.__init__(self,
                      name = "InversionRule<%s>"%(get_type_name(link_type),),
                      outputs=[chainer.link(link_type, [B, A])],
                      inputs=[chainer.link(link_type, [A, B]), A, B],
                      formula=formulas.inversionFormula)
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()

        Rule.__init__(self,
                      name="SymmetricModusPonensRule<%s>"%(get_type_name(link_type),),
                      outputs=[B],
                      inputs=[chainer.link(link_type, [A, B]),
                              A],
                      formula=formulas.symmetricModusPonensFormula)
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()

        Rule.__init__(self,
                      name="AndToSubsetRule1<%s>"%(get_type_name(link_type),),
                      outputs=[chainer.link(link_type, [A, B])],
                      inputs=[chainer.link(types.AndLink, [A, B]),
                              A],
                      formula=formulas.subsetFormula)
Beispiel #6
0
def vertices_from_atomset(atomset):
    """
    Converts an atomset representing a subhypergraph into a set of vertices
    representing a graph
    """
    vertices = []
    for atom in atomset:
        vertex = {"type": get_type_name(atom.type), "name": atom.name, "handle": atom.h.value()}
        vertices.append(vertex)
    return vertices
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()
        C = chainer.new_variable()

        Rule.__init__(self,
            name="DeductionGeometryRule<%s>"%(get_type_name(link_type),),
            formula=formulas.deductionGeometryFormula,
            outputs=[chainer.link(link_type, [A, C])],
            inputs=[chainer.link(link_type, [A, B]),
                    chainer.link(link_type, [B, C])])
 def __init__(self, chainer, link_type1, link_type2, *args):
     A = chainer.new_variable()
     B = chainer.new_variable()
     C = chainer.new_variable()
     # compositions can encompass either 1, 3, 5, 9 or 13 relations
     outputs = []
     for output_type in args:
         outputs.append(chainer.link(output_type, [A, C]))
     Rule.__init__(self,
                   name="TemporalCompositionRule ({0}).({1}) = ({2})"
                   .format(
                       get_type_name(link_type1),
                       get_type_name(link_type2),
                       " ".join([get_type_name(output_type)
                                 for output_type in args])),
                   # a formula is still needed
                   formula=None,
                   inputs=[chainer.link(link_type1, [A, B]),
                           chainer.link(link_type2, [B, C])],
                   outputs=outputs)
    def __init__(self, chainer, link_type):
        S = chainer.new_variable()
        M = chainer.new_variable()
        L = chainer.new_variable()

        Rule.__init__(self,
                      name="AbductionRule<%s>"%(get_type_name(link_type),),
                      outputs=[chainer.link(link_type, [S, L])],
                      inputs=[chainer.link(link_type, [S, M]),
                              chainer.link(link_type, [L, M]), S, M, L],
                      formula=formulas.abductionFormula)
Beispiel #10
0
 def __init__(self, chainer, link_type1, link_type2, *args):
     A = chainer.new_variable()
     B = chainer.new_variable()
     C = chainer.new_variable()
     # compositions can encompass either 1, 3, 5, 9 or 13 relations
     outputs = []
     for output_type in args:
         outputs.append(chainer.link(output_type, [A, C]))
     Rule.__init__(self,
                   name="TemporalCompositionRule ({0}).({1}) = ({2})"
                   .format(
                       get_type_name(link_type1),
                       get_type_name(link_type2),
                       " ".join([get_type_name(output_type)
                                 for output_type in args])),
                   # a formula is still needed
                   formula=None,
                   inputs=[chainer.link(link_type1, [A, B]),
                           chainer.link(link_type2, [B, C])],
                   outputs=outputs)
Beispiel #11
0
    def __init__(self, chainer, link_type, formula= formulas.deductionSimpleFormula):
        A = chainer.new_variable()
        B = chainer.new_variable()
        C = chainer.new_variable()

        Rule.__init__(self, formula=formula,
            outputs= [chainer.link(link_type, [A, C])],
            inputs=  [chainer.link(link_type, [A, B]),
                      chainer.link(link_type, [B, C])]
            )

        self.name = get_type_name(link_type) + 'TransitivityRule'
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()
        C = chainer.new_variable()

        Rule.__init__(self,
                      name="TransitiveSimilarityRule<%s>"%(get_type_name(link_type),),
                      formula=formulas.transitiveSimilarityFormula,
                      outputs=[chainer.link(link_type, [A, C])],
                      inputs=[chainer.link(link_type, [A, B]),
                              chainer.link(link_type, [B, C]),
                              A, B, C])
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()

        AB = chainer.link(link_type, [A, B])
        BA = chainer.link(link_type, [B, A])

        Rule.__init__(self,
                      name="TermProbabilityRule<%s>"%(get_type_name(link_type),),
                      outputs=[B],
                      inputs=[AB, BA, A],
                      formula=formulas.termProbabilityFormula)
    def __init__(self, chainer, link_type, formula= formulas.deductionIndependenceBasedFormula):
        A = chainer.new_variable()
        B = chainer.new_variable()
        C = chainer.new_variable()

        Rule.__init__(self, formula=formula,
            outputs= [chainer.link(link_type, [A, C])],
            inputs=  [chainer.link(link_type, [A, B]),
                      chainer.link(link_type, [B, C])]
            )

        self.name = get_type_name(link_type) + 'TransitivityRule'
    def __init__(self, chainer, link_type, N):
        vars = chainer.make_n_variables(N)
        
        lhs = chainer.link(types.AndLink, vars[:-1])
        rhs = vars[-1]

        Rule.__init__(self,
                      name="AndToSubsetRuleN<%s,%s>"%(get_type_name(link_type),N),
                      outputs=[chainer.link(link_type, [lhs, rhs])],
                      inputs=[chainer.link(types.AndLink, vars),
                              lhs],
                      formula=formulas.subsetFormula)
    def __init__(self, chainer, link_type, formula):
        A = chainer.new_variable()
        B = chainer.new_variable()
        ta = chainer.new_variable()
        tb = chainer.new_variable()

        Rule.__init__(self,
            formula= formula,
            outputs= [chainer.link(link_type, [A, B])],
            inputs=  [chainer.link(types.AtTimeLink, [ta, A]),
                      chainer.link(types.AtTimeLink, [tb, B])])

        self.name = get_type_name(link_type) + 'EvaluationRule'
Beispiel #17
0
    def __init__(self, chainer, link_type, formula):
        A = chainer.new_variable()
        B = chainer.new_variable()
        ta = chainer.new_variable()
        tb = chainer.new_variable()

        Rule.__init__(self,
            formula= formula,
            outputs= [chainer.link(link_type, [A, B])],
            inputs=  [chainer.link(types.AtTimeLink, [ta, A]),
                      chainer.link(types.AtTimeLink, [tb, B])])

        self.name = get_type_name(link_type) + 'EvaluationRule'
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()

        notA = chainer.link(types.NotLink, [A])

        Rule.__init__(self,
                      name="PreciseModusPonensRule<%s>"%(get_type_name(link_type),),
                      outputs=[B],
                      inputs=[chainer.link(link_type, [A, B]),
                              chainer.link(link_type, [notA, B]),
                              A],
                      formula=formulas.preciseModusPonensFormula)
Beispiel #19
0
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_variable()
        C = chainer.new_variable()
        AndAB = chainer.link(types.AndLink, [A, B])

        Rule.__init__(self,
                      name="AndAs1stArgInsideLinkRule<%s>"
                           %(get_type_name(link_type)),
                      inputs=[C, chainer.link(link_type, [A, C]),
                              chainer.link(link_type, [B, C]), A, B],
                      outputs=[chainer.link(link_type, [AndAB, C]),
                               AndAB],
                      formula=formulas.andAs1stArgInsideLinkFormula)
Beispiel #20
0
    def __init__(self, chainer, N, link_type=None):

        self._chainer = chainer
        if link_type is not None:
            atoms = [chainer.link(link_type, chainer.make_n_variables(2)) for i in range(N)]
        else:
            atoms = chainer.make_n_variables(N)

        Rule.__init__(self,
                      formula=formulas.andFormula,
                      outputs=[chainer.link(types.AndLink, atoms)],
                      inputs=atoms,
                      name = "AndCreationRule<"+str(N) +
                             "%s>"%("" if link_type is None else ", " + get_type_name(link_type)))
Beispiel #21
0
    def __init__(self, chainer, link_type, formula= formulas.deductionIndependenceBasedFormula):
        A = chainer.new_variable()
        B = chainer.new_variable()
        C = chainer.new_variable()

        rules.Rule.__init__(self, formula=formula,
            outputs= [chainer.link(link_type, [A, C])],
            inputs=  [chainer.link(link_type, [A, B]),
                      chainer.link(link_type, [B, C])]
            )

        self.name = get_type_name(link_type) + 'TransitivityRule'

        self.probabilistic_inputs = False
Beispiel #22
0
def vertices_from_atomset(atomset):
    """
    Converts an atomset representing a subhypergraph into a set of vertices
    representing a graph
    """
    vertices = []
    for atom in atomset:
        vertex = {
            'type': get_type_name(atom.type),
            'name': atom.name,
            'handle': atom.h.value()
        }
        vertices.append(vertex)
    return vertices
Beispiel #23
0
    def __init__(self, chainer, link_type):
        A = chainer.new_variable()
        B = chainer.new_varialbe()
        C = chainer.new_variable()
        AndBC = chainer.link(types.AndLink, [B, C])

        Rule.__init__(self,
                      name="AndAs2ndArgInsideLinkRule<%s>"
                           %(get_type_name(link_type)),
                      inputs=[chainer.link(types.InheritanceLink, [A, B]),
                              chainer.link(types.InheritanceLink, [A, C]),
                              A, B, C],
                      outputs=[chainer.link(types.InheritanceLink, [A, AndBC]),
                               AndBC],
                      formula=formulas.andAs2ndArgInsideLinkFormula)
Beispiel #24
0
    def __init__(self, chainer, link_type, formula):
        A = chainer.new_variable()
        B = chainer.new_variable()
        ta = chainer.new_variable()
        tb = chainer.new_variable()

        Rule.__init__(self,
                      formula=formula,
                      outputs=[chainer.link(link_type, [A, B])],
                      inputs=[
                          chainer.link(types.AtTimeLink, [A, ta]),
                          chainer.link(types.AtTimeLink, [B, tb])
                      ])

        self.name = get_type_name(link_type) + 'EvaluationRule'

        self.probabilistic_inputs = False
Beispiel #25
0
#! /usr/bin/env python
#
# atom_type_names.py
#
"""
Example of how to obtain atom type names and atom type IDs in Python
"""

__author__ = 'Cosmo Harrigan'

from opencog.atomspace import AtomSpace, types, get_type_name

atomspace = AtomSpace()

atom = atomspace.add(types.ConceptNode, "Frog #1")

# To get one type name
print get_type_name(3) + '\n'

# To get one atom's type name
print get_type_name(atom.type) + '\n'

# Get a list of all possible type names and numbers
for key, value in sorted(types.__dict__.iteritems()):
    if '__' not in key:
        print key, value
Beispiel #26
0
 def test_get_type_name(self):
     self.assertEqual(get_type_name(types.Node), "Node")
     self.assertEqual(get_type_name(2231), "")
     self.assertEqual(get_type_name(types.NO_TYPE), "")
Beispiel #27
0
 def test_get_type_name(self):
     self.assertEqual(get_type_name(types.Node), "Node")
     self.assertEqual(get_type_name(2231), "")
     self.assertEqual(get_type_name(types.NO_TYPE), "")
Beispiel #28
0
#
"""
Example of how to obtain atom type names and atom type IDs in Python
"""

__author__ = 'Cosmo Harrigan'

from opencog.atomspace import AtomSpace, TruthValue, types, get_type_name
from opencog.scheme_wrapper import load_scm, scheme_eval, scheme_eval_h, __init__

atomspace = AtomSpace()
__init__(atomspace)

data = ["opencog/atomspace/core_types.scm", "opencog/scm/utilities.scm"]

for item in data:
    load_scm(atomspace, item)

atom = atomspace.add(types.ConceptNode, "Frog #1")

# To get one type name
print get_type_name(3) + '\n'

# To get one atom's type name
print get_type_name(atom.type) + '\n'

# Get a list of all possible type names and numbers
for key, value in sorted(types.__dict__.iteritems()):
    if '__' not in key:
        print key, value
Beispiel #29
0
 def test_get_type_name(self):
     self.assertEqual(get_type_name(types.Node), "Node")
     self.assertEqual(get_type_name(2231), "")
     # XXX FIXME is testing the name of the bottom type
     # a sane thing to do?
     self.assertEqual(get_type_name(types.NO_TYPE), "*** Bottom Type! ***")
Beispiel #30
0
#! /usr/bin/env python
#
# atom_type_names.py
#
"""
Example of how to obtain atom type names and atom type IDs in Python
"""

__author__ = 'Cosmo Harrigan'

from opencog.atomspace import AtomSpace, types, get_type_name

atomspace = AtomSpace()

atom = atomspace.add(types.ConceptNode, "Frog #1")

# To get one type name
print(get_type_name(3) + '\n')

# To get one atom's type name
print(get_type_name(atom.type) + '\n')

# Get a list of all possible type names and numbers
for key, value in sorted(types.__dict__.items()):
    if '__' not in key:
        print(key, value)