Skip to content

Commit

Permalink
Fix relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirill89 committed Apr 6, 2022
1 parent 28fc9a4 commit 32e4875
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import {readFileSync, writeFileSync} from 'node:fs';
import {fileURLToPath} from 'node:url';
import {dirname, join} from 'node:path'

const dataDir = join(dirname(fileURLToPath(import.meta.url)), 'data');

const acceptedChars = 'abcdefghijklmnopqrstuvwxyz ';
const pos = [...acceptedChars].reduce((acc, char, idx) => {
Expand Down Expand Up @@ -35,10 +39,10 @@ export function avgTransitionProb(l, logProbMat) {

// Write a simple model as a JSON file
export function train(
modelPath = './data/model.json',
datasetPath = './data/big.txt',
goodProbesPath = './data/good.txt',
badProbesPath = './data/bad.txt') {
modelPath = join(dataDir, 'model.json'),
datasetPath = join(dataDir, 'big.txt'),
goodProbesPath = join(dataDir, 'good.txt'),
badProbesPath = join(dataDir, 'bad.txt')) {
const k = acceptedChars.length;
// Assume we have seen 10 of each character pair. This acts as a kind of
// prior or smoothing factor. This way, if we see a character transition
Expand Down Expand Up @@ -97,7 +101,7 @@ function loadModelCached(modelPath) {
return model;
}

export function isGibberish(text, modelPath = './data/model.json') {
export function isGibberish(text, modelPath = join(dataDir, 'model.json')) {
const model = loadModelCached(modelPath);

return avgTransitionProb(text, model.mat) <= model.thresh;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gibb",
"version": "1.0.2",
"version": "1.0.3",
"description": "Gibberish detection algorithm based on Markov chain",
"main": "index.mjs",
"scripts": {
Expand Down

0 comments on commit 32e4875

Please sign in to comment.