-2

I am working on an application that takes a topic and match it with existing topics in a column and return the percentage similarity of the topics. I am using power builder and sybase. I have a string variable(topic) that stores the topic. I need help on how to match the variable with the field "restopic" in "tblres".The query to return the percentage similarity between "topic" and all the items in "restopic" and order the result by highest percentage similarity.

Topic= Data supplied from user inputs

tblres

ID RES_TOPIC

001 The challenges of teaching large classes

002 The cause of high rate of accidents on a particular road

003 The impact of computers in teaching

I want data supplied from user input to be matched against RES_TOPIC to determine percentage similarity

Deens
  • 43
  • 1
  • 1
  • 5
  • Please, can you show the data you have now and the information you want to get? I can not understand what you are asking. – Eduardo G. Feb 17 '17 at 07:04
  • Depending upon what you define as 'matching' you may be able to do this within the SQL statement generating the results for the datawindow object. – Matt Balent Feb 20 '17 at 12:52

2 Answers2

1

Not sure if this is what you're looking for, but if you query the database using the CONTAINS cause, it will include a SCORE column in the results.

SCORE indicates how close the match is, and can be used to rank the results.

You need a Text Index on any column(s) you wish to be included in the search condition.

0

It's unclear what you are asking for. How do you define percentage of similarity?

I guess you are looking for a way to search in strings. You can use the Pos() function. But it's your job to define the similarity in a function. Once this is done, just loop your datawindow.

ll_rows = tblres.rowcount()
FOR ll_row = 1 to ll_rows
    ll_similarity = similarity(tblres.getItemString( ll_row, 'res_topic' ), topic )
    // do something with ll_similarity
NEXT

function similarity(string res_topic, string topic)
    //do something with pos() and mid()
    //this is the place where the magic happens
     return ll_percentage