-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
46 lines (41 loc) · 1.2 KB
/
index.ts
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
40
41
42
43
44
45
46
import { window, OverviewItemLoadEvent, IResource, utility } from 'civet'
class Segmentor {
private _segment: any;
#POSTAG: any;
constructor() {
const Segment = require('segment')
this.#POSTAG = Segment.POSTAG
this._segment = new Segment()
this._segment.useDefault()
}
parse(text: string) {
return this._segment.doSegment(text)
}
}
let webContentView = window.createContentView('webContentView',
['html']);
webContentView.onViewInitialize(():string => {
const fs = require('fs')
const html = fs.readFileSync(utility.extensionPath + '/web/content.html', 'utf-8')
return html
});
export function activate() {
const jsDom = require('jsdom')
const { JSDOM } = jsDom
const segment = new Segmentor()
return {
read: async (filepath: string, resource: IResource) => {
const fs = require('fs')
const html = fs.readFileSync(filepath, 'utf-8')
// console.debug('read html:', html)
const dom = new JSDOM(html)
let text = dom.window.document.body.textContent.replace(/\s+/g, '')
console.debug('html view:', text)
const words = segment.parse(text)
if (words.length) {
resource.keyword = words
}
return
}
}
}