Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
'use strict';
const fs = require('fs');
const FILE1 = './dbr_Karlsruhe_properties.txt';
const FILE2 = './KPProperties-DBpedia39-22.txt';
const CLUSTER = 1;
let properties = {};
let result = [];
let input1 = fs.createReadStream(FILE1);
let input2 = fs.createReadStream(FILE2);
readLines(input1, line => {
properties[line.replace(/"/g, '')] = true;
}, () => {
let currentCluster = 0;
readLines(input2, line => {
if (line.indexOf('Cluster') === 0) currentCluster = parseInt(line.replace(/:/, '').replace(/ /, '').replace(/Cluster/, ''));
let prop = line.substr(1, line.indexOf('>') - 1);
if (properties[prop] && currentCluster == CLUSTER) result.push(line);
}, () => {
console.log(`${result.length} properties in common.`);
fs.writeFileSync('result.txt', result);
});
});
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.