Browse Source

Generative manifesto is being built. Todo: add in generatige ____ as nn

master
suroh 2 years ago
parent
commit
1b84ccf776
4 changed files with 60 additions and 12 deletions
  1. +1
    -1
      assets/manifestos.json
  2. +1
    -1
      dat.json
  3. +44
    -3
      js/manifestoParse.js
  4. +14
    -7
      js/script.js

+ 1
- 1
assets/manifestos.json
File diff suppressed because it is too large
View File


+ 1
- 1
dat.json View File

@ -6,4 +6,4 @@
]
},
"fallback_page": "/index.html"
}
}

+ 44
- 3
js/manifestoParse.js View File

@ -1,3 +1,9 @@
// TODO
//
// Run the analysis and the bulk writer when
// there are new entries to the manifesto list.
//
console.log('manifestoParse!')
const jsonParser = async (file) => {
@ -10,6 +16,26 @@ const jsonParser = async (file) => {
}
}
const unlist = (text) => {
let regEx = /([0-9]\.\s)/g
if (regEx.test(text)) {
let _t = text.split(regEx)
let list = []
for (let t of _t) {
if (!regEx.test(t) && t != "") {
list.push(t)
}
}
text = list.join(' ')
return text
} else {
return text
}
}
export const analyser = async (file) => {
const _j = await jsonParser(file)
@ -18,6 +44,14 @@ export const analyser = async (file) => {
return
}
if (!_j.bulktext) {
const bulk = []
for (let m of _j.manifestos) {
bulk.push(unlist(m.text))
}
_j.bulktext = bulk.join(' ')
}
for (let m of _j.manifestos) {
if (!m.analysis) {
console.log(`${m.title} analysing...`)
@ -46,17 +80,24 @@ export const manifestoWriter = async (file) => {
let ranNum = Math.floor(Math.random() * (json.manifestos.length-1))
let manifesto = json.manifestos[ranNum]
// Manifesto Generation
let rm = new RiMarkov(3, true, false)
rm.loadText(json.bulktext)
rm.loadTokens(manifesto.analysis)
let sentences = rm.generateSentences(4)
manifesto = sentences.join(' ')
return manifesto
}
export const manifestoRender = (manifesto, domEl) => {
export const manifestoRender = async (manifesto, domEl) => {
// Render Manifesto to DOM
if (!manifesto) {
console.error('No manifesto to render')
return
}
domEl.textContent = manifesto.text
domEl.textContent = manifesto
}

+ 14
- 7
js/script.js View File

@ -1,10 +1,6 @@
import {
analyser,
analysisWriter,
manifestoWriter,
manifestoRender
} from '/js/manifestoParse.js'
import {analyser,analysisWriter,manifestoWriter,manifestoRender} from '/js/manifestoParse.js'
// DAT ARCHIVE & manifesto file
const dat = new DatArchive(window.location)
const MANIFESTO_FILE = '/assets/manifestos.json'
@ -12,8 +8,19 @@ const MANIFESTO_FILE = '/assets/manifestos.json'
const genButtonEl = document.querySelector('#genWhat')
const manifestoEl = document.querySelector('#manifesto')
// WORD GENERATION VARIABLES
let generativeType = ""
// CLICK THE GENERATIVE
genButtonEl.addEventListener('click', () => {
genButtonEl.addEventListener('click', async () => {
// generativeType = RiTa.randomWord("nn")
let manifestoFile = await dat.readFile(MANIFESTO_FILE)
let newManifesto = await manifestoWriter(manifestoFile)
Promise.all([manifestoFile], () => {
})
dat.readFile(MANIFESTO_FILE)
.then((d) => {
manifestoWriter(d)

Loading…
Cancel
Save