-1

I want to implement a small code I am not able to understand from where to start. I want to create a text field if user enter some text into text field I want to detect category of this text. For example if user enter "How to create an app for iOs".. utlity should detect this category as information technology. another example "good hotels in Singapore" this utility should detect treat this category as Travel....

4

1 回答 1

0

我的想法是用文字创建图书馆。

var categories = new Object();
categories = {
'IT' : {'iOS', 'Android'},
'Travel' : {'USA', 'London', 'Singapore'}
};

var text = 'How to create an app for iOs';
var spitter = text.split(' ');

for (var i = 0; i < spitter.length; i++) {
     var word = spitter[i];
     for (var categoryKey in categories) {
         for (var categoryKeyWord in categories[categoryKey])  {
            var regExp = new RegExp(categories[categoryKey][categoryKeyWord], i);
            if (regEpx.match(word) {
               //Your logic
            }
         }
     }
}
于 2013-07-09T04:59:39.017 回答