| … | … | @@ -4,33 +4,25 @@ |
| 4 | 4 | # |
| 5 | 5 | """ |
| 6 | 6 | Example of how the cogserver can be started from python. |
| 7 | | Once the server is started, it can be accessed via it's TCP/IP ports. |
| 8 | | In this example, an AtomSpace will be created and some data poked into |
| 9 | | it. Only afterwards will the cogserver be started. It could also be |
| 10 | | done the other way around: the cogserver could have been started first; |
| 11 | | the order does not matter. |
| 7 | Once the server is started, it can be accessed via its TCP/IP ports. |
| 8 | In this example, some Atoms are created in the AtomSpace before the |
| 9 | cogserver is started. It could also be done the other way around: |
| 10 | the cogserver could have been started first; the order does not matter. |
| 12 | 11 | |
| 13 | 12 | The cogserver will use the same AtomSpace as the python shell; thus, |
| 14 | 13 | the Atoms created here will be visible there, and vice-versa. |
| 15 | 14 | |
| 16 | | Once the cogserver is running, The AtomSpace contents are available |
| 17 | | via webspockets in JSON format. The python and scheme evaluators are |
| 18 | | also avialbe through websockets; and all three: python, scheme and json, |
| 15 | Once the cogserver is running, the AtomSpace contents are available |
| 16 | via websockets in JSON format. The python and scheme evaluators are |
| 17 | also available through websockets; and all three: python, scheme and json, |
| 19 | 18 | are available through telnet. See the html pages in the example |
| 20 | 19 | directory for more. |
| 21 | 20 | """ |
| 22 | 21 | |
| 23 | | # First, import the usual AtomSpace python modules. |
| 24 | | from opencog.atomspace import AtomSpace |
| 25 | 22 | from opencog.type_constructors import * |
| 23 | from opencog.cogserver import start_cogserver, stop_cogserver |
| 26 | 24 | |
| 27 | | # Create an AtomSpace. |
| 28 | | my_atomspace = AtomSpace() |
| 29 | | |
| 30 | | # Tell the type constructors to use it. |
| 31 | | set_thread_atomspace(my_atomspace) |
| 32 | | |
| 33 | | print("\nCreating an AtomSpace and putting some data into it...") |
| 25 | print("\nCreating some Atoms in the AtomSpace...") |
| 34 | 26 | A = ConceptNode('Apple') |
| 35 | 27 | B = ConceptNode('Berry') |
| 36 | 28 | C = ConceptNode('Comestible') |
| … | … | @@ -39,18 +31,12 @@ EdgeLink(PredicateNode("is a"), ListLink(A, ConceptNode("fruit"))) |
| 39 | 31 | EdgeLink(PredicateNode("has a"), ListLink(A, ConceptNode("stem"))) |
| 40 | 32 | is_red = EdgeLink(PredicateNode("often colored"), ListLink(A, ConceptNode("red"))) |
| 41 | 33 | |
| 42 | | from opencog.cogserver import ( |
| 43 | | start_cogserver, |
| 44 | | stop_cogserver, |
| 45 | | is_cogserver_running, |
| 46 | | get_server_atomspace |
| 47 | | ) |
| 48 | | |
| 49 | 34 | print("Starting the CogServer ...") |
| 50 | | start_cogserver(atomspace=my_atomspace, |
| 51 | | console_port=17300, # Default is 17001 |
| 52 | | web_port=18381, # Default is 18080 |
| 53 | | mcp_port=19999) # Default is 18888 |
| 35 | server = start_cogserver(console_port=17300, # Default is 17001 |
| 36 | web_port=18381, # Default is 18080 |
| 37 | mcp_port=19999) # Default is 18888 |
| 38 | |
| 39 | print(f"\nCogServer started: {server}") |
| 54 | 40 | |
| 55 | 41 | print("\nYou can connect using:") |
| 56 | 42 | print(" rlwrap telnet localhost 17300") |
| … | … | @@ -64,17 +50,18 @@ print("Enter the scm shell with `scm` and then run") |
| 64 | 50 | print(" (cog-prt-atomspace)") |
| 65 | 51 | print("Exit the scheme shell with a single dot or a ^D") |
| 66 | 52 | |
| 67 | | print("\nAlternately, enter the pythonshell with `py` and then run") |
| 68 | | print(" print(\"my atomspace=\", list(my_atomspace))") |
| 53 | print("\nAlternately, enter the python shell with `py` and then run") |
| 54 | print(" from opencog.type_constructors import get_thread_atomspace") |
| 55 | print(" print(list(get_thread_atomspace()))") |
| 69 | 56 | |
| 70 | 57 | print("\nYou can create new Atoms in those shells; they will appear here") |
| 71 | | print("because this AtomSpace and the CofserverAtomSpace are one and the same.") |
| 58 | print("because this AtomSpace and the CogServer AtomSpace are one and the same.") |
| 72 | 59 | print("If you run MCP, you can even ask Claude to create Atoms for you.") |
| 73 | 60 | |
| 74 | 61 | print("\nWill now sleep for ten minutes; after this, the cogserver will stop") |
| 75 | 62 | import time |
| 76 | 63 | time.sleep(600) |
| 77 | | stop_cogserver() |
| 78 | | print("... Times up! Goodbye!") |
| 64 | stop_cogserver(server) |
| 65 | print("... Time's up! Goodbye!") |
| 79 | 66 | |
| 80 | 67 | # THE END. That's All, Folks! |