Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
const fs = require('fs');
const SEARCH_CLASS = 'http://yago-knowledge.org/resource/wikicat_Towns_in_Baden-Württemberg';
const FILE = './KPClasses-Yago2-22.txt';
let weights = [];
function func(line) {
if (line.indexOf(SEARCH_CLASS) === 0) {
weights.push(parseFloat(line.substr(SEARCH_CLASS.length).replace(',', '.')));
}
}
function end() {
let max = 0;
let index = -1;
for (let i = 0; i < weights.length; i++) {
if (weights[i] > max) {
max = weights[i];
index = i + 1;
}
}
console.log('Total # found:', weights.length);
console.log('Max:', max);
console.log('Cluster:', index);
}
let input = fs.createReadStream(FILE);
readLines(input, func, end);
function readLines(input, func, end) {
let remaining = '';
input.on('data', data => {
remaining += data;
let index = remaining.indexOf('\n');
let last = 0;
while (index > -1) {
let line = remaining.substring(last, index);
last = index + 1;
func(line);
index = remaining.indexOf('\n', last);
}
remaining = remaining.substring(last);
});
input.on('end', end);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.