Skip to content

Commit

Permalink
feat (report/bilou): multiple categories
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Jan 19, 2024
1 parent 5bed458 commit 5f35fee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/adonisjs/public/report/annotations/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@
<dcc-rest id="harena-room-load-case" bind="harena-room-load-case"
subscribe="case/source/get"></dcc-rest>
<dcc-button label="Export Analysis" xstyle="in" topic="report/download"></dcc-button>
<dcc-button label="Export BILOU" xstyle="in" topic="report/bilou"></dcc-button>
<dcc-button label="Export BILOU Single" xstyle="in" topic="report/bilou/single"></dcc-button>
<dcc-button label="Export BILOU Multiple" xstyle="in" topic="report/bilou/multiple"></dcc-button>
<dcc-button label="Export JSON" xstyle="in" topic="report/json"></dcc-button>
</div>

Expand Down
50 changes: 37 additions & 13 deletions src/adonisjs/public/report/js/report-annotations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
class ReportManager {
start () {
MessageBus.i.subscribe('report/download', this._downloadAnalysis.bind(this))
MessageBus.i.subscribe('report/bilou', this._downloadBILOU.bind(this))
MessageBus.i.subscribe('report/bilou/single', this._downloadBILOU.bind(this))
MessageBus.i.subscribe('report/bilou/multiple', this._downloadBILOU.bind(this))
MessageBus.i.subscribe('report/json', this._downloadJSON.bind(this))
this._roomId = new URL(document.location).searchParams.get('roomid')
}
Expand Down Expand Up @@ -196,21 +197,25 @@ class ReportManager {
* Export BILOU
*/

async _buildBILOU (caseId, annotations) {
async _buildBILOU (caseId, annotations, multiple) {
console.log('=== multiple')
console.log(multiple)
const tt = await this._tokenize(caseId)
const tokens = tt.tokens
let tokens = tt.tokens
const extraTokens = []

const ranges = []
for (const an of annotations) {
// find a proper category
let cat = null
// gather proper categories
let cat = []
for (const c of an.categories)
if (ReportManager.catList.includes(c)) {
cat = c
break
}
if (ReportManager.catList.includes(c))
cat.push(c)

if (cat != null) {
console.log('=== cat')
console.log(cat)

if (cat.length >0) {
if (!this._rangeConflict(ranges, an.fragments)) {
this._addRanges(ranges, an.fragments)
for (let f = 0; f < an.fragments.length; f++) {
Expand All @@ -228,7 +233,14 @@ class ReportManager {
: ((f+1 < an.fragments.length) || (tk[2] < an.fragments[f].last))
? 'I'
: 'L')
tk[4] = cat
tk[4] = cat[0]
if (multiple && cat.length > 1) {
for (let c = 1; c < cat.length; c++) {
const tk2 = tk.slice()
tk2[4] = cat[c]
extraTokens.push(tk2)
}
}
if (firstMatch)
firstToken = tk
else if (firstToken != -1) {
Expand All @@ -249,6 +261,15 @@ class ReportManager {
}
}

console.log('=== extraTokens')
console.log(extraTokens)

// reorganize tokens by position
if (multiple) {
tokens = tokens.concat(extraTokens)
tokens = tokens.sort((a, b) => a[1] - b[1])
}

console.log('=== tokens NER')
console.log(tokens)

Expand Down Expand Up @@ -340,7 +361,9 @@ class ReportManager {
ranges.push([f.start, f.start + f.size - 1])
}

async _downloadBILOU () {
async _downloadBILOU (topic, message) {
const multiple = (topic == 'report/bilou/multiple')

const tprefix = document.querySelector('#tprefix').value

const cases = await this._requestCases()
Expand All @@ -350,7 +373,8 @@ class ReportManager {
if (cases != null) {
for (const c of cases.message) {
const ant = await this._loadAnnotations(c.id)
const bilou = await this._buildBILOU(c.id, ant.annotations)
const bilou =
await this._buildBILOU(c.id, ant.annotations, multiple)
table += JSON.stringify(bilou) + '\n'
}

Expand Down

0 comments on commit 5f35fee

Please sign in to comment.