Beispiel #1
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST
    API defined in apimain.py

    See examples @ github.com/opencog/opencog/tree/master/examples/restapi
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
                  "This will provide a REST interface to the Atomspace,\n" \
                  "allowing you to create, read, update and delete atoms " \
                  "across the network using\nHTTP requests/responses with " \
                  "JSON-formatted data.\n\nDefault endpoint: " \
                  "http://127.0.0.1:5000/api/v1.1/\nExample request: " \
                  "http://127.0.0.1:5000/api/v1.1/atoms?type=ConceptNode"

    def __init__(self):
        self.atomspace = None  # Will be passed as argument in run method

    def run(self, args, atomspace):
        self.atomspace = atomspace
        '''
        make a daemon thread so that it can be interrupted
        '''
        thread = Thread(target=self.invoke)
        thread.setDaemon(True)
        thread.start()
        print "REST API is now running in a separate daemon thread."

    def invoke(self):
        self.api = RESTAPI(self.atomspace)
        self.api.run(host=IP_ADDRESS, port=PORT)
Beispiel #2
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST
    API defined in apimain.py

    Prerequisites:
        1) Requires installation of the Python dependencies by running:
            sudo ./install_dependencies.sh

        2) Requires the configuration file (opencog.conf) to contain the
           following parameters:
            - PYTHON_EXTENSION_DIRS must specify the relative location of the
              API scripts
                Example: PYTHON_EXTENSION_DIRS = ../opencog/python/web/api
            - PYTHON_PRELOAD must specify the restapi module
                Example: PYTHON_PRELOAD = restapi

    To start the REST API, type restapi.Start at the CogServer shell
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
                  "This will provide a REST interface to the Atomspace,\n" \
                  "allowing you to create, read, update and delete atoms " \
                  "across the network using\nHTTP requests/responses with " \
                  "JSON-formatted data.\n\nDefault endpoint: " \
                  "http://127.0.0.1:5000/api/v1.1/\nExample request: " \
                  "http://127.0.0.1:5000/api/v1.1/atoms?type=ConceptNode"

    def __init__(self):
        self.process = Process(target=self.invoke)
        self.atomspace = None  # Will be passed as argument in run method

    def run(self, args, atomspace):
        """
        Loads the REST API into a separate process and invokes it, so that it
        will continue serving requests in the background after the Request
        that loads it has returned control to the CogServer
        """
        self.atomspace = atomspace

        '''
        By using multiprocessing and setting the daemon attribute of the
        process serving background REST API requests to True, when the
        parent process exits, it will attempt to terminate the daemonic
        child process (https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Process.daemon)
        '''
        self.process.daemon = True
        self.process.start()

        print "REST API is now running in a separate process."

    def invoke(self):
        self.api = RESTAPI(self.atomspace)
        self.api.run(host=IP_ADDRESS, port=PORT)
Beispiel #3
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST
    API defined in apimain.py

    Prerequisites:
        1) Requires installation of the Python dependencies by running:
            sudo ./install_dependencies.sh

        2) Requires the configuration file (opencog.conf) to contain the
           following parameters:
            - PYTHON_EXTENSION_DIRS must specify the relative location of the
              API scripts
                Example: PYTHON_EXTENSION_DIRS = ../opencog/python/web/api
            - PYTHON_PRELOAD must specify the restapi module
                Example: PYTHON_PRELOAD = restapi

    To start the REST API, type restapi.Start at the CogServer shell
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
                  "This will provide a REST interface to the Atomspace,\n" \
                  "allowing you to create, read, update and delete atoms " \
                  "across the network using\nHTTP requests/responses with " \
                  "JSON-formatted data.\n\nDefault endpoint: " \
                  "http://127.0.0.1:5000/api/v1.1/\nExample request: " \
                  "http://127.0.0.1:5000/api/v1.1/atoms?type=ConceptNode"

    def __init__(self):
        self.process = Process(target=self.invoke)
        self.atomspace = None  # Will be passed as argument in run method

    def run(self, args, atomspace):
        """
        Loads the REST API into a separate process and invokes it, so that it
        will continue serving requests in the background after the Request
        that loads it has returned control to the CogServer
        """
        self.atomspace = atomspace
        '''
        By using multiprocessing and setting the daemon attribute of the
        process serving background REST API requests to True, when the
        parent process exits, it will attempt to terminate the daemonic
        child process (https://docs.python.org/2/library/multiprocessing.html#multiprocessing.Process.daemon)
        '''
        self.process.daemon = True
        self.process.start()

        print "REST API is now running in a separate process."

    def invoke(self):
        self.api = RESTAPI(self.atomspace)
        self.api.run(host=IP_ADDRESS, port=PORT)
Beispiel #4
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST
    API defined in apimain.py

    Prerequisites:
        1) Requires installation of the Python dependencies by running:
            sudo ./install_dependencies.sh

        2) Requires the configuration file (opencog.conf) to contain the
           following parameters:
            - PYTHON_EXTENSION_DIRS must specify the relative location of the
              API scripts
                Example: PYTHON_EXTENSION_DIRS = ../opencog/python/web/api
            - PYTHON_PRELOAD must specify the restapi module
                Example: PYTHON_PRELOAD = restapi

    To start the REST API, type restapi.Start at the CogServer shell
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
                  "This will provide a REST interface to the Atomspace,\n" \
                  "allowing you to create, read, update and delete atoms " \
                  "across the network using\nHTTP requests/responses with " \
                  "JSON-formatted data.\n\nDefault endpoint: " \
                  "http://127.0.0.1:5000/api/v1.1/\nExample request: " \
                  "http://127.0.0.1:5000/api/v1.1/atoms?type=ConceptNode"

    def __init__(self):
        self.atomspace = None  # Will be passed as argument in run method

    def run(self, args, atomspace):
        self.atomspace = atomspace
        '''
        make a daemon thread so that it can be interrupted
        '''
        thread = Thread(target=self.invoke)
        thread.setDaemon(True)
        thread.start()
        print "REST API is now running in a separate daemon thread."

    def invoke(self):
        self.api = RESTAPI(self.atomspace)
        self.api.run(host=IP_ADDRESS, port=PORT)
Beispiel #5
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST
    API defined in apimain.py

    Prerequisites:
        1) Requires installation of the Python dependencies by running:
            sudo ./install_dependencies.sh

        2) Requires the configuration file (opencog.conf) to contain the
           following parameters:
            - PYTHON_EXTENSION_DIRS must specify the relative location of the
              API scripts
                Example: PYTHON_EXTENSION_DIRS = ../opencog/python/web/api
            - PYTHON_PRELOAD must specify the restapi module
                Example: PYTHON_PRELOAD = restapi

    To start the REST API, type restapi.Start at the CogServer shell
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
                  "This will provide a REST interface to the Atomspace,\n" \
                  "allowing you to create, read, update and delete atoms " \
                  "across the network using\nHTTP requests/responses with " \
                  "JSON-formatted data.\n\nDefault endpoint: " \
                  "http://127.0.0.1:5000/api/v1.1/\nExample request: " \
                  "http://127.0.0.1:5000/api/v1.1/atoms?type=ConceptNode"

    def __init__(self):
        self.atomspace = None  # Will be passed as argument in run method

    def run(self, args, atomspace):        
        self.atomspace = atomspace
        '''
        make a daemon thread so that it can be interrupted
        '''
        thread = Thread(target=self.invoke)
        thread.setDaemon(True)
        thread.start()
        print "REST API is now running in a separate daemon thread."        

    def invoke(self):
        self.api = RESTAPI(self.atomspace)
        self.api.run(host=IP_ADDRESS, port=PORT)
Beispiel #6
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST
    API defined in apimain.py

    See examples @ github.com/opencog/opencog/tree/master/examples/restapi
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\nStarts the OpenCog REST API. " \
                  "This will provide a REST interface to the Atomspace,\n" \
                  "allowing you to create, read, update and delete atoms " \
                  "across the network using\nHTTP requests/responses with " \
                  "JSON-formatted data.\n\nDefault endpoint: " \
                  "http://127.0.0.1:5000/api/v1.1/\nExample request: " \
                  "http://127.0.0.1:5000/api/v1.1/atoms?type=ConceptNode"

    def __init__(self):
        self.atomspace = None  # Will be passed as argument in run method

    def run(self, args, atomspace):
        self.atomspace = atomspace
        '''
        make a daemon thread so that it can be interrupted
        '''
        thread = Thread(target=self.invoke)
        thread.setDaemon(True)
        thread.start()
        print "REST API is now running in a separate daemon thread."

    def invoke(self):
        self.api = RESTAPI(self.atomspace)

        # OK, so if the remote end closes the pipe, we get a SIGPIPE
        # error, and the server dies.  So just restart the server in
        # that situation. See bug opencog/ros-behavior-scripting/issues/108
        try_again = True
        while try_again:
            try_again = False
            try:
                self.api.run(host=IP_ADDRESS, port=PORT)
            except socket.error, e:
                try_again = True
Beispiel #7
0
	def run (self):

		atomspace=AtomSpace()
		scheme_clear=\
			"""
			(clear)
			"""
		scheme_code=\
				"""
				(load-scm-from-file "/home/mahlet/webCodes/moses_result.scm")
				"""
		scheme_eval(atomspace,scheme_clear)
		scheme_eval(atomspace,scheme_code)

		#start the REST API
		IP_ADDRESS = '0.0.0.0'
		PORT = 5000
		api = RESTAPI(atomspace)
		api.run(host=IP_ADDRESS, port=PORT)
Beispiel #8
0
    def run(self):

        atomspace = AtomSpace()
        scheme_clear=\
         """
			(clear)
			"""
        scheme_code=\
          """
				(load-scm-from-file "/home/mahlet/webCodes/moses_result.scm")
				"""
        scheme_eval(atomspace, scheme_clear)
        scheme_eval(atomspace, scheme_code)

        #start the REST API
        IP_ADDRESS = '0.0.0.0'
        PORT = 5000
        api = RESTAPI(atomspace)
        api.run(host=IP_ADDRESS, port=PORT)
Beispiel #9
0
class Start(opencog.cogserver.Request):
    """
    Implements a CogServer Module to load upon startup that will load the REST API defined in apimain.py

    Prerequisites:
        1) Requires installation of the Python dependencies by running:
            sudo ./install_dependencies.sh

        2) Requires the configuration file (opencog.conf) to contain the following parameters:
            - PYTHON_EXTENSION_DIRS must specify the relative location of the API scripts
                Example: PYTHON_EXTENSION_DIRS = ../opencog/python/web/api
            - PYTHON_PRELOAD must specify the restapi module
                Example: PYTHON_PRELOAD = restapi

    To start the REST API, type restapi.Start at the CogServer shell
    """

    summary = "Start the OpenCog REST API"
    description = "Usage: restapi.Start\n\n" \
    "Starts the OpenCog REST API. This will provide a REST interface to the Atomspace,\n" \
    "allowing you to create, read, update and delete atoms across the network using\n" \
    "HTTP requests/responses with JSON-formatted data.\n\n" \
    "Default endpoint: http://127.0.0.1:5000/api/v1.0/\n" \
    "Example request: http://127.0.0.1:5000/api/v1.0/atoms?type=ConceptNode"

    def run(self, args, atomspace):
        """
        Loads the REST API into a separate thread and invokes it, so that it will continue serving requests in the
        background after the Request that loads it has returned control to the CogServer
        """
        self.atomspace = atomspace
        thread = Thread(target=self.invoke)
        thread.start()
        print "REST API is now running in a separate thread."
        # @todo: detect Control-C to end the thread

    def invoke(self):
        self.api = RESTAPI(self.atomspace)
        self.api.run(host=IP_ADDRESS, port=PORT)
from web.api.apimain import RESTAPI
from opencog.atomspace import AtomSpace, types
from opencog.utilities import initialize_opencog
from opencog.type_constructors import *

# Endpoint configuration
# To allow public access, set to 0.0.0.0; for local access, set to 127.0.0.1
IP_ADDRESS = '0.0.0.0'
PORT = 5000

atomspace = AtomSpace()
initialize_opencog(atomspace)

Link(ConceptNode("Test Concept"), ConceptNode("another one"))

api = RESTAPI(atomspace)
api.run(host=IP_ADDRESS, port=PORT)
Beispiel #11
0
from web.api.apimain import RESTAPI
from opencog.atomspace import AtomSpace, types
from opencog.utilities import initialize_opencog
from opencog.type_constructors import *

# Endpoint configuration
# To allow public access, set to 0.0.0.0; for local access, set to 127.0.0.1
IP_ADDRESS = '0.0.0.0'
PORT = 5000

atomspace = AtomSpace()
initialize_opencog(atomspace)

Link(
    ConceptNode("Test Concept"),
    ConceptNode("another one")
)

api = RESTAPI(atomspace)
api.run(host=IP_ADDRESS, port=PORT)