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)
def prep_predicates(atomspace): scheme.__init__(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
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 bound (VariableNode "$var") (ImplicationLink ;; The pattern to be searched for (InheritanceLink (VariableNode "$var") (ConceptNode "animal") ) ;; The value to be returned. (VariableNode "$var") ) ) ''' self.bindlink_handle = scheme_eval_h(self.atomspace, bind_link_query)
def setUp(self): self.atomspace = AtomSpace() __init__(self.atomspace) data = [ "opencog/scm/config.scm", "opencog/atomspace/core_types.scm", "spacetime/spacetime_types.scm", "opencog/nlp/types/nlp_types.scm", "opencog/dynamics/attention/attention_types.scm", "opencog/embodiment/AtomSpaceExtensions/embodiment_types.scm", "opencog/learning/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", "opencog/nlp/scm/relex-to-logic.scm", ] for item in data: status = load_scm(self.atomspace, item) self.hobbsAgent = HobbsAgent()
def prep_predicates(atomspace): scheme.__init__(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
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()
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
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)
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)
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")
def __init__(self, atomspace=None): if not atomspace: atomspace = AtomSpace() self.a = self.atomspace = atomspace #hmmmm.. is this needed? not sure where it came from __init__(self.atomspace) # To run this script outside of the cogserver required # adding the 'add_type' python binding in cython, which i have not yet # requested to be pulled to the project repo. # See https://github.com/opencog/agi-bio/tree/master/bioscience for # instructions on how to add the custom bio atom types and use config to # load when the cogserver starts up # if not is_defined('GeneNode'): # types.GeneNode = add_type(types.ConceptNode, 'GeneNode') # if not is_defined('ProteinNode'): # types.ProteinNode = add_type(types.ConceptNode, 'ProteinNode') # geneset (dicrect) members cache self.set_members_dict = {} # geneset members including descendents cache self.set_members_with_descendents_dict = {} # member genesets cache self.member_sets_dict = {} # subset relationship truth value dictionary cache self.subset_values = {} # dict of importance score for a generated relationship link self.relationship_importance_score = {} #dict of category ancestors self.category_ancestors = {} self.scheme_loaded = False
def __init__(self, atomspace=None): if not atomspace: atomspace = AtomSpace() self.a = self.atomspace = atomspace __init__(self.atomspace) # To run this script outside of the cogserver required # adding the 'add_type' python binding in cython, which i have not yet # requested to be pulled to the project repo. # See https://github.com/opencog/agi-bio/tree/master/bioscience for # instructions on how to add the custom bio atom types and use config to # load when the cogserver starts up if not is_defined('GeneNode'): types.GeneNode = add_type(types.ConceptNode, 'GeneNode') if not is_defined('ProteinNode'): types.ProteinNode = add_type(types.ConceptNode, 'ProteinNode') # geneset (dicrect) members cache self.set_members_dict = {} # geneset members including descendents cache self.set_members_with_descendents_dict = {} # member genesets cache self.member_sets_dict = {} # subset relationship truth value dictionary cache self.subset_values = {} # dict of importance score for a generated relationship link self.relationship_importance_score = {} #dict of category ancestors self.category_ancestors = {} self.scheme_loaded = False
from pln.chainers import Chainer from pln.rules.temporal_rules import create_temporal_rules __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()
from unittest import TestCase from opencog.atomspace import AtomSpace, TruthValue, Atom, Handle from opencog.atomspace import types, is_a, get_type, get_type_name from opencog.scheme_wrapper import load_scm, scheme_eval, scheme_eval_h, __init__ # We are poking atoms into this from the scm files, so we want # them to still be there, later. shared_space = AtomSpace() __init__(shared_space) class SchemeTest(TestCase): def setUp(self): global shared_space self.space = shared_space def tearDown(self): pass # Load several different scheme files, containin atom type # declarations, and utuilites. They should load just fine. # These don't actually put any tomes into the atomspace. def test_a_load_core_types(self): # These relative paths are horridly ugly. # Ther must be a better way ... status = load_scm(self.space, "../../opencog/atomspace/core_types.scm") self.assertTrue(status)
def __init__(self, atomspace=None): if not atomspace: atomspace = AtomSpace() self.a = self.atomspace = atomspace scheme.__init__(self.atomspace)
from unittest import TestCase from opencog.atomspace import AtomSpace, TruthValue, Atom, Handle from opencog.atomspace import types, is_a, get_type, get_type_name from opencog.scheme_wrapper import load_scm, scheme_eval, scheme_eval_h, __init__ # We are poking atoms into this from the scm files, so we want # them to still be there, later. shared_space = AtomSpace() __init__(shared_space) class SchemeTest(TestCase): def setUp(self): global shared_space self.space = shared_space def tearDown(self): pass # Load several different scheme files, containing atom type # declarations, and utilities. They should load just fine. # These don't actually put any atoms into the atomspace. 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)
def prep_scheme(atomspace): scheme.__init__(atomspace)
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/scm/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 (GroundedSchemaNode \"py: add_link\")
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/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 = \ '''
def __init__(self,atomspace=None): if not atomspace: atomspace = AtomSpace() self.a = self.atomspace = atomspace scheme.__init__(self.atomspace)