Code viewer for World: Practise1
// Replace 'YOUR_API_KEY' with your actual Google Cloud API key
const apiKey = 'AIzaSyCFn8hJsljCPNoyBT_oAVUOoYo8OjFEfwo';

// Function to perform basic text analysis using Google Cloud Natural Language API
function performTextAnalysis(text) {
  const apiUrl = `https://language.googleapis.com/v1/documents:analyzeEntities?key=${apiKey}`;

  const requestData = {
    document: {
      content: text,
      type: 'PLAIN_TEXT',
    },
    encodingType: 'UTF8',
  };

  return fetch(apiUrl, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(requestData),
  })
    .then(response => response.json())
    .then(data => {
      // Display the results of the basic text analysis
      console.log('Entities:', data.entities);
      console.log('Sentiment:', data.documentSentiment);
      console.log('Syntax:', data.tokens);
      // Modify the response to fit the Ancient Brain World display
      const result = `Entities: ${JSON.stringify(data.entities)}\nSentiment: ${JSON.stringify(data.documentSentiment)}\nSyntax: ${JSON.stringify(data.tokens)}`;
      $("#them").html(result);
    })
    .catch(error => console.error('Error:', error));
}

// Function to perform language translation using Google Cloud Translation API
function performTranslation(text, targetLanguage, translationAccuracy) {
  const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;

  const requestData = {
    q: text,
    target: targetLanguage,
    format: 'text',
    model: 'nmt',
    source: 'en',
  };

  return fetch(apiUrl, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(requestData),
  })
    .then(response => response.json())
    .then(data => {
      // Display the translated text
      console.log('Translation:', data.data.translations[0].translatedText);
      // Modify the response to fit the Ancient Brain World display
      $("#them").html(`Translation: ${data.data.translations[0].translatedText}`);
    })
    .catch(error => console.error('Error:', error));
}

// Example usage:
// Hello World
//performTextAnalysis('Hello, how are you? This is a test.');

// Impressive Use Case
//performTranslation('Hello, how are you?', 'es', 0.8); // Translate to Spanish with 80% accuracy

/*
// Function to perform basic text analysis using Google Cloud Natural Language API
function performTextAnalysis(text) {
  const apiUrl = `https://language.googleapis.com/v1/documents:analyzeEntities?key=${apiKey}`;

  const requestData = {
    document: {
      content: text,
      type: 'PLAIN_TEXT',
    },
    encodingType: 'UTF8',
  };

  return fetch(apiUrl, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(requestData),
  })
    .then(response => response.json())
    .then(data => {
      // Display the results of the basic text analysis
      console.log('Entities:', data.entities);
      console.log('Sentiment:', data.documentSentiment);
      console.log('Syntax:', data.tokens);
    })
    .catch(error => console.error('Error:', error));
}

// Function to perform language translation using Google Cloud Translation API
function performTranslation(text, targetLanguage, translationAccuracy) {
  const apiUrl = `https://translation.googleapis.com/language/translate/v2?key=${apiKey}`;

  const requestData = {
    q: text,
    target: targetLanguage,
    format: 'text',
    model: 'nmt',
    source: 'en',
    // You can adjust accuracy with 'q' parameter, but it might not be as fine-tuned as a slider
    // Adjust translation accuracy using the 'q' parameter
    // q: `Hello world.`, // Example
  };

  return fetch(apiUrl, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify(requestData),
  })
    .then(response => response.json())
    .then(data => {
      // Display the translated text
      console.log('Translation:', data.data.translations[0].translatedText);
    })
    .catch(error => console.error('Error:', error));
}

// Example usage:
// Hello World
//performTextAnalysis('Hello, how are you? This is a test.');

// Impressive Use Case
//performTranslation('Hello, how are you?', 'es', 0.8); // Translate to Spanish with 80% accuracy
*/