-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
77 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import path from 'path' | ||
import { CorpusArchive } from '../src/corpus/archive/corpusArchive' | ||
import { extractContentUsingMozillaReadability } from '../src/corpus/doc/contentExtractor' | ||
import { createCorpusIndex } from '../src/corpus/index/corpusIndex' | ||
|
||
function usage(): void { | ||
console.error() | ||
console.error(`Usage: ${path.basename(process.argv[1])} < /path/to/archive.json`) | ||
console.error() | ||
console.error('Note: Use the `create-archive` script to create the archive.json file.') | ||
process.exit(1) | ||
} | ||
|
||
const args = process.argv.slice(2) | ||
if (args.length !== 0) { | ||
console.error('Error: invalid arguments') | ||
usage() | ||
} | ||
|
||
const archive: CorpusArchive = await readJSONFromStdin() | ||
console.error(`# Indexing archive: ${archive.docs.length} docs, content ID ${archive.contentID}`) | ||
|
||
const index = await createCorpusIndex(archive, { contentExtractor: extractContentUsingMozillaReadability }) | ||
|
||
function readJSONFromStdin(): Promise<any> { | ||
return new Promise((resolve, reject) => { | ||
const data: string[] = [] | ||
process.stdin.on('data', chunk => { | ||
data.push(chunk.toString('utf8')) | ||
}) | ||
process.stdin.once('end', () => { | ||
try { | ||
const json = JSON.parse(data.join('')) | ||
resolve(json) | ||
} catch (error) { | ||
reject(error) | ||
} | ||
}) | ||
process.stdin.once('error', error => { | ||
reject(error) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { describe, expect, test } from 'vitest' | ||
import { createCorpusArchive } from '../archive/corpusArchive' | ||
import { type Doc, type DocID } from '../doc/doc' | ||
import { indexCorpus } from './corpusIndex' | ||
import { createCorpusIndex } from './corpusIndex' | ||
|
||
export function doc(id: DocID, text: string): Doc { | ||
return { id, text } | ||
} | ||
|
||
describe('indexCorpus', () => { | ||
test('#docs', async () => { | ||
expect((await indexCorpus(await createCorpusArchive([doc(1, 'a'), doc(2, 'b')]))).docs.length).toBe(2) | ||
expect((await createCorpusIndex(await createCorpusArchive([doc(1, 'a'), doc(2, 'b')]))).docs.length).toBe(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters