cancel
Showing results for 
Search instead for 
Did you mean: 

Text Mining Using XS API

DeepakVarandani
Explorer
0 Kudos

Hello Experts,

  

         I am using SAP HANA SPS 09 and want to do text mining using XS API. I have created below .xsjs file in which I have used $.db.textmining.Session. I want to know how I can connect the xsjs file to the database, whether I have to create .sqlcc configuration

or any other type to connect to database ??

While running the text mining file it is giving error as Possible Web Forgery Attack.

XSJS file for Text Mining :-

function displayResults(results)

{

  var propName = null;

  var propNames = [];

  var result = null;

  var row = 0;

  var col = 0;

  if (results.length === 0)

  {

  output += "<p>(empty result table)</p>";

  return;

  }

  output += "<table border='1'>";

  // Get and save property names from first result row and put in the table header.

  output += "<tr>";

  for (propName in results[0])

  {

  if (results[0].hasOwnProperty(propName))

  {

  propNames[propNames.length] = propName;

  output += "<th>" + propName + "</th>";

  }

  }

  output += "</tr>";

  // For each result row, put in the table property values.

  for (row = 0; row < results.length; ++row)

  {

  result = results[row];

  output += "<tr>";

  for (col = 0; col < propNames.length; ++col)

  {

  output += "<td>" + result[propNames[col]].slice(0,50) + "</td>";

  }

  output += "</tr>";

  }

  output += "</table>";

}

try

{

  output += "<p>create session</p>";

// var conn = $.db.getConnection();

  var TM = new $.db.textmining.Session

  ({

  referenceTable: "TEXT_MINING:TEST",

  referenceColumn: "TEXT",

// connection: conn

  });

  output += "<p>initialize</p>";

  var init = TM.initialize({ });

  output += "<p>getRelatedTerms</p>";

  var termResults = TM.getRelatedTerms

  ({

  top: 16,

  inputTermText: "animal",

  });

  displayResults(termResults);

  output += "<p>Done -- no errors detected.</p>";

}

catch(err)

{

  output += "<p>" + err + "</p>";

}

//-----------------------------------------------------------------------------

output += "</body>";

$.response.contentType = "text/html";

$.response.setBody(output);

Accepted Solutions (0)

Answers (2)

Answers (2)

lucas_oliveira
Advisor
Advisor
0 Kudos

Can you share your project here? Maybe I can find time and try it internally.

BRs,

Lucas

DeepakVarandani
Explorer
0 Kudos

Hi Lucas,

   I have changed  force_ssl to true (previously false) in .xsaccessfile, by doing this output of above xsjs file is coming. But I want to know whether it is recommended practice to do.

Thanks !!!

lucas_oliveira
Advisor
Advisor
0 Kudos

Hello,

Depending on what you're doing forcing https is a must (in which case force_ssl is necessary). Example: processing anything with sensitive data through HTTP surely needs some level of security.

It really depends on your requirements.

[]'s,

Lucas de Oliveira

DeepakVarandani
Explorer
0 Kudos

Hi Lucas,

    Thanks a lot for your help !!!

Really appreciate your effort...

Regards,

Deepak

lucas_oliveira
Advisor
Advisor
0 Kudos

Hi Deepak,

Your code is just a copy of the one from the SAP HANA Tutorial for Text Mining so it should work.

I believe the error you're facing is related to the option for automatic prevention of cross-site request forgery. Check your .xsaccess file. Value prevent_xsrf should be true (which is a good thing).

There's probably a point of your code allowing that sort of attack...

Of course, for the sake of *testing* you could deactivate that and keep working on your tests.

BRs,

Lucas de Oliveira

DeepakVarandani
Explorer
0 Kudos

Hi Lucas,

   Thanks for your reply. I have already tried deactivating prevent_xsrf  in .xsaccessfile, but it still gives the same error.

lucas_oliveira
Advisor
Advisor
0 Kudos

That would need a closer look. I just tried it from my side without any trouble. Which revision of SAP HANA you're using?

DeepakVarandani
Explorer
0 Kudos

Hi Lucas,

     I am currently using SAP HANA SPS 09 Rev 94.