Skip to content

Commit

Permalink
Entity Linker args, readme, license, fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ensaremirerol committed Apr 14, 2024
1 parent 8bde487 commit cba2b60
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 40 deletions.
18 changes: 18 additions & 0 deletions LICENSE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright 2024 Ensar Emir EROL

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
44 changes: 44 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# aidava-openrefine-tagger

This is a simple OpenRefine extension that allows you to tag columns with dummy operations.
It is useful when you want to keep extra information in operation history for other applications.

## How to install

Download the latest release from the [releases page](https://github.com/AIDAVA-DEV/aidava-openrefine-tagger/releases)
and extract it to the `extensions` folder of your OpenRefine installation.

**Note:** module folder should be in the following path: `extensions/aidava-openrefine-tagger/module`. Do not directly
copy `module` folder to `extensions` folder. It should be in `aidava-openrefine-tagger` folder.

## How to use

After installing the extension, you will see a new option in the column menu called `Tag Column for ...`.

(1) Click the arrow on the column header to open the column menu.
(2) Go into the `Edit column` submenu.
(3) Click on `Tag Column for ...`.
(4) Select required arguments for the operation.
(5) Click `Tag` button.

## Current Tags

```json
[
{
"op": "aidava-tagger/tag-nlp-operation",
"columnName": "SUBTYPE",
"modelName": "model1",
"index": 2,
"description": "NLPTaggerOperation on SUBTYPE with model model1"
},
{
"op": "aidava-tagger/tag-entity-linking-operation",
"columnName": "SUBTYPE_NAME",
"language": "en",
"terminology": "snomed",
"index": 3,
"description": "EntityLinkingTaggerOperation on SUBTYPE_NAME with language en and terminology snomed"
}
]
```
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ protected AbstractOperation createOperation(Project project, HttpServletRequest
final String columnName = httpServletRequest.getParameter("column");
final Column column = project.columnModel.getColumnByName(columnName);

final String modelName = httpServletRequest.getParameter("model");
final String language = httpServletRequest.getParameter("language");
if (language == null) {
throw new Exception("Missing language parameter");
}
final String terminology = httpServletRequest.getParameter("terminology");

if (column == null) {
throw new Exception("Invalid column name: " + columnName);
}

return new EntityLinkingTaggerOperation(
column.getName(),
modelName,
language,
terminology,
column.getCellIndex()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
public class EntityLinkingTaggerOperation extends ColumnMoveOperation {
private final String language;

private final String terminology;

public EntityLinkingTaggerOperation(
@JsonProperty("columnName")
String columnName,
@JsonProperty("language")
String language,
@JsonProperty("terminology")
String terminology,
@JsonProperty("index")
int index
) {
super(columnName, index);
this.language = language;
this.terminology = terminology;
}


Expand All @@ -25,8 +30,13 @@ public String getLanguage() {
return language;
}

@JsonProperty("terminology")
public String getTerminology() {
return terminology;
}

@Override
protected String getBriefDescription(Project project) {
return "EntityLinkingTaggerOperation on " + getColumnName() + " with language " + language;
return "EntityLinkingTaggerOperation on " + getColumnName() + " with language " + language + " and terminology " + terminology;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
<p>
Select the Language that is used in the column.
</p>
<ol bind="el-langs"></ol>
<ol bind="el-langs" class="language"></ol>
</fieldset>
<br/>
<fieldset>
<p>
Select the Target Terminology for the column.
</p>
<ol bind="el-terminologies" class="terminology"></ol>
</fieldset>
</div>
<div class="dialog-footer">
Expand Down
81 changes: 45 additions & 36 deletions src/main/resources/module/dialogs/entity-linking-tagger-dialog.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,27 @@
// <div className="dialog-frame aidava-tagger">
// <div className="dialog-header">
// Tag column named "<span className="tagger-column-name">column</span>" for Entity Linking Workflow
// <div class="dialog-frame aidava-tagger">
// <div class="dialog-header">
// Tag column named "<span class="tagger-column-name">column</span>" for Entity Linking Workflow
// </div>
// <div className="dialog-body">
// <div class="dialog-body">
// <fieldset>
// <p>
// Select the Language that is used in the column.
// </p>
// <ol bind="el-langs"></ol>
// <ol bind="el-langs" class="language"></ol>
// </fieldset>
// </div>
// <div className="dialog-footer">
// <button bind="cancel" className="button">Cancel</button>
// <button bind="tag" className="button default" disabled>Tag</button>
// </div>
// </div>

//
// JS File for Tagger Dialog
// HTML: src/main/resources/module/dialogs/nlp-tagger-dialog.html
// <div class="dialog-frame">
// <div class="dialog-header">
// Tag column named "<span class="tagger-column-name">column</span>" for NLP Workflow
// </div>
// <div class="dialog-body">
// <br/>
// <fieldset>
// <p>
// Select the NLP model that needs to be used for this column.
// Select the Target Terminology for the column.
// </p>
// <ol bind="nlp-models"></ol>
// <ol bind="el-terminologies" class="terminology"></ol>
// </fieldset>
// </div>
// <div class="dialog-footer">
// <button class="button" bind="cancel">Cancel</button>
// <button class="button default" bind="tag">Tag</button>
// <button bind="cancel" class="button">Cancel</button>
// <button bind="tag" class="button default" disabled>Tag</button>
// </div>
// </div>
//


function EntityLinkingTaggerDialog(column) {
this.column = column;
Expand All @@ -46,15 +30,16 @@ function EntityLinkingTaggerDialog(column) {
EntityLinkingTaggerDialog.prototype = {
init: function (callback) {
let self = this,
selectedModel = null,
selectedLanguage = null,
selectedTerminology = null,
dialogElement = this.dialogElement = $(DOM.loadHTML("aidava-tagger", "dialogs/entity-linking-tagger-dialog.html"));
// Populate labels
$(".tagger-column-name", dialogElement).text(this.column.name);
// Bind controls
let controls = DOM.bind(dialogElement);
controls.cancel.click(this.bound("hide"));
controls.tag.click(() => {
self.tag(selectedModel);
self.tag(selectedLanguage, selectedTerminology);
});

// Load NLP models
Expand All @@ -64,14 +49,35 @@ EntityLinkingTaggerDialog.prototype = {
{name: "Estonian", value: "et"}
];

let modelList = $("ol", dialogElement);
let terminologies = [
{name: "Snomed CT", value: "snomed"},
{name: "ICD-10", value: "icd10"},
{name: "LOINC", value: "loinc"}
];

let langList = $("ol.language", dialogElement);
let terminologyList = $("ol.terminology", dialogElement);

langs.forEach((model) => {
let li = $("<li></li>").appendTo(modelList);
let radio = $('<input type="radio" name="nlp-model" value="' + model.value + '">').appendTo(li);
let li = $("<li></li>").appendTo(langList);
let radio = $('<input type="radio" name="language" value="' + model.value + '">').appendTo(li);
radio.click(() => {
selectedLanguage = model.value;
if (selectedTerminology) {
controls.tag.prop("disabled", false);
}
});
$('<label>' + model.name + '</label>').appendTo(li);
});

terminologies.forEach((model) => {
let li = $("<li></li>").appendTo(terminologyList);
let radio = $('<input type="radio" name="terminology" value="' + model.value + '">').appendTo(li);
radio.click(() => {
selectedModel = model.value;
controls.tag.prop("disabled", false);
selectedTerminology = model.value;
if (selectedLanguage) {
controls.tag.prop("disabled", false);
}
});
$('<label>' + model.name + '</label>').appendTo(li);
});
Expand All @@ -80,12 +86,15 @@ EntityLinkingTaggerDialog.prototype = {
}
},

tag: function (model) {
tag: function (
language,
terminology
) {
// Tag the column with the selected model
console.log("Tagging column", this.column.name, "with model", model);
let data = {
column: this.column.name,
model: model
language: language,
terminology: terminology
}
Refine.postProcess("aidava-tagger", "tag-entity-linking", data, {}, {rowsChanged: false, modelsChanged: false});
this.hide();
Expand Down

0 comments on commit cba2b60

Please sign in to comment.