Identifying languages within text file

61 Views Asked by At

I am trying to create a program on p5.js Web Editor, which from a text file written in multiple languages can detect the different languages. I was advised to use the franc library. So far this is my code:

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>p5.js Sketch</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/p5.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.6.0/addons/p5.sound.min.js"></script>
    <script src="./Libraries/franc.js"></script>
  </head>
  <body>
    <script src="sketch.js"></script>
  </body>
</html>

sketch.js

let song;

function preload() {
  song = loadStrings('data/Chansonegocentrique.txt');
}

function setup() {
  let languageCounts = {};

  // Loop through each line of text and detect the language
  for (let line of song) {
    let languageCode = franc(line);
    
    // Increment the count for this language
    if (languageCounts[languageCode]) {
      languageCounts[languageCode]++;
    } else {
      languageCounts[languageCode] = 1;
    }
  }
  
  // Print out the language counts
  console.log(languageCounts);
}

Then I have two folders, one called 'data' which holds the .txt file, and the other one called 'libraries' with the franc.js index code.

However this code is not working, could anyone tell me why?

I was also told that I could add the 'franc' library directly on the p5.js web editor, through a library option on the top left, but I can't see it. Apparently I should enable the 'advanced mode' but I can't see that either.

0

There are 0 best solutions below