Basic ConceptNet XML-RPC query

replace ConceptNetXMLRPCServer.py with the one from here
http://209.168.33.226/AIMLpad/ConceptNetXMLRPCServer.py

or apply the diff


$ diff ConceptNetXMLRPCServer.py ConceptNetXMLRPCServer.py.0

4c4
< config_filename = 'ConceptNet.ini'
---
> pred_filename = "predicates.txt"
6,9c6,9
<     config_filename = sys.argv[-1]
< print "Syntax: python ConceptNetXMLRPCServer.py [configuration_file]"
< print "Determining which knowledge libraries to load from %s..."%config_filename
< c =ConceptNetDB.ConceptNetDB(None,config_filename)
---
>     pred_filename = sys.argv[-1]
> print "Syntax: python ConceptNetXMLRPCServer.py [predicates_file]"
> print "Loading Predicates from %s..."%pred_filename
> c =ConceptNetDB.ConceptNetDB(None,pred_filename)
14a15
> xmlrpc.register_instance(c)
16,22d16
< xmlrpc.register_function(c.get_context)
< xmlrpc.register_function(c.get_analogous_concepts)
< xmlrpc.register_function(c.get_all_projections)
< xmlrpc.register_function(c.project_affective)
< xmlrpc.register_function(c.project_consequences)
< xmlrpc.register_function(c.project_details)
< xmlrpc.register_function(c.project_spatial)

kill Darwin(Quicktime) streaming server if it is running.
start the server
$ python ConceptNetXMLRPCServer.py

xml-rpc client in python

#!/usr/local/bin/python

import sys
reload(sys)

from xmlrpclib import ServerProxy, Error

processor = ServerProxy("http://localhost:8000") # local server
# processor = ServerProxy("http://betty.userland.com")
# print processor

phrase = sys.argv[1]
# print phrase

try:
    text = processor.guess_mood(phrase)
    print text
except Error, v:
    print "ERROR", v
	

query and result
$ python _test-rpc.py "Now is the time for all good men to come to the aid of the party"
[['disgusted', 0.4862797314730406], ['angry', 0.44568548377190498], ['sad', 0.25683556430435933], ['fearful', 0.2219426823049894], ['happy', 0.11441016214900629], ['surprised', 0.0]]