コード例 #1
0
ファイル: test_bindlink.py プロジェクト: boradin/opencog
    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)
コード例 #2
0
ファイル: benchmark.py プロジェクト: rohit12/atomspace
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
コード例 #3
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 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)
コード例 #4
0
    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()
コード例 #5
0
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
コード例 #6
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()
コード例 #7
0
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
コード例 #8
0
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
コード例 #9
0
ファイル: benchmark.py プロジェクト: rohit12/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)
コード例 #10
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)
コード例 #11
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")
コード例 #12
0
    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
コード例 #13
0
ファイル: bio.py プロジェクト: ceefour/agi-bio
    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
コード例 #14
0
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()
コード例 #15
0
ファイル: test_pattern.py プロジェクト: BlastarIndia/opencog
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)
コード例 #16
0
ファイル: subgraph.py プロジェクト: stjordanis/agi-bio
 def __init__(self, atomspace=None):
     if not atomspace:
         atomspace = AtomSpace()
     self.a = self.atomspace = atomspace
     scheme.__init__(self.atomspace)
コード例 #17
0
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)
コード例 #18
0
def prep_scheme(atomspace):
    scheme.__init__(atomspace)
コード例 #19
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/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\")
コード例 #20
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/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 = \
    '''
コード例 #21
0
ファイル: subgraph.py プロジェクト: ceefour/agi-bio
 def __init__(self,atomspace=None):
     if not atomspace:
         atomspace = AtomSpace()
     self.a = self.atomspace = atomspace
     scheme.__init__(self.atomspace)
コード例 #22
0
ファイル: benchmark.py プロジェクト: rohit12/atomspace
def prep_scheme(atomspace):
    scheme.__init__(atomspace)