Skip to content

Commit

Permalink
Update to backbone v3.0.0 api
Browse files Browse the repository at this point in the history
  • Loading branch information
qqndrew committed Mar 9, 2023
1 parent cc9f881 commit 093efe1
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 25 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.ohnlp.medtagger</groupId>
<artifactId>medtagger</artifactId>
<version>1.0.55</version>
<version>1.0.56</version>
<description>The MedTagger biomedical information extraction pipeline</description>


Expand Down Expand Up @@ -141,7 +141,7 @@
<properties>
<uimaj.version>2.10.0</uimaj.version>
<uimafit.version>2.5.0</uimafit.version>
<backbone.version>2.0.0</backbone.version>
<backbone.version>3.0.0</backbone.version>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package org.ohnlp.medtagger.backbone;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.apache.beam.sdk.schemas.Schema;
import org.apache.beam.sdk.transforms.DoFn;
import org.apache.beam.sdk.transforms.ParDo;
Expand All @@ -24,7 +21,9 @@
import org.apache.uima.util.CasCreationUtils;
import org.apache.uima.util.InvalidXMLException;
import org.joda.time.Instant;
import org.ohnlp.backbone.api.Transform;
import org.ohnlp.backbone.api.annotations.ComponentDescription;
import org.ohnlp.backbone.api.annotations.ConfigurationProperty;
import org.ohnlp.backbone.api.components.OneToOneTransform;
import org.ohnlp.backbone.api.exceptions.ComponentInitializationException;
import org.ohnlp.medtagger.context.RuleContextAnnotator;
import org.ohnlp.medtagger.type.ConceptMention;
Expand All @@ -48,25 +47,54 @@
/**
* An implementation of a MedTagger pipeline as an OHNLP Backbone Transform component
*/
public class MedTaggerBackboneTransform extends Transform {
@ComponentDescription(
name = "MedTagger NLP",
desc = "Executes a MedTagger IE or Dictionary-Based Ruleset as a Backbone Component"
)
public class MedTaggerBackboneTransform extends OneToOneTransform {

@ConfigurationProperty(
path = "input",
desc = "Column to use as input"
)
private String inputField;

@ConfigurationProperty(
path = "mode",
desc = "Whether to use IE or dictionary-based rulesets, or both, or retrieve from web. Defaults to STANDALONE_IE_ONLY",
required = false
)
private RunMode mode = RunMode.STANDALONE_IE_ONLY;
@ConfigurationProperty(
path = "ruleset",
desc = "The ruleset definition as located within the resources folder, or the dictionary name, " +
"or resources folder|dictionary name if both, or URL if in web mode"
)
private String resources;
private RunMode mode;
private String noteIdField;
@ConfigurationProperty(
path = "identifier_col",
desc = "The column to use as a note identifier. Defaults to note_id",
required = false
)
private String noteIdField = "note_id";
private Schema outputSchema;
private boolean outputJSON;

@Override
public void initFromConfig(JsonNode config) throws ComponentInitializationException {
try {
this.inputField = config.get("input").asText();
this.mode = config.has("mode") ? RunMode.valueOf(config.get("mode").textValue().toUpperCase(Locale.ROOT)) : RunMode.STANDALONE;
this.resources = config.get("ruleset").asText();
this.noteIdField = config.has("identifier_col") ? config.get("identifier_col").asText() : "note_id";
} catch (Throwable t) {
throw new ComponentInitializationException(t);
}
public void init() throws ComponentInitializationException {
}

@Override
public boolean hasRequiredColumns() {
return true;
}

@Override
public Schema getRequiredColumns() {
return Schema.of(
Schema.Field.of(this.noteIdField, Schema.FieldType.STRING),
Schema.Field.of(this.inputField, Schema.FieldType.STRING)
);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import org.apache.beam.sdk.values.Row;
import org.joda.time.Instant;
import org.ohnlp.backbone.api.Transform;
import org.ohnlp.backbone.api.annotations.ComponentDescription;
import org.ohnlp.backbone.api.annotations.ConfigurationProperty;
import org.ohnlp.backbone.api.components.OneToOneTransform;
import org.ohnlp.backbone.api.exceptions.ComponentInitializationException;

import java.io.BufferedReader;
Expand All @@ -27,17 +30,21 @@
* <p>
* Note: Assumes that rulesets supply a concept normalization -> OHDSI concept id mapping in ohdsi_mappings.txt
*/
public class MedTaggerOutputToOHDSIFormatTransform extends Transform {
@ComponentDescription(
name = "MedTagger to OHDSI CDM Format Transform",
desc = "Converts MedTagger Output into one complaint with the OHDSI OMOP CDM note_nlp table",
requires = {"org.ohnlp.medtagger.backbone.MedTaggerBackboneTransform"}
)
public class MedTaggerOutputToOHDSIFormatTransform extends OneToOneTransform {
private static ThreadLocal<SimpleDateFormat> sdf = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ssXXX"));

@ConfigurationProperty(
path = "ruleset",
desc = "The ruleset folder containing a ohdsi_mappings.txt to map output concepts to OHDSI Athena concept codes, or NONE if output already in Athena concept code format"
)
private String resources;
private Schema schema;


@Override
public void initFromConfig(JsonNode config) throws ComponentInitializationException {
this.resources = config.get("ruleset").asText();
}

@Override
public Schema calculateOutputSchema(Schema schema) {
List<Schema.Field> fields = new LinkedList<>(schema.getFields());
Expand Down Expand Up @@ -144,4 +151,8 @@ public void processElement(@Element Row input, OutputReceiver<Row> output) throw
}


@Override
public void init() throws ComponentInitializationException {

}
}

0 comments on commit 093efe1

Please sign in to comment.