JavaScript - Getting First Sentence From Wiki Article
Does anyone know of an easy way, using javascript/jscript/jquery only, to get the first sentence of any Wikipedia article?
I've tried using ajax to grab all the html and then narrow it down using a couple of split() functions, but not every article is the same, so I don't think I can do it that way. Any ideas? Similar TutorialsIn my functionality, I need to replace all the apostrophes(') present in the sentence with double apotrophes('') so that it can be stored in the database. I am able to replace the first apostrophe with indexOf() and replace() methods. How do I replace the other apostrophes present in the string? I am taking a Javascript class and the teacher assigned this: Quote: Write a script that uses a random number generation to create sentences and name it sentences.html. Use five arrays of strings called: uppercase article (uarticle), noun, verb, lowercase article (larticle), and preposition. You will need to use the correct case for the article arrays. Create a sentence by selecting a word at random from each array in the following order: uarticle, noun, verb, preposition, larticle, noun. You can find examples of generating random numbers in both Fig. 8.6 (dice-rolling) and Fig. 8.7 (random image) of Chapter 8. The arrays should be filled at minimum, as follows: the article array(s) should contain the articles: the, a, one, some and any. The noun array should contain the nouns: boy, girl, dog, town and car. The verb array should contain the verbs: drove, jumped, ran, walked, and skipped. The preposition array should contain the prepositions: to, from, over, under and on. If you would like to add more words, adjust the arrays appropriately. As each word is picked, concatenate it to the previous words in the sentence. The words should be separated by spaces. When the final sentence is output, it should start with a capital letter and end with a period. The program should generate 20 sentences and output them to the screen (document.write or document.writeln). You should use a for loop similarly to the one used in Fig. 8.6 in order to get it to print 20 times. I haven't gotten to the loop yet, I'm just working on the random sentence first. Here is what I have: Code: <script type="text/javascript"> <!-- uarticle = new Array("The", "A", "One", "Some", "Any"); noun = new Array("boy", "girl", "dog", "town", "car"); verb = new Array("drove", "jumped", "ran", "walked", "skipped"); larticle = new Array("the", "a", "one", "some", "any"); preposition = new Array("to", "from", "over", "under", "on"); var rand1 = [Math.floor ( Math.random() * uarticle.length )]; var rand2 = [Math.floor ( Math.random() * noun.length )]; var rand3 = [Math.floor ( Math.random() * verb.length )]; var rand4 = [Math.floor ( Math.random() * larticle.length )]; var rand5 = [Math.floor ( Math.random() * preposition.length )]; document.write(uarticle[rand2] + " " + noun[rand2] + " " + verb[rand3] + " " + preposition[rand1] + " " + larticle[rand4] + " " + noun[rand2] + "."); --> </script> Am I on the right track? How would I loop the sentences using a for statement? please give me the code for checking the company name entered in textbox using javascript .Only sentence case to be allowed.Only abbreviations (without a full name) should not be allowed.(eg DPS) Abbreviations if any should be allowed only at the end of the name within ().eg Delhi Public School(DPS)
Using Joomla 1.5.26, I'm trying to have Diigo bookmarks show up in an article. Diigo has an API that will fetch the bookmarks and return them in a JSON format. For these bookmarks to be updated, I suppose the page would need to be refreshed; it's not like a Twitter real-time feed... Example API call to: https://secure.diigo.com/api/v2/book...itman&count=10 Here's what's returned: [{"updated_at":"2012/05/14 19:04:31 +0000","url":"http://etc.fdresa.org/index.php?option=com_content&%3Bview=article&%3Bid=93%3A2012-summer-technology-offerings&%3Bcatid=42%3A2012-courses&%3BItemid=2#.T7FW-LgvBMw.diigo","annotations":[],"user":"dritman","readlater":"no","shared":"yes","tags":"etc,technology,courses","created_at":"2 012/05/14 19:04:31 +0000","title":"2012 Summer Technology Offerings","comments":[],"desc":""},{"updated_at":"2012/05/11 16:51:38 +0000","url":"http://etc.fdresa.org/index.php?option=com_content&%3Bview=article&%3Bid=94%3Alive-feeds&%3Bcatid=43%3Alinks&%3BItemid=50#.T61DemaIB_w.diigo","annotations":[],"user":"dritman","readlater":"no","shared":"yes","tags":"no_tag","created_at":"2012/05/11 16:51:38 +0000","title":"Live feeds","comments":[],"desc":"Testing"}] How do I go about parsing this JSON info into a readable format within a Joomla article? Thanks! |