Return-Path: X-Original-To: apmail-ctakes-commits-archive@www.apache.org Delivered-To: apmail-ctakes-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DEDC218665 for ; Wed, 8 Jul 2015 20:28:48 +0000 (UTC) Received: (qmail 86279 invoked by uid 500); 8 Jul 2015 20:28:48 -0000 Delivered-To: apmail-ctakes-commits-archive@ctakes.apache.org Received: (qmail 86244 invoked by uid 500); 8 Jul 2015 20:28:48 -0000 Mailing-List: contact commits-help@ctakes.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ctakes.apache.org Delivered-To: mailing list commits@ctakes.apache.org Received: (qmail 86235 invoked by uid 99); 8 Jul 2015 20:28:48 -0000 Received: from eris.apache.org (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 08 Jul 2015 20:28:48 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id 6E245AC00B4 for ; Wed, 8 Jul 2015 20:28:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1689954 - in /ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines: ClinicalConceptViewer.java Utils.java Date: Wed, 08 Jul 2015 20:28:48 -0000 To: commits@ctakes.apache.org From: dligach@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150708202848.6E245AC00B4@hades.apache.org> Author: dligach Date: Wed Jul 8 20:28:48 2015 New Revision: 1689954 URL: http://svn.apache.org/r1689954 Log: added a simple consumer to print CUIs Added: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/ClinicalConceptViewer.java (with props) ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/Utils.java (with props) Added: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/ClinicalConceptViewer.java URL: http://svn.apache.org/viewvc/ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/ClinicalConceptViewer.java?rev=1689954&view=auto ============================================================================== --- ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/ClinicalConceptViewer.java (added) +++ ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/ClinicalConceptViewer.java Wed Jul 8 20:28:48 2015 @@ -0,0 +1,88 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ctakes.pipelines; + +import java.io.File; + +import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation; +import org.apache.uima.analysis_engine.AnalysisEngine; +import org.apache.uima.analysis_engine.AnalysisEngineProcessException; +import org.apache.uima.cas.CASException; +import org.apache.uima.collection.CollectionReader; +import org.apache.uima.fit.component.JCasAnnotator_ImplBase; +import org.apache.uima.fit.factory.AnalysisEngineFactory; +import org.apache.uima.fit.pipeline.SimplePipeline; +import org.apache.uima.fit.util.JCasUtil; +import org.apache.uima.jcas.JCas; + +import com.lexicalscope.jewel.cli.CliFactory; +import com.lexicalscope.jewel.cli.Option; + +/** + * Print gold standard relations and their context. + * Full set of relations annotated in SHARP is the following: + * + * affects, causes/brings_about, complicates/disrupts, contraindicates, degree_of, diagnoses, + * indicates, is_indicated_for, location_of, manages/treats, manifestation_of, result_of + * + * @author dmitriy dligach + */ +public class ClinicalConceptViewer { + + static interface Options { + + @Option( + longName = "xmi-dir", + description = "path to xmi files") + public File getInputDirectory(); + } + + public static void main(String[] args) throws Exception { + + Options options = CliFactory.parseArguments(Options.class, args); + CollectionReader collectionReader = Utils.getCollectionReader(options.getInputDirectory()); + AnalysisEngine annotationConsumer = AnalysisEngineFactory.createEngine(RelationContextPrinter.class); + SimplePipeline.runPipeline(collectionReader, annotationConsumer); + } + + /** + * Print CUIs and their attributes. + * + * @author dmitriy dligach + */ + public static class RelationContextPrinter extends JCasAnnotator_ImplBase { + + @Override + public void process(JCas jCas) throws AnalysisEngineProcessException { + + JCas systemView; + try { + systemView = jCas.getView("_InitialView"); + } catch (CASException e) { + throw new AnalysisEngineProcessException(e); + } + + for(IdentifiedAnnotation idedAnnot : JCasUtil.select(systemView, IdentifiedAnnotation.class)) { + System.out.println(idedAnnot.getCoveredText()); + } + } + } +} + + \ No newline at end of file Propchange: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/ClinicalConceptViewer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/Utils.java URL: http://svn.apache.org/viewvc/ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/Utils.java?rev=1689954&view=auto ============================================================================== --- ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/Utils.java (added) +++ ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/Utils.java Wed Jul 8 20:28:48 2015 @@ -0,0 +1,56 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.ctakes.pipelines; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import org.apache.ctakes.core.cr.XMIReader; +import org.apache.uima.collection.CollectionReader; +import org.apache.uima.fit.factory.CollectionReaderFactory; + +/** + * Various useful classes and methods. + */ +public class Utils { + + public static final String embeddingPath = "/Users/dima/Boston/Vectors/Python/sharp-arg-head-word-vectors.txt"; + + /** + * Instantiate an XMI collection reader. + */ + public static CollectionReader getCollectionReader(File inputDirectory) throws Exception { + + List fileNames = new ArrayList<>(); + for(File file : inputDirectory.listFiles()) { + if(! (file.isHidden())) { + fileNames.add(file.getPath()); + } + } + + String[] paths = new String[fileNames.size()]; + fileNames.toArray(paths); + + return CollectionReaderFactory.createReader( + XMIReader.class, + XMIReader.PARAM_FILES, + paths); + } +} \ No newline at end of file Propchange: ctakes/sandbox/ctakes-wsd/src/main/java/org/apache/ctakes/pipelines/Utils.java ------------------------------------------------------------------------------ svn:mime-type = text/plain