Xml Code To Find The Words And Index Them
1
0
Entering edit mode
11.9 years ago
AP ▴ 60

This is an xml code for the fetching the article content of a science direct content. I want to know how would i extend this code and try finding fetching the words in the article with space, ie it should take a single word separated by a space. and from this i want to strip off the words which are common and index only those words which are unique.


<Module>
  <ModulePrefs title="GetArticleContentGadget" author_email="">
    <Require feature="sciverse"/>
    <Require feature="dynamic-height"/>
  </ModulePrefs>
  <Content type="html" view="canvas,profile">  
  
    
Profile view
<script type="text/javascript"> // Get userprefs var prefs = new gadgets.Prefs(); function getHtml() { var params = {}; var requestHeaders = {}; requestHeaders['X-ELS-APIKey'] = "72f54b470474297f4b552839c3b57522"; requestHeaders['X-ELS-ResourceVersion'] = "XOCS"; requestHeaders['Accept'] = "text/xml"; params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT; params[gadgets.io.RequestParameters.HEADERS] = requestHeaders; var url = "http://api.elsevier.com/content/article/DOI:10.1016/0092-8674(93)90500-P?view=FULL"; gadgets.io.makeRequest(url, response, params); }; function response(obj) { //obj.text contains the text of the page that was requested var str = obj.text; var html = str; document.getElementById('content_div').innerHTML = html; }; gadgets.util.registerOnLoadHandler(getHtml); /* * This function calls the container to get the current article content. */ function getContent() { gadgets.sciverse.getArticleContent(getContentCallback); } /* * Call back function to process content * * response - response from getArticleContent call, string of article page body * */ function getContentCallback(response) { document.getElementById("articleHTML").innerHTML = "test"; if (response != null) { document.getElementById("articleHTML").innerHTML=response; WebRequest req = HttpWebRequest.Create(""); WebResponse webResponse = req.GetResponse(); } // Tells gadget to resize itself gadgets.window.adjustHeight(); } </script>

Get Article Content

]]></Content>
xml • 3.4k views
ADD COMMENT
1
Entering edit mode

i dont know why am not able to show the code properly?

ADD REPLY
0
Entering edit mode

Code lines need to be indented with 4 or more spaces. However, there are still issues with your code after editing; I don't know why.

ADD REPLY
0
Entering edit mode

I don't understand what you want to do exactly? You want to parse the content and index unique words in javascript?

ADD REPLY
0
Entering edit mode

yes . I need to parse the content of the article and index the unique words.

ADD REPLY
0
Entering edit mode
11.8 years ago

It's hard to read your javascript code, but you just need to parse the content in your callback function. Something like this, assuming 'txt' is the content text:

var formatStr = txt.replace(/\W+/g,' ');
var words = newString.split(' ');

var data = {};
for (var i = 0, l = words.length; i < l; i++) {
   if (words[i] in data) {
      data[words[i]] += 1;
   } else {
      data[words[i]] = 1;
   }
}

var unique = [];
for (var word in data) {
   if (data[word] == 1) {
      unique.push(data[word]);
   }
}

The word splitting statements just replace all non-characters with space and a subsequent split by space. You might have to play around with that part to how you want to define words. The 'unique' array should contain unique words. Not tested. There might be bugs.

ADD COMMENT
0
Entering edit mode

Thanks, the unique variable will have all the words?

ADD REPLY
0
Entering edit mode

The unique array contains unique words only. I wouldn't just simply copy and paste code without understanding what it is actually doing. The code sample I posted is just a rough guide on how you can do what you want to do. From your previous questions yesterday, it sounds like you are undertaking quite a complicated project. I don't want to discourage you from trying to take it on. But you should really try to understand every component of what you are tying to build instead of cobbling a bunch of components together and hope it works out.

ADD REPLY
0
Entering edit mode

i understand, but am also helpless state. time constrain and learning and also no guidance are taking a toll..anyways thanks for the rough code.

ADD REPLY

Login before adding your answer.

Traffic: 2268 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6