You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by se...@apache.org on 2026/01/21 22:55:43 UTC
(ctakes) branch main updated: JavaDocs
This is an automated email from the ASF dual-hosted git repository.
seanfinan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ctakes.git
The following commit(s) were added to refs/heads/main by this push:
new 1775845 JavaDocs
1775845 is described below
commit 1775845c5ce7b5f4a83b3d55027509ba7367c3ba
Author: Sean Finan <se...@childrens.harvard.edu>
AuthorDate: Wed Jan 21 17:55:26 2026 -0500
JavaDocs
---
.../util/annotation/EssentialAnnotationUtil.java | 126 ++++++++++----
.../ctakes/core/util/annotation/SemanticGroup.java | 53 ++++++
.../ctakes/core/util/annotation/SemanticTui.java | 189 +++++++++++++++++++++
.../apache/ctakes/core/util/doc/JCasBuilder.java | 111 +++++++++++-
.../ctakes/core/util/log/FinishedLogger.java | 44 +++--
.../ctakes/core/util/regex/ThreadString.java | 15 ++
6 files changed, 489 insertions(+), 49 deletions(-)
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/EssentialAnnotationUtil.java b/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/EssentialAnnotationUtil.java
index c20d10f..ca1c0bc 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/EssentialAnnotationUtil.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/EssentialAnnotationUtil.java
@@ -22,6 +22,7 @@ import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
+ * Utility to fetch integrated, coordinated collections of entities, events, and coreferences in a CAS.
* @author SPF , chip-nlp
* @version %I%
* @since 12/29/2017
@@ -40,13 +41,22 @@ final public class EssentialAnnotationUtil {
|| TimeMention.class.isInstance( a )
|| EntityMention.class.isInstance( a );
+ /**
+ * From a collection of annotations, get the events, times, and entities.
+ * @param annotations all IdentifiedAnnotations, regardless of type.
+ * @return Collection of EventMentions, TimeMentions, and EntityMentions.
+ */
static private Collection<IdentifiedAnnotation> getEssentialAnnotations(
final Collection<IdentifiedAnnotation> annotations ) {
return annotations.stream()
.filter( ESSENTIALS )
- .collect( Collectors.toList() );
+ .toList();
}
+ /**
+ * From multiple collections of annotations, remove everything that isn't an event, time, or entity.
+ * @param annotationCollections all IdentifiedAnnotations, regardless of type.
+ */
static private void cullToEssentialAnnotations(
final Collection<Collection<IdentifiedAnnotation>> annotationCollections ) {
final Collection<IdentifiedAnnotation> keepers = new HashSet<>();
@@ -59,27 +69,52 @@ final public class EssentialAnnotationUtil {
}
}
+ /**
+ * From a collection of annotations, get everything that is not in the collection of essential annotations.
+ * @param allAnnotations all IdentifiedAnnotations, regardless of type.
+ * @param unwantedAnnotations unwanted annotations.
+ * @return Collection of EventMentions, TimeMentions, and EntityMentions.
+ */
static private Collection<IdentifiedAnnotation> getNonEssentialAnnotations(
final Collection<IdentifiedAnnotation> allAnnotations,
- final Collection<IdentifiedAnnotation> essentialAnnotations ) {
+ final Collection<IdentifiedAnnotation> unwantedAnnotations ) {
return allAnnotations.stream()
- .filter( a -> !essentialAnnotations.contains( a ) )
+ .filter( a -> !unwantedAnnotations.contains( a ) )
.filter( a -> !Markable.class.isInstance( a ) )
- .collect( Collectors.toList() );
+ .toList();
}
-
+ /**
+ * To allow fulfilled relations and coreference chains, we need essential annotations and related non-essential annotations.
+ * @param jCas ye olde ...
+ * @param corefIndexed map of identified annotations to coreference chains containing them.
+ * @return all events, times, and entities, plus annotations that are required for coreferences and relations.
+ */
static public Collection<IdentifiedAnnotation> getRequiredAnnotations( final JCas jCas,
final Map<IdentifiedAnnotation, Collection<Integer>> corefIndexed ) {
return getRequiredAnnotations( jCas, JCasUtil.select( jCas, IdentifiedAnnotation.class ), corefIndexed );
}
+ /**
+ * To allow fulfilled relations and coreference chains, we need essential annotations and related non-essential annotations.
+ * @param jCas ye olds ...
+ * @param allAnnotations all IdentifiedAnnotations, regardless of type.
+ * @param corefIndexed map of identified annotations to coreference chains containing them.
+ * @return all events, times, and entities, plus annotations that are required for coreferences and relations.
+ */
static public Collection<IdentifiedAnnotation> getRequiredAnnotations( final JCas jCas,
final Collection<IdentifiedAnnotation> allAnnotations,
final Map<IdentifiedAnnotation, Collection<Integer>> corefIndexed ) {
return getRequiredAnnotations( allAnnotations, corefIndexed, JCasUtil.select( jCas, BinaryTextRelation.class ) );
}
+ /**
+ * To allow fulfilled relations and coreference chains, we need essential annotations and related non-essential annotations.
+ * @param allAnnotations all IdentifiedAnnotations, regardless of type.
+ * @param corefIndexed map of identified annotations to coreference chains containing them.
+ * @param relations relations between annotations.
+ * @return all events, times, and entities, plus annotations that are required for coreferences and relations.
+ */
static public Collection<IdentifiedAnnotation> getRequiredAnnotations(
final Collection<IdentifiedAnnotation> allAnnotations,
final Map<IdentifiedAnnotation, Collection<Integer>> corefIndexed,
@@ -94,7 +129,7 @@ final public class EssentialAnnotationUtil {
/**
* @param jCas ye olde ...
- * @return a map of markables to indexed chain numbers
+ * @return a map of coreferent annotations to indexed chain numbers.
*/
static public Map<IdentifiedAnnotation, Collection<Integer>> createMarkableCorefs( final JCas jCas ) {
final Collection<CollectionTextRelation> corefs = JCasUtil.select( jCas, CollectionTextRelation.class );
@@ -103,8 +138,9 @@ final public class EssentialAnnotationUtil {
}
/**
- * @param corefs coreference chains
- * @return a map of markables to indexed chain numbers
+ * @param corefs coreference chains.
+ * @param markableAnnotations annotations that should be allowed in coreferences.
+ * @return a map of coreferent annotations to indexed chain numbers.
*/
static public Map<IdentifiedAnnotation, Collection<Integer>> createMarkableCorefs(
final Collection<CollectionTextRelation> corefs,
@@ -129,8 +165,11 @@ final public class EssentialAnnotationUtil {
}
/**
- * @param corefs coreference chains
- * @return a map of markables to indexed chain numbers
+ * Sometimes there will be two overlapping annotations, 1 affirmed 1 negated.
+ * Use this for matching assertions in coreference chains.
+ * @param corefs coreference chains.
+ * @param markableAnnotations annotations that should be allowed in coreferences.
+ * @return a map of annotations to indexed chain numbers, separated by assertion status.
*/
static public Map<IdentifiedAnnotation, Collection<Integer>> createMarkableAssertedCorefs(
final Collection<CollectionTextRelation> corefs,
@@ -138,7 +177,6 @@ final public class EssentialAnnotationUtil {
if ( corefs == null || corefs.isEmpty() ) {
return Collections.emptyMap();
}
-
final List<List<IdentifiedAnnotation>> chains = new ArrayList<>();
for ( CollectionTextRelation coref : corefs ) {
final Map<String, List<IdentifiedAnnotation>> assertionMap = new HashMap<>();
@@ -156,7 +194,7 @@ final public class EssentialAnnotationUtil {
}
}
}
- chains.sort( ( l1, l2 ) -> l1.get( 0 ).getBegin() - l2.get( 0 ).getBegin() );
+ chains.sort( Comparator.comparingInt( l -> l.get( 0 ).getBegin() ) );
final Map<IdentifiedAnnotation, Collection<Integer>> corefMarkables = new HashMap<>();
int index = 1;
@@ -172,9 +210,8 @@ final public class EssentialAnnotationUtil {
/**
* Sometimes there will be two overlapping annotations, 1 affirmed 1 negated.
* Use this for matching assertions in coreference chains.
- *
* @param jCas ye olde ...
- * @return a map of markables to indexed chain numbers
+ * @return a map of annotations to indexed chain numbers, separated by assertion status.
*/
static public Map<IdentifiedAnnotation, Collection<Integer>> createAllMarkableAssertedCorefs( final JCas jCas ) {
final Collection<CollectionTextRelation> corefs = JCasUtil.select( jCas, CollectionTextRelation.class );
@@ -184,8 +221,11 @@ final public class EssentialAnnotationUtil {
}
/**
- * @param corefs coreference chains
- * @return a map of markables to indexed chain numbers
+ * Sometimes there will be two overlapping annotations, 1 affirmed 1 negated.
+ * Use this for matching assertions in coreference chains.
+ * @param corefs coreference chains.
+ * @param markableAnnotations annotations that should be allowed in coreferences.
+ * @return a map of annotations to indexed chain numbers, separated by assertion status.
*/
static public Map<IdentifiedAnnotation, Collection<Integer>> createAllMarkableAssertedCorefs(
final Collection<CollectionTextRelation> corefs,
@@ -193,7 +233,6 @@ final public class EssentialAnnotationUtil {
if ( corefs == null || corefs.isEmpty() ) {
return Collections.emptyMap();
}
-
final List<List<IdentifiedAnnotation>> chains = new ArrayList<>();
for ( CollectionTextRelation coref : corefs ) {
final Map<String, List<IdentifiedAnnotation>> assertionMap = new HashMap<>();
@@ -212,8 +251,7 @@ final public class EssentialAnnotationUtil {
}
}
}
- chains.sort( ( l1, l2 ) -> l1.get( 0 ).getBegin() - l2.get( 0 ).getBegin() );
-
+ chains.sort( Comparator.comparingInt( l -> l.get( 0 ).getBegin() ) );
final Map<IdentifiedAnnotation, Collection<Integer>> corefMarkables = new HashMap<>();
int index = 1;
for ( Collection<IdentifiedAnnotation> chain : chains ) {
@@ -225,7 +263,10 @@ final public class EssentialAnnotationUtil {
return corefMarkables;
}
-
+ /**
+ * @param annotation -
+ * @return string of concatenated assertion values: AFFIRMED, NEGATED, UNCERTAIN, GENERIC, CONDITIONAL.
+ */
static private String getAssertion( final IdentifiedAnnotation annotation ) {
final StringBuilder sb = new StringBuilder();
if ( annotation.getPolarity() == CONST.NE_POLARITY_NEGATION_PRESENT ) {
@@ -246,11 +287,10 @@ final public class EssentialAnnotationUtil {
}
/**
- * This is a bit messy, but necessary.
- *
- * @param jCas -
- * @param corefs -
- * @return map of markable to identified annotation
+ * We can create a map of "best fit" single identified annotations for each coreference markable.
+ * @param jCas ye olde ...
+ * @param corefs collection of coref relations.
+ * @return map of each coref markable to an identified annotation.
*/
static private Map<Markable, IdentifiedAnnotation> mapMarkableAnnotations(
final JCas jCas, final Collection<CollectionTextRelation> corefs ) {
@@ -313,11 +353,10 @@ final public class EssentialAnnotationUtil {
}
/**
- * This is a bit messy, but necessary.
- *
- * @param jCas -
- * @param corefs -
- * @return map of markable to identified annotation
+ * We can create a map of multiple overlapping identified annotations for each coreference markable.
+ * @param jCas ye olde ...
+ * @param corefs collection of coref relations.
+ * @return map of each coref markable to an identified annotation.
*/
static public Map<Markable, Collection<IdentifiedAnnotation>> mapAllMarkableAnnotations(
final JCas jCas, final Collection<CollectionTextRelation> corefs ) {
@@ -405,6 +444,8 @@ final public class EssentialAnnotationUtil {
/**
* Finds the head node out of a few ConllDependencyNodes. Biased toward nouns.
+ * @param nodes dependency nodes.
+ * @return best head node.
**/
static public ConllDependencyNode getNominalHeadNode( final List<ConllDependencyNode> nodes ) {
final ArrayList<ConllDependencyNode> anodes = new ArrayList<>( nodes );
@@ -477,7 +518,10 @@ final public class EssentialAnnotationUtil {
}
}
-
+ /**
+ * @param relations -
+ * @return all annotations in relations.
+ */
static public Collection<IdentifiedAnnotation> getRelationAnnotations(
final Collection<BinaryTextRelation> relations ) {
final Collection<IdentifiedAnnotation> relationAnnotations = new HashSet<>();
@@ -489,7 +533,7 @@ final public class EssentialAnnotationUtil {
if ( source instanceof IdentifiedAnnotation ) {
sourceIA = (IdentifiedAnnotation)source;
} else {
- LOGGER.error( "Relation source is not an IdentifiedAnnotation " + source.getCoveredText() );
+ LOGGER.error( "Relation source is not an IdentifiedAnnotation {}", source.getCoveredText() );
continue;
}
final RelationArgument arg2 = relation.getArg2();
@@ -497,7 +541,7 @@ final public class EssentialAnnotationUtil {
if ( target instanceof IdentifiedAnnotation ) {
targetIA = (IdentifiedAnnotation)target;
} else {
- LOGGER.error( "Relation target is not an IdentifiedAnnotation " + source.getCoveredText() );
+ LOGGER.error( "Relation target is not an IdentifiedAnnotation {}", source.getCoveredText() );
continue;
}
relationAnnotations.add( sourceIA );
@@ -507,7 +551,10 @@ final public class EssentialAnnotationUtil {
}
- // The assumption is that any given span can only have one exact EventMention.
+ /**
+ * @param annotations all IdentifiedAnnotations, regardless of type.
+ * @return collection of events in the annotations.
+ */
static private Collection<IdentifiedAnnotation> getEventMentions(
final Collection<IdentifiedAnnotation> annotations ) {
return annotations.stream()
@@ -516,8 +563,8 @@ final public class EssentialAnnotationUtil {
}
/**
- * @param annotationMap -
- * @return map of umls annotations to events
+ * @param annotationMap map of TextSpans for IdentifiedAnnotations with those text spans.
+ * @return map of annotations to events.
*/
static private Map<IdentifiedAnnotation, Collection<IdentifiedAnnotation>> getAnnotationEvents(
final Map<TextSpan, Collection<IdentifiedAnnotation>> annotationMap ) {
@@ -575,12 +622,17 @@ final public class EssentialAnnotationUtil {
.filter( e -> e.getValue()
.isEmpty() )
.map( Map.Entry::getKey )
- .collect( Collectors.toList() );
+ .toList();
annotationMap.keySet()
.removeAll( emptySpans );
return annotationEvents;
}
+ /**
+ * There may be multiple sections with the same preferred name. We want unique names for each section.
+ * @param section -
+ * @return Section Name + section ID or section ID or section Name or "Unknown Section".
+ */
static private String createSectionName( final Segment section ) {
final String sectionPref = section.getPreferredText();
final String sectionId = section.getId();
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticGroup.java b/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticGroup.java
index bd186a3..f6be136 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticGroup.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticGroup.java
@@ -12,6 +12,11 @@ import java.util.stream.Collectors;
import static org.apache.ctakes.typesystem.type.constants.CONST.*;
+/**
+ * The major UMLS-related semantic groups as decided at the inception of cTAKES.
+ * The major 5 groups are: Medication, Disease/Disorder, Sign/Symptom, Procedure, Anatomical Site.
+ * Minor groups are: Clinical Attribute, Device, Lab, Phenomenon, Subject, Person Title, Event, Entity, Time, Modifier, Lab Modifier, and Unknown.
+ */
public enum SemanticGroup {
DRUG( NE_TYPE_ID_DRUG, "Drug", "Medication", MedicationMention.class, MedicationMention::new ),
DISORDER( NE_TYPE_ID_DISORDER, "Disorder", "Disease/Disorder", DiseaseDisorderMention.class, DiseaseDisorderMention::new ),
@@ -48,26 +53,45 @@ public enum SemanticGroup {
_creator = creator;
}
+ /**
+ * @return internal cTAKES CONST code for group. These were old constants that shouldn't be used.
+ */
public int getCode() {
return _code;
}
+ /**
+ * @return Short name for the group. e.g. "Disease" or "Drug".
+ */
public String getName() {
return _name;
}
+ /**
+ * @return Long name for the group. e.g. "Disease/Disorder" or "Medication".
+ */
public String getLongName() {
return _longName;
}
+ /**
+ * @return the cTAKES java / type system class that represents the group.
+ */
public Class<? extends IdentifiedAnnotation> getCtakesClass() {
return _clazz;
}
+ /**
+ * @return A function that can create the java / type system class that represents the group.
+ */
public Function<JCas, ? extends IdentifiedAnnotation> getCreator() {
return _creator;
}
+ /**
+ * @param code internal cTAKES CONST code for a group. These were old constants that shouldn't be used.
+ * @return the group with the given code.
+ */
static public SemanticGroup getGroup( final int code ) {
return Arrays.stream( values() )
.filter( g -> g._code == code )
@@ -75,6 +99,10 @@ public enum SemanticGroup {
.orElse( UNKNOWN );
}
+ /**
+ * @param name -short- name for a group.
+ * @return the group with the given -short- name.
+ */
static public SemanticGroup getGroup( final String name ) {
return Arrays.stream( values() )
.filter( g -> g._name.equals( name ) )
@@ -82,6 +110,10 @@ public enum SemanticGroup {
.orElse( UNKNOWN );
}
+ /**
+ * @param name old name for a group. These were old constants that shouldn't be used.
+ * @return the group with the given -short- name.
+ */
static public SemanticGroup getGroupFromOld( final String name ) {
return switch ( name ) {
case "Disease_Disorder" -> DISORDER;
@@ -92,6 +124,10 @@ public enum SemanticGroup {
};
}
+ /**
+ * @param annotation Some annotation.
+ * @return The groups appropriate for the annotation. Done using known TUIs for the annotation.
+ */
static public Collection<SemanticGroup> getGroups( final IdentifiedAnnotation annotation ) {
final Collection<SemanticGroup> groups
= SemanticTui.getTuis( annotation )
@@ -107,6 +143,9 @@ public enum SemanticGroup {
return allGroups;
}
+ /**
+ * Compares two groups for the most descriptive/accurate. e.g. Procedure is before Phenomenon.
+ */
static private final class BestGrouper implements Comparator<SemanticGroup> {
static private final BestGrouper INSTANCE = new BestGrouper();
@@ -121,6 +160,10 @@ public enum SemanticGroup {
}
}
+ /**
+ * @param annotation Some annotation.
+ * @return The most appropriate group for the annotation. Done using known TUIs for the annotation.
+ */
static public SemanticGroup getBestGroup( final IdentifiedAnnotation annotation ) {
final SemanticGroup typeIdGroup = getBestTypeIdGroup( annotation );
if ( typeIdGroup != UNKNOWN ) {
@@ -129,12 +172,22 @@ public enum SemanticGroup {
return getBestGroup( getGroups( annotation ) );
}
+ /**
+ * @param groups collection of groups.
+ * @return The most appropriate group for the annotation.
+ */
static public SemanticGroup getBestGroup( final Collection<SemanticGroup> groups ) {
return groups.stream()
.min( BestGrouper.INSTANCE )
.orElse( UNKNOWN );
}
+ /**
+ * Gets the best group based upon internal cTAKES type code for a group.
+ * These were old constants that shouldn't be used. However, an annotation may have a type id but no TUIs.
+ * @param annotation -
+ * @return the group based upon a type id set in the annotation.
+ */
static private SemanticGroup getBestTypeIdGroup( final IdentifiedAnnotation annotation ) {
final int typeId = annotation.getTypeID();
return Arrays.stream( values() )
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticTui.java b/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticTui.java
index 00bd596..7d7c2d0 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticTui.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/util/annotation/SemanticTui.java
@@ -13,6 +13,147 @@ import java.util.stream.Collectors;
import static org.apache.ctakes.core.util.annotation.SemanticGroup.*;
+/**
+ * The major UMLS-related semantic types as decided at the inception of cTAKES.
+ * Each semantic type has a single UMLS TUI. Semantic types are collected in Semantic Groups.
+ * T116, "Amino Acid, Peptide, or Protein", DRUG
+ * T020, "Acquired Abnormality", DISORDER
+ * T052, "Activity", EVENT
+ * T100, "Age Group", SUBJECT
+ * T003, "Alga", ENTITY
+ * T087, "Amino Acid Sequence", DRUG
+ * T011, "Amphibian", ENTITY
+ * T190, "Anatomical Abnormality", DISORDER
+ * T008, "Animal", ENTITY
+ * T017, "Anatomical Structure", ANATOMY
+ * T195, "Antibiotic", DRUG
+ * T194, "Archaeon", ENTITY
+ * T123, "Biologically Active Substance", DRUG
+ * T007, "Bacterium", ENTITY
+ * T031, "Body Substance", FINDING
+ * T022, "Body System", ANATOMY
+ * T053, "Behavior", FINDING
+ * T038, "Biologic Function", PHENOMENON
+ * T012, "Bird", ENTITY
+ * T029, "Body Location or Region", ANATOMY
+ * T091, "Biomedical Occupation or Discipline", TITLE
+ * T122, "Biomedical or Dental Material", DRUG
+ * T023, "Body Part, Organ, or Organ Component", ANATOMY
+ * T030, "Body Space or Junction", ANATOMY
+ * T118, "Carbohydrate", DRUG
+ * T026, "Cell Component", ANATOMY
+ * T043, "Cell Function", FINDING
+ * T025, "Cell", ANATOMY
+ * T019, "Congenital Abnormality", DISORDER
+ * T103, "Chemical", DRUG
+ * T120, "Chemical Viewed Functionally", DRUG
+ * T104, "Chemical Viewed Structurally", DRUG
+ * T185, "Classification", FINDING
+ * T201, "Clinical Attribute", CLINICAL_ATTRIBUTE
+ * T200, "Clinical Drug", DRUG
+ * T077, "Conceptual Entity", FINDING
+ * T049, "Cell or Molecular Dysfunction", DISORDER
+ * T088, "Carbohydrate Sequence", DRUG
+ * T060, "Diagnostic Procedure", PROCEDURE
+ * T056, "Daily or Recreational Activity", FINDING
+ * T047, "Disease or Syndrome", DISORDER
+ * T203, "Drug Delivery Device", DEVICE
+ * T065, "Educational Activity", PROCEDURE
+ * T069, "Environmental Effect of Humans", PHENOMENON
+ * T111, "Eicosanoid", ENTITY
+ * T196, "Element, Ion, or Isotope", DRUG
+ * T050, "Experimental Model of Disease", DISORDER
+ * T018, "Embryonic Structure", ANATOMY
+ * T071, "Entity", ENTITY
+ * T126, "Enzyme", DRUG
+ * T051, "Event", EVENT
+ * T099, "Family Group", SUBJECT
+ * T021, "Fully Formed Anatomical Structure", ANATOMY
+ * T013, "Fish", ENTITY
+ * T033, "Finding", FINDING
+ * T004, "Fungus", ENTITY
+ * T168, "Food", DRUG
+ * T169, "Functional Concept", FINDING
+ * T045, "Genetic Function", FINDING
+ * T083, "Geographic Area", ENTITY
+ * T028, "Gene or Genome", FINDING
+ * T064, "Governmental or Regulatory Activity", EVENT
+ * T102, "Group Attribute", SUBJECT
+ * T096, "Group", SUBJECT
+ * T068, "Human-caused Phenomenon or Process", PHENOMENON
+ * T093, "Health Care Related Organization", ENTITY
+ * T058, "Health Care Activity", PROCEDURE
+ * T131, "Hazardous or Poisonous Substance", DRUG
+ * T125, "Hormone", DRUG
+ * T016, "Human", SUBJECT
+ * T078, "Idea or Concept", FINDING
+ * T129, "Immunologic Factor", DRUG
+ * T055, "Individual Behavior", FINDING
+ * T197, "Inorganic Chemical", DRUG
+ * T037, "Injury or Poisoning", DISORDER
+ * T170, "Intellectual Product", FINDING
+ * T009, "Invertebrate", ENTITY
+ * T130, "Indicator, Reagent, or Diagnostic Aid", DRUG
+ * T171, "Language", ENTITY
+ * T059, "Laboratory Procedure", PROCEDURE
+ * T034, "Laboratory or Test Result", LAB
+ * T119, "Lipid", DRUG
+ * T015, "Mammal", ENTITY
+ * T063, "Molecular Biology Research Technique", PROCEDURE
+ * T066, "Machine Activity", PROCEDURE
+ * T074, "Medical Device", DEVICE
+ * T041, "Mental Process", FINDING
+ * T073, "Manufactured Object", DEVICE
+ * T048, "Mental or Behavioral Dysfunction", DISORDER
+ * T044, "Molecular Function", FINDING
+ * T085, "Molecular Sequence", FINDING
+ * T191, "Neoplastic Process", DISORDER
+ * T114, "Nucleic Acid, Nucleoside, or Nucleotide", DRUG
+ * T070, "Natural Phenomenon or Process", PHENOMENON
+ * T124, "Neuroreactive Substance or Biogenic Amine", DRUG
+ * T086, "Nucleotide Sequence", FINDING
+ * T057, "Occupational Activity", EVENT
+ * T090, "Occupation or Discipline", SUBJECT
+ * T115, "Organophosphorous Compound", DRUG
+ * T109, "Organic Chemical", DRUG
+ * T032, "Organism Attribute", SUBJECT
+ * T040, "Organism Function", FINDING
+ * T001, "Organism", ENTITY
+ * T092, "Organization", ENTITY
+ * T042, "Organ or * Tissue Function", FINDING
+ * T046, "Pathologic Function", FINDING
+ * T072, "Physical Object", ENTITY
+ * T067, "Phenomenon or Process", PHENOMENON
+ * T039, "Physiologic Function", FINDING
+ * T121, "Pharmacologic Substance", DRUG
+ * T002, "Plant", ENTITY
+ * T101, "Patient or Disabled Group", SUBJECT
+ * T098, "Population Group", SUBJECT
+ * T097, "Professional or Occupational Group", SUBJECT
+ * T094, "Professional Society", ENTITY
+ * T080, "Qualitative Concept", MODIFIER
+ * T081, "Quantitative Concept", LAB_MODIFIER
+ * T192, "Receptor", FINDING
+ * T014, "Reptile", ENTITY
+ * T062, "Research Activity", PROCEDURE
+ * T075, "Research Device", DEVICE
+ * T006, "Rickettsia or Chlamydia", DISORDER
+ * T089, "Regulation or Law", ENTITY
+ * T167, "Substance", DRUG
+ * T095, "Self-help or Relief Organization", ENTITY
+ * T054, "Social Behavior", FINDING
+ * T184, "Sign or Symptom", FINDING
+ * T082, "Spatial Concept", MODIFIER
+ * T110, "Steroid", DRUG
+ * T024, "Tissue", ANATOMY
+ * T079, "Temporal Concept", TIME
+ * T061, "Therapeutic or Preventive Procedure", PROCEDURE
+ * T005, "Virus", DISORDER
+ * T127, "Vitamin", DRUG
+ * T010, "Vertebrate", ENTITY
+ * T204, "Eukaryote", ENTITY
+ * UNKNOWN, "Unknown", SemanticGroup.UNKNOWN
+ */
public enum SemanticTui {
T116( 116, "Amino Acid, Peptide, or Protein", DRUG ),
T020( 20, "Acquired Abnormality", DISORDER ),
@@ -165,10 +306,16 @@ public enum SemanticTui {
_group = group;
}
+ /**
+ * @return type for UMLS TUI.
+ */
public int getCode() {
return _code;
}
+ /**
+ * @return Name for the type.
+ */
public String getSemanticType() {
return _name;
}
@@ -183,30 +330,52 @@ public enum SemanticTui {
_group = group;
}
+ /**
+ * @return semantic group for this type.
+ */
public SemanticGroup getGroup() {
return _group;
}
+ /**
+ * @return internal cTAKES CONST code for group. These were old constants that shouldn't be used.
+ */
public int getGroupCode() {
return _group.getCode();
}
+ /**
+ * @return Short name for the group for this type. e.g. "Disease" or "Drug".
+ */
public String getGroupName() {
return _group.getName();
}
+ /**
+ * @return the cTAKES java / type system class that represents the group for this type.
+ */
public Class<? extends IdentifiedAnnotation> getCtakesClass() {
return _group.getCtakesClass();
}
+ /**
+ * @return A function that can create the java / type system class that represents the group for this type.
+ */
public Function<JCas, ? extends IdentifiedAnnotation> getCreator() {
return _group.getCreator();
}
+ /**
+ * @return name of this type to lowercase and without commas.
+ */
private String getMatchType() {
return getMatchable( _name );
}
+ /**
+ * @param semanticType name of a semantic type.
+ * @return Type for the given type name.
+ */
static public SemanticTui getTui( final String semanticType ) {
// Attempt to match name ( e.g. "Cell" ).
final String toMatch = getMatchable( semanticType );
@@ -220,6 +389,10 @@ public enum SemanticTui {
return getTuiFromCode( toMatch );
}
+ /**
+ * @param code UMLS TUI code of a semantic type, not including "T" prefix.
+ * @return Type for the given TUI.
+ */
static public SemanticTui getTui( final int code ) {
for ( SemanticTui tui : SemanticTui.values() ) {
if ( tui.getCode() == code ) {
@@ -229,6 +402,10 @@ public enum SemanticTui {
return UNKNOWN;
}
+ /**
+ * @param tuiCode UMLS TUI code of a semantic type, including "T" prefix.
+ * @return Type for the given TUI.
+ */
static public SemanticTui getTuiFromCode( final String tuiCode ) {
for ( SemanticTui tui : SemanticTui.values() ) {
if ( tui.name()
@@ -240,6 +417,10 @@ public enum SemanticTui {
}
+ /**
+ * @param annotation Some annotation.
+ * @return The types appropriate for the annotation. Done using known TUIs for the annotation.
+ */
static public Collection<SemanticTui> getTuis( final IdentifiedAnnotation annotation ) {
final Collection<UmlsConcept> umlsConcepts = OntologyConceptUtil.getUmlsConcepts( annotation );
if ( umlsConcepts != null && !umlsConcepts.isEmpty() ) {
@@ -257,6 +438,10 @@ public enum SemanticTui {
return Collections.singletonList( UNKNOWN );
}
+ /**
+ * @param umlsConcept Some UMLS concept of a real-world thing.
+ * @return The type appropriate for the concept.
+ */
static public SemanticTui getTui( final UmlsConcept umlsConcept ) {
return getTuiFromCode( umlsConcept.getTui() );
}
@@ -283,6 +468,10 @@ public enum SemanticTui {
getTui( type ).setGroup( SemanticGroup.getGroup( group ) );
}
+ /**
+ * @param text -
+ * @return text to lowercase and without commas.
+ */
static private String getMatchable( final String text ) {
return text.toLowerCase()
.replaceAll( ",", "" );
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/util/doc/JCasBuilder.java b/ctakes-core/src/main/java/org/apache/ctakes/core/util/doc/JCasBuilder.java
index bbb47ce..30c8cc9 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/util/doc/JCasBuilder.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/util/doc/JCasBuilder.java
@@ -10,7 +10,8 @@ import java.text.DateFormat;
import java.text.SimpleDateFormat;
/**
- * Facade to "easily" populate a JCas with creator, patient and note information.
+ * Populate a JCas with creator, patient and document information.
+ * This follows the Builder pattern, but can be used to modify an existing cas as well as create one.
*
* @author SPF , chip-nlp
* @version %I%
@@ -61,66 +62,119 @@ final public class JCasBuilder {
private boolean _overwrite = false;
+ /**
+ * Overwrite any information already in a JCas.
+ * @return this builder.
+ */
public JCasBuilder overwrite() {
_overwrite = true;
return this;
}
+ /**
+ * @param institutionId Identity of the institution. e.g. hospital, health system, insurance company, study, etc.
+ * @return this builder
+ */
public JCasBuilder setInstitutionId( final String institutionId ) {
_institutionId = institutionId;
return this;
}
+ /**
+ * @param authorSpecialty The medical (or professional) specialty of a document's author.
+ * @return this builder
+ */
public JCasBuilder setAuthorSpecialty( final String authorSpecialty ) {
_authorSpecialty = authorSpecialty;
return this;
}
+ /**
+ * @param patientId The unique ID of a patient at an institution, in a study, in an insurance database, etc.
+ * @return this builder
+ */
public JCasBuilder setPatientId( final String patientId ) {
_patientId = patientId;
return this;
}
+ /**
+ * @param patientNum Depends upon user. e.g. Index of a patient in the run, index/number of the patient in a database, etc.
+ * @return this builder
+ */
public JCasBuilder setPatientNum( final long patientNum ) {
_patientNum = patientNum;
return this;
}
+ /**
+ * @param firstName Patient's first name.
+ * @return this builder
+ */
public JCasBuilder setFirstName( final String firstName ) {
_firstName = firstName;
return this;
}
+ /**
+ * @param middleName Patient's middle name.
+ * @return this builder
+ */
public JCasBuilder setMiddleName( final String middleName ) {
_middleName = middleName;
return this;
}
+ /**
+ * @param lastName Patient's last name.
+ * @return this builder
+ */
public JCasBuilder setLastName( final String lastName ) {
_lastName = lastName;
return this;
}
+ /**
+ * @param birthday Patient's date of birth. Format of this date is not controlled.
+ * @return this builder
+ */
public JCasBuilder setBirthDay( final String birthday ) {
_birthday = birthday;
return this;
}
+ /**
+ * @param deathday Patient's date of death. Format of this date is not controlled.
+ * @return this builder
+ */
public JCasBuilder setDeathday( final String deathday ) {
_deathday = deathday;
return this;
}
+ /**
+ * @param gender Patient's date of gender. Format of this value is not controlled.
+ * @return this builder
+ */
public JCasBuilder setGender( final String gender ) {
_gender = gender;
return this;
}
+ /**
+ * @param instanceId This is pretty nebulous, and can be used for anything.
+ * @return this builder
+ */
public JCasBuilder setInstanceId( final String instanceId ) {
_instanceId = instanceId;
return this;
}
+
+ /**
+ * @param encounterId Can be the same or different from a document ID, or empty.
+ * @return this builder
+ */
public JCasBuilder setEncounterId( final String encounterId ) {
_encounterId = encounterId;
return this;
@@ -131,51 +185,91 @@ final public class JCasBuilder {
// return this;
// }
+ /**
+ * @param docId Document ID. Depending upon requirements of the run, this may need to be unique.
+ * @return this builder
+ */
public JCasBuilder setDocId( final String docId ) {
_docId = docId;
return this;
}
+ /**
+ * @param docIdPrefix Can be anything identifying a collection of documents. Patient ID, Document Type, etc.
+ * @return this builder
+ */
public JCasBuilder setDocIdPrefix( final String docIdPrefix ) {
_docIdPrefix = docIdPrefix;
return this;
}
+ /**
+ * @param docType the type of document, for instance imaging note or pathology report.
+ * @return this builder
+ */
public JCasBuilder setDocType( final String docType ) {
_docType = docType;
return this;
}
+ /**
+ * @param docSubType a subtype. e.g. type = pathology report, subtype = biopsy analysis.
+ * @return this builder
+ */
public JCasBuilder setDocSubType( final String docSubType ) {
_docSubType = docSubType;
return this;
}
+ /**
+ * @param docStandard -
+ * @return this builder
+ */
public JCasBuilder setDocStandard( final String docStandard ) {
_docStandard = docStandard;
return this;
}
+ /**
+ * @param docRevisionNum for a document that may have had several iterations of editing.
+ * @return this builder
+ */
public JCasBuilder setDocRevisionNum( final int docRevisionNum ) {
_docRevisionNum = docRevisionNum;
return this;
}
+ /**
+ * @param docTime time of document. Nebulous. First write? Sign off? Also, time format is not specified.
+ * @return this builder
+ */
public JCasBuilder setDocTime( final String docTime ) {
_docTime = docTime;
return this;
}
+ /**
+ * @param docPath path to the file containing the doc, a database cell containing the doc, net location, etc.
+ * @return this builder
+ */
public JCasBuilder setDocPath( final String docPath ) {
_docPath = docPath;
return this;
}
+ /**
+ * Use if the document text should be null.
+ * @return this builder
+ */
public JCasBuilder nullDocText() {
_nullDocText = true;
return this;
}
+ /**
+ * @param docText text contents of the document.
+ * @return this builder
+ */
public JCasBuilder setDocText( final String docText ) {
_docText = docText;
return this;
@@ -198,14 +292,29 @@ final public class JCasBuilder {
return populate( jCas );
}
+ /**
+ * @param value set by user or null
+ * @param defaultValue -
+ * @return true if the value is not null, and is not the default value or overwrite is true.
+ */
private boolean ifWrite( final String value, final String defaultValue ) {
return value != null && ( _overwrite || !defaultValue.equals( value ) );
}
+ /**
+ * @param value set by user or null
+ * @param defaultValue -
+ * @return true if the value is not the default value or overwrite is true.
+ */
private boolean ifWrite( final int value, final int defaultValue ) {
return _overwrite || value != defaultValue;
}
+ /**
+ * @param value set by user or null
+ * @param defaultValue -
+ * @return true if the value is not the default value or overwrite is true.
+ */
private boolean ifWrite( final long value, final long defaultValue ) {
return _overwrite || value != defaultValue;
}
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/util/log/FinishedLogger.java b/ctakes-core/src/main/java/org/apache/ctakes/core/util/log/FinishedLogger.java
index d136b31..5de1600 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/util/log/FinishedLogger.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/util/log/FinishedLogger.java
@@ -20,6 +20,7 @@ import java.util.jar.JarFile;
import java.util.jar.Manifest;
/**
+ * Logs basic information on the run, such as the version of cTAKES, the total run time and time per document.
* @author SPF , chip-nlp
* @version %I%
* @since 5/21/2018
@@ -48,6 +49,7 @@ final public class FinishedLogger extends JCasAnnotator_ImplBase {
}
/**
+ * Increase the count of documents being processed.
* {@inheritDoc}
*/
@Override
@@ -56,28 +58,42 @@ final public class FinishedLogger extends JCasAnnotator_ImplBase {
ProgressManager.getInstance().updateProgress( Long.valueOf( _docCount ).intValue() );
}
+ /**
+ * Logs basic information on the run, such as total run time and time per document.
+ * {@inheritDoc}
+ * @throws AnalysisEngineProcessException -
+ */
+ @Override
public void collectionProcessComplete() throws AnalysisEngineProcessException {
super.collectionProcessComplete();
final long endMillis = System.currentTimeMillis();
final long instantMillis = ManagementFactory.getRuntimeMXBean().getStartTime();
final Map<String,String> buildInfo = getBuildInfo( BUILD_VERSION, BUILD_DATE );
- LOGGER.info( "Build Version: " + buildInfo.getOrDefault( BUILD_VERSION, "" ) );
- LOGGER.info( "Build Date: " + buildInfo.getOrDefault( BUILD_DATE, "" ) );
- LOGGER.info( "Run Start Time: " + getTime( instantMillis ) );
- LOGGER.info( "Processing Start Time: " + getTime( _initMillis ) );
- LOGGER.info( "Processing End Time: " + getTime( endMillis ) );
- LOGGER.info( "Initialization Time Elapsed: " + getSpan( _initMillis - instantMillis ) );
- LOGGER.info( "Processing Time Elapsed: " + getSpan( endMillis - _initMillis ) );
- LOGGER.info( "Total Run Time Elapsed: " + getSpan( endMillis - instantMillis ) );
- LOGGER.info( "Documents Processed: " + _docCount );
+ LOGGER.info( "Build Version: {}", buildInfo.getOrDefault( BUILD_VERSION, "" ) );
+ LOGGER.info( "Build Date: {}", buildInfo.getOrDefault( BUILD_DATE, "" ) );
+ LOGGER.info( "Run Start Time: {}", getTime( instantMillis ) );
+ LOGGER.info( "Processing Start Time: {}", getTime( _initMillis ) );
+ LOGGER.info( "Processing End Time: {}", getTime( endMillis ) );
+ LOGGER.info( "Initialization Time Elapsed: {}", getSpan( _initMillis - instantMillis ) );
+ LOGGER.info( "Processing Time Elapsed: {}", getSpan( endMillis - _initMillis ) );
+ LOGGER.info( "Total Run Time Elapsed: {}", getSpan( endMillis - instantMillis ) );
+ LOGGER.info( "Documents Processed: {}", _docCount );
final long millisPerNote = _docCount == 0 ? 0 : (endMillis - _initMillis) / _docCount;
LOGGER.info( String.format( "Average Seconds per Document: %.2f", (millisPerNote / 1000f) ) );
}
+ /**
+ * @param millis milliseconds for a time and date since January 1, 1970.
+ * @return formatted text for the time and date.
+ */
static private String getTime( final long millis ) {
return new Date( millis ).toString();
}
+ /**
+ * @param millis milliseconds of a span of time, for instance milliseconds in an hour.
+ * @return formatted text in days, hours, minutes, and seconds.
+ */
static private String getSpan( final long millis ) {
long seconds = millis / 1000;
long minutes = seconds / 60;
@@ -105,11 +121,12 @@ final public class FinishedLogger extends JCasAnnotator_ImplBase {
/**
+ * Get cTAKES build information. This only works for a cTAKES binary installation jars, not simply compiled code.
* Example:
* Build Version: 4.0.1-SNAPSHOT
* Build Date: 2022-10-26 15:59
- * @param attributeNames -
- * @return build information or an empty map if none is found.
+ * @param attributeNames formatted jar constants for version, build date, etc.
+ * @return build information for the running cTAKES version or an empty map if none is found.
*/
static public Map<String,String> getBuildInfo( final String... attributeNames ) {
final File libDir = FileLocator.getFileQuiet( "lib" );
@@ -141,6 +158,11 @@ final public class FinishedLogger extends JCasAnnotator_ImplBase {
return attributeMap;
}
+ /**
+ * @param attributes all attributes in a jar manifest.
+ * @param attributeName name of the wanted attribute.
+ * @return text value of the wanted attribute, or empty text if the attribute is not found.
+ */
static private String getAttribute( final Attributes attributes, final String attributeName ) {
final String value = attributes.getValue( attributeName );
return value == null ? "" : value;
diff --git a/ctakes-core/src/main/java/org/apache/ctakes/core/util/regex/ThreadString.java b/ctakes-core/src/main/java/org/apache/ctakes/core/util/regex/ThreadString.java
index 2f3827b..a313db3 100644
--- a/ctakes-core/src/main/java/org/apache/ctakes/core/util/regex/ThreadString.java
+++ b/ctakes-core/src/main/java/org/apache/ctakes/core/util/regex/ThreadString.java
@@ -7,10 +7,16 @@ package org.apache.ctakes.core.util.regex;
final class ThreadString implements CharSequence {
private final CharSequence _delegate;
+ /**
+ * @param delegate a String to wrap for thread safety.
+ */
ThreadString( final CharSequence delegate ) {
_delegate = delegate;
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public char charAt( final int index ) {
if ( Thread.currentThread().isInterrupted() ) {
@@ -19,11 +25,17 @@ final class ThreadString implements CharSequence {
return _delegate.charAt( index );
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public int length() {
return _delegate.length();
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public CharSequence subSequence( final int start, final int end ) {
if ( Thread.currentThread().isInterrupted() ) {
@@ -32,6 +44,9 @@ final class ThreadString implements CharSequence {
return new ThreadString( _delegate.subSequence( start, end ) );
}
+ /**
+ * {@inheritDoc}
+ */
@Override
public String toString() {
return _delegate.toString();