How to Access WS-NLP Service Version 2.1

      
        // Get the values needed for the bridge.
        $key_sentences = 'One or more sentences go here. The bridge can handle multiple sentences at a time';
        $target_sentences = 'However, the more sentences compared at a time, the longer the computation will take.';
        $value = 1; // Similarity between 0 and 1 will be multiplied by this value.
        $method = 'bpm'; // Currently 'old' is the only other available method.
        $language = 'en'; // Or 'fr' or 'hi'.

        // Prepare POST request.
        $json = array(
          'key' => $key_sentences,
          'target' => $target_sentences,
          'value' => $value,
          'method' => $method,
          'language' => $language
        );
        $json = json_encode($json);

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

        // Get the similarity data.
        $contents = file_get_contents('https://ws-nlp.vipresearch.ca/bridge/', false, $context);
        $contents = json_decode($contents);

        // The bridge returns different data depending on whether the comparison was
        // between single sentences or paragraphs and whether the 'bpm' method was used.
        // For single sentence comparisons:
        $contents->similarity; // Float. 
        $contents->matrix; // Array.
        $contents->key_sentences; // Array.
        $contents->target_sentences; // Array.
        $contents->multi_sentence; // Boolean.
        $contents->tokens; // Array.
        $contents->mappings; // Array.
        $contents->combination; // Array.
        // If method == 'bpm', then in addition to the above:
        $contents->combination_maxBPM; // Array.
        $contents->combination_mapping; // Array.
    
        // Paragraph comparisons will have the same data as single sentence comparisons plus:
        $contents->matrix_indexed_by_sentence; // Array.
        $contents->sentence_connection_mappings; // Array.
        // If method == 'bpm', then the combination_maxBPM data is absent.