Running Relex2Logic with OpenCog

From OpenCog
Jump to: navigation, search

This page describes how to run Relex2Logic with OpenCog.

In short, there is a Relex network server which listens to a socket, and parses all (English-language) sentences on that socket, returning the parsed results. There is a simple command within opencog to send sentences to that server; the resulting parses then automatically show up in the AtomSpace. Other processes must then take over and do something with the AtomSpace contents. The steps below should be followed in order.

See also:

Start the cogserver

In the opencog build directory, enter

./opencog/cogserver/server/cogserver

Run the Relex server

If you built RelEx with Maven

In the root of RelEx source-code folder, run:

target/relex/bin/relexd-link

(The script should work for both Linux/OS X and Windows, however I haven't tested whether RelEx itself runs on Windows --Hendy (talk) 01:48, 11 July 2014 (CDT))

If you built RelEx with Ant

Run opencog-server.sh:

./opencog-server.sh

Testing

You can test the server to see if its working, by doing the following:

telnet localhost 4444
this is a test.

This opens a socket to the server (which, by default, listens on port 4444). The next line sends a test sentence; the parsed results are then returned. They are the scheme that the opencog server will be receiving. If you are running RelEx with vagrant, replace localhost with 192.168.50.2, the default vagrant address.

Connect to cogserver

Telnet into the guile REPL shell:

rlwrap telnet localhost 18001

Or, use the cog-server scheme shell at port 17001.

rlwrap telnet localhost 17001

and type scm at the prompt to enter the scheme shell. If you are running opencog with vagrant, replace localhost with 192.168.50.2, the default vagrant address.

Parse and get the R2L outputs for a sentence

First load the R2L-English-rulebase for the Unified rule engine and other scheme function by running

(use-modules (opencog) (opencog nlp) (opencog nlp chatbot) (opencog nlp relex2logic))

Get R2L output for a sentence as follows,

(nlp-parse "this is a test sentence")

The above runs relex-parse to send the sentence to the relex network server. The resulting atoms in the RelEx OpenCog format will appear in the opencog server some fraction of a second later. r2l-parse will then use the result as the focus-set for URE's forward-chainer to generate the logic-representations (aka R2L output). It will also create a temporary InterpretationLink and InterpretationNode of the form

 (ReferenceLink 
   (InterpretationNode "sentence@1d220-c7ace2f_parse_2_interpretation_$X")
   (SetLink

      different links that are a result of r2l rule-functions being applied

   )
 )
 (InterpretationLink
   (InterpretationNode "sentence@1d220-c7ace2f_parse_2_interpretation_$X")
   (ParseNode "sentence@1d220-c7ace2f_parse_2")
 )

The name of the InterpretationNode ends with "_interpretation_$X" because wsd and other post processes haven't yet been performed on the output yet. Once the interpretation of the different Atoms in the SetLink is resolved then a number replaces $X as described here

Analyze the output

By default, nlp-parse will return a list of SentenceNode. There are some relex functions that allow you to view part of the output. For example, you can get the first ParseNode associated with a SentenceNode by

(car (sentence-get-parses (SentenceNode "sentence@2ac41081-45a2-44c6-aae4-a95351a9ae21")))

and then

(parse-get-r2l-outputs (ParseNode "sentence@2ac41081-45a2-44c6-aae4-a95351a9ae21_parse_0" (stv 1 0.991)))

get the list of R2L outputs.

Other utilities that can help with processing the information can be found in the opencog/scm/utilities.scm and the opencog/nlp/scm/nlp-utils.scm files.

Perhaps one of the cogserver graphical Atomspace Visualization tools would be useful.