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 9C1C310D05 for ; Thu, 27 Mar 2014 18:12:02 +0000 (UTC) Received: (qmail 60341 invoked by uid 500); 27 Mar 2014 18:12:01 -0000 Delivered-To: apmail-ctakes-commits-archive@ctakes.apache.org Received: (qmail 60308 invoked by uid 500); 27 Mar 2014 18:12:01 -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 60301 invoked by uid 99); 27 Mar 2014 18:12:01 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Mar 2014 18:12:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 27 Mar 2014 18:11:59 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id C6E842388868; Thu, 27 Mar 2014 18:11:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1582431 - /ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java Date: Thu, 27 Mar 2014 18:11:39 -0000 To: commits@ctakes.apache.org From: dligach@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140327181139.C6E842388868@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dligach Date: Thu Mar 27 18:11:39 2014 New Revision: 1582431 URL: http://svn.apache.org/r1582431 Log: Feature extractor for time unit duration only Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java (with props) Added: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java?rev=1582431&view=auto ============================================================================== --- ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java (added) +++ ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java Thu Mar 27 18:11:39 2014 @@ -0,0 +1,69 @@ +/** + * 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.temporal.ae.feature.duration; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.ctakes.relationextractor.ae.features.RelationFeaturesExtractor; +import org.apache.ctakes.typesystem.type.textsem.IdentifiedAnnotation; +import org.apache.uima.analysis_engine.AnalysisEngineProcessException; +import org.apache.uima.jcas.JCas; +import org.cleartk.classifier.Feature; +import org.threeten.bp.temporal.TemporalUnit; + +import scala.collection.immutable.Set; + +/** + * Assumes all relations whose argument have no duration data have been deleted. + */ +public class DurationTimeUnitFeatureExtractor implements RelationFeaturesExtractor { + + @Override + public List extract(JCas jCas, IdentifiedAnnotation arg1, IdentifiedAnnotation arg2) + throws AnalysisEngineProcessException { + + List features = new ArrayList(); + String timeText = arg2.getCoveredText().toLowerCase(); // arg2 is a time mention + + Set units = Utils.normalize(timeText); + if(units == null) { + features.add(new Feature("failed_normalization", true)); + return features; + } + + scala.collection.Iterator iterator = units.iterator(); + while(iterator.hasNext()) { + TemporalUnit unit = iterator.next(); + String coarseTimeUnit = Utils.makeCoarse(unit.getName()); + + if(coarseTimeUnit == null) { + features.add(new Feature("failed_normalization", true)); + return features; + } + + Map distribution = Utils.convertToDistribution(coarseTimeUnit); + float timeExpectedDuration = Utils.expectedDuration(distribution); + features.add(new Feature("time_duration", timeExpectedDuration)); + } + + return features; + } +} Propchange: ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/duration/DurationTimeUnitFeatureExtractor.java ------------------------------------------------------------------------------ svn:mime-type = text/plain