Recipe 15.3. Using XML-RPC with MedusaCredit: Jeff Bauer ProblemYou need to establish a lightweight, highly scalable, distributed processing system and want to use the XML-RPC protocol. SolutionPackage medusa lets you implement lightweight, highly scalable, asynchronous (event-driven) network servers. An XML-RPC handler is included in the Medusa distribution. Here is how you can code an XML-RPC server with Medusa: # xmlrpc_server.py from socket import gethostname from medusa.xmlrpc_handler import xmlrpc_handler from medusa.http_server import http_server from medusa import asyncore class xmlrpc_server(xmlrpc_handler): # initialize and run the server def _ _init_ _(self, host=None, port=8182): if host is None: host = gethostname( ) hs = http_server(host, port) hs.install_handler(self) asyncore.loop( ) # an example of a method to be exposed via the XML-RPC protocol def add(self, op1, op2): return op1 + op2 # the infrastructure ("plumbing") to expose methods def call(self, method, params): print "calling method: %s, params: %s" % (method, params) if method == 'add': return self.add(*params) return "method not found: %s" % method if _ _name_ _ == '_ _main_ _': server = xmlrpc_server( ) And here is a client script that accesses the server you just wrote: # xmlrpc_client.py from socket import gethostname from xmlrpclib import Transport, dumps class xmlrpc_connection(object): def _ _init_ _(self, host=None, port=8182): if host is None: host = gethostname( ) self.host = "%s:%s" % (host, port) self.transport = Transport( ) def remote(self, method, params=( )): """ Invoke the server with the given method name and parameters. The return value is always a tuple. """ return self.transport.request(self.host, '/RPC2', dumps(params, method)) if _ _name_ _ == '_ _main_ _': connection = xmlrpc_connection( ) answer, = connection.remote("add", (40, 2)) print "The answer is:", answer DiscussionThis recipe demonstrates remote method calls between two machines (or two processes, even on the same machine) using the XML-RPC protocol and provides a complete example of working client/server code. XML-RPC is one of the easiest ways to handle distributed processing tasks. There's no messing around with the low-level socket details, nor is it necessary to write an interface definition. The protocol is platform and language neutral. The XML-RPC specification can be found at http://www.xml-rpc.com and is well worth studying. It's nowhere as functionally rich as heavyweight stuff like CORBA, but, to compensate, it is much simpler! To run this recipe's Solution, you must download the Medusa library from http://www.nightmare.com (the Python Standard Library includes the asyncore and asynchat modules, originally from Medusa, but not the other parts of Medusa required for this recipe). With Medusa, you implement an XML-RPC server by subclassing the xmlrpc_handler class and passing an instance of your class to the install_handler method of an instance of http_server. HTTP is the transport-level protocol used by the XML-RPC standard, and http_server handles all transport-level issues on your behalf. You need to provide only the handler part, by customizing xmlrpc_handler through subclassing and method overriding. Specifically, you must override the call method, which the Medusa framework calls on your instance with the name of the XML-RPC method being called, along with its parameters, as arguments. This is exactly what we do in this recipe, in which we expose a single XML-RPC method named add which accepts two numeric parameters and returns their sum as the method's result. This recipe's XML-RPC client uses xmlrpclib in a more sophisticated way than Recipe 15.1, by accessing the TRansport class explicitly. In theory, this approach allows finer-grained control. However, this recipe does not exert that kind of control, and it's rarely required in XML-RPC clients that you actually deploy, anyway. See AlsoThe xmlrpclib module is part of the Python Standard Library and is documented in a chapter of the Library Reference portion of Python's online documentation. Medusa is at http://www.nightmare.com. |


@@include('../styles.html') @@include('../analytics-code.html')
The sharing economy allows people to easy access to products and services from someone else through an internet platform. Online platforms in the Sharing Economy, such as AirBnB or BlaBlaCar, are becoming more and more popular. We enable you to jump on that train fast and we build you an online marketplace platform. No matter which industry it includes or which marketplace use case you have in mind. You name it, win the challenge and we make it work.
You wonder when it’s the right time to bring your idea into life and start your own sharing economy platform? We have the answer: It’s now! VQ Labs offers you significant discounts on Marketplace technologies, and consulting in business development from professionals. You are not around? no worries we do the consulting over Skype!
The better or the more creative your idea, the bigger chance you have to win! The challenge is open to anyone (subject to terms & conditions) with a creative and innovative idea in the field of the Sharing Economy.
Anyone, who has an idea but needs help in building and bringing it into life, can submit his/her idea. Go to form below and describe your project with the problems it adresses in a specific industry and the solution your idea brings. Try to keep your description as clear as possible and remember applying before deadline!
All entries must be submitted by 7th December 2017 at 6 pm GMT
Once the application period is over, all ideas will be open to be voted by people. The 10 ideas, which collect the most votes, will pass to the second phase. Once you are in the second phase, we will evaluate all the finalists and choose the top 3!


Score
Past HackerRank Challenges
Home
Past HackerRank Challenges
Past Challenges
Solutions to Past Challenges
Madison v. Milwaukee Score


text_classification_query()
Automatically fits a text_classification model to your dataset. All standard text modification procedures are applied automatically if applicable..
Dataset Guidelines
- One column in the file should contain the text to be classified
- One column should contain the label of each text and SHOULD BE NAMED LABEL. If is named something else, please specify the name with the label_column parameter.
- Your instruction should be about the text you want to classify, for example in a problem where you have a tweet column (with the text) and a sentiment column (with 0-2 representing mood) your instruction should be about the tweet: 'please perform analysis on tweets'.
| Arguments | |
| instruction=None | An English language statement that represents the task you would like to be completed. eg: 'predict the median house value' or 'please estimate the number of households'. Should correspond to the column of text that you want to classify. |
| label_column='label' | Represents the column name in which your label exists. If the name is already similar to 'label' then this parameter is not required. |
| preprocess=True | Whether you want your dataset to be intelligently preprocessed. |
| test_size=0.2 | The proportion of your entire dataset that is used for testing. |
| random_state=49 | The randomization channel that you want to be set at. |
| learning_rate=1e-2 | The default rate at which your model learns based on gradient descent. |
| epochs=20 | Number of epochs. This is for every model that's created in the process. |
| epochs=50 | Number of epochs for every model attempted |
| monitor='val_loss' | The parameter that you want the query to minimize/maximize. For example, the default setting will try to minimize your validation loss. |
| generate_plots=True | Whether you want libra to create accuracy and loss plots for you. |
| batch_size=32 | The number of dataset points that will be provided to your model in every pass. |
| max_text_length=200 | The maximum amount of text that can be used to classify. If larger, it will cut off the rest. |
| max_features=20000 | The size of the input embedding layer in the model. |
| generate_plots=True | Whether you want libra to create accuracy and loss plots for you. |
| save_model=False | Do you want the model weights and architecture to be saved as a .json and .h5 file. |
| save_path=os.getcwd() | Where do you want the save_model information to be stored. Default is current working directory. |
new_client = client('path_to_csv') new_client.text_classification_query('Please estimate the sentiment') new_client.classify_text('new text to classify')
summarization_query()
Automatically fits a transfer-learning doc_summarization model to your dataset. This model will have frozen layers with pretrained weights to help with small dataset sizes.
Dataset Guidelines
- The data that you want to summarized should be the target of the instruction. So if you want to summarize tweets, the instruction could be 'summarize long textual tweets'.
- The result, or the summary should be in a column called 'summary'. THIS IS ESSENTIAL.
- Your instruction should be about the label column, not the text.
| Arguments | |
| drop=None | Columns to drop manually, drop columns with links, weirdly formatted numbers, and others. |
| epochs=10 | Number of epochs. This is for every model that's created in the process. |
| batch_size=32 | The number of dataset points that will be provided to your model in every pass. |
| learning_rate=1e-2 | The default rate at which your model learns based on gradient descent. |
| max_text_length=512 | The maximum amount of text that can be summarized |
| max_summary_length=150 | Maximum outputted summary length. The longer this is, the less accurate it will be. |
| gpu=False | Determines whether a built in cpu or gpu will be used. |
| generate_plots=True | Whether you want libra to create accuracy and loss plots for you. |
| save_model=False | Do you want the model weights and architecture to be saved as a .json and .h5 file. |
| save_path=os.getcwd() | Where do you want the save_model information to be stored. Default is current working directory. |
newClient = client('path_to_csv') newClient.summarization_query("Please summarize original text") newClient.get_summary('new text to summarize')
image_caption_query()
Automatically fits an caption generation transfer learning model to your dataset. This model will have frozen layers with pretrained weights to help with small dataset sizes.
Dataset Guidelines
- One column in the file should be that path to the images. This will be found automatically.
- The target of your instruction should be the caption column. So, maybe if your caption column is called short tweets, have your instruction be 'please shorten this text into short tweets'.
| Arguments | |
| instruction | An English language statement that represents the task you would like to be completed. eg: 'predict the median house value' or 'please estimate the number of households'. Should correspond to the column of captions in the dataset. |
| drop=None | Columns to drop manually, drop columns with links, weirdly formatted numbers, and others. |
| epochs=10 | Number of epochs. This is for every model that's created in the process. |
| preprocess=True | Whether you want your dataset to be intelligently preprocessed. |
| random_state=49 | he randomization channel that you want to be set at. |
| buffer_size=1000 | Maximum number of elements that will be buffered to be selected for the caption. |
| embedding_dim=256 | Sets the size of the word embedding mapping. |
| units=512 | The exact number of recurrent units present in the decoder. |
| gpu=False | Determines whether a built in cpu or gpu will be used. |
| generate_plots=True | Whether you want libra to create accuracy and loss plots for you. |
newClient = client('path_to_csv') newClient.image_caption_query('Generate image_captions') newClient.generate_caption('path to image')


The Wordpress site was my first personal project, before I attended the web development program. It was built on the foundation of wordpress.
Click here for more details about my WordpressNGUYEN Thoai My - Wordpress
The Wordpress site was my first personal project, before I attended the web development program. It was built on the foundation of wordpress.
Click here for more details about my Wordpress


I am Doug! I love computers, art, and creativity. I enjoy writing code, playing video games, and working on my own stories.


Applications can add SPARQL functions to the query engine. This is done by
writing a class implementing the right interface, then either registering it or
using the fake java:
URI scheme to dynamically call the function.
A SPARQL value function is an extension point of the SPARQL query language that allows URI to name a function in the query processor.
In the ARQ engine, code to implement function must implement the interface
com.hp.hpl.jena.sparql.function.Function
although it is easier to
work with one of the abstract classes for specific numbers of arguments like
com.hp.hpl.jena.sparql.function.FunctionBase1
for one argument functions.
Functions do not have to have a fixed number of arguments.
The abstract class
FunctionBase
, the superclass of
FunctionBase1
to
FunctionBase4
, evaluates its arguments and calls the implementation code
with argument values (if a variable was unbound, an error will have been
generated)
It is possible to get unevaluated arguments but care must be taken not to
violate the rules of function evaluation. The standard functions that access
unevaluated arguments are the logical 'or' and logical 'and' operations that
back ||
and &&
are special forms to allow for the
special exception handling rules.
Normally, function should be a pure evaluation based on it's argument. It should not access a graph nor return different values for the same arguments (to allow expression optimization). Usually, these requirements can be better met with a property function. Functions can't bind a variables; this would be done in a property function as well.
Example: (this is the max function in the standard ARQ library):
public class max extends FunctionBase2 { public max() { super() ; } public NodeValue exec(NodeValue nv1, NodeValue nv2) { return Functions.max(nv1, nv2) ; } }
The function takes two arguments and returns a single value. The class NodeValue represents values and supports value-based operations. NodeValue value support includes the XSD datatypes, xsd:decimal and all it's subtypes like xsd:integer and xsd:byte, xsd';doiuble, xsd:float, xsd:boolean, xsd:dateTime and xsd:date. Literals with language tags are also treated as values in additional "value spaces" determined by the language tag without regard to case.
The
Functions
class contains the core XML Functions and Operators operations.
Class NodeFunctions contains the implementations of node-centric operations like
isLiteral
and str
.
If any of the arguments are wrong, then the function should throw
ExprEvalException
.
Example: calculate the canonical namespace from a URI (calls the Jena operation for the actual work):
public class namespace extends FunctionBase1 { public namespace() { super() ; } public NodeValue exec(NodeValue v) { Node n = v.asNode() ; if ( ! n.isURI() ) throw new ExprEvalException("Not a URI: "+FmtUtils.stringForNode(n)) ; String str = n.getNameSpace() ; return NodeValue.makeString(str) ; } }
This throws an evaluation exception if it is passed a value that is not a URI.
The standard library, in package
com.hp.hpl.jena.sparql.function.library
, contains many examples.
The query compiler finds functions based on the functions URI. There is a global registry of known functions, but any query execution can have it's own function registry.
For each function, there is a function factory associated with the URI. A new function instance is created for each use of a function in each query execution.
// Register with the global registry. FunctionRegistry.get().put("http://example.org/function#myFunction", new MyFunctionFactory()) ;
A common case is registering a specific class for a function implementation so there is an addition method that takes a class, wraps in a built-in function factory and registers the function implementation.
// Register with the global registry. FunctionRegistry.get().put("http://example.org/function#myFunction", MyFunction.class) ;
Another convenience route to function calling is to use the
java:
URI scheme. This dynamical loads
the code, which must be on the Java classpath. With this scheme, the function
URI gives the class name. There is automatic registration of a wrapper into the
function registry. This way, no explicit registration step is needed by the
application and queries issues with the command line tools can load custom
functions.
PREFIX f: <java:app.myFunctions.> ... FILTER f:myTest(?x, ?y) ... FILTER (?x + f:myIntToXSD(?y)) ...