Datasets:

Modalities:
Image
Text
Formats:
parquet
Languages:
Danish
ArXiv:
DOI:
Libraries:
Datasets
Dask
License:
File size: 1,304 Bytes
4781621
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// wtf_bridge.js
// Usage: node wtf_bridge.js
// Reads newline-delimited JSON from stdin: {"wikitext":"...","lang":"da"}
// Writes newline-delimited JSON to stdout: {"text":"...","isRedirect":false} or {"error":"..."}
const wtf = require('wtf_wikipedia');
const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});

process.on('uncaughtException', (err) => {
  // emit as JSON so Python can see it
  try {
    process.stdout.write(JSON.stringify({ error: String(err && err.stack || err) }) + '\n');
  } catch (e) {}
  process.exit(1);
});

rl.on('line', (line) => {
  (async () => {
    try {
      const payload = JSON.parse(line);
      const wikitext = payload.wikitext || '';
      const lang = payload.lang || null;

      // parse wikitext into a document (sync)
      const doc = lang ? wtf(wikitext, lang) : wtf(wikitext);
      const text = (doc && typeof doc.text === 'function') ? doc.text() : '';
      const isRedirect = (doc && typeof doc.isRedirect === 'function') ? doc.isRedirect() : false;

      process.stdout.write(JSON.stringify({ text, isRedirect }) + '\n');
    } catch (err) {
      process.stdout.write(JSON.stringify({ error: String(err && err.stack || err) }) + '\n');
    }
  })();
});