How to Access WS-NLP Service Version Two

      
        $key_sentences = $_POST[key];  //will be the correct answer of a short-answer quest
        $target_sentences = $_POST[target]; //will be what the player enters into the textbox
        $value = $_POST[value]; //maximum mark value, the return result will be 0 to value. Could be 1 so you will get a number in the range of 0 to 1.
        $maxBPM = true;  //use Bipartite Matching algorithm, or false and not pass maxBPM for using v1's conventional keyword matching and distribution method
        $language = $_POST[language]; //en, fr, or hi

        // Prepare POST request with the ith key sentence, jth
        // target sentence, and the value. The JSON object will
        // get sent to a PHP bridge where the similarity between
        // the key sentence and target sentence will be calculated
        $json = array(
          'key' => $key_sentences,
          'target' => $target_sentences,
          'value' => $value,
          'maxBPM' => $maxBPM,
          'language' => $language
        );

        $json = json_encode($json);

        $context = array('http' =>
          array(
              'method'  => 'POST',
              'header'  => 'Content-Type: application/json',
              'content' => $json
          )
        );
        $context  = stream_context_create($context);

        // use file_get_get_contents or AJAX to send request to WS-NLP service bridge
        $contents = file_get_contents('https://ws-nlp.vipresearch.ca/bridge/', false, $context);

        // use json_decode to capture response
        $contents = json_decode($contents);

        // will be the similarity between the key and target text
        $contents->similarity;

        // see more JSON structure of the response in the instruction page