Skip to content

HeyHeyChicken/Non-Natural-Language-Processing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NOVA

Non-Natural-Language-Processing is a general non natural language utility in JS.


Currently supporting:
- Extract variables
- Multi language
- No training required

Usage

  1. Load the library.
const LIBRARIES = {
    NNLP: require("./src/NNLP")
};
  1. Instantiate
const NNLP = new LIBRARIES.NNLP();
  1. Define a corpus.
const CORPUS = [
    {
        "intent": "music.play.specific.name.artist",
        "utterances": [
            "Mets la musique {name} de {artist}",
        ],
        "answers": [
            "Très bien, voici %name% de l'artiste %artist%.",
            "OK, voici %name% de l'artiste %artist%.",
            "Voici %name% de l'artiste %artist%."
        ]
    },
    {
        "intent": "music.play",
        "utterances": [
            "Remets la musique",
            "Remets de la musique",
            "Mets de la musique",
            "Mets-moi de la musique",
            "Joue-moi de la musique",
            "Remets-moi de la musique",
            "Rejoue moi de la musique"
        ],
        "answers": [
            "Ok",
            "C'est parti"
        ]
    },
    {
        "intent": "music.next",
        "utterances": [
            "Musique suivante",
            "Mets la musique d'après"
        ],
        "errors": {
            "noMusic": [
                "Il n'y a plus de musiques disponibles.",
                "Votre bibliothèque ne dispose plus de musiques."
            ]
        }
    },
    {
        "intent": "music.previous",
        "utterances": [
            "Musique précédente",
            "Remets la musique d'avant"
        ]
    },
    {
        "intent": "music.pause",
        "utterances": [
            "Pose",
            "Pause",
            "Stop"
        ]
    },
    {
        "intent": "music.play.specific.name",
        "utterances": [
            "Mets la musique {name}"
        ],
        "answers": [
            "Très bien, voici %name%.",
            "OK, voici %name%.",
            "Voici %name%."
        ]
    }
];
  1. Load the corpus.
NNLP.loadCorpus(CORPUS);
  1. Add actions and trigger errors if needed.
NNLP.addAction("music.play", function(_intent, _result){
    // You can do what you want here
    console.log("Ok, je lance une musique aléatoire !");
});
NNLP.addAction("music.next", function(_intent, _result){
    // If you detect an error, you can trigger them like this.
    _result.answer = _intent.error("noMusic");
});
  1. Let the magic happen.
console.log(NNLP.process("Mets la musique No Beef de Afrojack"));
{
  utterance: 'Mets la musique No Beef de Afrojack',
  intent: 'music.play.specific.name.artist',
  variables: { name: 'No Beef', artist: 'Afrojack' },
  answers: [
    "Très bien, voici %name% de l'artiste %artist%.",
    "OK, voici %name% de l'artiste %artist%.",
    "Voici %name% de l'artiste %artist%."
  ],
  answer: "OK, voici No Beef de l'artiste Afrojack."
}
console.log(NNLP.process("Je ne sais pas quoi te demander"));
{
  utterance: 'Je ne sais pas quoi te demander',
  intent: 'none',
  variables: null,
  answers: undefined,
  answer: undefined
}
console.log(NNLP.process("Mets de la musique"));
Ok, je lance une musique aléatoire !
{
  utterance: 'Mets de la musique',
  intent: 'music.play',
  variables: {},
  answers: [ 'Ok', "C'est parti" ],
  answer: 'Ok'
}
console.log(NNLP.process("Musique suivante"));
{
  utterance: 'Musique suivante',
  intent: 'music.next',
  variables: {},
  answers: [],
  answer: "Il n'y a plus de musiques disponibles."
}
console.log(NNLP.process("Mets la musique Crossfire"));
{
  utterance: 'Mets la musique Crossfire',
  intent: 'music.play.specific.name',
  variables: { name: 'Crossfire' },
  answers: [ 'Très bien, voici %name%.', 'OK, voici %name%.', 'Voici %name%.' ],
  answer: 'Très bien, voici Crossfire.'
}

Created by Antoine Duval (HeyHeyChicken) with ❤ and ☕ (chocolate) in Mesnil-Panneville.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published