Advertisement
caLLowCreation

Oxford Parse

Sep 9th, 2017
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         const results = [];
  2.         for (let i = 0; i < data.results.length; i++) {
  3.             const result = data.results[i];
  4.             const item = {
  5.                 result: [],
  6.                 pronunciations: [],
  7.             };
  8.  
  9.             for (let j = 0; j < result.lexicalEntries.length; j++) {
  10.                 const lexicalEntry = result.lexicalEntries[j];
  11.                
  12.                 for (let k = 0; k < lexicalEntry.entries.length; k++) {
  13.                     const entry = lexicalEntry.entries[k];
  14.                    
  15.                     for (let m = 0; m < entry.senses.length; m++) {
  16.                         const sense = entry.senses[m];
  17.                         const defExa = { definitions: [], examples: [] };
  18.                         if(useSearch === false) {
  19.                             for (let n = 0; n < sense.definitions.length; n++) {
  20.                                 const definition = sense.definitions[n];
  21.                                 defExa.definitions.push(definition);
  22.                                 //console.log(definition);
  23.                             }
  24.                         } else {
  25.                             if(sense.hasOwnProperty('examples')) {
  26.                                 for (let n = 0; n < sense.examples.length; n++) {
  27.                                     const example = sense.examples[n];
  28.                                     defExa.examples.push(example.text);
  29.                                     //console.log(examples);
  30.                                 }
  31.                             }
  32.                         }
  33.                         item.result.push(defExa);
  34.                     }
  35.                 }
  36.                 for (let k = 0; k < lexicalEntry.pronunciations.length; k++) {
  37.                     const pronunciation = lexicalEntry.pronunciations[k];
  38.                     item.pronunciations.push(pronunciation.audioFile);
  39.                     //console.log(pronunciation.audioFile);
  40.                 }
  41.             }
  42.            
  43.             results.push(item);
  44.         }
  45.         //console.log(results);
  46.  
  47.         const displaySet = [];
  48.         let displayText = query + ': ';
  49.         let hasDefinitions = false;
  50.         let hasExamples = false;
  51.         for (let i = 0; i < results.length; i++) {
  52.             const item = results[i];
  53.            
  54.             for (let j = 0; j < item.result.length; j++) {
  55.  
  56.                 const result = item.result[j];
  57.                 hasDefinitions = result.definitions.length > 0;
  58.                 hasExamples = result.examples.length > 0;
  59.                 const text = '(' + (hasDefinitions ? result.definitions.join(' | ') : '') + (hasExamples ? result.examples.join(' | ') : '') + ')';
  60.                 displayText += text;
  61.                 if(displayText.length < 500) {
  62.                     displaySet.push(text);
  63.                 }
  64.             }
  65.         }
  66.         if(hasDefinitions === true || hasExamples === true) {
  67.             chatCommand.sendNotice(irc, event, `@${event.data.user.username} ${query}: ${displaySet.join(',')}`);
  68.         }
  69.         else {
  70.             chatCommand.sendNotice(irc, event, `@${event.data.user.username} ${query}: Has no results.`);            
  71.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement