Example #1
0
    def test_pleonastic_if(self):

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#1.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#2.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#3.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#4.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/pleonastic_it/data_#5.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()
Example #2
0
    def setUp(self):
        self.atomspace = AtomSpace()
        scheme.__init__(self.atomspace)
        for scheme_file in scheme_preload:
            load_scm(self.atomspace, scheme_file)
        
        # Define several animals and something of a different type as well
        scheme_animals = \
            '''
            (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
            (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
            '''
        scheme_eval_h(self.atomspace, scheme_animals)

        # Define a graph search query
        bind_link_query = \
            '''
            (BindLink
                ;; The variable to be grounded
                (VariableNode "$var")
                (ImplicationLink
                    ;; The pattern to be grounded
                    (InheritanceLink
                        (VariableNode "$var")
                        (ConceptNode "animal")
                    )
                    ;; The grounding to be returned.
                    (VariableNode "$var")
                )
            )
            '''
        self.bindlink_handle = scheme_eval_h(self.atomspace, bind_link_query)
Example #3
0
def prep_predicates(atomspace):
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)

    # Define dogs relationships
    scheme_dog_predicates = \
        '''
        (EvaluationLink
            (PredicateNode "IsA")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "mammal")
            )
        )
        (EvaluationLink
            (PredicateNode "IsA")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "animal")
            )
        )
        (EvaluationLink
            (PredicateNode "Loves")
            (ListLink
                (ConceptNode "dog")
                (ConceptNode "biscuits")
            )
        )
        '''
    scheme_eval_h(atomspace, scheme_dog_predicates)
    dog = atomspace.add_node(types.ConceptNode, "dog")
    isA = atomspace.add_node(types.PredicateNode, "IsA")
    return dog, isA
Example #4
0
    def test_a_load_core_types(self):

        # These relative paths are horridly ugly.
        # There must be a better way ...
        status = load_scm(self.space, "build/opencog/atomspace/core_types.scm")
        self.assertTrue(status)

        status = load_scm(self.space, "opencog/scm/utilities.scm")
        self.assertTrue(status)
Example #5
0
    def initilization(self,atomspace):
        self.atomspace = atomspace

        self.currentPronounNode = atomspace.add_node(types.AnchorNode, 'CurrentPronoun', TruthValue(1.0, 100))
        self.currentTarget = atomspace.add_node(types.AnchorNode, 'CurrentTarget', TruthValue(1.0, 100))
        self.currentResult = atomspace.add_node(types.AnchorNode, 'CurrentResult', TruthValue(1.0, 100))
        self.currentProposal = atomspace.add_node(types.AnchorNode, 'CurrentProposal', TruthValue(1.0, 100))
        self.unresolvedReferences=atomspace.add_node(types.AnchorNode, 'Recent Unresolved references', TruthValue(1.0, 100))
        self.resolvedReferences=atomspace.add_node(types.AnchorNode, 'Resolved references', TruthValue(1.0, 100))
        self.currentResolutionNode=atomspace.add_node(types.AnchorNode, 'CurrentResolution', TruthValue(1.0, 100))
        self.currentResolutionLink_proposal=self.atomspace.add_link(types.ListLink, [self.currentResolutionNode, self.currentProposal], TruthValue(1.0, 100))
        self.currentResolutionLink_pronoun=self.atomspace.add_link(types.ListLink, [self.currentResolutionNode, self.currentPronounNode], TruthValue(1.0, 100))
        self.pronounNumber = -1

        data=["opencog/nlp/anaphora/rules/getChildren.scm",
              "opencog/nlp/anaphora/rules/getNumberNode_WordInstanceNode.scm",
              "opencog/nlp/anaphora/rules/getNumberNode_ParseNode.scm",
              "opencog/nlp/anaphora/rules/connectRootsToParseNodes.scm",
              "opencog/nlp/anaphora/rules/getPronouns.scm",
              "opencog/nlp/anaphora/rules/propose.scm",
              "opencog/nlp/anaphora/rules/getResults.scm",
              "opencog/nlp/anaphora/rules/getAllNumberNodes.scm",
              "opencog/nlp/anaphora/rules/getAllParseNodes.scm",
              "opencog/nlp/anaphora/rules/getConjunction.scm",
              "opencog/nlp/anaphora/rules/getParseNode.scm",

              "opencog/nlp/anaphora/rules/filtersGenerator.scm",

              "opencog/nlp/anaphora/rules/filters/filter-#1.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#2.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#3.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#4.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#5.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#6.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#7.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#8.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#9.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#10.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#11.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#12.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#13.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#14.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#15.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#16.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#17.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#18.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#19.scm",
              ]

        self.numOfFilters=len(data)
        for item in data:
            load_scm(atomspace, item)

        self.getAllNumberNodes()
        self.pronouns = self.getPronouns()
        self.roots = self.getRoots()
Example #6
0
        def filter_18():

            print("Testing filter #18...")
            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#18/data_#1.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),18))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#18/data_#2.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),18))
            self.atomspace.clear()
Example #7
0
        def filter_12():

            print("Testing filter #12...")
            self.assertTrue(load_scm(self.atomspace, "tests/python/test_anaphora/data/propose/filter-#12/data_#1.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent',types.ParseNode),12))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/python/test_anaphora/data/propose/filter-#12/data_#2.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),12))
            self.atomspace.clear()
def set_up_atomspace():
    """
    Initializes a new atomspace, loads the core types and utitities.
    :return: an atomspace
    """
    coreTypes = "opencog/atomspace/core_types.scm"
    utilities = "opencog/scm/utilities.scm"
    newly_created_atomspace = AtomSpace()
    __init__(newly_created_atomspace)
    for item in [coreTypes, utilities]:
        load_scm(newly_created_atomspace, item)
    return newly_created_atomspace
Example #9
0
def prep_bind(atomspace):
    scheme.__init__(atomspace)
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)

    # Define several animals and something of a different type as well
    scheme_animals = """
        (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
        """
    scheme_eval_h(atomspace, scheme_animals)
Example #10
0
    def test_a_load_core_types(self):

        # These relative paths are horridly ugly.
        # There must be a better way ...
        # status = load_scm(self.space, "/usr/local/share/opencog/scm/core_types.scm")
        status = load_scm(self.space, "scm/core_types.scm")
        self.assertTrue(status)

        status = load_scm(self.space, "./build/opencog/nlp/types/nlp_types.scm")
        self.assertTrue(status)

        status = load_scm(self.space, "scm/utilities.scm")
        self.assertTrue(status)
Example #11
0
def prep_bind(atomspace):
    for scheme_file in scheme_preload:
        load_scm(atomspace, scheme_file)
    scheme_eval(atomspace, "(use-modules (opencog))")
    scheme_eval(atomspace, "(use-modules (opencog query))")

    # Define several animals and something of a different type as well
    scheme_animals = \
        '''
        (InheritanceLink (ConceptNode "Frog") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Zebra") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Deer") (ConceptNode "animal"))
        (InheritanceLink (ConceptNode "Spaceship") (ConceptNode "machine"))
        '''
    scheme_eval_h(atomspace, scheme_animals)
Example #12
0
    def setUp(self):

        self.atomspace= AtomSpace()

        scheme_eval(self.atomspace, "(add-to-load-path \"/usr/local/share/opencog/scm\")")
        scheme_eval(self.atomspace, "(use-modules (opencog))")
        scheme_eval(self.atomspace, "(use-modules (opencog atom-types))")
        scheme_eval(self.atomspace, "(use-modules (opencog query))")

        data=["opencog/scm/config.scm",
              "opencog/scm/core_types.scm",
              "opencog/scm/apply.scm",
              "opencog/scm/file-utils.scm",
              "opencog/scm/utilities.scm",
              "opencog/scm/av-tv.scm",
              "opencog/nlp/scm/type-definitions.scm",
              "opencog/nlp/scm/config.scm",
              "opencog/nlp/scm/file-utils.scm",
              "opencog/nlp/scm/nlp-utils.scm",
              "opencog/nlp/scm/disjunct-list.scm",
              "opencog/nlp/scm/processing-utils.scm",
              ]


        for item in data:
            status=load_scm(self.atomspace, item)
            # print "load status=", status, " item=", item

        self.hobbsAgent=HobbsAgent()
Example #13
0
    def setUp(self):

        self.atomspace= AtomSpace()
        __init__(self.atomspace)
        data=["opencog/scm/config.scm",
              "opencog/scm/core_types.scm",
              "spacetime/spacetime_types.scm",
              "opencog/nlp/types/nlp_types.scm",
              "opencog/dynamics/attention/attention_types.scm",
              "opencog/embodiment/embodiment_types.scm",
              "opencog/reasoning/pln/pln_types.scm",
              "opencog/scm/apply.scm",
              "opencog/scm/file-utils.scm",
              "opencog/scm/persistence.scm",
              #"opencog/scm/repl-shell.scm",
              "opencog/scm/utilities.scm",
              "opencog/scm/av-tv.scm",
              "opencog/nlp/scm/type-definitions.scm",
              "opencog/nlp/scm/config.scm",
              "opencog/nlp/scm/file-utils.scm",
              "opencog/nlp/scm/nlp-utils.scm",
              "opencog/nlp/scm/disjunct-list.scm",
              "opencog/nlp/scm/processing-utils.scm",
              ]


        for item in data:
            status=load_scm(self.atomspace, item)
        self.hobbsAgent=HobbsAgent()
Example #14
0
        def filter_9():

            print("Testing filter #9...")
            self.assertTrue(load_scm(self.atomspace, "tests/python/test_anaphora/data/propose/filter-#9/data_#1.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent'),9))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/python/test_anaphora/data/propose/filter-#9/data_#2.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),9))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/python/test_anaphora/data/propose/filter-#9/data_#3.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent'),9))
            self.atomspace.clear()
Example #15
0
 def __init__(self):
     self.a = AtomSpace()
     self.nodes = {}
     
     # Initialize Scheme
     scheme_preload = [  
                 "opencog/atomspace/core_types.scm",
                 "opencog/scm/utilities.scm"          ]
     scheme.__init__(self.a)
     for scheme_file in scheme_preload:
         load_scm(self.a, scheme_file)
     initialize_opencog(self.a)
     
     #add 3 nodes with integer values
     self.nodes[0] = self.a.add(types.ConceptNode, "0")
     self.nodes[1] = self.a.add(types.ConceptNode, "1")
     self.nodes[2] = self.a.add(types.ConceptNode, "2")
Example #16
0
    def test_getWords(self):

        '''
        Testing the getWords function
        '''

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/getWords.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.compare(['a','b','c','d','e','f','g','h','j'],self.hobbsAgent.getWords()))
        self.atomspace.clear()
Example #17
0
    def test_b_load_file(self):

        status = load_scm(self.space, "../../../tests/cython/guile/basic_unify.scm")
        self.assertTrue(status)

        a1 = self.space.add_node(types.ConceptNode, "hello")
        self.assertTrue(a1)

        # Make sure the truth value is what's in the SCM file.
        expected = TruthValue(0.5, 800)
        self.assertEquals(a1.tv, expected)
Example #18
0
        def filter_12():

            print("Testing filter #12...")
            self.assertTrue(
                load_scm(
                    self.atomspace,
                    "tests/nlp/anaphora/data/propose/filter-#12/data_#1.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertFalse(
                self.hobbsAgent.propose(
                    self.getWord('antecedent', types.ParseNode), 12))
            self.atomspace.clear()

            self.assertTrue(
                load_scm(
                    self.atomspace,
                    "tests/nlp/anaphora/data/propose/filter-#12/data_#2.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(
                self.hobbsAgent.propose(self.getWord('antecedent'), 12))
            self.atomspace.clear()
Example #19
0
    def test_b_load_file(self):

        status = load_scm(self.space,
                          "../../../tests/cython/guile/basic_unify.scm")
        self.assertTrue(status)

        a1 = self.space.add_node(types.ConceptNode, "hello")
        self.assertTrue(a1)

        # Make sure the truth value is what's in the SCM file.
        expected = TruthValue(0.5, 800)
        self.assertEquals(a1.tv, expected)
Example #20
0
    def test_getWords(self):
        '''
        Testing the getWords function
        '''

        self.assertTrue(
            load_scm(self.atomspace, "tests/nlp/anaphora/data/getWords.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(
            self.compare(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j'],
                         self.hobbsAgent.getWords()))
        self.atomspace.clear()
Example #21
0
    def test_bfs(self):

        '''
        Testing the bfs function
        '''

        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(load_scm(self.atomspace, "tests/python/test_anaphora/data/bfs.scm"))

        self.hobbsAgent.run(self.atomspace)
        self.assertTrue(self.compare(['a','b','c','d','e','f','g'],self.hobbsAgent.bfs(self.getWord('a'))))
        self.atomspace.clear()
Example #22
0
        def filter_1():

            print("Testing filter #1...")
            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#1.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent')))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#2.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertFalse(self.hobbsAgent.propose(self.getWord('antecedent')))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#3.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent')))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#4.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent')))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#5.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent')))
            self.atomspace.clear()

            self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/propose/filter-#1/data_#6.scm"))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(self.hobbsAgent.propose(self.getWord('antecedent')))
            self.atomspace.clear()
Example #23
0
    def test_unifier(self):
        status = load_scm(self.space, "opencog/scm/opencog.scm")
        self.assertTrue(status)
        status = load_scm(self.space, "opencog/scm/opencog/query.scm")
        self.assertTrue(status)

        scheme_eval(self.space, "(use-modules (opencog query))")
        h = scheme_eval_h(self.space, "cap-deduce")
        self.assertTrue(h)
        print "\nThe question is:"
        print h
        question = Atom(h, self.space)
        print question

        h = scheme_eval_h(self.space, "(cog-bind cap-deduce)")
        self.assertTrue(h)
        print h
        answer = Atom(h, self.space)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 2)
Example #24
0
        def filter_18():

            print("Testing filter #18...")
            self.assertTrue(
                load_scm(
                    self.atomspace,
                    "tests/python/test_anaphora/data/propose/filter-#18/data_#1.scm"
                ))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertFalse(
                self.hobbsAgent.propose(self.getWord('antecedent'), 18))
            self.atomspace.clear()

            self.assertTrue(
                load_scm(
                    self.atomspace,
                    "tests/python/test_anaphora/data/propose/filter-#18/data_#2.scm"
                ))
            self.hobbsAgent.initilization(self.atomspace)
            self.assertTrue(
                self.hobbsAgent.propose(self.getWord('antecedent'), 18))
            self.atomspace.clear()
Example #25
0
    def test_bfs(self):
        '''
        Testing the bfs function
        '''

        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(
            load_scm(self.atomspace,
                     "tests/python/test_anaphora/data/bfs.scm"))

        self.hobbsAgent.run(self.atomspace)
        self.assertTrue(
            self.compare(['a', 'b', 'c', 'd', 'e', 'f', 'g'],
                         self.hobbsAgent.bfs(self.getWord('a'))))
        self.atomspace.clear()
Example #26
0
    def test_pleonastic_if(self):

        self.assertTrue(
            load_scm(self.atomspace,
                     "tests/nlp/anaphora/data/pleonastic_it/data_#1.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(
            load_scm(self.atomspace,
                     "tests/nlp/anaphora/data/pleonastic_it/data_#2.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(
            load_scm(self.atomspace,
                     "tests/nlp/anaphora/data/pleonastic_it/data_#3.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertTrue(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(
            load_scm(self.atomspace,
                     "tests/nlp/anaphora/data/pleonastic_it/data_#4.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()

        self.assertTrue(
            load_scm(self.atomspace,
                     "tests/nlp/anaphora/data/pleonastic_it/data_#5.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('it')))
        self.atomspace.clear()
Example #27
0
    def load_subset_rels_from_scheme(self, filepath=None):
        """
        Populates the atomspace with subset mining results saved to file from
        previous run of subset mining.

        :param filepath:
        :return:
        """
        if not filepath:
            filepath = SUBSET_SCHEME_FILE
        print "Loading subset relationships from {0}".format(filepath)
        start = time.clock()
        if not load_scm(self.atomspace, filepath):
            print "*** Error loading scheme file: {0}".format(filepath)
        else:
            print "Loaded subset relationships in {0} seconds".format(
                int(time.clock() - start))
Example #28
0
    def test_unifier(self):

        status = load_scm(self.space, "opencog/scm/opencog/query.scm")
        self.assertTrue(status)

        scheme_eval(self.space, "(use-modules (opencog query))")
        question = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(question)
        print "\nThe question is:"
        print question

        answer = scheme_eval_h(self.space, "(cog-bind find-animals)")
        self.assertTrue(answer)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Example #29
0
    def test_unifier(self):

        status = load_scm(self.space, "opencog/scm/opencog/query.scm")
        self.assertTrue(status)

        scheme_eval(self.space, "(use-modules (opencog query))")
        question = scheme_eval_h(self.space, "find-animals")
        self.assertTrue(question)
        print "\nThe question is:"
        print question

        answer = scheme_eval_h(self.space, "(cog-bind find-animals)")
        self.assertTrue(answer)
        print "\nThe answer is:"
        print answer
        self.assertEqual(answer.type, types.SetLink)
        self.assertEqual(answer.arity, 3)
Example #30
0
    def load_subset_rels_from_scheme(self,filepath=None):
        """
        Populates the atomspace with subset mining results saved to file from
        previous run of subset mining.

        :param filepath:
        :return:
        """
        if not filepath:
            filepath = SUBSET_SCHEME_FILE
        print "Loading subset relationships from {0}".format(filepath)
        start = time.clock()
        if not load_scm(self.atomspace,filepath):
            print "*** Error loading scheme file: {0}".format(filepath)
        else:
            print "Loaded subset relationships in {0} seconds".format(
                int(time.clock()-start)
            )
Example #31
0
def load_scheme_files(atomspace,files,label=''):
    """
    Load list of scheme files into the atomspace.

    :param atomspace:
    :param files:
    :param label:
    :return: time elapsed in seconds
    """
    print "Loading scheme files - {}".format(label)
    start = time.clock()
    for file in files:
        print "  Loading scheme file: " + file
        if not load_scm(atomspace, file):
            print "***  Error loading scheme file: " + file + "  ***"

    scheme_load_time = int(time.clock() - start)
    print 'Scheme file loading completed in {} seconds'.format(scheme_load_time)

    return scheme_load_time
Example #32
0
def load_scheme_files(atomspace, files, label=""):
    """
    Load list of scheme files into the atomspace.

    :param atomspace:
    :param files:
    :param label:
    :return: time elapsed in seconds
    """
    print "Loading scheme files - {}".format(label)
    start = time.clock()
    for file in files:
        print "  Loading scheme file: " + file
        if not load_scm(atomspace, file):
            print "***  Error loading scheme file: " + file + "  ***"

    scheme_load_time = int(time.clock() - start)
    print "Scheme file loading completed in {} seconds".format(scheme_load_time)

    return scheme_load_time
Example #33
0
 def test_conjunctions(self):
     self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/conjunction.scm"))
     self.hobbsAgent.initilization(self.atomspace)
     self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('waitresses')))
     self.atomspace.clear()
Example #34
0
 def load_file_into_atomspace(self, fullPath, atomSpace):
     load_scm(atomSpace, fullPath)
Example #35
0
 def load_file_into_atomspace(self, fullPath, atomSpace):
     if os.path.exists(fullPath):
         load_scm(atomSpace, fullPath)
     else:
         print "Path '" + fullPath + "' does not exist."
    # Syllogism files
    syllogisms = [
        # "abductive-syllogism.scm",
        # "conditional-syllogism.scm",
        # "disjunctive-syllogism.scm",
        # "syllogism-boat.scm",
        "syllogism-canadian.scm"
    ]

    syllogism_path = "opencog/python/pln/examples/relex2logic/syllogisms/"

    for syllogism in syllogisms:
        # sets up atomspace where inputs, rules, and outputs can be retrieved
        configuration_space = set_up_atomspace()
        load_scm(configuration_space, syllogism_path + syllogism)

        # sets up atomspace that is used for the actual inference
        inference_space = set_up_atomspace()
        for atom in get_predicate_arguments(configuration_space, "inputs"):
            transfer_atom(inference_space, atom)

        if print_starting_contents:
            print('AtomSpace starting contents:')
            inference_space.print_list()

        syllogism_chainer = create_chainer(
            inference_space,
            get_predicate_arguments(configuration_space, "rules"))

        outputs_produced = 0
Example #37
0
    def test_conjunctions(self):

        self.assertTrue(load_scm(self.atomspace, "tests/nlp/anaphora/data/conjunction.scm"))
        self.hobbsAgent.initilization(self.atomspace)
        self.assertFalse(self.hobbsAgent.pleonastic_it(self.getWord('waitresses')))
        self.atomspace.clear()
Example #38
0
    def initilization(self, atomspace):
        self.atomspace = atomspace

        self.currentPronounNode = atomspace.add_node(types.AnchorNode,
                                                     'CurrentPronoun',
                                                     TruthValue(1.0, 100))
        self.currentTarget = atomspace.add_node(types.AnchorNode,
                                                'CurrentTarget',
                                                TruthValue(1.0, 100))
        self.currentResult = atomspace.add_node(types.AnchorNode,
                                                'CurrentResult',
                                                TruthValue(1.0, 100))
        self.currentProposal = atomspace.add_node(types.AnchorNode,
                                                  'CurrentProposal',
                                                  TruthValue(1.0, 100))
        self.unresolvedReferences = atomspace.add_node(
            types.AnchorNode, 'Recent Unresolved references',
            TruthValue(1.0, 100))
        self.resolvedReferences = atomspace.add_node(types.AnchorNode,
                                                     'Resolved references',
                                                     TruthValue(1.0, 100))
        self.currentResolutionNode = atomspace.add_node(
            types.AnchorNode, 'CurrentResolution', TruthValue(1.0, 100))
        self.currentResolutionLink_proposal = self.atomspace.add_link(
            types.ListLink, [self.currentResolutionNode, self.currentProposal],
            TruthValue(1.0, 100))
        self.currentResolutionLink_pronoun = self.atomspace.add_link(
            types.ListLink,
            [self.currentResolutionNode, self.currentPronounNode],
            TruthValue(1.0, 100))
        self.pronounNumber = -1

        data = [
            "opencog/nlp/anaphora/rules/getChildren.scm",
            "opencog/nlp/anaphora/rules/getNumberNode_WordInstanceNode.scm",
            "opencog/nlp/anaphora/rules/getNumberNode_ParseNode.scm",
            "opencog/nlp/anaphora/rules/connectRootsToParseNodes.scm",
            "opencog/nlp/anaphora/rules/getPronouns.scm",
            "opencog/nlp/anaphora/rules/propose.scm",
            "opencog/nlp/anaphora/rules/getResults.scm",
            "opencog/nlp/anaphora/rules/getAllNumberNodes.scm",
            "opencog/nlp/anaphora/rules/getAllParseNodes.scm",
            "opencog/nlp/anaphora/rules/getConjunction.scm",
            "opencog/nlp/anaphora/rules/getParseNode.scm",
            "opencog/nlp/anaphora/rules/filtersGenerator.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#1.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#2.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#3.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#4.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#5.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#6.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#7.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#8.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#9.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#10.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#11.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#12.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#13.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#14.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#15.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#16.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#17.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#18.scm",
            "opencog/nlp/anaphora/rules/filters/filter-#19.scm",
        ]

        self.numOfFilters = len(data)
        for item in data:
            load_scm(atomspace, item)

        self.getAllNumberNodes()
        self.pronouns = self.getPronouns()
        self.roots = self.getRoots()
Example #39
0
 def load_file_into_atomspace(self, fullPath, atomSpace):
     load_scm(atomSpace, fullPath)
Example #40
0
from opencog.utilities import initialize_opencog, finalize_opencog
from opencog.bindlink import execute_atom
import opencog.scheme_wrapper as scheme
from opencog.scheme_wrapper import load_scm, scheme_eval
from opencog.type_constructors import *

atomspace = AtomSpace()

# Initialize Scheme
scheme_preload = [  
                    "opencog/atomspace/core_types.scm",
                    "opencog/scm/utilities.scm" 
                 ]
scheme.__init__(atomspace)
for scheme_file in scheme_preload:
    load_scm(atomspace, scheme_file)

initialize_opencog(atomspace, "utilities_test.conf")

executed = False

def add_link(atom1, atom2):
    global executed
    link = ListLink(atom1, atom2)
    executed = True
    return link

execute_code = \
    '''
    (cog-execute!
        (ExecutionOutputLink
Example #41
0
from opencog.atomspace import AtomSpace, types
from opencog.utilities import initialize_opencog, finalize_opencog
from opencog.bindlink import execute_atom
import opencog.scheme_wrapper as scheme
from opencog.scheme_wrapper import load_scm, scheme_eval
from opencog.type_constructors import *

atomspace = AtomSpace()

# Initialize Scheme
scheme_preload = [
    "opencog/atoms/proto/core_types.scm", "opencog/scm/utilities.scm"
]

for scheme_file in scheme_preload:
    load_scm(atomspace, scheme_file)

initialize_opencog(atomspace)

executed = False


def add_link(atom1, atom2):
    global executed
    link = ListLink(atom1, atom2)
    executed = True
    return link


# Fix up the module for cog-execute. Most Python users won't be using cog-execute
# since there is now a Cython call execute_atom which does the same thing, so we
Example #42
0
__author__ = 'Sebastian Ruder'

num_steps = 100
print_starting_contents = True
coreTypes = "opencog/scm/core_types.scm"
utilities = "opencog/scm/utilities.scm"
timeLinks = "opencog/spacetime/spacetime_types.scm"
data = "tests/python/test_pln/scm_disabled/temporal/temporalToyExample.scm"
# data = "opencog/python/pln_old/examples/temporal/temporal-r2l-input.scm"

# initialize atomspace
atomspace = AtomSpace()
__init__(atomspace)
for item in [coreTypes, utilities, timeLinks, data]:
    load_scm(atomspace, item)

# initialize chainer
chainer = Chainer(atomspace,
                  stimulateAtoms=False,
                  allow_output_with_variables=True,
                  delete_temporary_variables=True)
for rule in create_temporal_rules(chainer):
    chainer.add_rule(rule)

if print_starting_contents:
    print('AtomSpace starting contents:')
    atomspace.print_list()

outputs_produced = 0
Example #43
0
    # Syllogism files
    syllogisms = [
        # "abductive-syllogism.scm",
        # "conditional-syllogism.scm",
        # "disjunctive-syllogism.scm",
        # "syllogism-boat.scm",
        "syllogism-canadian.scm"
    ]

    syllogism_path = "opencog/python/pln/examples/relex2logic/syllogisms/"

    for syllogism in syllogisms:
        # sets up atomspace where inputs, rules, and outputs can be retrieved
        configuration_space = set_up_atomspace()
        load_scm(configuration_space, syllogism_path + syllogism)

        # sets up atomspace that is used for the actual inference
        inference_space = set_up_atomspace()
        for atom in get_predicate_arguments(configuration_space, "inputs"):
            transfer_atom(inference_space, atom)

        if print_starting_contents:
            print('AtomSpace starting contents:')
            inference_space.print_list()

        syllogism_chainer = create_chainer(
            inference_space,
            get_predicate_arguments(configuration_space, "rules"))

        outputs_produced = 0
Example #44
0
    def initilization(self,atomspace):
        '''
        Initializes necessary variables. Loads rules.
        '''

        self.atomspace = atomspace

        self.PleonasticItNode=atomspace.add_node(types.AnchorNode, 'Pleonastic-it', TruthValue(1.0, 100))
        self.currentPronounNode = atomspace.add_node(types.AnchorNode, 'CurrentPronoun', TruthValue(1.0, 100))
        self.currentTarget = atomspace.add_node(types.AnchorNode, 'CurrentTarget', TruthValue(1.0, 100))
        self.currentResult = atomspace.add_node(types.AnchorNode, 'CurrentResult', TruthValue(1.0, 100))
        self.currentProposal = atomspace.add_node(types.AnchorNode, 'CurrentProposal', TruthValue(1.0, 100))
        self.unresolvedReferences=atomspace.add_node(types.AnchorNode, 'Recent Unresolved references', TruthValue(1.0, 100))
        self.resolvedReferences=atomspace.add_node(types.AnchorNode, 'Resolved references', TruthValue(1.0, 100))
        self.currentResolutionNode=atomspace.add_node(types.AnchorNode, 'CurrentResolution', TruthValue(1.0, 100))
        self.currentResolutionLink_proposal=self.atomspace.add_link(types.ListLink, [self.currentResolutionNode, self.currentProposal], TruthValue(1.0, 100))
        self.currentResolutionLink_pronoun=self.atomspace.add_link(types.ListLink, [self.currentResolutionNode, self.currentPronounNode], TruthValue(1.0, 100))
        self.pronounNumber = -1

        data=["opencog/nlp/anaphora/rules/getChildren.scm",
              "opencog/nlp/anaphora/rules/getNumberNode_WordInstanceNode.scm",
              "opencog/nlp/anaphora/rules/getNumberNode_ParseNode.scm",
              "opencog/nlp/anaphora/rules/connectRootsToParseNodes.scm",
              "opencog/nlp/anaphora/rules/getAllNumberNodes.scm",
              "opencog/nlp/anaphora/rules/getAllParseNodes.scm",
              "opencog/nlp/anaphora/rules/getConjunction.scm",
              "opencog/nlp/anaphora/rules/getParseNode.scm",
              "opencog/nlp/anaphora/rules/getWords.scm",
              "opencog/nlp/anaphora/rules/isIt.scm",

              "opencog/nlp/anaphora/rules/filters/filter-#1.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#2.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#3.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#4.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#5.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#6.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#7.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#8.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#9.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#10.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#11.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#12.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#13.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#14.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#15.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#16.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#17.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#18.scm",

              "opencog/nlp/anaphora/rules/pre-process/pre-process-#1.scm",
              "opencog/nlp/anaphora/rules/pre-process/pre-process-#2.scm",
              "opencog/nlp/anaphora/rules/pre-process/pre-process-#3.scm",

              "opencog/nlp/anaphora/rules/pleonastic-it/pleonastic-it-#1.scm",
              "opencog/nlp/anaphora/rules/pleonastic-it/pleonastic-it-#2.scm",
              "opencog/nlp/anaphora/rules/pleonastic-it/pleonastic-it-#3.scm",

              ]

        self.numOfFilters=18
        self.numOfPrePatterns=3
        self.numOfPleonasticItPatterns=3

        for item in data:
            load_scm(atomspace, item)

        self.getAllNumberNodes()
        self.pronouns=self.getTargets(self.getWords())
        self.roots = self.getRoots()
Example #45
0
    def initilization(self,atomspace):
        '''
        Initializes necessary variables. Loads rules.
        '''

        self.atomspace = atomspace

        self.PleonasticItNode=atomspace.add_node(types.AnchorNode, 'Pleonastic-it', TruthValue(1.0, 100))
        self.currentPronounNode = atomspace.add_node(types.AnchorNode, 'CurrentPronoun', TruthValue(1.0, 100))
        self.currentTarget = atomspace.add_node(types.AnchorNode, 'CurrentTarget', TruthValue(1.0, 100))
        self.currentResult = atomspace.add_node(types.AnchorNode, 'CurrentResult', TruthValue(1.0, 100))
        self.currentProposal = atomspace.add_node(types.AnchorNode, 'CurrentProposal', TruthValue(1.0, 100))
        self.unresolvedReferences=atomspace.add_node(types.AnchorNode, 'Recent Unresolved references', TruthValue(1.0, 100))
        self.resolvedReferences=atomspace.add_node(types.AnchorNode, 'Resolved references', TruthValue(1.0, 100))
        self.currentResolutionNode=atomspace.add_node(types.AnchorNode, 'CurrentResolution', TruthValue(1.0, 100))
        self.currentResolutionLink_proposal=self.atomspace.add_link(types.ListLink, [self.currentResolutionNode, self.currentProposal], TruthValue(1.0, 100))
        self.currentResolutionLink_pronoun=self.atomspace.add_link(types.ListLink, [self.currentResolutionNode, self.currentPronounNode], TruthValue(1.0, 100))
        self.pronounNumber = -1

        data=["opencog/nlp/anaphora/rules/getChildren.scm",
              "opencog/nlp/anaphora/rules/getNumberNode_WordInstanceNode.scm",
              "opencog/nlp/anaphora/rules/getNumberNode_ParseNode.scm",
              "opencog/nlp/anaphora/rules/connectRootsToParseNodes.scm",
              "opencog/nlp/anaphora/rules/getAllNumberNodes.scm",
              "opencog/nlp/anaphora/rules/getAllParseNodes.scm",
              "opencog/nlp/anaphora/rules/getConjunction.scm",
              "opencog/nlp/anaphora/rules/getParseNode.scm",
              "opencog/nlp/anaphora/rules/getWords.scm",
              "opencog/nlp/anaphora/rules/isIt.scm",

              "opencog/nlp/anaphora/rules/filters/filter-#1.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#2.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#3.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#4.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#5.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#6.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#7.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#8.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#9.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#10.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#11.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#12.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#13.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#14.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#15.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#16.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#17.scm",
              "opencog/nlp/anaphora/rules/filters/filter-#18.scm",

              "opencog/nlp/anaphora/rules/pre-process/pre-process-#1.scm",
              "opencog/nlp/anaphora/rules/pre-process/pre-process-#2.scm",
              "opencog/nlp/anaphora/rules/pre-process/pre-process-#3.scm",

              "opencog/nlp/anaphora/rules/pleonastic-it/pleonastic-it-#1.scm",
              "opencog/nlp/anaphora/rules/pleonastic-it/pleonastic-it-#2.scm",
              "opencog/nlp/anaphora/rules/pleonastic-it/pleonastic-it-#3.scm",

              ]

        self.numOfFilters=20
        self.numOfPrePatterns=3
        self.numOfPleonasticItPatterns=3

        for item in data:
            load_scm(atomspace, item)

        self.getAllNumberNodes()
        self.pronouns=self.getTargets(self.getWords())
        self.roots = self.getRoots()