Skip to content

Commit

Permalink
fold embedding vectors in item labels
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz committed Jan 1, 2025
1 parent 4638fea commit aa5bf7e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 62 deletions.
5 changes: 4 additions & 1 deletion src/components/common/CategorizedItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</d-badge>
<span
style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif">
{{ item.Labels }}
{{ fold(item.Labels) }}
</span>
</div>

Expand All @@ -73,6 +73,8 @@
</template>

<script>
import utils from '@/utils';
const axios = require('axios');
export default {
Expand Down Expand Up @@ -152,6 +154,7 @@ export default {
this.items = response.data === null ? [] : response.data;
});
},
fold: utils.fold,
},
};
</script>
5 changes: 4 additions & 1 deletion src/components/common/TopItemsCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
{{ label }}
</d-badge>
<span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif">
{{ item.Labels }}
{{ fold(item.Labels) }}
</span>
</div>

Expand Down Expand Up @@ -69,6 +69,8 @@
</template>

<script>
import utils from '@/utils';
export default {
name: 'ao-top-referrals',
props: {
Expand Down Expand Up @@ -108,6 +110,7 @@ export default {
nextPage() {
this.pageNumber += 1;
},
fold: utils.fold,
},
};
</script>
5 changes: 4 additions & 1 deletion src/components/common/UserRecommend.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<!-- Content - Actions -->
<div class="blog-comments__actions">
<span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif">
{{ item.Labels }}
{{ fold(item.Labels) }}
</span>
</div>

Expand Down Expand Up @@ -93,6 +93,8 @@
</template>

<script>
import utils from '@/utils';
const axios = require('axios');
export default {
Expand Down Expand Up @@ -158,6 +160,7 @@ export default {
this.items = response.data;
});
},
fold: utils.fold,
},
mounted() {
axios
Expand Down
2 changes: 1 addition & 1 deletion src/components/layout/MainFooter/MainFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export default {
*/
copyright: {
type: String,
default: 'Copyright © 2021 zhenghaoz',
default: `Copyright © ${new Date().getFullYear()} zhenghaoz`,
},
/**
* Whether the footer should be wrapped in a container, or not.
Expand Down
78 changes: 23 additions & 55 deletions src/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,30 @@
const utils = {
parseLines(text, sep) {
const table = [];
let quoted = false;
let fields = [];
let cell = '';
const lines = text.split(/\r?\n/);
lines.forEach((line) => {
// start of line
if (quoted) {
cell += '\r\n';
fold(o) {
const that = this;
if (Array.isArray(o)) {
if (o.length > 5 && typeof o[0] === 'number') {
return `[${o.slice(0, 5).map(v => that.fold(v)).join(', ')}, ...]`;
}
// skip empty line
if (line.length === 0) {
return;
}
// parse line
for (let i = 0; i < line.length; i += 1) {
if (line[i] === sep && !quoted) {
// end of field
fields.push(cell);
cell = '';
} else if (line[i] === '"') {
if (quoted) {
if (i + 1 >= line.length || line[i + 1] !== '"') {
// end of quoted
quoted = false;
} else {
i += 1;
cell += '"';
}
} else {
// start of quoted
quoted = true;
}
} else {
cell += line[i];
}
}
// end of line
if (!quoted) {
fields.push(cell);
table.push(fields);
cell = '';
fields = [];
}
});
return table;
},
mapFields(data, placement) {
if (data.length !== placement.length) {
throw new Error('the length of data and placement must be equal');
return `[${o.map(v => that.fold(v)).join(', ')}]`;
} else if (typeof o === 'object') {
let out = '{';
out += Object.entries(o).map(([key, value]) => `"${key}": ${that.fold(value)}`).join(', ');
out += '}';
return out;
}
const length = Math.max.apply(null, placement);
const mapping = new Array(length).fill('_');
for (let i = 0; i < placement.length; i += 1) {
mapping[placement[i]] = data[i];
return JSON.stringify(o);
},
stringify(o) {
const that = this;
if (Array.isArray(o)) {
return `[${o.map(v => that.fold(v)).join(', ')}]`;
} else if (typeof o === 'object') {
let out = '{\n';
out += Object.entries(o).map(([key, value]) => ` "${key}": ${that.stringify(value)}`).join(',\n');
out += '\n}';
return out;
}
return mapping.join('');
return JSON.stringify(o);
},
};

Expand Down
7 changes: 5 additions & 2 deletions src/views/ItemNeighbors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</d-col>
<d-col sm="12" md="10">
<div>
<highlightjs language='json' :code="JSON.stringify(current_item.Labels, null, 2)" />
<highlightjs language='json' :code="stringify(current_item.Labels)" />
</div>
</d-col>
</d-row>
Expand Down Expand Up @@ -117,7 +117,7 @@
<td>{{ format_date_time(item.Timestamp) }}</td>
<td>
<span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif">
{{ item.Labels }}
{{ fold(item.Labels) }}
</span>
</td>
<td>{{ item.Comment }}</td>
Expand All @@ -134,6 +134,7 @@

<script>
import moment from 'moment';
import utils from '../utils';
const axios = require('axios');
Expand Down Expand Up @@ -180,6 +181,8 @@ export default {
this.items = response.data;
});
},
fold: utils.fold,
stringify: utils.stringify,
},
};
</script>
4 changes: 3 additions & 1 deletion src/views/Items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<td>{{ format_date_time(item.Timestamp) }}</td>
<td>
<span style="font-family: Consolas, Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, monospace, serif">
{{ item.Labels }}
{{ fold(item.Labels) }}
</span>
</td>
<td>{{ item.Comment }}</td>
Expand Down Expand Up @@ -110,6 +110,7 @@

<script>
import moment from 'moment';
import utils from '../utils';
const axios = require('axios');
Expand Down Expand Up @@ -196,6 +197,7 @@ export default {
}
});
},
fold: utils.fold,
},
};
</script>

0 comments on commit aa5bf7e

Please sign in to comment.