Skip to content

Commit

Permalink
Prep work for ScrollSet upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Breck Yunits authored and Breck Yunits committed May 20, 2024
1 parent 6e7c714 commit 12c13eb
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 75 deletions.
86 changes: 39 additions & 47 deletions Computer.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,8 @@ class ConceptPage {
return this._getFilePath()
}

get filename() {
return path.basename(this.absolutePath)
}

get permalink() {
return this.filename.replace(".scroll", ".html")
return this.id + ".html"
}

get domainName() {
Expand Down Expand Up @@ -187,7 +183,7 @@ class ConceptPage {

get helpfulResearchLinks() {
const id = this.id
const title = this.get("title")
const title = this.get("name")
const references = this.node
.findNodes("reference")
.map(node => "Reference: " + node.content)
Expand Down Expand Up @@ -219,7 +215,7 @@ Wayback Machine: https://web.archive.org/web/20220000000000*/${title}`
get names() {
return [
this.id,
this.title,
this.name,
this.get("standsFor"),
this.get("githubLanguage"),
this.wikipediaTitle,
Expand Down Expand Up @@ -691,11 +687,11 @@ pipeTable
}

get sourceUrl() {
return `https://github.com/breck7/pldb/blob/main/concepts/${this.filename}`
return `https://github.com/breck7/pldb/blob/main/concepts/${this.id}.scroll`
}

get title() {
return this.get("id")
return this.get("name")
}

toScroll() {
Expand Down Expand Up @@ -819,7 +815,7 @@ image ${image}
twitter: this.get("twitter"),
edit: `https://jtree.treenotation.org/designer#${encodeURIComponent(
new TreeNode(
`url https://pldb.io/pldb.grammar\nprogramUrl https://pldb.io/concepts/${this.filename}`
`url https://pldb.io/pldb.grammar\nprogramUrl https://pldb.io/concepts/${this.id}.scroll`
).toString()
)}`
}
Expand Down Expand Up @@ -1371,23 +1367,23 @@ class Feature {

const positives = this.languagesWithThisFeature
const positiveText = `* Languages *with* ${title} include ${positives
.map(file => `<a href="../concepts/${file.filename.replace(".scroll", ".html")}">${file.id}</a>`)
.map(file => `<a href="../concepts/${file.id}.html">${file.id}</a>`)
.join(", ")}`

const negatives = this.languagesWithoutThisFeature
const negativeText = negatives.length
? `* Languages *without* ${title} include ${negatives
.map(file => `<a href="../concepts/${file.filename.replace(".scroll", ".html")}">${file.id}</a>`)
.map(file => `<a href="../concepts/${file.id}.html">${file.id}</a>`)
.join(", ")}`
: ""

const examples = positives
.filter(file => this.computer.getConceptFile(file.filename).getNode(id).length)
.filter(file => this.computer.getConceptFile(file.id).getNode(id).length)
.map(file => {
return {
id: file.filename,
title: file.id,
example: this.computer.getConceptFile(file.filename).getNode(id).childrenToString()
id: file.id,
title: file.title,
example: this.computer.getConceptFile(file.id).getNode(id).childrenToString()
}
})
const grouped = lodash.groupBy(examples, "example")
Expand Down Expand Up @@ -1487,10 +1483,9 @@ class Tables {
}

_cache = {}
getConceptFile(filename) {
if (!this._cache[filename])
this._cache[filename] = new TreeNode(Disk.read(path.join(__dirname, "concepts", filename)))
return this._cache[filename]
getConceptFile(id) {
if (!this._cache[id]) this._cache[id] = new TreeNode(Disk.read(path.join(__dirname, "concepts", id + ".scroll")))
return this._cache[id]
}

toTable(data) {
Expand All @@ -1510,7 +1505,7 @@ class Tables {
.map(row =>
lodash.pick(row, [
"id",
"filename",
"title",
"rank",
"appeared",
PLDBKeywords.tags,
Expand All @@ -1524,8 +1519,8 @@ class Tables {
)
.value()
.map(row => {
row.idLink = "../concepts/" + row.filename.replace(".scroll", ".html")
delete row.filename
row.title = "../concepts/" + row.id + ".html"
delete row.id
return row
})
return this._top
Expand All @@ -1540,7 +1535,7 @@ class Tables {
const count = Object.keys(ranks).length
if (rank < 0) rank = count - 1
if (rank >= count) rank = 0
return this.getConceptPage(ranks[rank].filename)
return this.getConceptPage(ranks[rank].id)
}

getFileAtRank(rank) {
Expand All @@ -1552,7 +1547,7 @@ class Tables {
this._conceptPageCache = {}
this._conceptPages = []
this.pldb.forEach(file => {
const name = file.filename.replace(".scroll", "")
const name = file.id
const page = new ConceptPage(name, file, this)
this._conceptPageCache[name] = page
this._conceptPages.push(page)
Expand Down Expand Up @@ -1668,9 +1663,7 @@ class Tables {
name: nameCol,
links: `<span class="creatorQuickLinks">${linksCol}</span>`,
born: person.born,
languages: group
.map(file => `<a href='../concepts/${file.filename.replace(".scroll", ".html")}'>${file.id}</a>`)
.join(" - "),
languages: group.map(file => `<a href='../concepts/${file.id}.html'>${file.id}</a>`).join(" - "),
count: group.length,
topRank: group[0].rank
}
Expand Down Expand Up @@ -1698,7 +1691,7 @@ class Tables {
.map(file => {
return {
name: file.id,
nameLink: `../concepts/${file.filename.replace(".scroll", ".html")}`,
nameLink: `../concepts/${file}.html`,
rank: file.rank,
extensions: file.extensions
}
Expand Down Expand Up @@ -1745,7 +1738,7 @@ class Tables {
get autocompleteJs() {
const json = JSON.stringify(
this.pldb.map(file => {
const permalink = file.filename.replace(".scroll", "")
const permalink = file.id
return {
label: file.id,
id: permalink,
Expand Down Expand Up @@ -1794,7 +1787,7 @@ class Tables {

const row = keywordsMap[keywordKey]

row.ids.push(file.filename)
row.ids.push(file.id)
})
})

Expand All @@ -1804,7 +1797,7 @@ class Tables {
row.langs = row.ids
.map(id => {
const file = this.getConceptPage(id)
return `<a href='../concepts/${file.filename.replace(".scroll", ".html")}'>${file.id}</a>`
return `<a href='../concepts/${file.id}.html'>${file.id}</a>`
})
.join(" ")
row.frequency = Math.round(100 * lodash.round(row.count / langsWithKeywordsCount, 2)) + "%"
Expand Down Expand Up @@ -1847,7 +1840,7 @@ class Tables {
return {
WRITTEN_IN_TABLE: lodash
.sortBy(writtenIn, "rank")
.map(file => `- ${file.id}\n link ../concepts/${file.filename.replace(".scroll", ".html")}`)
.map(file => `- ${file.id}\n link ../concepts/${file.id}.html`)
.join("\n"),
PACKAGES_TABLE: npmPackages.map(s => `- ${s}\n https://www.npmjs.com/package/${s}`).join("\n"),
SOURCES_TABLE: sources.map(s => `- ${s}\n https://${s}`).join("\n"),
Expand Down Expand Up @@ -1939,19 +1932,19 @@ const computeds = {
},

rank(concept, computer) {
return computer.ranks[concept.get("filename")].index
return computer.ranks[concept.get("id")].index
},

pldbScore(concept, computer) {
return computer.ranks[concept.get("filename")].pldbScore
return computer.ranks[concept.get("id")].pldbScore
},

inboundLinks(concept, computer) {
return computer.inboundLinks[concept.get("filename")].length
return computer.inboundLinks[concept.get("id")].length
},

foundationScore(concept, computer) {
return computer.writtenIn[concept.get("filename").replace(".scroll", "")].length
return computer.writtenIn[concept.get("id")].length
}
}

Expand All @@ -1967,10 +1960,10 @@ class MeasureComputer {
makeWrittenInCache() {
const writtenInCache = {}
this.concepts.forEach(concept => {
writtenInCache[concept.get("filename").replace(".scroll", "")] = []
writtenInCache[concept.get("id")] = []
})
this.concepts.forEach(concept => {
const conceptId = concept.get("filename").replace(".scroll", "")
const conceptId = concept.get("id")
const writtenIn = concept.get("writtenIn")
if (!writtenIn) return
writtenIn.split(" ").forEach(id => writtenInCache[id].push(conceptId))
Expand All @@ -1981,20 +1974,20 @@ class MeasureComputer {
makeInboundLinksCache() {
const inboundLinks = {}
this.concepts.forEach(concept => {
inboundLinks[concept.get("filename")] = []
inboundLinks[concept.get("id")] = []
})

this.concepts.forEach(concept => {
const filename = concept.get("filename")
const id = concept.get("id")
concept
.filter(node => node.isLinks)
.forEach(node => {
const links = node.content.split(" ")
links.forEach(link => {
link += ".scroll"
if (!inboundLinks[link]) throw new Error(`No file "${link}" found in "${filename}"`)
if (!inboundLinks[link]) throw new Error(`No file "${link}" found in "${id}"`)

inboundLinks[link].push(filename)
inboundLinks[link].push(id)
})
})
})
Expand Down Expand Up @@ -2022,10 +2015,9 @@ const calcRanks = computer => {
]

let objects = concepts.map(concept => {
const filename = concept.get("filename")
const id = filename.replace(".scroll", "")
const id = concept.get("id")
const object = {}
object.filename = filename
object.id = id
categories.forEach(category => (object[category] = computer.get(category, concept)))

return object
Expand All @@ -2043,7 +2035,7 @@ const calcRanks = computer => {
const ranks = {}
objects.forEach((obj, index) => {
obj.index = index + 1
ranks[obj.filename] = obj
ranks[obj.id] = obj
})
return ranks
}
Expand Down
33 changes: 23 additions & 10 deletions ScrollSet.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ class ScrollSetCLI {
importCommand(filename) {
// todo: add support for updating as well
const processEntry = (node, index) => {
const filename = node.get("filename")
node.delete("filename")
const target = path.join(__dirname, "concepts", filename)
const id = node.get("id")
node.delete("id")
const target = this.makeFilePath(id)
Disk.write(target, new TreeNode(Disk.read(target)).patch(node).toString())
console.log(`Processed ${filename}`)
}
Expand All @@ -35,11 +35,11 @@ class ScrollSetCLI {
}

makeFilePath(id) {
return path.join(this.conceptsFolder, id.replace(".scroll", "") + ".scroll")
return path.join(this.conceptsFolder, id + ".scroll")
}

getTree(file) {
return new TreeNode(Disk.read(this.makeFilePath(file.filename)))
return new TreeNode(Disk.read(this.makeFilePath(file.id)))
}

setAndSave(file, measurementPath, measurementValue) {
Expand All @@ -49,21 +49,20 @@ class ScrollSetCLI {
}

save(file, tree) {
const dest = this.makeFilePath(file.filename)
const dest = this.makeFilePath(file.id)
return Disk.write(dest, tree.toString())
}

makeNameSearchIndex(files = this.concepts.slice(0).reverse()) {
const map = new Map()
files.forEach(parsedConcept => {
const id = parsedConcept.filename.replace(".scroll", "")
files.forEach(parsedConcept =>
this.makeNames(parsedConcept).forEach(name => map.set(name.toLowerCase(), parsedConcept))
})
)
return map
}

makeNames(concept) {
return [concept.filename.replace(".scroll", ""), concept.id].filter(i => i)
return [concept.id]
}

searchForConcept(query) {
Expand All @@ -85,6 +84,20 @@ class ScrollSetCLI {
return require(this.compiledConcepts)
}

async updateIdsCommand() {
this.concepts.forEach(file => {
const tree = this.getTree(file)
const newTree = tree.toString().replace(
`import ../code/conceptPage.scroll
id `,
`import ../code/conceptPage.scroll
id ${file.filename.replace(".scroll", "")}
name `
)
this.save(file, newTree.toString())
})
}

buildGrammarFileCommand() {
const code = `node_modules/scroll-cli/grammar/cellTypes.grammar
node_modules/scroll-cli/grammar/root.grammar
Expand Down
7 changes: 3 additions & 4 deletions browser/explorer/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class ExploreApp {
return this.objectFromHash.columns || this.defaultColumns
}

defaultColumns = "rank id appeared tags creators".replace(/ /g, this.columnDelimiter)
defaultColumns = "rank name id appeared tags creators".replace(/ /g, this.columnDelimiter)

makeColumns(measureNames) {
return measureNames
Expand All @@ -202,9 +202,8 @@ class ExploreApp {
.map(measure => {
const col = { data: measure, title: measure }

if (measure === "id")
col.render = (data, type, row, meta) =>
`<a href="../concepts/${row.filename.replace(".scroll", ".html")}">${row.id}</a>`
if (measure === "name")
col.render = (data, type, row, meta) => `<a href="../concepts/${row.id}.html">${row.name}</a>`

return col
})
Expand Down
Loading

0 comments on commit 12c13eb

Please sign in to comment.