You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by jo...@apache.org on 2025/09/16 15:28:54 UTC

(ctakes) branch main updated: final working version of spacey example, will continue working on cas_doc_bridge impl in another branch

This is an automated email from the ASF dual-hosted git repository.

johnsd 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 8ed6e17  final working version of spacey example, will continue working on cas_doc_bridge impl in another branch
8ed6e17 is described below

commit 8ed6e1783dfdf108bd6869688d223a9a896812f0
Author: Dennis Johns <jo...@gmail.com>
AuthorDate: Tue Sep 16 11:28:37 2025 -0400

    final working version of spacey example, will continue working on cas_doc_bridge impl in another branch
---
 .../src/ctakes_pbj/examples/spacey_negation.py      | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/ctakes-pbj/src/user/resources/org/apache/ctakes/pbj/ctakes_pbj_py/src/ctakes_pbj/examples/spacey_negation.py b/ctakes-pbj/src/user/resources/org/apache/ctakes/pbj/ctakes_pbj_py/src/ctakes_pbj/examples/spacey_negation.py
index 31dd3d9..00c2a47 100644
--- a/ctakes-pbj/src/user/resources/org/apache/ctakes/pbj/ctakes_pbj_py/src/ctakes_pbj/examples/spacey_negation.py
+++ b/ctakes-pbj/src/user/resources/org/apache/ctakes/pbj/ctakes_pbj_py/src/ctakes_pbj/examples/spacey_negation.py
@@ -7,6 +7,8 @@
 from spacy.lang.en import English
 from negspacy.termsets import termset
 import logging
+import os
+from pathlib import Path
 
 logger = logging.getLogger(__name__)
 def a_sort_by(a):
@@ -15,7 +17,13 @@ def a_sort_by(a):
 
 class ExampleNegationAnnotator(cas_annotator.CasAnnotator):
     def __init__(self, ts=None):
-        log_path = "C:/Users/ch229935/Desktop/spacey_output/spacey.log"
+        # Use current directory or user home instead of hardcoded path
+        log_dir = Path.cwd() / "spacey_output"  # User's current working directory
+        log_path = log_dir / "spacey.log"
+
+        # Create directory
+        log_path.parent.mkdir(parents=True, exist_ok=True)
+
         handler = logging.FileHandler(log_path, mode="w", encoding="utf-8")
         formatter = logging.Formatter("%(asctime)s [%(levelname)s] %(message)s")
         handler.setFormatter(formatter)
@@ -26,7 +34,6 @@ def __init__(self, ts=None):
         logger.propagate = False
         super().__init__()
 
-        logger.info(f"Spacy version: {spacy.__version__}")
         logger.info("Initializing ExampleNegationAnnotator")
         self.ts = ts
 
@@ -47,7 +54,6 @@ def process(self, cas):
         logger.info(f"Spacy version: {spacy.__version__}")
 
         for sentence in cas.select(ctakes_types.Sentence):
-            logger.info(f"Sentence: {sentence.get_covered_text()}")
             tokens = cas.select_covered(ctakes_types.BaseToken, sentence)
             event_mentions = cas.select_covered(ctakes_types.EventMention, sentence)
             tokens.sort(key=a_sort_by)
@@ -58,10 +64,10 @@ def process(self, cas):
             # For spacy 3.x - use words= parameter
             doc = Doc(self.nlp.vocab, words=words)
             logger.info(f"Doc created successfully: '{doc.text}'")
-            logger.info(f"Doc length: {len(doc)}")
 
             try:
                 logger.info("About to create entities...")
+                # need to create spans because doc does not take raw token data!
                 doc.ents = [Span(doc, i, i+1, label="CONCEPT") for i in range(len(doc))]
                 logger.info(f"Created {len(doc.ents)} entities successfully")
 
@@ -69,13 +75,6 @@ def process(self, cas):
                 doc = self.nlp(doc)
                 logger.info("Doc processed through negspacy pipeline successfully")
 
-                logger.info("About to check negation results...")
-                # logger.info("=== NEGATION RESULTS ===")
-                for i, ent in enumerate(doc.ents):
-                    # logger.info(f"Processing entity {i}: '{ent.text}'")
-                    negated = ent._.negex
-                    # logger.info(f"Token: '{ent.text}' - Negated: {negated}")
-
                 # Create token negation mapping
                 token_negations = {}
                 for i, token in enumerate(doc):