Skip to content

Commit

Permalink
Display vectors in models directory if available (see #1457)
Browse files Browse the repository at this point in the history
  • Loading branch information
ines committed Oct 25, 2017
1 parent 11e3f19 commit 70de2dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion website/_includes/_page_models.jade
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ for id in CURRENT_MODELS
+cell #[+label Size]
+cell #[+tag=comps.size] #[span(data-tpl=id data-tpl-key="size") #[em n/a]]

each label in ["Pipeline", "Sources", "Author", "License"]
each label in ["Pipeline", "Vectors", "Sources", "Author", "License"]
- var field = label.toLowerCase()
+row
+cell.u-nowrap
Expand Down
11 changes: 9 additions & 2 deletions website/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ class ModelLoader {
else return ({ ok: res.ok })
}

convertNumber(num, separator = ',') {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
}

getModels(compat) {
this.compat = compat;
for (let modelId of this.modelIds) {
Expand All @@ -159,21 +163,22 @@ class ModelLoader {
const template = new Templater(modelId);
template.get('table').removeAttribute('data-loading');
template.get('error').style.display = 'block';
for (let key of ['sources', 'pipeline', 'author', 'license']) {
for (let key of ['sources', 'pipeline', 'vectors', 'author', 'license']) {
template.get(key).parentElement.parentElement.style.display = 'none';
}
}

/**
* Update model details in tables. Currently quite hacky :(
*/
render({ lang, name, version, sources, pipeline, url, author, license, accuracy, size, description, notes }) {
render({ lang, name, version, sources, pipeline, vectors, url, author, license, accuracy, size, description, notes }) {
const modelId = `${lang}_${name}`;
const model = `${modelId}-${version}`;
const template = new Templater(modelId);

const getSources = s => (s instanceof Array) ? s.join(', ') : s;
const getPipeline = p => p.map(comp => `<code>${comp}</code>`).join(', ');
const getVectors = v => `${this.convertNumber(v.entries)} (${v.width} dimensions)`;
const getLink = (t, l) => `<a href="${l}" target="_blank">${t}</a>`;

const keys = { version, size, description, notes }
Expand All @@ -182,6 +187,8 @@ class ModelLoader {
if (sources) template.fill('sources', getSources(sources));
if (pipeline && pipeline.length) template.fill('pipeline', getPipeline(pipeline), true);
else template.get('pipeline').parentElement.parentElement.style.display = 'none';
if (vectors) template.fill('vectors', getVectors(vectors));
else template.get('vectors').parentElement.parentElement.style.display = 'none';

if (author) template.fill('author', url ? getLink(author, url) : author, true);
if (license) template.fill('license', this.licenses[license] ? getLink(license, this.licenses[license]) : license, true);
Expand Down

0 comments on commit 70de2dd

Please sign in to comment.