I want to write a web server with python where there is a text box and a user inputs something and I run a python function on it which gives me an output for the users input and render it on the same page, essentially like a chat with a computer
I have this function that segments a string, and I am returning the top scoring segmentation which I have a helper function score. I am wondering how to return the top k segmentations
def segment(text):
# Return a list of words that is the best segmentation of text.
if not text:
return []
candidates = ([first] + segment(rem) for first, rem in splits(text, max_length))
return max(candidates, key=score)
<script>
var url = sample url;
var flag_to_set = value of the flag;
//use $.get or $.post or $.ajax if you use jquery. For traditional javascript use XMLHttpRequest. You will get code snippets for the same. I am using jquery $.post for the same as example.
$.post(url,{flag: flag_to_set},function(data)
{
// callback for success.
}
</script>